/* * Task state bitmask. NOTE! These bits are also * encoded in fs/proc/array.c: get_task_state(). * * We have two separate sets of flags: task->state * is about runnability, while task->exit_state are * about the task exiting. Confusing, but this way * modifying one set can't modify the other one by * mistake. */
/* Used in tsk->state: */ #define TASK_RUNNING 0x0000 #define TASK_INTERRUPTIBLE 0x0001 #define TASK_UNINTERRUPTIBLE 0x0002 #define __TASK_STOPPED 0x0004 #define __TASK_TRACED 0x0008 /* Used in tsk->exit_state: */ #define EXIT_DEAD 0x0010 #define EXIT_ZOMBIE 0x0020 #define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) /* Used in tsk->state again: */ #define TASK_PARKED 0x0040 #define TASK_DEAD 0x0080 #define TASK_WAKEKILL 0x0100 #define TASK_WAKING 0x0200 #define TASK_NOLOAD 0x0400 #define TASK_NEW 0x0800 /* RT specific auxilliary flag to mark RT lock waiters */ #define TASK_RTLOCK_WAIT 0x1000 #define TASK_STATE_MAX 0x2000
/* Convenience macros for the sake of set_current_state: */ #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)
/* * Per process flags */ #define PF_VCPU 0x00000001 /* I'm a virtual CPU */ #define PF_IDLE 0x00000002 /* I am an IDLE thread */ #define PF_EXITING 0x00000004 /* Getting shut down */ #define PF_POSTCOREDUMP 0x00000008 /* Coredumps should ignore this task */ #define PF_IO_WORKER 0x00000010 /* Task is an IO worker */ #define PF_WQ_WORKER 0x00000020 /* I'm a workqueue worker */ #define PF_FORKNOEXEC 0x00000040 /* Forked but didn't exec */ #define PF_MCE_PROCESS 0x00000080 /* Process policy on mce errors */ #define PF_SUPERPRIV 0x00000100 /* Used super-user privileges */ #define PF_DUMPCORE 0x00000200 /* Dumped core */ #define PF_SIGNALED 0x00000400 /* Killed by a signal */ #define PF_MEMALLOC 0x00000800 /* Allocating memory */ #define PF_NPROC_EXCEEDED 0x00001000 /* set_user() noticed that RLIMIT_NPROC was exceeded */ #define PF_USED_MATH 0x00002000 /* If unset the fpu must be initialized before use */ #define PF_NOFREEZE 0x00008000 /* This thread should not be frozen */ #define PF_FROZEN 0x00010000 /* Frozen for system suspend */ #define PF_KSWAPD 0x00020000 /* I am kswapd */ #define PF_MEMALLOC_NOFS 0x00040000 /* All allocation requests will inherit GFP_NOFS */ #define PF_MEMALLOC_NOIO 0x00080000 /* All allocation requests will inherit GFP_NOIO */ #define PF_LOCAL_THROTTLE 0x00100000 /* Throttle writes only against the bdi I write to, * I am cleaning dirty pages from some other bdi. */ #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ #define PF_RANDOMIZE 0x00400000 /* Randomize virtual address space */ #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */ #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_mask */ #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ #define PF_MEMALLOC_PIN 0x10000000 /* Allocation context constrained to zones which allow long term pinning. */ #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezable */ #define PF_SUSPEND_TASK 0x80000000 /* This thread called freeze_processes() and should not be frozen */
常用状态:
PF_FORKNOEXEC:进程刚被创建,但还没有执行
PF_SUPERPRIV:进程拥有超级用户特权
PF_SIGNALED:进程被信号杀出
PF_EXITING:进程开始关闭
任务亲属关系
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* * Pointers to the (original) parent process, youngest child, younger sibling, * older sibling, respectively. (p->father can be replaced with * p->real_parent->pid) */
/* Real parent process: */ structtask_struct __rcu *real_parent;
/* Recipient of SIGCHLD, wait4() reports: */ structtask_struct __rcu *parent;
/* * Children/sibling form the list of natural children: */ structlist_headchildren; structlist_headsibling; structtask_struct *group_leader;
unsignedint ptrace; /* * 'ptraced' is the list of tasks this task is using ptrace() on. * * This includes both natural children and PTRACE_ATTACH targets. * 'ptrace_entry' is this task's link on the p->parent->ptraced list. */ structlist_headptraced; structlist_headptrace_entry; /* Ptrace state: */ unsignedlong ptrace_message; kernel_siginfo_t *last_siginfo;
/* * Ptrace flags * * The owner ship rules for task->ptrace which holds the ptrace * flags is simple. When a task is running it owns it's task->ptrace * flags. When the a task is stopped the ptracer owns task->ptrace. */
/* single stepping state bits (used on ARM and PA-RISC) */ #define PT_SINGLESTEP_BIT 31 #define PT_SINGLESTEP (1<<PT_SINGLESTEP_BIT) #define PT_BLOCKSTEP_BIT 30 #define PT_BLOCKSTEP (1<<PT_BLOCKSTEP_BIT)
Performance Event
Performance Event是一款随 Linux 内核代码一同发布和维护的性能诊断工具。这些成员用于帮助PerformanceEvent分析进程的性能问题。
/* * Priority of a process goes from 0..MAX_PRIO-1, valid RT * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority * values are inverted: lower p->prio value means higher priority. */
int exit_state; int exit_code; int exit_signal; /* The signal sent when the parent dies: */ int pdeath_signal; /* JOBCTL_*, siglock protected: */ unsignedlong jobctl;
/* Used for emulating ABI behavior of previous Linux versions: */ unsignedint personality;
/* Force alignment to the next boundary: */ unsigned :0;
/* Unserialized, strictly 'current' */
/* * This field must not be in the scheduler word above due to wakelist * queueing no longer being serialized by p->on_cpu. However: * * p->XXX = X; ttwu() * schedule() if (p->on_rq && ..) // false * smp_mb__after_spinlock(); if (smp_load_acquire(&p->on_cpu) && //true * deactivate_task() ttwu_queue_wakelist()) * p->on_rq = 0; p->sched_remote_wakeup = Y; * * guarantees all stores of 'current' are visible before * ->sched_remote_wakeup gets used, so it can be in this word. */ unsigned sched_remote_wakeup:1;
/* Bit to tell LSMs we're in execve(): */ unsigned in_execve:1; unsigned in_iowait:1;
/* Signal handlers: */ structsignal_struct *signal; structsighand_struct __rcu *sighand; sigset_t blocked; sigset_t real_blocked; /* Restored if set_restore_sigmask() was used: */ sigset_t saved_sigmask; structsigpendingpending; unsignedlong sas_ss_sp; size_t sas_ss_size; unsignedint sas_ss_flags;
signal:指向进程的信号描述符
sighand:指向进程的信号处理程序描述符
blocked:表示被阻塞信号的掩码,real_blocked表示临时掩码
pending:存放私有挂起信号的数据结构
sas_ss_sp:是信号处理程序备用堆栈的地址,sas_ss_size表示堆栈的大小
其他
用于保护资源分配或释放的自旋锁
1 2 3 4
/* Protection against (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, mempolicy: */ spinlock_t alloc_lock; /* Protection of the PI data structures: */ raw_spinlock_t pi_lock;
/* * recent_used_cpu is initially set as the last CPU used by a task * that wakes affine another task. Waker/wakee relationships can * push tasks around a CPU where each wakeup moves to the next one. * Tracking a recently used CPU allows a quick search for a recently * used CPU that may be idle. */ int recent_used_cpu; int wake_cpu; #endif
prempt_notifier结构体链表
1 2 3 4
#ifdef CONFIG_PREEMPT_NOTIFIERS /* List of struct preempt_notifier: */ structhlist_headpreempt_notifiers; #endif
#ifdef CONFIG_RT_MUTEXES /* PI waiters blocked on a rt_mutex held by this task: */ structrb_root_cachedpi_waiters; /* Updated under owner's pi_lock and rq lock */ structtask_struct *pi_top_task; /* Deadlock detection and priority inheritance handling: */ structrt_mutex_waiter *pi_blocked_on; #endif
#ifdef CONFIG_CPUSETS /* Protected by ->alloc_lock: */ nodemask_t mems_allowed; /* Sequence number to catch updates: */ seqcount_spinlock_t mems_allowed_seq; int cpuset_mem_spread_rotor; int cpuset_slab_spread_rotor; #endif
Control Groups
1 2 3 4 5 6
#ifdef CONFIG_CGROUPS /* Control Group info protected by css_set_lock: */ structcss_set __rcu *cgroups; /* cg_list protected by css_set_lock and tsk->alloc_lock: */ structlist_headcg_list; #endif
#ifdef CONFIG_FAULT_INJECTION int make_it_fail; unsignedint fail_nth; #endif
Infrastructure for displayinglatency
1 2 3 4
#ifdef CONFIG_LATENCYTOP int latency_record_count; structlatency_recordlatency_record[LT_SAVECOUNT]; #endif
tim slack values 常用于poll和select函数
1 2 3 4 5 6
/* * Time slack values; these are used to round up poll() and * select() etc timeout values. These are in nanoseconds. */ u64 timer_slack_ns; u64 default_timer_slack_ns;