【一】 sched.h
第一個數據結構體是task_struct ,這個數據結構被內核用來表示進程,包含其所有信息。
定義于文件include/linux/sched.h 中,先看看其完整定義
1 struct task_struct {
2 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
3 void *stack;
4 atomic_t usage;
5 unsigned int flags; /* per process flags, defined below */
6 unsigned int ptrace;
7
8 #ifdef CONFIG_SMP
9 struct llist_node wake_entry;
10 int on_cpu;
11 #endif
12 int on_rq;
13
14 int prio, static_prio, normal_prio;
15 unsigned int rt_priority;
16 const struct sched_class *sched_class;
17 struct sched_entity se;
18 struct sched_rt_entity rt;
19 #ifdef CONFIG_CGROUP_SCHED
20 struct task_group *sched_task_group;
21 #endif
22
23 #ifdef CONFIG_PREEMPT_NOTIFIERS
24 /* list of struct preempt_notifier: */
25 struct hlist_head preempt_notifiers;
26 #endif
27
28 /*
29 * fpu_counter contains the number of consecutive context switches
30 * that the FPU is used. If this is over a threshold, the lazy fpu
31 * saving becomes unlazy to save the trap. This is an unsigned char
32 * so that after 256 times the counter wraps and the behavior turns
33 * lazy again; this to deal with bursty apps that only use FPU for
34 * a short time
35 */
36 unsigned char fpu_counter;
37 #ifdef CONFIG_BLK_DEV_IO_TRACE
38 unsigned int btrace_seq;
39 #endif
40
41 unsigned int policy;
42 int nr_cpus_allowed;
43 cpumask_t cpus_allowed;
44
45 #ifdef CONFIG_PREEMPT_RCU
46 int rcu_read_lock_nesting;
47 char rcu_read_unlock_special;
48 struct list_head rcu_node_entry;
49 #endif /* #ifdef CONFIG_PREEMPT_RCU */
50 #ifdef CONFIG_TREE_PREEMPT_RCU
51 struct rcu_node *rcu_blocked_node;
52 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
53 #ifdef CONFIG_RCU_BOOST
54 struct rt_mutex *rcu_boost_mutex;
55 #endif /* #ifdef CONFIG_RCU_BOOST */
56
57 #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
58 struct sched_info sched_info;
59 #endif
60
61 struct list_head tasks;
62 #ifdef CONFIG_SMP
63 struct plist_node pushable_tasks;
64 #endif
65
66 struct mm_struct *mm, *active_mm;
67 #ifdef CONFIG_COMPAT_BRK
68 unsigned brk_randomized:1;
69 #endif
70 #if defined(SPLIT_RSS_COUNTING)
71 struct task_rss_stat rss_stat;
72 #endif
73 /* task state */
74 int exit_state;
75 int exit_code, exit_signal;
76 int pdeath_signal; /* The signal sent when the parent dies */
77 unsigned int jobctl; /* JOBCTL_*, siglock protected */
78
79 /* Used for emulating ABI behavior of previous Linux versions */
80 unsigned int personality;
81
82 unsigned did_exec:1;
83 unsigned in_execve:1; /* Tell the LSMs that the process is doing an
84 * execve */
85 unsigned in_iowait:1;
86
87 /* Revert to default priority/policy when forking */
88 unsigned sched_reset_on_fork:1;
89 unsigned sched_contributes_to_load:1;
90
91 unsigned long atomic_flags; /* Flags needing atomic access. */
92
93 pid_t pid;
94 pid_t tgid;
95
96 #ifdef CONFIG_CC_STACKPROTECTOR
97 /* Canary value for the -fstack-protector gcc feature */
98 unsigned long stack_canary;
99 #endif
100 /*
101 * pointers to (original) parent process, youngest child, younger sibling,
102 * older sibling, respectively. (p->father can be replaced with
103 * p->real_parent->pid)
104 */
105 struct task_struct __rcu *real_parent; /* real parent process */
106 struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
107 /*
108 * children/sibling forms the list of my natural children
109 */
110 struct list_head children; /* list of my children */
111 struct list_head sibling; /* linkage in my parent's children list */
112 struct task_struct *group_leader; /* threadgroup leader */
113
114 #ifdef CONFIG_MTK_SCHED_CMP_TGS
115 raw_spinlock_t thread_group_info_lock;
116 struct thread_group_info_t thread_group_info[NUM_CLUSTER];
117 #endif
118
119 /*
120 * ptraced is the list of tasks this task is using ptrace on.
121 * This includes both natural children and PTRACE_ATTACH targets.
122 * p->ptrace_entry is p's link on the p->parent->ptraced list.
123 */
124 struct list_head ptraced;
125 struct list_head ptrace_entry;
126
127 /* PID/PID hash table linkage. */
128 struct pid_link pids[PIDTYPE_MAX];
129 struct list_head thread_group;
130 struct list_head thread_node;
131
132 struct completion *vfork_done; /* for vfork() */
133 int __user *set_child_tid; /* CLONE_CHILD_SETTID */
134 int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
135
136 cputime_t utime, stime, utimescaled, stimescaled;
137 cputime_t gtime;
138 #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
139 struct cputime prev_cputime;
140 #endif
141 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
142 seqlock_t vtime_seqlock;
143 unsigned long long vtime_snap;
144 enum {
145 VTIME_SLEEPING = 0,
146 VTIME_USER,
147 VTIME_SYS,
148 } vtime_snap_whence;
149 #endif
150 unsigned long nvcsw, nivcsw; /* context switch counts */
151 struct timespec start_time; /* monotonic time */
152 struct timespec real_start_time; /* boot based time */
153 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
154 unsigned long min_flt, maj_flt;
155 /* for thrashing accounting */
156 #ifdef CONFIG_ZRAM
157 unsigned long fm_flt, swap_in, swap_out;
158 #endif
159
160 struct task_cputime cputime_expires;
161 struct list_head cpu_timers[3];
162
163 /* process credentials */
164 const struct cred __rcu *real_cred; /* objective and real subjective task
165 * credentials (COW) */
166 const struct cred __rcu *cred; /* effective (overridable) subjective task
167 * credentials (COW) */
168 char comm[TASK_COMM_LEN]; /* executable name excluding path
169 - access with [gs]et_task_comm (which lock
170 it with task_lock())
171 - initialized normally by setup_new_exec */
172 /* file system info */
173 int link_count, total_link_count;
174 #ifdef CONFIG_SYSVIPC
175 /* ipc stuff */
176 struct sysv_sem sysvsem;
177 #endif
178 #ifdef CONFIG_DETECT_HUNG_TASK
179 /* hung task detection */
180 unsigned long last_switch_count;
181 #endif
182 /* CPU-specific state of this task */
183 struct thread_struct thread;
184 /* filesystem information */
185 struct fs_struct *fs;
186 /* open file information */
187 struct files_struct *files;
188 /* namespaces */
189 struct nsproxy *nsproxy;
190 /* signal handlers */
191 struct signal_struct *signal;
192 struct sighand_struct *sighand;
193
194 sigset_t blocked, real_blocked;
195 sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
196 struct sigpending pending;
197
198 unsigned long sas_ss_sp;
199 size_t sas_ss_size;
200 int (*notifier)(void *priv);
201 void *notifier_data;
202 sigset_t *notifier_mask;
203 struct callback_head *task_works;
204
205 struct audit_context *audit_context;
206 #ifdef CONFIG_AUDITSYSCALL
207 kuid_t loginuid;
208 unsigned int sessionid;
209 #endif
210 struct seccomp seccomp;
211
212 /* Thread group tracking */
213 u32 parent_exec_id;
214 u32 self_exec_id;
215 /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
216 * mempolicy */
217 spinlock_t alloc_lock;
218
219 /* Protection of the PI data structures: */
220 raw_spinlock_t pi_lock;
221
222 #ifdef CONFIG_RT_MUTEXES
223 /* PI waiters blocked on a rt_mutex held by this task */
224 struct plist_head pi_waiters;
225 /* Deadlock detection and priority inheritance handling */
226 struct rt_mutex_waiter *pi_blocked_on;
227 #endif
228
229 #ifdef CONFIG_DEBUG_MUTEXES
230 /* mutex deadlock detection */
231 struct mutex_waiter *blocked_on;
232 #endif
233 #ifdef CONFIG_TRACE_IRQFLAGS
234 unsigned int irq_events;
235 unsigned long hardirq_enable_ip;
236 unsigned long hardirq_disable_ip;
237 unsigned int hardirq_enable_event;
238 unsigned int hardirq_disable_event;
239 int hardirqs_enabled;
240 int hardirq_context;
241 unsigned long softirq_disable_ip;
242 unsigned long softirq_enable_ip;
243 unsigned int softirq_disable_event;
244 unsigned int softirq_enable_event;
245 int softirqs_enabled;
246 int softirq_context;
247 #endif
248 #ifdef CONFIG_LOCKDEP
249 # define MAX_LOCK_DEPTH 48UL
250 u64 curr_chain_key;
251 int lockdep_depth;
252 unsigned int lockdep_recursion;
253 struct held_lock held_locks[MAX_LOCK_DEPTH];
254 gfp_t lockdep_reclaim_gfp;
255 #endif
256
257 /* journalling filesystem info */
258 void *journal_info;
259
260 /* stacked block device info */
261 struct bio_list *bio_list;
262
263 #ifdef CONFIG_BLOCK
264 /* stack plugging */
265 struct blk_plug *plug;
266 #endif
267
268 /* VM state */
269 struct reclaim_state *reclaim_state;
270
271 struct backing_dev_info *backing_dev_info;
272
273 struct io_context *io_context;
274
275 unsigned long ptrace_message;
276 siginfo_t *last_siginfo; /* For ptrace use. */
277 struct task_io_accounting ioac;
278 #if defined(CONFIG_TASK_XACCT)
279 u64 acct_rss_mem1; /* accumulated rss usage */
280 u64 acct_vm_mem1; /* accumulated virtual memory usage */
281 cputime_t acct_timexpd; /* stime + utime since last update */
282 #endif
283 #ifdef CONFIG_CPUSETS
284 nodemask_t mems_allowed; /* Protected by alloc_lock */
285 seqcount_t mems_allowed_seq; /* Seqence no to catch updates */
286 int cpuset_mem_spread_rotor;
287 int cpuset_slab_spread_rotor;
288 #endif
289 #ifdef CONFIG_CGROUPS
290 /* Control Group info protected by css_set_lock */
291 struct css_set __rcu *cgroups;
292 /* cg_list protected by css_set_lock and tsk->alloc_lock */
293 struct list_head cg_list;
294 #endif
295 #ifdef CONFIG_FUTEX
296 struct robust_list_head __user *robust_list;
297 #ifdef CONFIG_COMPAT
298 struct compat_robust_list_head __user *compat_robust_list;
299 #endif
300 struct list_head pi_state_list;
301 struct futex_pi_state *pi_state_cache;
302 #endif
303 #ifdef CONFIG_PERF_EVENTS
304 struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
305 struct mutex perf_event_mutex;
306 struct list_head perf_event_list;
307 #endif
308 #ifdef CONFIG_NUMA
309 struct mempolicy *mempolicy; /* Protected by alloc_lock */
310 short il_next;
311 short pref_node_fork;
312 #endif
313 #ifdef CONFIG_NUMA_BALANCING
314 int numa_scan_seq;
315 int numa_migrate_seq;
316 unsigned int numa_scan_period;
317 u64 node_stamp; /* migration stamp */
318 struct callback_head numa_work;
319 #endif /* CONFIG_NUMA_BALANCING */
320
321 struct rcu_head rcu;
322
323 /*
324 * cache last used pipe for splice
325 */
326 struct pipe_inode_info *splice_pipe;
327
328 struct page_frag task_frag;
329
330 #ifdef CONFIG_TASK_DELAY_ACCT
331 struct task_delay_info *delays;
332 #endif
333 #ifdef CONFIG_FAULT_INJECTION
334 int make_it_fail;
335 #endif
336 /*
337 * when (nr_dirtied >= nr_dirtied_pause), it's time to call
338 * balance_dirty_pages() for some dirty throttling pause
339 */
340 int nr_dirtied;
341 int nr_dirtied_pause;
342 unsigned long dirty_paused_when; /* start of a write-and-pause period */
343
344 #ifdef CONFIG_LATENCYTOP
345 int latency_record_count;
346 struct latency_record latency_record[LT_SAVECOUNT];
347 #endif
348 /*
349 * time slack values; these are used to round up poll() and
350 * select() etc timeout values. These are in nanoseconds.
351 */
352 unsigned long timer_slack_ns;
353 unsigned long default_timer_slack_ns;
354
355 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
356 /* Index of current stored address in ret_stack */
357 int curr_ret_stack;
358 /* Stack of return addresses for return function tracing */
359 struct ftrace_ret_stack *ret_stack;
360 /* time stamp for last schedule */
361 unsigned long long ftrace_timestamp;
362 /*
363 * Number of functions that haven't been traced
364 * because of depth overrun.
365 */
366 atomic_t trace_overrun;
367 /* Pause for the tracing */
368 atomic_t tracing_graph_pause;
369 #endif
370 #ifdef CONFIG_TRACING
371 /* state flags for use by tracers */
372 unsigned long trace;
373 /* bitmask and counter of trace recursion */
374 unsigned long trace_recursion;
375 #endif /* CONFIG_TRACING */
376 #ifdef CONFIG_MEMCG /* memcg uses this to do batch job */
377 struct memcg_batch_info {
378 int do_batch; /* incremented when batch uncharge started */
379 struct mem_cgroup *memcg; /* target memcg of uncharge */
380 unsigned long nr_pages; /* uncharged usage */
381 unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
382 } memcg_batch;
383 unsigned int memcg_kmem_skip_account;
384 struct memcg_oom_info {
385 struct mem_cgroup *memcg;
386 gfp_t gfp_mask;
387 int order;
388 unsigned int may_oom:1;
389 } memcg_oom;
390 #endif
391 #ifdef CONFIG_HAVE_HW_BREAKPOINT
392 atomic_t ptrace_bp_refcnt;
393 #endif
394 #ifdef CONFIG_UPROBES
395 struct uprobe_task *utask;
396 #endif
397 #if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE)
398 unsigned int sequential_io;
399 unsigned int sequential_io_avg;
400 #endif
401 };
下面一個結構一個結構的看
1. volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
當前進程的狀態,由以下宏定義
1 /* 2 * Task state bitmask. NOTE! These bits are also 3 * encoded in fs/proc/array.c: get_task_state(). 4 * 5 * We have two separate sets of flags: task->state 6 * is about runnability, while task->exit_state are 7 * about the task exiting. Confusing, but this way 8 * modifying one set can't modify the other one by 9 * mistake. 10 */ 11 #define TASK_RUNNING 0 12 #define TASK_INTERRUPTIBLE 1 13 #define TASK_UNINTERRUPTIBLE 2 14 #define __TASK_STOPPED 4 15 #define __TASK_TRACED 8 16 /* in tsk->exit_state */ 17 #define EXIT_ZOMBIE 16 18 #define EXIT_DEAD 32 19 /* in tsk->state again */ 20 #define TASK_DEAD 64 21 #define TASK_WAKEKILL 128 22 #define TASK_WAKING 256 23 #define TASK_PARKED 512 24 #define TASK_STATE_MAX 1024
宏定義還包含了exit state的狀態
還有以下組合宏,以方便使用
1 /* Convenience macros for the sake of set_task_state */ 2 #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) 3 #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) 4 #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) 5 6 /* Convenience macros for the sake of wake_up */ 7 #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) 8 #define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED) 9 10 /* get_task_state() */ 11 #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | 12 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | 13 __TASK_TRACED)
判斷task狀態的宏
1 #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) 2 #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) 3 #define task_is_dead(task) ((task)->exit_state != 0) 4 #define task_is_stopped_or_traced(task) 5 ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) 6 #define task_contributes_to_load(task) 7 ((task->state & TASK_UNINTERRUPTIBLE) != 0 && 8 (task->flags & PF_FROZEN) == 0)
設置task state的宏,分為mb順序執行版本和讀寫內存操作亂序執行版本
1 #define __set_task_state(tsk, state_value)
2 do { (tsk)->state = (state_value); } while (0)
3 #define set_task_state(tsk, state_value)
4 set_mb((tsk)->state, (state_value))
5
6 /*
7 * set_current_state() includes a barrier so that the write of current->state
8 * is correctly serialised wrt the caller's subsequent test of whether to
9 * actually sleep:
10 *
11 * set_current_state(TASK_UNINTERRUPTIBLE);
12 * if (do_i_need_to_sleep())
13 * schedule();
14 *
15 * If the caller does not need such serialisation then use __set_current_state()
16 */
17 #define __set_current_state(state_value)
18 do { current->state = (state_value); } while (0)
19 #define set_current_state(state_value)
20 set_mb(current->state, (state_value))
task command名長度宏
1 /* Task command name length */ 2 #define TASK_COMM_LEN 16
下邊這兩個不知道干什么用的
1 #define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" 2 3 extern char ___assert_task_state[1 - 2*!!( 4 sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)];
2. void *stack;
指明進程stack地址
3. atomic_t usage;
fork里邊用到,但暫時不知道作用
4. unsigned int flags; /* per process flags, defined below */
每個進程的flag,定義如下
/* * Per process flags */ #define PF_EXITING 0x00000004 /* getting shut down */ #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ #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_USED_ASYNC 0x00004000 /* used async_schedule*(), used by module init */ #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ #define PF_FROZEN 0x00010000 /* frozen for system suspend */ #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ #define PF_KSWAPD 0x00040000 /* I am kswapd */ #define PF_MEMALLOC_NOIO 0x00080000 /* Allocating memory without IO involved */ #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */ #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_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */ #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */ #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */ #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */ #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */ #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezable */ #define PF_MTKPASR 0x80000000 /* I am in MTKPASR process */
下邊的宏操作flag,mtk的定制flag和fpu的使用有關,包括了current和非current的
1 #define task_in_mtkpasr(task) unlikely(task->flags & PF_MTKPASR)
2
3 /*
4 * Only the _current_ task can read/write to tsk->flags, but other
5 * tasks can access tsk->flags in readonly mode for example
6 * with tsk_used_math (like during threaded core dumping).
7 * There is however an exception to this rule during ptrace
8 * or during fork: the ptracer task is allowed to write to the
9 * child->flags of its traced child (same goes for fork, the parent
10 * can write to the child->flags), because we're guaranteed the
11 * child is not running and in turn not changing child->flags
12 * at the same time the parent does it.
13 */
14 #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
15 #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
16 #define clear_used_math() clear_stopped_child_used_math(current)
17 #define set_used_math() set_stopped_child_used_math(current)
18 #define conditional_stopped_child_used_math(condition, child)
19 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
20 #define conditional_used_math(condition)
21 conditional_stopped_child_used_math(condition, current)
22 #define copy_to_stopped_child_used_math(child)
23 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
24 /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
25 #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
26 #define used_math() tsk_used_math(current)
memory alloc no io相關的操作
1 /* __GFP_IO isn't allowed if PF_MEMALLOC_NOIO is set in current->flags
2 * __GFP_FS is also cleared as it implies __GFP_IO.
3 */
4 static inline gfp_t memalloc_noio_flags(gfp_t flags)
5 {
6 if (unlikely(current->flags & PF_MEMALLOC_NOIO))
7 flags &= ~(__GFP_IO | __GFP_FS);
8 return flags;
9 }
10
11 static inline unsigned int memalloc_noio_save(void)
12 {
13 unsigned int flags = current->flags & PF_MEMALLOC_NOIO;
14 current->flags |= PF_MEMALLOC_NOIO;
15 return flags;
16 }
17
18 static inline void memalloc_noio_restore(unsigned int flags)
19 {
20 current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags;
21 }
5. unsigned int ptrace;
跟ptrace相關,目前不知道怎么用
6.
1 #ifdef CONFIG_SMP 2 struct llist_node wake_entry;
被喚醒對象的linked list
7.
1 int on_cpu; 2 #endif
進程跑在哪個CPU上
8. int on_rq;
不清楚
9. 10. 11. int prio, static_prio, normal_prio;
進程的優先級
12. unsigned int rt_priority;
實時優先級
13. const struct sched_class *sched_class;
調度類別
14. struct sched_entity se;
調度實體
15. struct sched_rt_entity rt;
實時調度實體
16.
1 #ifdef CONFIG_CGROUP_SCHED 2 struct task_group *sched_task_group; 3 #endif
調度任務組
17.
1 #ifdef CONFIG_PREEMPT_NOTIFIERS 2 /* list of struct preempt_notifier: */ 3 struct hlist_head preempt_notifiers; 4 #endif
搶占通知hlist,MTK沒定義宏CONFIG_PREEMPT_NOTIFIERS
18.
1 /* 2 * fpu_counter contains the number of consecutive context switches 3 * that the FPU is used. If this is over a threshold, the lazy fpu 4 * saving becomes unlazy to save the trap. This is an unsigned char 5 * so that after 256 times the counter wraps and the behavior turns 6 * lazy again; this to deal with bursty apps that only use FPU for 7 * a short time 8 */ 9 unsigned char fpu_counter;
不清楚
19.
1 #ifdef CONFIG_BLK_DEV_IO_TRACE 2 unsigned int btrace_seq; 3 #endif
不清楚
20. unsigned int policy;
策略
21. int nr_cpus_allowed;
允許的CPU數量
22. cpumask_t cpus_allowed;
不清楚,類型cpumask_t 要看
23.
1 #ifdef CONFIG_PREEMPT_RCU 2 int rcu_read_lock_nesting
rcu讀鎖的嵌套層數
24. 25.
1 char rcu_read_unlock_special; 2 struct list_head rcu_node_entry; 3 #endif /* #ifdef CONFIG_PREEMPT_RCU */
不清楚
26.
1 #ifdef CONFIG_TREE_PREEMPT_RCU 2 struct rcu_node *rcu_blocked_node; 3 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
不清楚
27.
1 #ifdef CONFIG_RCU_BOOST 2 struct rt_mutex *rcu_boost_mutex; 3 #endif /* #ifdef CONFIG_RCU_BOOST */
不清楚,MTK沒定義宏CONFIG_RCU_BOOST
28.
1 #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 2 struct sched_info sched_info; 3 #endif
調度信息,宏CONFIG_SCHEDSTATS 和CONFIG_TASK_DELAY_ACCT 未定義
29. struct list_head tasks;
tasks列表,不知道是否為子進程列表
30.
1 #ifdef CONFIG_SMP 2 struct plist_node pushable_tasks; 3 #endif
不清楚
31. 32 struct mm_struct *mm, *active_mm;
該進程內存管理的數據結構
33.
1 #ifdef CONFIG_COMPAT_BRK 2 unsigned brk_randomized:1; 3 #endif
不清楚
34.
1 #if defined(SPLIT_RSS_COUNTING) 2 struct task_rss_stat rss_stat; 3 #endif
不清楚
35.
1 /* task state */ 2 int exit_state;
進程退出時的狀態
36. 37. int exit_code, exit_signal;
進程退出碼和退出信號量
38. int pdeath_signal; /* The signal sent when the parent dies */
父進程死掉的信號量
39. unsigned int jobctl; /* JOBCTL_*, siglock protected */
job ctrl,信號鎖保護
與之相關的宏定義如下
1 /* 2 * task->jobctl flags 3 */ 4 #define JOBCTL_STOP_SIGMASK 0xffff /* signr of the last group stop */ 5 6 #define JOBCTL_STOP_DEQUEUED_BIT 16 /* stop signal dequeued */ 7 #define JOBCTL_STOP_PENDING_BIT 17 /* task should stop for group stop */ 8 #define JOBCTL_STOP_CONSUME_BIT 18 /* consume group stop count */ 9 #define JOBCTL_TRAP_STOP_BIT 19 /* trap for STOP */ 10 #define JOBCTL_TRAP_NOTIFY_BIT 20 /* trap for NOTIFY */ 11 #define JOBCTL_TRAPPING_BIT 21 /* switching to TRACED */ 12 #define JOBCTL_LISTENING_BIT 22 /* ptracer is listening for events */ 13 14 #define JOBCTL_STOP_DEQUEUED (1 << JOBCTL_STOP_DEQUEUED_BIT) 15 #define JOBCTL_STOP_PENDING (1 << JOBCTL_STOP_PENDING_BIT) 16 #define JOBCTL_STOP_CONSUME (1 << JOBCTL_STOP_CONSUME_BIT) 17 #define JOBCTL_TRAP_STOP (1 << JOBCTL_TRAP_STOP_BIT) 18 #define JOBCTL_TRAP_NOTIFY (1 << JOBCTL_TRAP_NOTIFY_BIT) 19 #define JOBCTL_TRAPPING (1 << JOBCTL_TRAPPING_BIT) 20 #define JOBCTL_LISTENING (1 << JOBCTL_LISTENING_BIT) 21 22 #define JOBCTL_TRAP_MASK (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY) 23 #define JOBCTL_PENDING_MASK (JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK)
操作函數的聲明如下,具體的實現位于kernel/signal.c 文件中
1 extern bool task_set_jobctl_pending(struct task_struct *task, 2 unsigned int mask); 3 extern void task_clear_jobctl_trapping(struct task_struct *task); 4 extern void task_clear_jobctl_pending(struct task_struct *task, 5 unsigned int mask);
40.
1 /* Used for emulating ABI behavior of previous Linux versions */ 2 unsigned int personality;
不清楚
41. unsigned did_exec:1;
不清楚
42.
1 unsigned in_execve:1; /* Tell the LSMs that the process is doing an 2 * execve */
進程在執行中
43. unsigned in_iowait:1;
進程在IO等待中
44.
1 /* Revert to default priority/policy when forking */ 2 unsigned sched_reset_on_fork:1;
在fork的時候調度reset
45. unsigned sched_contributes_to_load:1;
調度對負載的影響
46. unsigned long atomic_flags; /* Flags needing atomic access. */
需要原子操作的flag
下邊為跟此flag有關的宏和函數
1 /* Per-process atomic flags. */
2 #define PFA_NO_NEW_PRIVS 0x00000001 /* May not gain new privileges. */
3
4 static inline bool task_no_new_privs(struct task_struct *p)
5 {
6 return test_bit(PFA_NO_NEW_PRIVS, &p->atomic_flags);
7 }
8
9 static inline void task_set_no_new_privs(struct task_struct *p)
10 {
11 set_bit(PFA_NO_NEW_PRIVS, &p->atomic_flags);
12 }
47. pid_t pid;
進程pid
48. pid_t tgid;
threadgroup id
49.
1 #ifdef CONFIG_CC_STACKPROTECTOR 2 /* Canary value for the -fstack-protector gcc feature */ 3 unsigned long stack_canary; 4 #endif
棧金絲雀,防止棧被篡改,宏CONFIG_CC_STACKPROTECTOR 未定義
50.
1 /* 2 * pointers to (original) parent process, youngest child, younger sibling, 3 * older sibling, respectively. (p->father can be replaced with 4 * p->real_parent->pid) 5 */ 6 struct task_struct __rcu *real_parent; /* real parent process */
真正的父進程
51. struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
不清楚
52.
1 /* 2 * children/sibling forms the list of my natural children 3 */ 4 struct list_head children; /* list of my children */
子進程的list
53. struct list_head sibling; /* linkage in my parent's children list */
兄弟姐妹的list
54. struct task_struct *group_leader; /* threadgroup leader */
thread group的leader
55. 56.
1 #ifdef CONFIG_MTK_SCHED_CMP_TGS 2 raw_spinlock_t thread_group_info_lock; 3 struct thread_group_info_t thread_group_info[NUM_CLUSTER]; 4 #endif
不清楚,宏CONFIG_MTK_SCHED_CMP_TGS 未定義
57. 58.
1 /* 2 * ptraced is the list of tasks this task is using ptrace on. 3 * This includes both natural children and PTRACE_ATTACH targets. 4 * p->ptrace_entry is p's link on the p->parent->ptraced list. 5 */ 6 struct list_head ptraced; 7 struct list_head ptrace_entry;
不清楚
59.
1 /* PID/PID hash table linkage. */ 2 struct pid_link pids[PIDTYPE_MAX];
跟進程namespace相關,不清楚
60. struct list_head thread_group;
thread group
61. struct list_head thread_node;
不清楚
62. struct completion *vfork_done; /* for vfork() */
不清楚
63. struct completion *vfork_done; /* for vfork() */
vfork是否完成
64. 65.
1 int __user *set_child_tid; /* CLONE_CHILD_SETTID */ 2 int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
不清楚
66. 67. 68. 69. 70.
1 cputime_t utime, stime, utimescaled, stimescaled; 2 cputime_t gtime;
不清楚
71.
1 #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE 2 struct cputime prev_cputime; 3 #endif
不清楚,宏CONFIG_VIRT_CPU_ACCOUNTING_NATIVE 未定義
72. 73.
1 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
2 seqlock_t vtime_seqlock;
3 unsigned long long vtime_snap;
4 enum {
5 VTIME_SLEEPING = 0,
6 VTIME_USER,
7 VTIME_SYS,
8 } vtime_snap_whence;
9 #endif
不清楚,宏CONFIG_VIRT_CPU_ACCOUNTING_GEN 未定義
74. 75.
unsigned long nvcsw, nivcsw; /* context switch counts */
不清楚
76. struct timespec start_time; /* monotonic time */
不清楚,單調時間不清楚
77. struct timespec real_start_time; /* boot based time */
真實啟動時間
78. 79.
1 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ 2 unsigned long min_flt, maj_flt;
不清楚
80. 81. 82.
1 /* for thrashing accounting */ 2 #ifdef CONFIG_ZRAM 3 unsigned long fm_flt, swap_in, swap_out; 4 #endif
不清楚,宏CONFIG_ZRAM 未定義
83. struct task_cputime cputime_expires;
cputime到期
84. struct list_head cpu_timers[3];
不清楚
85. 86. 87.
1 /* process credentials */ 2 const struct cred __rcu *real_cred; /* objective and real subjective task 3 * credentials (COW) */ 4 const struct cred __rcu *cred; /* effective (overridable) subjective task 5 * credentials (COW) */ 6 char comm[TASK_COMM_LEN]; /* executable name excluding path 7 - access with [gs]et_task_comm (which lock 8 it with task_lock()) 9 - initialized normally by setup_new_exec */
不清楚,什么是process credential
88. 89.
1 /* file system info */ 2 int link_count, total_link_count;
link數和總共link數
90.
1 #ifdef CONFIG_SYSVIPC 2 /* ipc stuff */ 3 struct sysv_sem sysvsem; 4 #endif
IPC相關,宏CONFIG_SYSVIPC 未定義
91.
1 #ifdef CONFIG_DETECT_HUNG_TASK 2 /* hung task detection */ 3 unsigned long last_switch_count; 4 #endif
task hung檢測,宏CONFIG_DETECT_HUNG_TASK 未定義
92.
1 /* CPU-specific state of this task */ 2 struct thread_struct thread;
task跟cpu相關的狀態
93.
1 /* filesystem information */ 2 struct fs_struct *fs;
這個進程與之相關的文件系統
94.
1 /* open file information */ 2 struct files_struct *files;
這個進程打開的文件
95.
1 /* namespaces */ 2 struct nsproxy *nsproxy;
進程的namespace代理
96.
1 /* signal handlers */ 2 struct signal_struct *signal;
進程的信號
97. struct sighand_struct *sighand;
signal handler
98. 99. 100. 101.
1 sigset_t blocked, real_blocked; 2 sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */ 3 struct sigpending pending;
不清楚
102.
1 unsigned long sas_ss_sp; 2 size_t sas_ss_size;
不清楚
103. 104. 105.
1 int (*notifier)(void *priv); 2 void *notifier_data; 3 sigset_t *notifier_mask;
notifier相關,不清楚具體通知什么
106. struct callback_head *task_works;
進程的回調隊列
107. struct audit_context *audit_context;
不清楚
108.
1 #ifdef CONFIG_AUDITSYSCALL 2 kuid_t loginuid; 3 unsigned int sessionid; 4 #endif
不清楚,宏CONFIG_AUDITSYSCALL 未定義
109. struct seccomp seccomp;
不清楚
110. 111.
1 /* Thread group tracking */ 2 u32 parent_exec_id; 3 u32 self_exec_id;
thread group中parent和self的執行id
112.
1 /* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed, 2 * mempolicy */ 3 spinlock_t alloc_lock;
mm、files、fs、tty、keyrings、mems_allowed、mempolicy分配的鎖
113.
1 /* Protection of the PI data structures: */ 2 raw_spinlock_t pi_lock;
pi data鎖,不清楚pi是什么
114. 115.
1 #ifdef CONFIG_RT_MUTEXES 2 /* PI waiters blocked on a rt_mutex held by this task */ 3 struct plist_head pi_waiters; 4 /* Deadlock detection and priority inheritance handling */ 5 struct rt_mutex_waiter *pi_blocked_on; 6 #endif
不清楚,宏CONFIG_RT_MUTEXES有定義
116.
1 #ifdef CONFIG_DEBUG_MUTEXES 2 /* mutex deadlock detection */ 3 struct mutex_waiter *blocked_on; 4 #endif
不清楚,宏CONFIG_DEBUG_MUTEXES 未定義
117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129.
1 #ifdef CONFIG_TRACE_IRQFLAGS 2 unsigned int irq_events; 3 unsigned long hardirq_enable_ip; 4 unsigned long hardirq_disable_ip; 5 unsigned int hardirq_enable_event; 6 unsigned int hardirq_disable_event; 7 int hardirqs_enabled; 8 int hardirq_context; 9 unsigned long softirq_disable_ip; 10 unsigned long softirq_enable_ip; 11 unsigned int softirq_disable_event; 12 unsigned int softirq_enable_event; 13 int softirqs_enabled; 14 int softirq_context; 15 #endif
中斷跟蹤,包括總的中斷數、hard和soft中斷的enable、disable中斷數,不清楚ip是什么意思
130. 131. 132. 133. 134.
1 #ifdef CONFIG_LOCKDEP 2 # define MAX_LOCK_DEPTH 48UL 3 u64 curr_chain_key; 4 int lockdep_depth; 5 unsigned int lockdep_recursion; 6 struct held_lock held_locks[MAX_LOCK_DEPTH]; 7 gfp_t lockdep_reclaim_gfp; 8 #endif
跟鎖依賴有關,不清楚具體做什么
135.
1 /* journalling filesystem info */ 2 void *journal_info;
文件系統的日志
136.
1 /* stacked block device info */ 2 struct bio_list *bio_list;
被存入堆棧的block device io list
137.
1 #ifdef CONFIG_BLOCK 2 /* stack plugging */ 3 struct blk_plug *plug; 4 #endif
block device的插拔
138.
1 /* VM state */ 2 struct reclaim_state *reclaim_state;
不清楚
139. struct backing_dev_info *backing_dev_info;
不清楚
140. struct io_context *io_context;
進程的io context
141. unsigned long ptrace_message;
ptrace message
142. siginfo_t *last_siginfo; /* For ptrace use. */
最后的signal信息
143. struct task_io_accounting ioac;
task io計數
144. 145. 146.
1 #if defined(CONFIG_TASK_XACCT) 2 u64 acct_rss_mem1; /* accumulated rss usage */ 3 u64 acct_vm_mem1; /* accumulated virtual memory usage */ 4 cputime_t acct_timexpd; /* stime + utime since last update */ 5 #endif
累積的rss memory、virtual memory、time話費,宏CONFIG_TASK_XACCT 未定義
147. 148. 149. 150.
1 #ifdef CONFIG_CPUSETS 2 nodemask_t mems_allowed; /* Protected by alloc_lock */ 3 seqcount_t mems_allowed_seq; /* Seqence no to catch updates */ 4 int cpuset_mem_spread_rotor; 5 int cpuset_slab_spread_rotor; 6 #endif
不清楚,宏CONFIG_CPUSETS 未定義
151. 152.
1 #ifdef CONFIG_CGROUPS 2 /* Control Group info protected by css_set_lock */ 3 struct css_set __rcu *cgroups; 4 /* cg_list protected by css_set_lock and tsk->alloc_lock */ 5 struct list_head cg_list; 6 #endif
css(cgroups subsys state)的cgroups和cgroup list
153. 154. 155. 156
1 #ifdef CONFIG_FUTEX 2 struct robust_list_head __user *robust_list; 3 #ifdef CONFIG_COMPAT 4 struct compat_robust_list_head __user *compat_robust_list; 5 #endif 6 struct list_head pi_state_list; 7 struct futex_pi_state *pi_state_cache; 8 #endif
不清楚,宏CONFIG_FUTEX 未定義
157. 158. 159.
1 #ifdef CONFIG_PERF_EVENTS 2 struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts]; 3 struct mutex perf_event_mutex; 4 struct list_head perf_event_list; 5 #endif
performance相關的event context數組、event mutex、event list
160. 161. 162.
1 #ifdef CONFIG_NUMA 2 struct mempolicy *mempolicy; /* Protected by alloc_lock */ 3 short il_next; 4 short pref_node_fork; 5 #endif
不清楚,宏CONFIG_NUMA (Non-uniform memory access )未定義
163. 164. 165. 166. 167.
1 #ifdef CONFIG_NUMA_BALANCING 2 int numa_scan_seq; 3 int numa_migrate_seq; 4 unsigned int numa_scan_period; 5 u64 node_stamp; /* migration stamp */ 6 struct callback_head numa_work; 7 #endif /* CONFIG_NUMA_BALANCING */
不清楚
168. struct rcu_head rcu;
read copy update頭
169.
1 /* 2 * cache last used pipe for splice 3 */ 4 struct pipe_inode_info *splice_pipe;
不清楚
170.
1 /* 2 * cache last used pipe for splice 3 */ 4 struct pipe_inode_info *splice_pipe;
splice pipe的信息
171. struct page_frag task_frag;
task的page fragment
172.
1 #ifdef CONFIG_TASK_DELAY_ACCT 2 struct task_delay_info *delays; 3 #endif
不清楚,宏CONFIG_TASK_DELAY_ACCT 未定義
173.
1 #ifdef CONFIG_FAULT_INJECTION 2 int make_it_fail; 3 #endif
不清楚
174. 175. 176.
1 /* 2 * when (nr_dirtied >= nr_dirtied_pause), it's time to call 3 * balance_dirty_pages() for some dirty throttling pause 4 */ 5 int nr_dirtied; 6 int nr_dirtied_pause; 7 unsigned long dirty_paused_when; /* start of a write-and-pause period */
dirty page相關
177. 178.
1 #ifdef CONFIG_LATENCYTOP 2 int latency_record_count; 3 struct latency_record latency_record[LT_SAVECOUNT]; 4 #endif
不清楚,宏CONFIG_LATENCYTOP 未定義
179. 180.
1 /* 2 * time slack values; these are used to round up poll() and 3 * select() etc timeout values. These are in nanoseconds. 4 */ 5 unsigned long timer_slack_ns; 6 unsigned long default_timer_slack_ns;
poll()和select()等的timeout值
181. 182. 183. 184. 185.
1 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 2 /* Index of current stored address in ret_stack */ 3 int curr_ret_stack; 4 /* Stack of return addresses for return function tracing */ 5 struct ftrace_ret_stack *ret_stack; 6 /* time stamp for last schedule */ 7 unsigned long long ftrace_timestamp; 8 /* 9 * Number of functions that haven't been traced 10 * because of depth overrun. 11 */ 12 atomic_t trace_overrun; 13 /* Pause for the tracing */ 14 atomic_t tracing_graph_pause; 15 #endif
ftrace的圖形化跟蹤變量,宏 CONFIG_FUNCTION_GRAPH_TRACER 未定義
186. 187.
1 #ifdef CONFIG_TRACING 2 /* state flags for use by tracers */ 3 unsigned long trace; 4 /* bitmask and counter of trace recursion */ 5 unsigned long trace_recursion; 6 #endif /* CONFIG_TRACING */
trace的flag和trace遞歸的數量和bitmask
188. 189. 190
1 #ifdef CONFIG_MEMCG /* memcg uses this to do batch job */
2 struct memcg_batch_info {
3 int do_batch; /* incremented when batch uncharge started */
4 struct mem_cgroup *memcg; /* target memcg of uncharge */
5 unsigned long nr_pages; /* uncharged usage */
6 unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
7 } memcg_batch;
8 unsigned int memcg_kmem_skip_account;
9 struct memcg_oom_info {
10 struct mem_cgroup *memcg;
11 gfp_t gfp_mask;
12 int order;
13 unsigned int may_oom:1;
14 } memcg_oom;
15 #endif
不清楚,宏 CONFIG_MEMCG 未定義
191.
1 #ifdef CONFIG_HAVE_HW_BREAKPOINT 2 atomic_t ptrace_bp_refcnt; 3 #endif
ptrace的斷點引用數量
192.
1 #ifdef CONFIG_UPROBES 2 struct uprobe_task *utask; 3 #endif
不清楚,宏CONFIG_UPROBES 未定義
193. 194.
1 #if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE) 2 unsigned int sequential_io; 3 unsigned int sequential_io_avg; 4 #endif
不清楚,宏CONFIG_BCACHE 和CONFIG_BCACHE 未定義
總結
以上是生活随笔為你收集整理的【一】 sched.h的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (转)SystemProcessesAn
- 下一篇: InstallSheild 获取系统环境