PageRenderTime 107ms CodeModel.GetById 12ms app.highlight 81ms RepoModel.GetById 1ms app.codeStats 1ms

/include/linux/sched.h

https://github.com/airy09/android_kernel_sony_apq8064
C Header | 2848 lines | 1843 code | 433 blank | 572 comment | 51 complexity | 50ea772be0b9726b241677024a712a43 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1#ifndef _LINUX_SCHED_H
   2#define _LINUX_SCHED_H
   3
   4/*
   5 * cloning flags:
   6 */
   7#define CSIGNAL		0x000000ff	/* signal mask to be sent at exit */
   8#define CLONE_VM	0x00000100	/* set if VM shared between processes */
   9#define CLONE_FS	0x00000200	/* set if fs info shared between processes */
  10#define CLONE_FILES	0x00000400	/* set if open files shared between processes */
  11#define CLONE_SIGHAND	0x00000800	/* set if signal handlers and blocked signals shared */
  12#define CLONE_PTRACE	0x00002000	/* set if we want to let tracing continue on the child too */
  13#define CLONE_VFORK	0x00004000	/* set if the parent wants the child to wake it up on mm_release */
  14#define CLONE_PARENT	0x00008000	/* set if we want to have the same parent as the cloner */
  15#define CLONE_THREAD	0x00010000	/* Same thread group? */
  16#define CLONE_NEWNS	0x00020000	/* New namespace group? */
  17#define CLONE_SYSVSEM	0x00040000	/* share system V SEM_UNDO semantics */
  18#define CLONE_SETTLS	0x00080000	/* create a new TLS for the child */
  19#define CLONE_PARENT_SETTID	0x00100000	/* set the TID in the parent */
  20#define CLONE_CHILD_CLEARTID	0x00200000	/* clear the TID in the child */
  21#define CLONE_DETACHED		0x00400000	/* Unused, ignored */
  22#define CLONE_UNTRACED		0x00800000	/* set if the tracing process can't force CLONE_PTRACE on this clone */
  23#define CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
  24/* 0x02000000 was previously the unused CLONE_STOPPED (Start in stopped state)
  25   and is now available for re-use. */
  26#define CLONE_NEWUTS		0x04000000	/* New utsname group? */
  27#define CLONE_NEWIPC		0x08000000	/* New ipcs */
  28#define CLONE_NEWUSER		0x10000000	/* New user namespace */
  29#define CLONE_NEWPID		0x20000000	/* New pid namespace */
  30#define CLONE_NEWNET		0x40000000	/* New network namespace */
  31#define CLONE_IO		0x80000000	/* Clone io context */
  32
  33/*
  34 * Scheduling policies
  35 */
  36#define SCHED_NORMAL		0
  37#define SCHED_FIFO		1
  38#define SCHED_RR		2
  39#define SCHED_BATCH		3
  40/* SCHED_ISO: reserved but not implemented yet */
  41#define SCHED_IDLE		5
  42/* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
  43#define SCHED_RESET_ON_FORK     0x40000000
  44
  45#ifdef __KERNEL__
  46
  47struct sched_param {
  48	int sched_priority;
  49};
  50
  51#include <asm/param.h>	/* for HZ */
  52
  53#include <linux/capability.h>
  54#include <linux/threads.h>
  55#include <linux/kernel.h>
  56#include <linux/types.h>
  57#include <linux/timex.h>
  58#include <linux/jiffies.h>
  59#include <linux/rbtree.h>
  60#include <linux/thread_info.h>
  61#include <linux/cpumask.h>
  62#include <linux/errno.h>
  63#include <linux/nodemask.h>
  64#include <linux/mm_types.h>
  65
  66#include <asm/page.h>
  67#include <asm/ptrace.h>
  68#include <asm/cputime.h>
  69
  70#include <linux/smp.h>
  71#include <linux/sem.h>
  72#include <linux/signal.h>
  73#include <linux/compiler.h>
  74#include <linux/completion.h>
  75#include <linux/pid.h>
  76#include <linux/percpu.h>
  77#include <linux/topology.h>
  78#include <linux/proportions.h>
  79#include <linux/seccomp.h>
  80#include <linux/rcupdate.h>
  81#include <linux/rculist.h>
  82#include <linux/rtmutex.h>
  83
  84#include <linux/time.h>
  85#include <linux/param.h>
  86#include <linux/resource.h>
  87#include <linux/timer.h>
  88#include <linux/hrtimer.h>
  89#include <linux/task_io_accounting.h>
  90#include <linux/latencytop.h>
  91#include <linux/cred.h>
  92#include <linux/llist.h>
  93
  94#include <asm/processor.h>
  95
  96struct exec_domain;
  97struct futex_pi_state;
  98struct robust_list_head;
  99struct bio_list;
 100struct fs_struct;
 101struct perf_event_context;
 102struct blk_plug;
 103
 104/*
 105 * List of flags we want to share for kernel threads,
 106 * if only because they are not used by them anyway.
 107 */
 108#define CLONE_KERNEL	(CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
 109
 110/*
 111 * These are the constant used to fake the fixed-point load-average
 112 * counting. Some notes:
 113 *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
 114 *    a load-average precision of 10 bits integer + 11 bits fractional
 115 *  - if you want to count load-averages more often, you need more
 116 *    precision, or rounding will get you. With 2-second counting freq,
 117 *    the EXP_n values would be 1981, 2034 and 2043 if still using only
 118 *    11 bit fractions.
 119 */
 120extern unsigned long avenrun[];		/* Load averages */
 121extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
 122
 123#define FSHIFT		11		/* nr of bits of precision */
 124#define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
 125#define LOAD_FREQ	(4*HZ+61)	/* 4.61 sec intervals */
 126#define EXP_1		1884		/* 1/exp(5sec/1min) as fixed-point */
 127#define EXP_5		2014		/* 1/exp(5sec/5min) */
 128#define EXP_15		2037		/* 1/exp(5sec/15min) */
 129
 130#define CALC_LOAD(load,exp,n) \
 131	load *= exp; \
 132	load += n*(FIXED_1-exp); \
 133	load >>= FSHIFT;
 134
 135extern unsigned long total_forks;
 136extern int nr_threads;
 137DECLARE_PER_CPU(unsigned long, process_counts);
 138extern int nr_processes(void);
 139extern unsigned long nr_running(void);
 140extern unsigned long nr_uninterruptible(void);
 141extern unsigned long nr_iowait(void);
 142extern unsigned long avg_nr_running(void);
 143extern unsigned long nr_iowait_cpu(int cpu);
 144extern unsigned long this_cpu_load(void);
 145
 146extern void sched_update_nr_prod(int cpu, unsigned long nr, bool inc);
 147extern void sched_get_nr_running_avg(int *avg, int *iowait_avg);
 148
 149extern void calc_global_load(unsigned long ticks);
 150
 151extern unsigned long get_parent_ip(unsigned long addr);
 152
 153struct seq_file;
 154struct cfs_rq;
 155struct task_group;
 156#ifdef CONFIG_SCHED_DEBUG
 157extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
 158extern void proc_sched_set_task(struct task_struct *p);
 159extern void
 160print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
 161#else
 162static inline void
 163proc_sched_show_task(struct task_struct *p, struct seq_file *m)
 164{
 165}
 166static inline void proc_sched_set_task(struct task_struct *p)
 167{
 168}
 169static inline void
 170print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
 171{
 172}
 173#endif
 174
 175/*
 176 * Task state bitmask. NOTE! These bits are also
 177 * encoded in fs/proc/array.c: get_task_state().
 178 *
 179 * We have two separate sets of flags: task->state
 180 * is about runnability, while task->exit_state are
 181 * about the task exiting. Confusing, but this way
 182 * modifying one set can't modify the other one by
 183 * mistake.
 184 */
 185#define TASK_RUNNING		0
 186#define TASK_INTERRUPTIBLE	1
 187#define TASK_UNINTERRUPTIBLE	2
 188#define __TASK_STOPPED		4
 189#define __TASK_TRACED		8
 190/* in tsk->exit_state */
 191#define EXIT_ZOMBIE		16
 192#define EXIT_DEAD		32
 193/* in tsk->state again */
 194#define TASK_DEAD		64
 195#define TASK_WAKEKILL		128
 196#define TASK_WAKING		256
 197#define TASK_STATE_MAX		512
 198
 199#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW"
 200
 201extern char ___assert_task_state[1 - 2*!!(
 202		sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)];
 203
 204/* Convenience macros for the sake of set_task_state */
 205#define TASK_KILLABLE		(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
 206#define TASK_STOPPED		(TASK_WAKEKILL | __TASK_STOPPED)
 207#define TASK_TRACED		(TASK_WAKEKILL | __TASK_TRACED)
 208
 209/* Convenience macros for the sake of wake_up */
 210#define TASK_NORMAL		(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
 211#define TASK_ALL		(TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
 212
 213/* get_task_state() */
 214#define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
 215				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
 216				 __TASK_TRACED)
 217
 218#define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
 219#define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
 220#define task_is_dead(task)	((task)->exit_state != 0)
 221#define task_is_stopped_or_traced(task)	\
 222			((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
 223#define task_contributes_to_load(task)	\
 224				((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
 225				 (task->flags & PF_FROZEN) == 0)
 226
 227#define __set_task_state(tsk, state_value)		\
 228	do { (tsk)->state = (state_value); } while (0)
 229#define set_task_state(tsk, state_value)		\
 230	set_mb((tsk)->state, (state_value))
 231
 232/*
 233 * set_current_state() includes a barrier so that the write of current->state
 234 * is correctly serialised wrt the caller's subsequent test of whether to
 235 * actually sleep:
 236 *
 237 *	set_current_state(TASK_UNINTERRUPTIBLE);
 238 *	if (do_i_need_to_sleep())
 239 *		schedule();
 240 *
 241 * If the caller does not need such serialisation then use __set_current_state()
 242 */
 243#define __set_current_state(state_value)			\
 244	do { current->state = (state_value); } while (0)
 245#define set_current_state(state_value)		\
 246	set_mb(current->state, (state_value))
 247
 248/* Task command name length */
 249#define TASK_COMM_LEN 16
 250
 251#include <linux/spinlock.h>
 252
 253/*
 254 * This serializes "schedule()" and also protects
 255 * the run-queue from deletions/modifications (but
 256 * _adding_ to the beginning of the run-queue has
 257 * a separate lock).
 258 */
 259extern rwlock_t tasklist_lock;
 260extern spinlock_t mmlist_lock;
 261
 262struct task_struct;
 263
 264#ifdef CONFIG_PROVE_RCU
 265extern int lockdep_tasklist_lock_is_held(void);
 266#endif /* #ifdef CONFIG_PROVE_RCU */
 267
 268extern void sched_init(void);
 269extern void sched_init_smp(void);
 270extern asmlinkage void schedule_tail(struct task_struct *prev);
 271extern void init_idle(struct task_struct *idle, int cpu);
 272extern void init_idle_bootup_task(struct task_struct *idle);
 273
 274extern int runqueue_is_locked(int cpu);
 275
 276#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
 277extern void select_nohz_load_balancer(int stop_tick);
 278extern void set_cpu_sd_state_idle(void);
 279extern int get_nohz_timer_target(void);
 280#else
 281static inline void select_nohz_load_balancer(int stop_tick) { }
 282static inline void set_cpu_sd_state_idle(void) { }
 283#endif
 284
 285/*
 286 * Only dump TASK_* tasks. (0 for all tasks)
 287 */
 288extern void show_state_filter(unsigned long state_filter);
 289
 290static inline void show_state(void)
 291{
 292	show_state_filter(0);
 293}
 294
 295extern void show_regs(struct pt_regs *);
 296
 297/*
 298 * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
 299 * task), SP is the stack pointer of the first frame that should be shown in the back
 300 * trace (or NULL if the entire call-chain of the task should be shown).
 301 */
 302extern void show_stack(struct task_struct *task, unsigned long *sp);
 303
 304void io_schedule(void);
 305long io_schedule_timeout(long timeout);
 306
 307extern void cpu_init (void);
 308extern void trap_init(void);
 309extern void update_process_times(int user);
 310extern void scheduler_tick(void);
 311
 312extern void sched_show_task(struct task_struct *p);
 313
 314#ifdef CONFIG_LOCKUP_DETECTOR
 315extern void touch_softlockup_watchdog(void);
 316extern void touch_softlockup_watchdog_sync(void);
 317extern void touch_all_softlockup_watchdogs(void);
 318extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
 319				  void __user *buffer,
 320				  size_t *lenp, loff_t *ppos);
 321extern unsigned int  softlockup_panic;
 322void lockup_detector_init(void);
 323#else
 324static inline void touch_softlockup_watchdog(void)
 325{
 326}
 327static inline void touch_softlockup_watchdog_sync(void)
 328{
 329}
 330static inline void touch_all_softlockup_watchdogs(void)
 331{
 332}
 333static inline void lockup_detector_init(void)
 334{
 335}
 336#endif
 337
 338#ifdef CONFIG_DETECT_HUNG_TASK
 339extern unsigned int  sysctl_hung_task_panic;
 340extern unsigned long sysctl_hung_task_check_count;
 341extern unsigned long sysctl_hung_task_timeout_secs;
 342extern unsigned long sysctl_hung_task_warnings;
 343extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
 344					 void __user *buffer,
 345					 size_t *lenp, loff_t *ppos);
 346#else
 347/* Avoid need for ifdefs elsewhere in the code */
 348enum { sysctl_hung_task_timeout_secs = 0 };
 349#endif
 350
 351/* Attach to any functions which should be ignored in wchan output. */
 352#define __sched		__attribute__((__section__(".sched.text")))
 353
 354/* Linker adds these: start and end of __sched functions */
 355extern char __sched_text_start[], __sched_text_end[];
 356
 357/* Is this address in the __sched functions? */
 358extern int in_sched_functions(unsigned long addr);
 359
 360#define	MAX_SCHEDULE_TIMEOUT	LONG_MAX
 361extern signed long schedule_timeout(signed long timeout);
 362extern signed long schedule_timeout_interruptible(signed long timeout);
 363extern signed long schedule_timeout_killable(signed long timeout);
 364extern signed long schedule_timeout_uninterruptible(signed long timeout);
 365asmlinkage void schedule(void);
 366extern void schedule_preempt_disabled(void);
 367extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
 368
 369struct nsproxy;
 370struct user_namespace;
 371
 372/*
 373 * Default maximum number of active map areas, this limits the number of vmas
 374 * per mm struct. Users can overwrite this number by sysctl but there is a
 375 * problem.
 376 *
 377 * When a program's coredump is generated as ELF format, a section is created
 378 * per a vma. In ELF, the number of sections is represented in unsigned short.
 379 * This means the number of sections should be smaller than 65535 at coredump.
 380 * Because the kernel adds some informative sections to a image of program at
 381 * generating coredump, we need some margin. The number of extra sections is
 382 * 1-3 now and depends on arch. We use "5" as safe margin, here.
 383 */
 384#define MAPCOUNT_ELF_CORE_MARGIN	(5)
 385#define DEFAULT_MAX_MAP_COUNT	(USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
 386
 387extern int sysctl_max_map_count;
 388
 389#include <linux/aio.h>
 390
 391#ifdef CONFIG_MMU
 392extern void arch_pick_mmap_layout(struct mm_struct *mm);
 393extern unsigned long
 394arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
 395		       unsigned long, unsigned long);
 396extern unsigned long
 397arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
 398			  unsigned long len, unsigned long pgoff,
 399			  unsigned long flags);
 400extern void arch_unmap_area(struct mm_struct *, unsigned long);
 401extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
 402#else
 403static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
 404#endif
 405
 406
 407extern void set_dumpable(struct mm_struct *mm, int value);
 408extern int get_dumpable(struct mm_struct *mm);
 409
 410/* mm flags */
 411/* dumpable bits */
 412#define MMF_DUMPABLE      0  /* core dump is permitted */
 413#define MMF_DUMP_SECURELY 1  /* core file is readable only by root */
 414
 415#define MMF_DUMPABLE_BITS 2
 416#define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1)
 417
 418/* coredump filter bits */
 419#define MMF_DUMP_ANON_PRIVATE	2
 420#define MMF_DUMP_ANON_SHARED	3
 421#define MMF_DUMP_MAPPED_PRIVATE	4
 422#define MMF_DUMP_MAPPED_SHARED	5
 423#define MMF_DUMP_ELF_HEADERS	6
 424#define MMF_DUMP_HUGETLB_PRIVATE 7
 425#define MMF_DUMP_HUGETLB_SHARED  8
 426
 427#define MMF_DUMP_FILTER_SHIFT	MMF_DUMPABLE_BITS
 428#define MMF_DUMP_FILTER_BITS	7
 429#define MMF_DUMP_FILTER_MASK \
 430	(((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
 431#define MMF_DUMP_FILTER_DEFAULT \
 432	((1 << MMF_DUMP_ANON_PRIVATE) |	(1 << MMF_DUMP_ANON_SHARED) |\
 433	 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
 434
 435#ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
 436# define MMF_DUMP_MASK_DEFAULT_ELF	(1 << MMF_DUMP_ELF_HEADERS)
 437#else
 438# define MMF_DUMP_MASK_DEFAULT_ELF	0
 439#endif
 440					/* leave room for more dump flags */
 441#define MMF_VM_MERGEABLE	16	/* KSM may merge identical pages */
 442#define MMF_VM_HUGEPAGE		17	/* set when VM_HUGEPAGE is set on vma */
 443
 444#define MMF_INIT_MASK		(MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
 445
 446struct sighand_struct {
 447	atomic_t		count;
 448	struct k_sigaction	action[_NSIG];
 449	spinlock_t		siglock;
 450	wait_queue_head_t	signalfd_wqh;
 451};
 452
 453struct pacct_struct {
 454	int			ac_flag;
 455	long			ac_exitcode;
 456	unsigned long		ac_mem;
 457	cputime_t		ac_utime, ac_stime;
 458	unsigned long		ac_minflt, ac_majflt;
 459};
 460
 461struct cpu_itimer {
 462	cputime_t expires;
 463	cputime_t incr;
 464	u32 error;
 465	u32 incr_error;
 466};
 467
 468/**
 469 * struct task_cputime - collected CPU time counts
 470 * @utime:		time spent in user mode, in &cputime_t units
 471 * @stime:		time spent in kernel mode, in &cputime_t units
 472 * @sum_exec_runtime:	total time spent on the CPU, in nanoseconds
 473 *
 474 * This structure groups together three kinds of CPU time that are
 475 * tracked for threads and thread groups.  Most things considering
 476 * CPU time want to group these counts together and treat all three
 477 * of them in parallel.
 478 */
 479struct task_cputime {
 480	cputime_t utime;
 481	cputime_t stime;
 482	unsigned long long sum_exec_runtime;
 483};
 484/* Alternate field names when used to cache expirations. */
 485#define prof_exp	stime
 486#define virt_exp	utime
 487#define sched_exp	sum_exec_runtime
 488
 489#define INIT_CPUTIME	\
 490	(struct task_cputime) {					\
 491		.utime = 0,					\
 492		.stime = 0,					\
 493		.sum_exec_runtime = 0,				\
 494	}
 495
 496/*
 497 * Disable preemption until the scheduler is running.
 498 * Reset by start_kernel()->sched_init()->init_idle().
 499 *
 500 * We include PREEMPT_ACTIVE to avoid cond_resched() from working
 501 * before the scheduler is active -- see should_resched().
 502 */
 503#define INIT_PREEMPT_COUNT	(1 + PREEMPT_ACTIVE)
 504
 505/**
 506 * struct thread_group_cputimer - thread group interval timer counts
 507 * @cputime:		thread group interval timers.
 508 * @running:		non-zero when there are timers running and
 509 * 			@cputime receives updates.
 510 * @lock:		lock for fields in this struct.
 511 *
 512 * This structure contains the version of task_cputime, above, that is
 513 * used for thread group CPU timer calculations.
 514 */
 515struct thread_group_cputimer {
 516	struct task_cputime cputime;
 517	int running;
 518	raw_spinlock_t lock;
 519};
 520
 521#include <linux/rwsem.h>
 522struct autogroup;
 523
 524/*
 525 * NOTE! "signal_struct" does not have its own
 526 * locking, because a shared signal_struct always
 527 * implies a shared sighand_struct, so locking
 528 * sighand_struct is always a proper superset of
 529 * the locking of signal_struct.
 530 */
 531struct signal_struct {
 532	atomic_t		sigcnt;
 533	atomic_t		live;
 534	int			nr_threads;
 535
 536	wait_queue_head_t	wait_chldexit;	/* for wait4() */
 537
 538	/* current thread group signal load-balancing target: */
 539	struct task_struct	*curr_target;
 540
 541	/* shared signal handling: */
 542	struct sigpending	shared_pending;
 543
 544	/* thread group exit support */
 545	int			group_exit_code;
 546	/* overloaded:
 547	 * - notify group_exit_task when ->count is equal to notify_count
 548	 * - everyone except group_exit_task is stopped during signal delivery
 549	 *   of fatal signals, group_exit_task processes the signal.
 550	 */
 551	int			notify_count;
 552	struct task_struct	*group_exit_task;
 553
 554	/* thread group stop support, overloads group_exit_code too */
 555	int			group_stop_count;
 556	unsigned int		flags; /* see SIGNAL_* flags below */
 557
 558	/*
 559	 * PR_SET_CHILD_SUBREAPER marks a process, like a service
 560	 * manager, to re-parent orphan (double-forking) child processes
 561	 * to this process instead of 'init'. The service manager is
 562	 * able to receive SIGCHLD signals and is able to investigate
 563	 * the process until it calls wait(). All children of this
 564	 * process will inherit a flag if they should look for a
 565	 * child_subreaper process at exit.
 566	 */
 567	unsigned int		is_child_subreaper:1;
 568	unsigned int		has_child_subreaper:1;
 569
 570	/* POSIX.1b Interval Timers */
 571	struct list_head posix_timers;
 572
 573	/* ITIMER_REAL timer for the process */
 574	struct hrtimer real_timer;
 575	struct pid *leader_pid;
 576	ktime_t it_real_incr;
 577
 578	/*
 579	 * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use
 580	 * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these
 581	 * values are defined to 0 and 1 respectively
 582	 */
 583	struct cpu_itimer it[2];
 584
 585	/*
 586	 * Thread group totals for process CPU timers.
 587	 * See thread_group_cputimer(), et al, for details.
 588	 */
 589	struct thread_group_cputimer cputimer;
 590
 591	/* Earliest-expiration cache. */
 592	struct task_cputime cputime_expires;
 593
 594	struct list_head cpu_timers[3];
 595
 596	struct pid *tty_old_pgrp;
 597
 598	/* boolean value for session group leader */
 599	int leader;
 600
 601	struct tty_struct *tty; /* NULL if no tty */
 602
 603#ifdef CONFIG_SCHED_AUTOGROUP
 604	struct autogroup *autogroup;
 605#endif
 606	/*
 607	 * Cumulative resource counters for dead threads in the group,
 608	 * and for reaped dead child processes forked by this group.
 609	 * Live threads maintain their own counters and add to these
 610	 * in __exit_signal, except for the group leader.
 611	 */
 612	cputime_t utime, stime, cutime, cstime;
 613	cputime_t gtime;
 614	cputime_t cgtime;
 615#ifndef CONFIG_VIRT_CPU_ACCOUNTING
 616	cputime_t prev_utime, prev_stime;
 617#endif
 618	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
 619	unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
 620	unsigned long inblock, oublock, cinblock, coublock;
 621	unsigned long maxrss, cmaxrss;
 622	struct task_io_accounting ioac;
 623
 624	/*
 625	 * Cumulative ns of schedule CPU time fo dead threads in the
 626	 * group, not including a zombie group leader, (This only differs
 627	 * from jiffies_to_ns(utime + stime) if sched_clock uses something
 628	 * other than jiffies.)
 629	 */
 630	unsigned long long sum_sched_runtime;
 631
 632	/*
 633	 * We don't bother to synchronize most readers of this at all,
 634	 * because there is no reader checking a limit that actually needs
 635	 * to get both rlim_cur and rlim_max atomically, and either one
 636	 * alone is a single word that can safely be read normally.
 637	 * getrlimit/setrlimit use task_lock(current->group_leader) to
 638	 * protect this instead of the siglock, because they really
 639	 * have no need to disable irqs.
 640	 */
 641	struct rlimit rlim[RLIM_NLIMITS];
 642
 643#ifdef CONFIG_BSD_PROCESS_ACCT
 644	struct pacct_struct pacct;	/* per-process accounting information */
 645#endif
 646#ifdef CONFIG_TASKSTATS
 647	struct taskstats *stats;
 648#endif
 649#ifdef CONFIG_AUDIT
 650	unsigned audit_tty;
 651	struct tty_audit_buf *tty_audit_buf;
 652#endif
 653#ifdef CONFIG_CGROUPS
 654	/*
 655	 * group_rwsem prevents new tasks from entering the threadgroup and
 656	 * member tasks from exiting,a more specifically, setting of
 657	 * PF_EXITING.  fork and exit paths are protected with this rwsem
 658	 * using threadgroup_change_begin/end().  Users which require
 659	 * threadgroup to remain stable should use threadgroup_[un]lock()
 660	 * which also takes care of exec path.  Currently, cgroup is the
 661	 * only user.
 662	 */
 663	struct rw_semaphore group_rwsem;
 664#endif
 665
 666	int oom_adj;		/* OOM kill score adjustment (bit shift) */
 667	int oom_score_adj;	/* OOM kill score adjustment */
 668	int oom_score_adj_min;	/* OOM kill score adjustment minimum value.
 669				 * Only settable by CAP_SYS_RESOURCE. */
 670
 671	struct mutex cred_guard_mutex;	/* guard against foreign influences on
 672					 * credential calculations
 673					 * (notably. ptrace) */
 674};
 675
 676/* Context switch must be unlocked if interrupts are to be enabled */
 677#ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
 678# define __ARCH_WANT_UNLOCKED_CTXSW
 679#endif
 680
 681/*
 682 * Bits in flags field of signal_struct.
 683 */
 684#define SIGNAL_STOP_STOPPED	0x00000001 /* job control stop in effect */
 685#define SIGNAL_STOP_CONTINUED	0x00000002 /* SIGCONT since WCONTINUED reap */
 686#define SIGNAL_GROUP_EXIT	0x00000004 /* group exit in progress */
 687/*
 688 * Pending notifications to parent.
 689 */
 690#define SIGNAL_CLD_STOPPED	0x00000010
 691#define SIGNAL_CLD_CONTINUED	0x00000020
 692#define SIGNAL_CLD_MASK		(SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
 693
 694#define SIGNAL_UNKILLABLE	0x00000040 /* for init: ignore fatal signals */
 695
 696/* If true, all threads except ->group_exit_task have pending SIGKILL */
 697static inline int signal_group_exit(const struct signal_struct *sig)
 698{
 699	return	(sig->flags & SIGNAL_GROUP_EXIT) ||
 700		(sig->group_exit_task != NULL);
 701}
 702
 703/*
 704 * Some day this will be a full-fledged user tracking system..
 705 */
 706struct user_struct {
 707	atomic_t __count;	/* reference count */
 708	atomic_t processes;	/* How many processes does this user have? */
 709	atomic_t files;		/* How many open files does this user have? */
 710	atomic_t sigpending;	/* How many pending signals does this user have? */
 711#ifdef CONFIG_INOTIFY_USER
 712	atomic_t inotify_watches; /* How many inotify watches does this user have? */
 713	atomic_t inotify_devs;	/* How many inotify devs does this user have opened? */
 714#endif
 715#ifdef CONFIG_FANOTIFY
 716	atomic_t fanotify_listeners;
 717#endif
 718#ifdef CONFIG_EPOLL
 719	atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
 720#endif
 721#ifdef CONFIG_POSIX_MQUEUE
 722	/* protected by mq_lock	*/
 723	unsigned long mq_bytes;	/* How many bytes can be allocated to mqueue? */
 724#endif
 725	unsigned long locked_shm; /* How many pages of mlocked shm ? */
 726
 727#ifdef CONFIG_KEYS
 728	struct key *uid_keyring;	/* UID specific keyring */
 729	struct key *session_keyring;	/* UID's default session keyring */
 730#endif
 731
 732	/* Hash table maintenance information */
 733	struct hlist_node uidhash_node;
 734	uid_t uid;
 735	struct user_namespace *user_ns;
 736
 737#ifdef CONFIG_PERF_EVENTS
 738	atomic_long_t locked_vm;
 739#endif
 740};
 741
 742extern int uids_sysfs_init(void);
 743
 744extern struct user_struct *find_user(uid_t);
 745
 746extern struct user_struct root_user;
 747#define INIT_USER (&root_user)
 748
 749
 750struct backing_dev_info;
 751struct reclaim_state;
 752
 753#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
 754struct sched_info {
 755	/* cumulative counters */
 756	unsigned long pcount;	      /* # of times run on this cpu */
 757	unsigned long long run_delay; /* time spent waiting on a runqueue */
 758
 759	/* timestamps */
 760	unsigned long long last_arrival,/* when we last ran on a cpu */
 761			   last_queued;	/* when we were last queued to run */
 762};
 763#endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
 764
 765#ifdef CONFIG_TASK_DELAY_ACCT
 766struct task_delay_info {
 767	spinlock_t	lock;
 768	unsigned int	flags;	/* Private per-task flags */
 769
 770	/* For each stat XXX, add following, aligned appropriately
 771	 *
 772	 * struct timespec XXX_start, XXX_end;
 773	 * u64 XXX_delay;
 774	 * u32 XXX_count;
 775	 *
 776	 * Atomicity of updates to XXX_delay, XXX_count protected by
 777	 * single lock above (split into XXX_lock if contention is an issue).
 778	 */
 779
 780	/*
 781	 * XXX_count is incremented on every XXX operation, the delay
 782	 * associated with the operation is added to XXX_delay.
 783	 * XXX_delay contains the accumulated delay time in nanoseconds.
 784	 */
 785	struct timespec blkio_start, blkio_end;	/* Shared by blkio, swapin */
 786	u64 blkio_delay;	/* wait for sync block io completion */
 787	u64 swapin_delay;	/* wait for swapin block io completion */
 788	u32 blkio_count;	/* total count of the number of sync block */
 789				/* io operations performed */
 790	u32 swapin_count;	/* total count of the number of swapin block */
 791				/* io operations performed */
 792
 793	struct timespec freepages_start, freepages_end;
 794	u64 freepages_delay;	/* wait for memory reclaim */
 795	u32 freepages_count;	/* total count of memory reclaim */
 796};
 797#endif	/* CONFIG_TASK_DELAY_ACCT */
 798
 799static inline int sched_info_on(void)
 800{
 801#ifdef CONFIG_SCHEDSTATS
 802	return 1;
 803#elif defined(CONFIG_TASK_DELAY_ACCT)
 804	extern int delayacct_on;
 805	return delayacct_on;
 806#else
 807	return 0;
 808#endif
 809}
 810
 811enum cpu_idle_type {
 812	CPU_IDLE,
 813	CPU_NOT_IDLE,
 814	CPU_NEWLY_IDLE,
 815	CPU_MAX_IDLE_TYPES
 816};
 817
 818/*
 819 * Increase resolution of nice-level calculations for 64-bit architectures.
 820 * The extra resolution improves shares distribution and load balancing of
 821 * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup
 822 * hierarchies, especially on larger systems. This is not a user-visible change
 823 * and does not change the user-interface for setting shares/weights.
 824 *
 825 * We increase resolution only if we have enough bits to allow this increased
 826 * resolution (i.e. BITS_PER_LONG > 32). The costs for increasing resolution
 827 * when BITS_PER_LONG <= 32 are pretty high and the returns do not justify the
 828 * increased costs.
 829 */
 830#if 0 /* BITS_PER_LONG > 32 -- currently broken: it increases power usage under light load  */
 831# define SCHED_LOAD_RESOLUTION	10
 832# define scale_load(w)		((w) << SCHED_LOAD_RESOLUTION)
 833# define scale_load_down(w)	((w) >> SCHED_LOAD_RESOLUTION)
 834#else
 835# define SCHED_LOAD_RESOLUTION	0
 836# define scale_load(w)		(w)
 837# define scale_load_down(w)	(w)
 838#endif
 839
 840#define SCHED_LOAD_SHIFT	(10 + SCHED_LOAD_RESOLUTION)
 841#define SCHED_LOAD_SCALE	(1L << SCHED_LOAD_SHIFT)
 842
 843/*
 844 * Increase resolution of cpu_power calculations
 845 */
 846#define SCHED_POWER_SHIFT	10
 847#define SCHED_POWER_SCALE	(1L << SCHED_POWER_SHIFT)
 848
 849/*
 850 * sched-domains (multiprocessor balancing) declarations:
 851 */
 852#ifdef CONFIG_SMP
 853#define SD_LOAD_BALANCE		0x0001	/* Do load balancing on this domain. */
 854#define SD_BALANCE_NEWIDLE	0x0002	/* Balance when about to become idle */
 855#define SD_BALANCE_EXEC		0x0004	/* Balance on exec */
 856#define SD_BALANCE_FORK		0x0008	/* Balance on fork, clone */
 857#define SD_BALANCE_WAKE		0x0010  /* Balance on wakeup */
 858#define SD_WAKE_AFFINE		0x0020	/* Wake task to waking CPU */
 859#define SD_PREFER_LOCAL		0x0040  /* Prefer to keep tasks local to this domain */
 860#define SD_SHARE_CPUPOWER	0x0080	/* Domain members share cpu power */
 861#define SD_POWERSAVINGS_BALANCE	0x0100	/* Balance for power savings */
 862#define SD_SHARE_PKG_RESOURCES	0x0200	/* Domain members share cpu pkg resources */
 863#define SD_SERIALIZE		0x0400	/* Only a single load balancing instance */
 864#define SD_ASYM_PACKING		0x0800  /* Place busy groups earlier in the domain */
 865#define SD_PREFER_SIBLING	0x1000	/* Prefer to place tasks in a sibling domain */
 866#define SD_OVERLAP		0x2000	/* sched_domains of this level overlap */
 867
 868enum powersavings_balance_level {
 869	POWERSAVINGS_BALANCE_NONE = 0,  /* No power saving load balance */
 870	POWERSAVINGS_BALANCE_BASIC,	/* Fill one thread/core/package
 871					 * first for long running threads
 872					 */
 873	POWERSAVINGS_BALANCE_WAKEUP,	/* Also bias task wakeups to semi-idle
 874					 * cpu package for power savings
 875					 */
 876	MAX_POWERSAVINGS_BALANCE_LEVELS
 877};
 878
 879extern int sched_mc_power_savings, sched_smt_power_savings;
 880
 881static inline int sd_balance_for_mc_power(void)
 882{
 883	if (sched_smt_power_savings)
 884		return SD_POWERSAVINGS_BALANCE;
 885
 886	if (!sched_mc_power_savings)
 887		return SD_PREFER_SIBLING;
 888
 889	return 0;
 890}
 891
 892static inline int sd_balance_for_package_power(void)
 893{
 894	if (sched_mc_power_savings | sched_smt_power_savings)
 895		return SD_POWERSAVINGS_BALANCE;
 896
 897	return SD_PREFER_SIBLING;
 898}
 899
 900extern int __weak arch_sd_sibiling_asym_packing(void);
 901
 902/*
 903 * Optimise SD flags for power savings:
 904 * SD_BALANCE_NEWIDLE helps aggressive task consolidation and power savings.
 905 * Keep default SD flags if sched_{smt,mc}_power_saving=0
 906 */
 907
 908static inline int sd_power_saving_flags(void)
 909{
 910	if (sched_mc_power_savings | sched_smt_power_savings)
 911		return SD_BALANCE_NEWIDLE;
 912
 913	return 0;
 914}
 915
 916struct sched_group_power {
 917	atomic_t ref;
 918	/*
 919	 * CPU power of this group, SCHED_LOAD_SCALE being max power for a
 920	 * single CPU.
 921	 */
 922	unsigned int power, power_orig;
 923	unsigned long next_update;
 924	/*
 925	 * Number of busy cpus in this group.
 926	 */
 927	atomic_t nr_busy_cpus;
 928};
 929
 930struct sched_group {
 931	struct sched_group *next;	/* Must be a circular list */
 932	atomic_t ref;
 933
 934	unsigned int group_weight;
 935	struct sched_group_power *sgp;
 936
 937	/*
 938	 * The CPUs this group covers.
 939	 *
 940	 * NOTE: this field is variable length. (Allocated dynamically
 941	 * by attaching extra space to the end of the structure,
 942	 * depending on how many CPUs the kernel has booted up with)
 943	 */
 944	unsigned long cpumask[0];
 945};
 946
 947static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
 948{
 949	return to_cpumask(sg->cpumask);
 950}
 951
 952/**
 953 * group_first_cpu - Returns the first cpu in the cpumask of a sched_group.
 954 * @group: The group whose first cpu is to be returned.
 955 */
 956static inline unsigned int group_first_cpu(struct sched_group *group)
 957{
 958	return cpumask_first(sched_group_cpus(group));
 959}
 960
 961struct sched_domain_attr {
 962	int relax_domain_level;
 963};
 964
 965#define SD_ATTR_INIT	(struct sched_domain_attr) {	\
 966	.relax_domain_level = -1,			\
 967}
 968
 969extern int sched_domain_level_max;
 970
 971struct sched_domain {
 972	/* These fields must be setup */
 973	struct sched_domain *parent;	/* top domain must be null terminated */
 974	struct sched_domain *child;	/* bottom domain must be null terminated */
 975	struct sched_group *groups;	/* the balancing groups of the domain */
 976	unsigned long min_interval;	/* Minimum balance interval ms */
 977	unsigned long max_interval;	/* Maximum balance interval ms */
 978	unsigned int busy_factor;	/* less balancing by factor if busy */
 979	unsigned int imbalance_pct;	/* No balance until over watermark */
 980	unsigned int cache_nice_tries;	/* Leave cache hot tasks for # tries */
 981	unsigned int busy_idx;
 982	unsigned int idle_idx;
 983	unsigned int newidle_idx;
 984	unsigned int wake_idx;
 985	unsigned int forkexec_idx;
 986	unsigned int smt_gain;
 987	int flags;			/* See SD_* */
 988	int level;
 989
 990	/* Runtime fields. */
 991	unsigned long last_balance;	/* init to jiffies. units in jiffies */
 992	unsigned int balance_interval;	/* initialise to 1. units in ms. */
 993	unsigned int nr_balance_failed; /* initialise to 0 */
 994
 995	u64 last_update;
 996
 997#ifdef CONFIG_SCHEDSTATS
 998	/* load_balance() stats */
 999	unsigned int lb_count[CPU_MAX_IDLE_TYPES];
1000	unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
1001	unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
1002	unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
1003	unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
1004	unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
1005	unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
1006	unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
1007
1008	/* Active load balancing */
1009	unsigned int alb_count;
1010	unsigned int alb_failed;
1011	unsigned int alb_pushed;
1012
1013	/* SD_BALANCE_EXEC stats */
1014	unsigned int sbe_count;
1015	unsigned int sbe_balanced;
1016	unsigned int sbe_pushed;
1017
1018	/* SD_BALANCE_FORK stats */
1019	unsigned int sbf_count;
1020	unsigned int sbf_balanced;
1021	unsigned int sbf_pushed;
1022
1023	/* try_to_wake_up() stats */
1024	unsigned int ttwu_wake_remote;
1025	unsigned int ttwu_move_affine;
1026	unsigned int ttwu_move_balance;
1027#endif
1028#ifdef CONFIG_SCHED_DEBUG
1029	char *name;
1030#endif
1031	union {
1032		void *private;		/* used during construction */
1033		struct rcu_head rcu;	/* used during destruction */
1034	};
1035
1036	unsigned int span_weight;
1037	/*
1038	 * Span of all CPUs in this domain.
1039	 *
1040	 * NOTE: this field is variable length. (Allocated dynamically
1041	 * by attaching extra space to the end of the structure,
1042	 * depending on how many CPUs the kernel has booted up with)
1043	 */
1044	unsigned long span[0];
1045};
1046
1047static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
1048{
1049	return to_cpumask(sd->span);
1050}
1051
1052extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
1053				    struct sched_domain_attr *dattr_new);
1054
1055/* Allocate an array of sched domains, for partition_sched_domains(). */
1056cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
1057void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
1058
1059/* Test a flag in parent sched domain */
1060static inline int test_sd_parent(struct sched_domain *sd, int flag)
1061{
1062	if (sd->parent && (sd->parent->flags & flag))
1063		return 1;
1064
1065	return 0;
1066}
1067
1068unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu);
1069unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu);
1070
1071bool cpus_share_cache(int this_cpu, int that_cpu);
1072
1073#else /* CONFIG_SMP */
1074
1075struct sched_domain_attr;
1076
1077static inline void
1078partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
1079			struct sched_domain_attr *dattr_new)
1080{
1081}
1082
1083static inline bool cpus_share_cache(int this_cpu, int that_cpu)
1084{
1085	return true;
1086}
1087
1088#endif	/* !CONFIG_SMP */
1089
1090
1091struct io_context;			/* See blkdev.h */
1092
1093
1094#ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
1095extern void prefetch_stack(struct task_struct *t);
1096#else
1097static inline void prefetch_stack(struct task_struct *t) { }
1098#endif
1099
1100struct audit_context;		/* See audit.c */
1101struct mempolicy;
1102struct pipe_inode_info;
1103struct uts_namespace;
1104
1105struct rq;
1106struct sched_domain;
1107
1108/*
1109 * wake flags
1110 */
1111#define WF_SYNC		0x01		/* waker goes to sleep after wakup */
1112#define WF_FORK		0x02		/* child wakeup after fork */
1113#define WF_MIGRATED	0x04		/* internal use, task got migrated */
1114
1115#define ENQUEUE_WAKEUP		1
1116#define ENQUEUE_HEAD		2
1117#ifdef CONFIG_SMP
1118#define ENQUEUE_WAKING		4	/* sched_class::task_waking was called */
1119#else
1120#define ENQUEUE_WAKING		0
1121#endif
1122
1123#define DEQUEUE_SLEEP		1
1124
1125struct sched_class {
1126	const struct sched_class *next;
1127
1128	void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
1129	void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
1130	void (*yield_task) (struct rq *rq);
1131	bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt);
1132
1133	void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
1134
1135	struct task_struct * (*pick_next_task) (struct rq *rq);
1136	void (*put_prev_task) (struct rq *rq, struct task_struct *p);
1137
1138#ifdef CONFIG_SMP
1139	int  (*select_task_rq)(struct task_struct *p, int sd_flag, int flags);
1140
1141	void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
1142	void (*post_schedule) (struct rq *this_rq);
1143	void (*task_waking) (struct task_struct *task);
1144	void (*task_woken) (struct rq *this_rq, struct task_struct *task);
1145
1146	void (*set_cpus_allowed)(struct task_struct *p,
1147				 const struct cpumask *newmask);
1148
1149	void (*rq_online)(struct rq *rq);
1150	void (*rq_offline)(struct rq *rq);
1151#endif
1152
1153	void (*set_curr_task) (struct rq *rq);
1154	void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
1155	void (*task_fork) (struct task_struct *p);
1156
1157	void (*switched_from) (struct rq *this_rq, struct task_struct *task);
1158	void (*switched_to) (struct rq *this_rq, struct task_struct *task);
1159	void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1160			     int oldprio);
1161
1162	unsigned int (*get_rr_interval) (struct rq *rq,
1163					 struct task_struct *task);
1164
1165#ifdef CONFIG_FAIR_GROUP_SCHED
1166	void (*task_move_group) (struct task_struct *p, int on_rq);
1167#endif
1168};
1169
1170struct load_weight {
1171	unsigned long weight, inv_weight;
1172};
1173
1174#ifdef CONFIG_SCHEDSTATS
1175struct sched_statistics {
1176	u64			wait_start;
1177	u64			wait_max;
1178	u64			wait_count;
1179	u64			wait_sum;
1180	u64			iowait_count;
1181	u64			iowait_sum;
1182
1183	u64			sleep_start;
1184	u64			sleep_max;
1185	s64			sum_sleep_runtime;
1186
1187	u64			block_start;
1188	u64			block_max;
1189	u64			exec_max;
1190	u64			slice_max;
1191
1192	u64			nr_migrations_cold;
1193	u64			nr_failed_migrations_affine;
1194	u64			nr_failed_migrations_running;
1195	u64			nr_failed_migrations_hot;
1196	u64			nr_forced_migrations;
1197
1198	u64			nr_wakeups;
1199	u64			nr_wakeups_sync;
1200	u64			nr_wakeups_migrate;
1201	u64			nr_wakeups_local;
1202	u64			nr_wakeups_remote;
1203	u64			nr_wakeups_affine;
1204	u64			nr_wakeups_affine_attempts;
1205	u64			nr_wakeups_passive;
1206	u64			nr_wakeups_idle;
1207};
1208#endif
1209
1210struct sched_entity {
1211	struct load_weight	load;		/* for load-balancing */
1212	struct rb_node		run_node;
1213	struct list_head	group_node;
1214	unsigned int		on_rq;
1215
1216	u64			exec_start;
1217	u64			sum_exec_runtime;
1218	u64			vruntime;
1219	u64			prev_sum_exec_runtime;
1220
1221	u64			nr_migrations;
1222
1223#ifdef CONFIG_SCHEDSTATS
1224	struct sched_statistics statistics;
1225#endif
1226
1227#ifdef CONFIG_FAIR_GROUP_SCHED
1228	struct sched_entity	*parent;
1229	/* rq on which this entity is (to be) queued: */
1230	struct cfs_rq		*cfs_rq;
1231	/* rq "owned" by this entity/group: */
1232	struct cfs_rq		*my_q;
1233#endif
1234};
1235
1236struct sched_rt_entity {
1237	struct list_head run_list;
1238	unsigned long timeout;
1239	unsigned int time_slice;
1240	int nr_cpus_allowed;
1241
1242	struct sched_rt_entity *back;
1243#ifdef CONFIG_RT_GROUP_SCHED
1244	struct sched_rt_entity	*parent;
1245	/* rq on which this entity is (to be) queued: */
1246	struct rt_rq		*rt_rq;
1247	/* rq "owned" by this entity/group: */
1248	struct rt_rq		*my_q;
1249#endif
1250};
1251
1252/*
1253 * default timeslice is 100 msecs (used only for SCHED_RR tasks).
1254 * Timeslices get refilled after they expire.
1255 */
1256#define RR_TIMESLICE		(100 * HZ / 1000)
1257
1258struct rcu_node;
1259
1260enum perf_event_task_context {
1261	perf_invalid_context = -1,
1262	perf_hw_context = 0,
1263	perf_sw_context,
1264	perf_nr_task_contexts,
1265};
1266
1267struct task_struct {
1268	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
1269	void *stack;
1270	atomic_t usage;
1271	unsigned int flags;	/* per process flags, defined below */
1272	unsigned int ptrace;
1273
1274#ifdef CONFIG_SMP
1275	struct llist_node wake_entry;
1276	int on_cpu;
1277#endif
1278	int on_rq;
1279
1280	int prio, static_prio, normal_prio;
1281	unsigned int rt_priority;
1282	const struct sched_class *sched_class;
1283	struct sched_entity se;
1284	struct sched_rt_entity rt;
1285
1286#ifdef CONFIG_PREEMPT_NOTIFIERS
1287	/* list of struct preempt_notifier: */
1288	struct hlist_head preempt_notifiers;
1289#endif
1290
1291	/*
1292	 * fpu_counter contains the number of consecutive context switches
1293	 * that the FPU is used. If this is over a threshold, the lazy fpu
1294	 * saving becomes unlazy to save the trap. This is an unsigned char
1295	 * so that after 256 times the counter wraps and the behavior turns
1296	 * lazy again; this to deal with bursty apps that only use FPU for
1297	 * a short time
1298	 */
1299	unsigned char fpu_counter;
1300#ifdef CONFIG_BLK_DEV_IO_TRACE
1301	unsigned int btrace_seq;
1302#endif
1303
1304	unsigned int policy;
1305	cpumask_t cpus_allowed;
1306
1307#ifdef CONFIG_PREEMPT_RCU
1308	int rcu_read_lock_nesting;
1309	char rcu_read_unlock_special;
1310	struct list_head rcu_node_entry;
1311#endif /* #ifdef CONFIG_PREEMPT_RCU */
1312#ifdef CONFIG_TREE_PREEMPT_RCU
1313	struct rcu_node *rcu_blocked_node;
1314#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
1315#ifdef CONFIG_RCU_BOOST
1316	struct rt_mutex *rcu_boost_mutex;
1317#endif /* #ifdef CONFIG_RCU_BOOST */
1318
1319#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
1320	struct sched_info sched_info;
1321#endif
1322
1323	struct list_head tasks;
1324#ifdef CONFIG_SMP
1325	struct plist_node pushable_tasks;
1326#endif
1327
1328	struct mm_struct *mm, *active_mm;
1329#ifdef CONFIG_COMPAT_BRK
1330	unsigned brk_randomized:1;
1331#endif
1332#if defined(SPLIT_RSS_COUNTING)
1333	struct task_rss_stat	rss_stat;
1334#endif
1335/* task state */
1336	int exit_state;
1337	int exit_code, exit_signal;
1338	int pdeath_signal;  /*  The signal sent when the parent dies  */
1339	unsigned int jobctl;	/* JOBCTL_*, siglock protected */
1340	/* ??? */
1341	unsigned int personality;
1342	unsigned did_exec:1;
1343	unsigned in_execve:1;	/* Tell the LSMs that the process is doing an
1344				 * execve */
1345	unsigned in_iowait:1;
1346
1347
1348	/* Revert to default priority/policy when forking */
1349	unsigned sched_reset_on_fork:1;
1350	unsigned sched_contributes_to_load:1;
1351
1352#ifdef CONFIG_GENERIC_HARDIRQS
1353	/* IRQ handler threads */
1354	unsigned irq_thread:1;
1355#endif
1356
1357	pid_t pid;
1358	pid_t tgid;
1359
1360#ifdef CONFIG_CC_STACKPROTECTOR
1361	/* Canary value for the -fstack-protector gcc feature */
1362	unsigned long stack_canary;
1363#endif
1364
1365	/* 
1366	 * pointers to (original) parent process, youngest child, younger sibling,
1367	 * older sibling, respectively.  (p->father can be replaced with 
1368	 * p->real_parent->pid)
1369	 */
1370	struct task_struct __rcu *real_parent; /* real parent process */
1371	struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
1372	/*
1373	 * children/sibling forms the list of my natural children
1374	 */
1375	struct list_head children;	/* list of my children */
1376	struct list_head sibling;	/* linkage in my parent's children list */
1377	struct task_struct *group_leader;	/* threadgroup leader */
1378
1379	/*
1380	 * ptraced is the list of tasks this task is using ptrace on.
1381	 * This includes both natural children and PTRACE_ATTACH targets.
1382	 * p->ptrace_entry is p's link on the p->parent->ptraced list.
1383	 */
1384	struct list_head ptraced;
1385	struct list_head ptrace_entry;
1386
1387	/* PID/PID hash table linkage. */
1388	struct pid_link pids[PIDTYPE_MAX];
1389	struct list_head thread_group;
1390
1391	struct completion *vfork_done;		/* for vfork() */
1392	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
1393	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */
1394
1395	cputime_t utime, stime, utimescaled, stimescaled;
1396	cputime_t gtime;
1397#ifndef CONFIG_VIRT_CPU_ACCOUNTING
1398	cputime_t prev_utime, prev_stime;
1399#endif
1400	unsigned long nvcsw, nivcsw; /* context switch counts */
1401	struct timespec start_time; 		/* monotonic time */
1402	struct timespec real_start_time;	/* boot based time */
1403/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
1404	unsigned long min_flt, maj_flt;
1405
1406	struct task_cputime cputime_expires;
1407	struct list_head cpu_timers[3];
1408
1409/* process credentials */
1410	const struct cred __rcu *real_cred; /* objective and real subjective task
1411					 * credentials (COW) */
1412	const struct cred __rcu *cred;	/* effective (overridable) subjective task
1413					 * credentials (COW) */
1414	struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
1415
1416	char comm[TASK_COMM_LEN]; /* executable name excluding path
1417				     - access with [gs]et_task_comm (which lock
1418				       it with task_lock())
1419				     - initialized normally by setup_new_exec */
1420/* file system info */
1421	int link_count, total_link_count;
1422#ifdef CONFIG_SYSVIPC
1423/* ipc stuff */
1424	struct sysv_sem sysvsem;
1425#endif
1426#ifdef CONFIG_DETECT_HUNG_TASK
1427/* hung task detection */
1428	unsigned long last_switch_count;
1429#endif
1430/* CPU-specific state of this task */
1431	struct thread_struct thread;
1432/* filesystem information */
1433	struct fs_struct *fs;
1434/* open file information */
1435	struct files_struct *files;
1436/* namespaces */
1437	struct nsproxy *nsproxy;
1438/* signal handlers */
1439	struct signal_struct *signal;
1440	struct sighand_struct *sighand;
1441
1442	sigset_t blocked, real_blocked;
1443	sigset_t saved_sigmask;	/* restored if set_restore_sigmask() was used */
1444	struct sigpending pending;
1445
1446	unsigned long sas_ss_sp;
1447	size_t sas_ss_size;
1448	int (*notifier)(void *priv);
1449	void *notifier_data;
1450	sigset_t *notifier_mask;
1451	struct audit_context *audit_context;
1452#ifdef CONFIG_AUDITSYSCALL
1453	uid_t loginuid;
1454	unsigned int sessionid;
1455#endif
1456	seccomp_t seccomp;
1457
1458/* Thread group tracking */
1459   	u32 parent_exec_id;
1460   	u32 self_exec_id;
1461/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
1462 * mempolicy */
1463	spinlock_t alloc_lock;
1464
1465	/* Protection of the PI data structures: */
1466	raw_spinlock_t pi_lock;
1467
1468#ifdef CONFIG_RT_MUTEXES
1469	/* PI waiters blocked on a rt_mutex held by this task */
1470	struct plist_head pi_waiters;
1471	/* Deadlock detection and priority inheritance handling */
1472	struct rt_mutex_waiter *pi_blocked_on;
1473#endif
1474
1475#ifdef CONFIG_DEBUG_MUTEXES
1476	/* mutex deadlock detection */
1477	struct mutex_waiter *blocked_on;
1478#endif
1479#ifdef CONFIG_TRACE_IRQFLAGS
1480	unsigned int irq_events;
1481	unsigned long hardirq_enable_ip;
1482	unsigned long hardirq_disable_ip;
1483	unsigned int hardirq_enable_event;
1484	unsigned int hardirq_disable_event;
1485	int hardirqs_enabled;
1486	int hardirq_context;
1487	unsigned long softirq_disable_ip;
1488	unsigned long softirq_enable_ip;
1489	unsigned int softirq_disable_event;
1490	unsigned int softirq_enable_event;
1491	int softirqs_enabled;
1492	int softirq_context;
1493#endif
1494#ifdef CONFIG_LOCKDEP
1495# define MAX_LOCK_DEPTH 48UL
1496	u64 curr_chain_key;
1497	int lockdep_depth;
1498	unsigned int lockdep_recursion;
1499	struct held_lock held_locks[MAX_LOCK_DEPTH];
1500	gfp_t lockdep_reclaim_gfp;
1501#endif
1502
1503/* journalling filesystem info */
1504	void *journal_info;
1505
1506/* stacked block device info */
1507	struct bio_list *bio_list;
1508
1509#ifdef CONFIG_BLOCK
1510/* stack plugging */
1511	struct blk_plug *plug;
1512#endif
1513
1514/* VM state */
1515	struct reclaim_state *reclaim_state;
1516
1517	struct backing_dev_info *backing_dev_info;
1518
1519	struct io_context *io_context;
1520
1521	unsigned long ptrace_message;
1522	siginfo_t *last_siginfo; /* For ptrace use.  */
1523	struct task_io_accounting ioac;
1524#if defined(CONFIG_TASK_XACCT)
1525	u64 acct_rss_mem1;	/* accumulated rss usage */
1526	u64 acct_vm_mem1;	/* accumulated virtual memory usage */
1527	cputime_t acct_timexpd;	/* stime + utime since last update */
1528#endif
1529#ifdef CONFIG_CPUSETS
1530	nodemask_t mems_allowed;	/* Protected by alloc_lock */
1531	seqcount_t mems_allowed_seq;	/* Seqence no to catch updates */
1532	int cpuset_mem_spread_rotor;
1533	int cpuset_slab_spread_rotor;
1534#endif
1535#ifdef CONFIG_CGROUPS
1536	/* Control Group info protected by css_set_lock */
1537	struct css_set __rcu *cgroups;
1538	/* cg_list protected by css_set_lock and tsk->alloc_lock */
1539	struct list_head cg_list;
1540#endif
1541#ifdef CONFIG_FUTEX
1542	struct robust_list_head __user *robust_list;
1543#ifdef CONFIG_COMPAT
1544	struct compat_robust_list_head __user *compat_robust_list;
1545#endif
1546	struct list_head pi_state_list;
1547	struct futex_pi_state *pi_state_cache;
1548#endif
1549#ifdef CONFIG_PERF_EVENTS
1550	struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
1551	struct mutex perf_event_mutex;
1552	struct list_head perf_event_list;
1553#endif
1554#ifdef CONFIG_NUMA
1555	struct mempolicy *mempolicy;	/* Protected by alloc_lock */
1556	short il_next;
1557	short pref_node_fork;
1558#endif
1559	struct rcu_head rcu;
1560
1561	/*
1562	 * cache last used pipe for splice
1563	 */
1564	struct pipe_inode_info *splice_pipe;
1565#ifdef	CONFIG_TASK_DELAY_ACCT
1566	struct task_delay_info *delays;
1567#endif
1568#ifdef CONFIG_FAULT_INJECTION
1569	int make_it_fail;
1570#endif
1571	/*
1572	 * when (nr_dirtied >= nr_dirtied_pause), it's time to call
1573	 * balance_dirty_pages() for some dirty throttling pause
1574	 */
1575	int nr_dirtied;
1576	int nr_dirtied_pause;
1577	unsigned long dirty_paused_when; /* start of a write-and-pause period */
1578
1579#ifdef CONFIG_LATENCYTOP
1580	int latency_record_count;
1581	struct latency_record latency_record[LT_SAVECOUNT];
1582#endif
1583	/*
1584	 * time slack values; these are used to round up poll() and
1585	 * select() etc timeout values. These are in nanoseconds.
1586	 */
1587	unsigned long timer_slack_ns;
1588	unsigned long default_timer_slack_ns;
1589
1590	struct list_head	*scm_work_list;
1591#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1592	/* Index of current stored address in ret_stack */
1593	int curr_ret_stack;
1594	/* Stack of return addresses for return function tracing */
1595	struct ftrace_ret_stack	*ret_stack;
1596	/* time stamp for last schedule */
1597	unsigned long long ftrace_timestamp;
1598	/*
1599	 * Number of functions that haven't been traced
1600	 * because of depth overrun.
1601	 */
1602	atomic_t trace_overrun;
1603	/* Pause for the tracing */
1604	atomic_t tracing_graph_pause;
1605#endif
1606#ifdef CONFIG_TRACING
1607	/* state flags for use by tracers */
1608	unsigned long trace;
1609	/* bitmask and counter of trace recursion */
1610	unsigned long trace_recursion;
1611#endif /* CONFIG_TRACING */
1612#ifdef CONFIG_CGROUP_MEM_RES_CTLR /* memcg uses this to do batch job */
1613	struct memcg_batch_info {
1614		int do_batch;	/* incremented when batch uncharge started */
1615		struct mem_cgroup *memcg; /* target memcg of uncharge */
1616		unsigned long nr_pages;	/* uncharged usage */
1617		unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
1618	} memcg_batch;
1619#endif
1620#ifdef CONFIG_HAVE_HW_BREAKPOINT
1621	atomic_t ptrace_bp_refcnt;
1622#endif
1623};
1624
1625/* Future-safe accessor for struct task_struct's cpus_allowed. */
1626#define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
1627
1628/*
1629 * Priority of a process goes from 0..MAX_PRIO-1, valid RT
1630 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
1631 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
1632 * values are inverted: lower p->prio value means higher priority.
1633 *
1634 * The MAX_USER_RT_PRIO value allows the actual maximum
1635 * RT priority to be separate from the value exported to
1636 * user-space.  This allows kernel threads to set their
1637 * priority to a value higher than any user task. Note:
1638 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
1639 */
1640
1641#define MAX_USER_RT_PRIO	100
1642#define MAX_RT_PRIO		MAX_USER_RT_PRIO
1643
1644#define MAX_PRIO		(MAX_RT_PRIO + 40)
1645#define DEFAULT_PRIO		(MAX_RT_PRIO + 20)
1646
1647static inline int rt_prio(int prio)
1648{
1649	if (unlikely(prio < MAX_RT_PRIO))
1650		return 1;
1651	return 0;
1652}
1653
1654static inline int rt_task(struct task_struct *p)
1655{
1656	return rt_prio(p->prio);
1657}
1658
1659static inline struct pid *task_pid(struct task_struct *task)
1660{
1661	return task->pids[PIDTYPE_PID].pid;
1662}
1663
1664static inline struct pid *task_tgid(struct task_struct *task)
1665{
1666	return task->group_leader->pids[PIDTYPE_PID].pid;
1667}
1668
1669/*
1670 * Without tasklist or rcu lock it is not safe to dereference
1671 * the result of …

Large files files are truncated, but you can click here to view the full file