sched.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455
  1. #ifndef _LINUX_SCHED_H
  2. #define _LINUX_SCHED_H
  3. /*
  4. * cloning flags:
  5. */
  6. #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
  7. #define CLONE_VM 0x00000100 /* set if VM shared between processes */
  8. #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
  9. #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
  10. #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
  11. #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
  12. #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
  13. #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
  14. #define CLONE_THREAD 0x00010000 /* Same thread group? */
  15. #define CLONE_NEWNS 0x00020000 /* New namespace group? */
  16. #define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */
  17. #define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */
  18. #define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */
  19. #define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */
  20. #define CLONE_DETACHED 0x00400000 /* Unused, ignored */
  21. #define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */
  22. #define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */
  23. #define CLONE_STOPPED 0x02000000 /* Start in stopped state */
  24. #define CLONE_NEWUTS 0x04000000 /* New utsname group? */
  25. #define CLONE_NEWIPC 0x08000000 /* New ipcs */
  26. #define CLONE_NEWUSER 0x10000000 /* New user namespace */
  27. #define CLONE_NEWPID 0x20000000 /* New pid namespace */
  28. #define CLONE_NEWNET 0x40000000 /* New network namespace */
  29. #define CLONE_IO 0x80000000 /* Clone io context */
  30. /*
  31. * Scheduling policies
  32. */
  33. #define SCHED_NORMAL 0
  34. #define SCHED_FIFO 1
  35. #define SCHED_RR 2
  36. #define SCHED_BATCH 3
  37. /* SCHED_ISO: reserved but not implemented yet */
  38. #define SCHED_IDLE 5
  39. /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
  40. #define SCHED_RESET_ON_FORK 0x40000000
  41. #ifdef __KERNEL__
  42. struct sched_param {
  43. int sched_priority;
  44. };
  45. #include <asm/param.h> /* for HZ */
  46. #include <linux/capability.h>
  47. #include <linux/threads.h>
  48. #include <linux/kernel.h>
  49. #include <linux/types.h>
  50. #include <linux/timex.h>
  51. #include <linux/jiffies.h>
  52. #include <linux/rbtree.h>
  53. #include <linux/thread_info.h>
  54. #include <linux/cpumask.h>
  55. #include <linux/errno.h>
  56. #include <linux/nodemask.h>
  57. #include <linux/mm_types.h>
  58. #include <asm/system.h>
  59. #include <asm/page.h>
  60. #include <asm/ptrace.h>
  61. #include <asm/cputime.h>
  62. #include <linux/smp.h>
  63. #include <linux/sem.h>
  64. #include <linux/signal.h>
  65. #include <linux/path.h>
  66. #include <linux/compiler.h>
  67. #include <linux/completion.h>
  68. #include <linux/pid.h>
  69. #include <linux/percpu.h>
  70. #include <linux/topology.h>
  71. #include <linux/proportions.h>
  72. #include <linux/seccomp.h>
  73. #include <linux/rcupdate.h>
  74. #include <linux/rculist.h>
  75. #include <linux/rtmutex.h>
  76. #include <linux/time.h>
  77. #include <linux/param.h>
  78. #include <linux/resource.h>
  79. #include <linux/timer.h>
  80. #include <linux/hrtimer.h>
  81. #include <linux/task_io_accounting.h>
  82. #include <linux/kobject.h>
  83. #include <linux/latencytop.h>
  84. #include <linux/cred.h>
  85. #include <asm/processor.h>
  86. struct mem_cgroup;
  87. struct exec_domain;
  88. struct futex_pi_state;
  89. struct robust_list_head;
  90. struct bio;
  91. struct fs_struct;
  92. struct bts_context;
  93. struct perf_counter_context;
  94. /*
  95. * List of flags we want to share for kernel threads,
  96. * if only because they are not used by them anyway.
  97. */
  98. #define CLONE_KERNEL (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
  99. /*
  100. * These are the constant used to fake the fixed-point load-average
  101. * counting. Some notes:
  102. * - 11 bit fractions expand to 22 bits by the multiplies: this gives
  103. * a load-average precision of 10 bits integer + 11 bits fractional
  104. * - if you want to count load-averages more often, you need more
  105. * precision, or rounding will get you. With 2-second counting freq,
  106. * the EXP_n values would be 1981, 2034 and 2043 if still using only
  107. * 11 bit fractions.
  108. */
  109. extern unsigned long avenrun[]; /* Load averages */
  110. extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
  111. #define FSHIFT 11 /* nr of bits of precision */
  112. #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
  113. #define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */
  114. #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
  115. #define EXP_5 2014 /* 1/exp(5sec/5min) */
  116. #define EXP_15 2037 /* 1/exp(5sec/15min) */
  117. #define CALC_LOAD(load,exp,n) \
  118. load *= exp; \
  119. load += n*(FIXED_1-exp); \
  120. load >>= FSHIFT;
  121. extern unsigned long total_forks;
  122. extern int nr_threads;
  123. DECLARE_PER_CPU(unsigned long, process_counts);
  124. extern int nr_processes(void);
  125. extern unsigned long nr_running(void);
  126. extern unsigned long nr_uninterruptible(void);
  127. extern unsigned long nr_iowait(void);
  128. extern void calc_global_load(void);
  129. extern u64 cpu_nr_migrations(int cpu);
  130. extern unsigned long get_parent_ip(unsigned long addr);
  131. struct seq_file;
  132. struct cfs_rq;
  133. struct task_group;
  134. #ifdef CONFIG_SCHED_DEBUG
  135. extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
  136. extern void proc_sched_set_task(struct task_struct *p);
  137. extern void
  138. print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
  139. #else
  140. static inline void
  141. proc_sched_show_task(struct task_struct *p, struct seq_file *m)
  142. {
  143. }
  144. static inline void proc_sched_set_task(struct task_struct *p)
  145. {
  146. }
  147. static inline void
  148. print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
  149. {
  150. }
  151. #endif
  152. extern unsigned long long time_sync_thresh;
  153. /*
  154. * Task state bitmask. NOTE! These bits are also
  155. * encoded in fs/proc/array.c: get_task_state().
  156. *
  157. * We have two separate sets of flags: task->state
  158. * is about runnability, while task->exit_state are
  159. * about the task exiting. Confusing, but this way
  160. * modifying one set can't modify the other one by
  161. * mistake.
  162. */
  163. #define TASK_RUNNING 0
  164. #define TASK_INTERRUPTIBLE 1
  165. #define TASK_UNINTERRUPTIBLE 2
  166. #define __TASK_STOPPED 4
  167. #define __TASK_TRACED 8
  168. /* in tsk->exit_state */
  169. #define EXIT_ZOMBIE 16
  170. #define EXIT_DEAD 32
  171. /* in tsk->state again */
  172. #define TASK_DEAD 64
  173. #define TASK_WAKEKILL 128
  174. /* Convenience macros for the sake of set_task_state */
  175. #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
  176. #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
  177. #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)
  178. /* Convenience macros for the sake of wake_up */
  179. #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
  180. #define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
  181. /* get_task_state() */
  182. #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \
  183. TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
  184. __TASK_TRACED)
  185. #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
  186. #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
  187. #define task_is_stopped_or_traced(task) \
  188. ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
  189. #define task_contributes_to_load(task) \
  190. ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
  191. (task->flags & PF_FROZEN) == 0)
  192. #define __set_task_state(tsk, state_value) \
  193. do { (tsk)->state = (state_value); } while (0)
  194. #define set_task_state(tsk, state_value) \
  195. set_mb((tsk)->state, (state_value))
  196. /*
  197. * set_current_state() includes a barrier so that the write of current->state
  198. * is correctly serialised wrt the caller's subsequent test of whether to
  199. * actually sleep:
  200. *
  201. * set_current_state(TASK_UNINTERRUPTIBLE);
  202. * if (do_i_need_to_sleep())
  203. * schedule();
  204. *
  205. * If the caller does not need such serialisation then use __set_current_state()
  206. */
  207. #define __set_current_state(state_value) \
  208. do { current->state = (state_value); } while (0)
  209. #define set_current_state(state_value) \
  210. set_mb(current->state, (state_value))
  211. /* Task command name length */
  212. #define TASK_COMM_LEN 16
  213. #include <linux/spinlock.h>
  214. /*
  215. * This serializes "schedule()" and also protects
  216. * the run-queue from deletions/modifications (but
  217. * _adding_ to the beginning of the run-queue has
  218. * a separate lock).
  219. */
  220. extern rwlock_t tasklist_lock;
  221. extern spinlock_t mmlist_lock;
  222. struct task_struct;
  223. extern void sched_init(void);
  224. extern void sched_init_smp(void);
  225. extern asmlinkage void schedule_tail(struct task_struct *prev);
  226. extern void init_idle(struct task_struct *idle, int cpu);
  227. extern void init_idle_bootup_task(struct task_struct *idle);
  228. extern int runqueue_is_locked(void);
  229. extern void task_rq_unlock_wait(struct task_struct *p);
  230. extern cpumask_var_t nohz_cpu_mask;
  231. #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
  232. extern int select_nohz_load_balancer(int cpu);
  233. #else
  234. static inline int select_nohz_load_balancer(int cpu)
  235. {
  236. return 0;
  237. }
  238. #endif
  239. /*
  240. * Only dump TASK_* tasks. (0 for all tasks)
  241. */
  242. extern void show_state_filter(unsigned long state_filter);
  243. static inline void show_state(void)
  244. {
  245. show_state_filter(0);
  246. }
  247. extern void show_regs(struct pt_regs *);
  248. /*
  249. * TASK is a pointer to the task whose backtrace we want to see (or NULL for current
  250. * task), SP is the stack pointer of the first frame that should be shown in the back
  251. * trace (or NULL if the entire call-chain of the task should be shown).
  252. */
  253. extern void show_stack(struct task_struct *task, unsigned long *sp);
  254. void io_schedule(void);
  255. long io_schedule_timeout(long timeout);
  256. extern void cpu_init (void);
  257. extern void trap_init(void);
  258. extern void update_process_times(int user);
  259. extern void scheduler_tick(void);
  260. extern void sched_show_task(struct task_struct *p);
  261. #ifdef CONFIG_DETECT_SOFTLOCKUP
  262. extern void softlockup_tick(void);
  263. extern void touch_softlockup_watchdog(void);
  264. extern void touch_all_softlockup_watchdogs(void);
  265. extern int proc_dosoftlockup_thresh(struct ctl_table *table, int write,
  266. struct file *filp, void __user *buffer,
  267. size_t *lenp, loff_t *ppos);
  268. extern unsigned int softlockup_panic;
  269. extern int softlockup_thresh;
  270. #else
  271. static inline void softlockup_tick(void)
  272. {
  273. }
  274. static inline void touch_softlockup_watchdog(void)
  275. {
  276. }
  277. static inline void touch_all_softlockup_watchdogs(void)
  278. {
  279. }
  280. #endif
  281. #ifdef CONFIG_DETECT_HUNG_TASK
  282. extern unsigned int sysctl_hung_task_panic;
  283. extern unsigned long sysctl_hung_task_check_count;
  284. extern unsigned long sysctl_hung_task_timeout_secs;
  285. extern unsigned long sysctl_hung_task_warnings;
  286. extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
  287. struct file *filp, void __user *buffer,
  288. size_t *lenp, loff_t *ppos);
  289. #endif
  290. /* Attach to any functions which should be ignored in wchan output. */
  291. #define __sched __attribute__((__section__(".sched.text")))
  292. /* Linker adds these: start and end of __sched functions */
  293. extern char __sched_text_start[], __sched_text_end[];
  294. /* Is this address in the __sched functions? */
  295. extern int in_sched_functions(unsigned long addr);
  296. #define MAX_SCHEDULE_TIMEOUT LONG_MAX
  297. extern signed long schedule_timeout(signed long timeout);
  298. extern signed long schedule_timeout_interruptible(signed long timeout);
  299. extern signed long schedule_timeout_killable(signed long timeout);
  300. extern signed long schedule_timeout_uninterruptible(signed long timeout);
  301. asmlinkage void __schedule(void);
  302. asmlinkage void schedule(void);
  303. extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
  304. struct nsproxy;
  305. struct user_namespace;
  306. /* Maximum number of active map areas.. This is a random (large) number */
  307. #define DEFAULT_MAX_MAP_COUNT 65536
  308. extern int sysctl_max_map_count;
  309. #include <linux/aio.h>
  310. extern unsigned long
  311. arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
  312. unsigned long, unsigned long);
  313. extern unsigned long
  314. arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
  315. unsigned long len, unsigned long pgoff,
  316. unsigned long flags);
  317. extern void arch_unmap_area(struct mm_struct *, unsigned long);
  318. extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
  319. #if USE_SPLIT_PTLOCKS
  320. /*
  321. * The mm counters are not protected by its page_table_lock,
  322. * so must be incremented atomically.
  323. */
  324. #define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
  325. #define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
  326. #define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
  327. #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
  328. #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
  329. #else /* !USE_SPLIT_PTLOCKS */
  330. /*
  331. * The mm counters are protected by its page_table_lock,
  332. * so can be incremented directly.
  333. */
  334. #define set_mm_counter(mm, member, value) (mm)->_##member = (value)
  335. #define get_mm_counter(mm, member) ((mm)->_##member)
  336. #define add_mm_counter(mm, member, value) (mm)->_##member += (value)
  337. #define inc_mm_counter(mm, member) (mm)->_##member++
  338. #define dec_mm_counter(mm, member) (mm)->_##member--
  339. #endif /* !USE_SPLIT_PTLOCKS */
  340. #define get_mm_rss(mm) \
  341. (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
  342. #define update_hiwater_rss(mm) do { \
  343. unsigned long _rss = get_mm_rss(mm); \
  344. if ((mm)->hiwater_rss < _rss) \
  345. (mm)->hiwater_rss = _rss; \
  346. } while (0)
  347. #define update_hiwater_vm(mm) do { \
  348. if ((mm)->hiwater_vm < (mm)->total_vm) \
  349. (mm)->hiwater_vm = (mm)->total_vm; \
  350. } while (0)
  351. static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)
  352. {
  353. return max(mm->hiwater_rss, get_mm_rss(mm));
  354. }
  355. static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm)
  356. {
  357. return max(mm->hiwater_vm, mm->total_vm);
  358. }
  359. extern void set_dumpable(struct mm_struct *mm, int value);
  360. extern int get_dumpable(struct mm_struct *mm);
  361. /* mm flags */
  362. /* dumpable bits */
  363. #define MMF_DUMPABLE 0 /* core dump is permitted */
  364. #define MMF_DUMP_SECURELY 1 /* core file is readable only by root */
  365. #define MMF_DUMPABLE_BITS 2
  366. /* coredump filter bits */
  367. #define MMF_DUMP_ANON_PRIVATE 2
  368. #define MMF_DUMP_ANON_SHARED 3
  369. #define MMF_DUMP_MAPPED_PRIVATE 4
  370. #define MMF_DUMP_MAPPED_SHARED 5
  371. #define MMF_DUMP_ELF_HEADERS 6
  372. #define MMF_DUMP_HUGETLB_PRIVATE 7
  373. #define MMF_DUMP_HUGETLB_SHARED 8
  374. #define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS
  375. #define MMF_DUMP_FILTER_BITS 7
  376. #define MMF_DUMP_FILTER_MASK \
  377. (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
  378. #define MMF_DUMP_FILTER_DEFAULT \
  379. ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\
  380. (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
  381. #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
  382. # define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS)
  383. #else
  384. # define MMF_DUMP_MASK_DEFAULT_ELF 0
  385. #endif
  386. struct sighand_struct {
  387. atomic_t count;
  388. struct k_sigaction action[_NSIG];
  389. spinlock_t siglock;
  390. wait_queue_head_t signalfd_wqh;
  391. };
  392. struct pacct_struct {
  393. int ac_flag;
  394. long ac_exitcode;
  395. unsigned long ac_mem;
  396. cputime_t ac_utime, ac_stime;
  397. unsigned long ac_minflt, ac_majflt;
  398. };
  399. /**
  400. * struct task_cputime - collected CPU time counts
  401. * @utime: time spent in user mode, in &cputime_t units
  402. * @stime: time spent in kernel mode, in &cputime_t units
  403. * @sum_exec_runtime: total time spent on the CPU, in nanoseconds
  404. *
  405. * This structure groups together three kinds of CPU time that are
  406. * tracked for threads and thread groups. Most things considering
  407. * CPU time want to group these counts together and treat all three
  408. * of them in parallel.
  409. */
  410. struct task_cputime {
  411. cputime_t utime;
  412. cputime_t stime;
  413. unsigned long long sum_exec_runtime;
  414. };
  415. /* Alternate field names when used to cache expirations. */
  416. #define prof_exp stime
  417. #define virt_exp utime
  418. #define sched_exp sum_exec_runtime
  419. #define INIT_CPUTIME \
  420. (struct task_cputime) { \
  421. .utime = cputime_zero, \
  422. .stime = cputime_zero, \
  423. .sum_exec_runtime = 0, \
  424. }
  425. /**
  426. * struct thread_group_cputimer - thread group interval timer counts
  427. * @cputime: thread group interval timers.
  428. * @running: non-zero when there are timers running and
  429. * @cputime receives updates.
  430. * @lock: lock for fields in this struct.
  431. *
  432. * This structure contains the version of task_cputime, above, that is
  433. * used for thread group CPU timer calculations.
  434. */
  435. struct thread_group_cputimer {
  436. struct task_cputime cputime;
  437. int running;
  438. spinlock_t lock;
  439. };
  440. /*
  441. * NOTE! "signal_struct" does not have it's own
  442. * locking, because a shared signal_struct always
  443. * implies a shared sighand_struct, so locking
  444. * sighand_struct is always a proper superset of
  445. * the locking of signal_struct.
  446. */
  447. struct signal_struct {
  448. atomic_t count;
  449. atomic_t live;
  450. wait_queue_head_t wait_chldexit; /* for wait4() */
  451. /* current thread group signal load-balancing target: */
  452. struct task_struct *curr_target;
  453. /* shared signal handling: */
  454. struct sigpending shared_pending;
  455. /* thread group exit support */
  456. int group_exit_code;
  457. /* overloaded:
  458. * - notify group_exit_task when ->count is equal to notify_count
  459. * - everyone except group_exit_task is stopped during signal delivery
  460. * of fatal signals, group_exit_task processes the signal.
  461. */
  462. int notify_count;
  463. struct task_struct *group_exit_task;
  464. /* thread group stop support, overloads group_exit_code too */
  465. int group_stop_count;
  466. unsigned int flags; /* see SIGNAL_* flags below */
  467. /* POSIX.1b Interval Timers */
  468. struct list_head posix_timers;
  469. /* ITIMER_REAL timer for the process */
  470. struct hrtimer real_timer;
  471. struct pid *leader_pid;
  472. ktime_t it_real_incr;
  473. /* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
  474. cputime_t it_prof_expires, it_virt_expires;
  475. cputime_t it_prof_incr, it_virt_incr;
  476. /*
  477. * Thread group totals for process CPU timers.
  478. * See thread_group_cputimer(), et al, for details.
  479. */
  480. struct thread_group_cputimer cputimer;
  481. /* Earliest-expiration cache. */
  482. struct task_cputime cputime_expires;
  483. struct list_head cpu_timers[3];
  484. struct pid *tty_old_pgrp;
  485. /* boolean value for session group leader */
  486. int leader;
  487. struct tty_struct *tty; /* NULL if no tty */
  488. /*
  489. * Cumulative resource counters for dead threads in the group,
  490. * and for reaped dead child processes forked by this group.
  491. * Live threads maintain their own counters and add to these
  492. * in __exit_signal, except for the group leader.
  493. */
  494. cputime_t utime, stime, cutime, cstime;
  495. cputime_t gtime;
  496. cputime_t cgtime;
  497. unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
  498. unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
  499. unsigned long inblock, oublock, cinblock, coublock;
  500. struct task_io_accounting ioac;
  501. /*
  502. * Cumulative ns of schedule CPU time fo dead threads in the
  503. * group, not including a zombie group leader, (This only differs
  504. * from jiffies_to_ns(utime + stime) if sched_clock uses something
  505. * other than jiffies.)
  506. */
  507. unsigned long long sum_sched_runtime;
  508. /*
  509. * We don't bother to synchronize most readers of this at all,
  510. * because there is no reader checking a limit that actually needs
  511. * to get both rlim_cur and rlim_max atomically, and either one
  512. * alone is a single word that can safely be read normally.
  513. * getrlimit/setrlimit use task_lock(current->group_leader) to
  514. * protect this instead of the siglock, because they really
  515. * have no need to disable irqs.
  516. */
  517. struct rlimit rlim[RLIM_NLIMITS];
  518. #ifdef CONFIG_BSD_PROCESS_ACCT
  519. struct pacct_struct pacct; /* per-process accounting information */
  520. #endif
  521. #ifdef CONFIG_TASKSTATS
  522. struct taskstats *stats;
  523. #endif
  524. #ifdef CONFIG_AUDIT
  525. unsigned audit_tty;
  526. struct tty_audit_buf *tty_audit_buf;
  527. #endif
  528. };
  529. /* Context switch must be unlocked if interrupts are to be enabled */
  530. #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
  531. # define __ARCH_WANT_UNLOCKED_CTXSW
  532. #endif
  533. /*
  534. * Bits in flags field of signal_struct.
  535. */
  536. #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */
  537. #define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */
  538. #define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */
  539. #define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */
  540. /*
  541. * Pending notifications to parent.
  542. */
  543. #define SIGNAL_CLD_STOPPED 0x00000010
  544. #define SIGNAL_CLD_CONTINUED 0x00000020
  545. #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
  546. #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */
  547. /* If true, all threads except ->group_exit_task have pending SIGKILL */
  548. static inline int signal_group_exit(const struct signal_struct *sig)
  549. {
  550. return (sig->flags & SIGNAL_GROUP_EXIT) ||
  551. (sig->group_exit_task != NULL);
  552. }
  553. /*
  554. * Some day this will be a full-fledged user tracking system..
  555. */
  556. struct user_struct {
  557. atomic_t __count; /* reference count */
  558. atomic_t processes; /* How many processes does this user have? */
  559. atomic_t files; /* How many open files does this user have? */
  560. atomic_t sigpending; /* How many pending signals does this user have? */
  561. #ifdef CONFIG_INOTIFY_USER
  562. atomic_t inotify_watches; /* How many inotify watches does this user have? */
  563. atomic_t inotify_devs; /* How many inotify devs does this user have opened? */
  564. #endif
  565. #ifdef CONFIG_EPOLL
  566. atomic_t epoll_watches; /* The number of file descriptors currently watched */
  567. #endif
  568. #ifdef CONFIG_POSIX_MQUEUE
  569. /* protected by mq_lock */
  570. unsigned long mq_bytes; /* How many bytes can be allocated to mqueue? */
  571. #endif
  572. unsigned long locked_shm; /* How many pages of mlocked shm ? */
  573. #ifdef CONFIG_KEYS
  574. struct key *uid_keyring; /* UID specific keyring */
  575. struct key *session_keyring; /* UID's default session keyring */
  576. #endif
  577. /* Hash table maintenance information */
  578. struct hlist_node uidhash_node;
  579. uid_t uid;
  580. struct user_namespace *user_ns;
  581. #ifdef CONFIG_USER_SCHED
  582. struct task_group *tg;
  583. #ifdef CONFIG_SYSFS
  584. struct kobject kobj;
  585. struct work_struct work;
  586. #endif
  587. #endif
  588. #ifdef CONFIG_PERF_COUNTERS
  589. atomic_long_t locked_vm;
  590. #endif
  591. };
  592. extern int uids_sysfs_init(void);
  593. extern struct user_struct *find_user(uid_t);
  594. extern struct user_struct root_user;
  595. #define INIT_USER (&root_user)
  596. struct backing_dev_info;
  597. struct reclaim_state;
  598. #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
  599. struct sched_info {
  600. /* cumulative counters */
  601. unsigned long pcount; /* # of times run on this cpu */
  602. unsigned long long run_delay; /* time spent waiting on a runqueue */
  603. /* timestamps */
  604. unsigned long long last_arrival,/* when we last ran on a cpu */
  605. last_queued; /* when we were last queued to run */
  606. #ifdef CONFIG_SCHEDSTATS
  607. /* BKL stats */
  608. unsigned int bkl_count;
  609. #endif
  610. };
  611. #endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
  612. #ifdef CONFIG_TASK_DELAY_ACCT
  613. struct task_delay_info {
  614. spinlock_t lock;
  615. unsigned int flags; /* Private per-task flags */
  616. /* For each stat XXX, add following, aligned appropriately
  617. *
  618. * struct timespec XXX_start, XXX_end;
  619. * u64 XXX_delay;
  620. * u32 XXX_count;
  621. *
  622. * Atomicity of updates to XXX_delay, XXX_count protected by
  623. * single lock above (split into XXX_lock if contention is an issue).
  624. */
  625. /*
  626. * XXX_count is incremented on every XXX operation, the delay
  627. * associated with the operation is added to XXX_delay.
  628. * XXX_delay contains the accumulated delay time in nanoseconds.
  629. */
  630. struct timespec blkio_start, blkio_end; /* Shared by blkio, swapin */
  631. u64 blkio_delay; /* wait for sync block io completion */
  632. u64 swapin_delay; /* wait for swapin block io completion */
  633. u32 blkio_count; /* total count of the number of sync block */
  634. /* io operations performed */
  635. u32 swapin_count; /* total count of the number of swapin block */
  636. /* io operations performed */
  637. struct timespec freepages_start, freepages_end;
  638. u64 freepages_delay; /* wait for memory reclaim */
  639. u32 freepages_count; /* total count of memory reclaim */
  640. };
  641. #endif /* CONFIG_TASK_DELAY_ACCT */
  642. static inline int sched_info_on(void)
  643. {
  644. #ifdef CONFIG_SCHEDSTATS
  645. return 1;
  646. #elif defined(CONFIG_TASK_DELAY_ACCT)
  647. extern int delayacct_on;
  648. return delayacct_on;
  649. #else
  650. return 0;
  651. #endif
  652. }
  653. enum cpu_idle_type {
  654. CPU_IDLE,
  655. CPU_NOT_IDLE,
  656. CPU_NEWLY_IDLE,
  657. CPU_MAX_IDLE_TYPES
  658. };
  659. /*
  660. * sched-domains (multiprocessor balancing) declarations:
  661. */
  662. /*
  663. * Increase resolution of nice-level calculations:
  664. */
  665. #define SCHED_LOAD_SHIFT 10
  666. #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
  667. #define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE
  668. #ifdef CONFIG_SMP
  669. #define SD_LOAD_BALANCE 1 /* Do load balancing on this domain. */
  670. #define SD_BALANCE_NEWIDLE 2 /* Balance when about to become idle */
  671. #define SD_BALANCE_EXEC 4 /* Balance on exec */
  672. #define SD_BALANCE_FORK 8 /* Balance on fork, clone */
  673. #define SD_WAKE_IDLE 16 /* Wake to idle CPU on task wakeup */
  674. #define SD_WAKE_AFFINE 32 /* Wake task to waking CPU */
  675. #define SD_WAKE_BALANCE 64 /* Perform balancing at task wakeup */
  676. #define SD_SHARE_CPUPOWER 128 /* Domain members share cpu power */
  677. #define SD_POWERSAVINGS_BALANCE 256 /* Balance for power savings */
  678. #define SD_SHARE_PKG_RESOURCES 512 /* Domain members share cpu pkg resources */
  679. #define SD_SERIALIZE 1024 /* Only a single load balancing instance */
  680. #define SD_WAKE_IDLE_FAR 2048 /* Gain latency sacrificing cache hit */
  681. enum powersavings_balance_level {
  682. POWERSAVINGS_BALANCE_NONE = 0, /* No power saving load balance */
  683. POWERSAVINGS_BALANCE_BASIC, /* Fill one thread/core/package
  684. * first for long running threads
  685. */
  686. POWERSAVINGS_BALANCE_WAKEUP, /* Also bias task wakeups to semi-idle
  687. * cpu package for power savings
  688. */
  689. MAX_POWERSAVINGS_BALANCE_LEVELS
  690. };
  691. extern int sched_mc_power_savings, sched_smt_power_savings;
  692. static inline int sd_balance_for_mc_power(void)
  693. {
  694. if (sched_smt_power_savings)
  695. return SD_POWERSAVINGS_BALANCE;
  696. return 0;
  697. }
  698. static inline int sd_balance_for_package_power(void)
  699. {
  700. if (sched_mc_power_savings | sched_smt_power_savings)
  701. return SD_POWERSAVINGS_BALANCE;
  702. return 0;
  703. }
  704. /*
  705. * Optimise SD flags for power savings:
  706. * SD_BALANCE_NEWIDLE helps agressive task consolidation and power savings.
  707. * Keep default SD flags if sched_{smt,mc}_power_saving=0
  708. */
  709. static inline int sd_power_saving_flags(void)
  710. {
  711. if (sched_mc_power_savings | sched_smt_power_savings)
  712. return SD_BALANCE_NEWIDLE;
  713. return 0;
  714. }
  715. struct sched_group {
  716. struct sched_group *next; /* Must be a circular list */
  717. /*
  718. * CPU power of this group, SCHED_LOAD_SCALE being max power for a
  719. * single CPU. This is read only (except for setup, hotplug CPU).
  720. * Note : Never change cpu_power without recompute its reciprocal
  721. */
  722. unsigned int __cpu_power;
  723. /*
  724. * reciprocal value of cpu_power to avoid expensive divides
  725. * (see include/linux/reciprocal_div.h)
  726. */
  727. u32 reciprocal_cpu_power;
  728. /*
  729. * The CPUs this group covers.
  730. *
  731. * NOTE: this field is variable length. (Allocated dynamically
  732. * by attaching extra space to the end of the structure,
  733. * depending on how many CPUs the kernel has booted up with)
  734. *
  735. * It is also be embedded into static data structures at build
  736. * time. (See 'struct static_sched_group' in kernel/sched.c)
  737. */
  738. unsigned long cpumask[0];
  739. };
  740. static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
  741. {
  742. return to_cpumask(sg->cpumask);
  743. }
  744. enum sched_domain_level {
  745. SD_LV_NONE = 0,
  746. SD_LV_SIBLING,
  747. SD_LV_MC,
  748. SD_LV_CPU,
  749. SD_LV_NODE,
  750. SD_LV_ALLNODES,
  751. SD_LV_MAX
  752. };
  753. struct sched_domain_attr {
  754. int relax_domain_level;
  755. };
  756. #define SD_ATTR_INIT (struct sched_domain_attr) { \
  757. .relax_domain_level = -1, \
  758. }
  759. struct sched_domain {
  760. /* These fields must be setup */
  761. struct sched_domain *parent; /* top domain must be null terminated */
  762. struct sched_domain *child; /* bottom domain must be null terminated */
  763. struct sched_group *groups; /* the balancing groups of the domain */
  764. unsigned long min_interval; /* Minimum balance interval ms */
  765. unsigned long max_interval; /* Maximum balance interval ms */
  766. unsigned int busy_factor; /* less balancing by factor if busy */
  767. unsigned int imbalance_pct; /* No balance until over watermark */
  768. unsigned int cache_nice_tries; /* Leave cache hot tasks for # tries */
  769. unsigned int busy_idx;
  770. unsigned int idle_idx;
  771. unsigned int newidle_idx;
  772. unsigned int wake_idx;
  773. unsigned int forkexec_idx;
  774. int flags; /* See SD_* */
  775. enum sched_domain_level level;
  776. /* Runtime fields. */
  777. unsigned long last_balance; /* init to jiffies. units in jiffies */
  778. unsigned int balance_interval; /* initialise to 1. units in ms. */
  779. unsigned int nr_balance_failed; /* initialise to 0 */
  780. u64 last_update;
  781. #ifdef CONFIG_SCHEDSTATS
  782. /* load_balance() stats */
  783. unsigned int lb_count[CPU_MAX_IDLE_TYPES];
  784. unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
  785. unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
  786. unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
  787. unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
  788. unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
  789. unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
  790. unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
  791. /* Active load balancing */
  792. unsigned int alb_count;
  793. unsigned int alb_failed;
  794. unsigned int alb_pushed;
  795. /* SD_BALANCE_EXEC stats */
  796. unsigned int sbe_count;
  797. unsigned int sbe_balanced;
  798. unsigned int sbe_pushed;
  799. /* SD_BALANCE_FORK stats */
  800. unsigned int sbf_count;
  801. unsigned int sbf_balanced;
  802. unsigned int sbf_pushed;
  803. /* try_to_wake_up() stats */
  804. unsigned int ttwu_wake_remote;
  805. unsigned int ttwu_move_affine;
  806. unsigned int ttwu_move_balance;
  807. #endif
  808. #ifdef CONFIG_SCHED_DEBUG
  809. char *name;
  810. #endif
  811. /*
  812. * Span of all CPUs in this domain.
  813. *
  814. * NOTE: this field is variable length. (Allocated dynamically
  815. * by attaching extra space to the end of the structure,
  816. * depending on how many CPUs the kernel has booted up with)
  817. *
  818. * It is also be embedded into static data structures at build
  819. * time. (See 'struct static_sched_domain' in kernel/sched.c)
  820. */
  821. unsigned long span[0];
  822. };
  823. static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
  824. {
  825. return to_cpumask(sd->span);
  826. }
  827. extern void partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
  828. struct sched_domain_attr *dattr_new);
  829. /* Test a flag in parent sched domain */
  830. static inline int test_sd_parent(struct sched_domain *sd, int flag)
  831. {
  832. if (sd->parent && (sd->parent->flags & flag))
  833. return 1;
  834. return 0;
  835. }
  836. #else /* CONFIG_SMP */
  837. struct sched_domain_attr;
  838. static inline void
  839. partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
  840. struct sched_domain_attr *dattr_new)
  841. {
  842. }
  843. #endif /* !CONFIG_SMP */
  844. struct io_context; /* See blkdev.h */
  845. #ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
  846. extern void prefetch_stack(struct task_struct *t);
  847. #else
  848. static inline void prefetch_stack(struct task_struct *t) { }
  849. #endif
  850. struct audit_context; /* See audit.c */
  851. struct mempolicy;
  852. struct pipe_inode_info;
  853. struct uts_namespace;
  854. struct rq;
  855. struct sched_domain;
  856. struct sched_class {
  857. const struct sched_class *next;
  858. void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup);
  859. void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
  860. void (*yield_task) (struct rq *rq);
  861. void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int sync);
  862. struct task_struct * (*pick_next_task) (struct rq *rq);
  863. void (*put_prev_task) (struct rq *rq, struct task_struct *p);
  864. #ifdef CONFIG_SMP
  865. int (*select_task_rq)(struct task_struct *p, int sync);
  866. unsigned long (*load_balance) (struct rq *this_rq, int this_cpu,
  867. struct rq *busiest, unsigned long max_load_move,
  868. struct sched_domain *sd, enum cpu_idle_type idle,
  869. int *all_pinned, int *this_best_prio);
  870. int (*move_one_task) (struct rq *this_rq, int this_cpu,
  871. struct rq *busiest, struct sched_domain *sd,
  872. enum cpu_idle_type idle);
  873. void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
  874. int (*needs_post_schedule) (struct rq *this_rq);
  875. void (*post_schedule) (struct rq *this_rq);
  876. void (*task_wake_up) (struct rq *this_rq, struct task_struct *task);
  877. void (*set_cpus_allowed)(struct task_struct *p,
  878. const struct cpumask *newmask);
  879. void (*rq_online)(struct rq *rq);
  880. void (*rq_offline)(struct rq *rq);
  881. #endif
  882. void (*set_curr_task) (struct rq *rq);
  883. void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
  884. void (*task_new) (struct rq *rq, struct task_struct *p);
  885. void (*switched_from) (struct rq *this_rq, struct task_struct *task,
  886. int running);
  887. void (*switched_to) (struct rq *this_rq, struct task_struct *task,
  888. int running);
  889. void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
  890. int oldprio, int running);
  891. #ifdef CONFIG_FAIR_GROUP_SCHED
  892. void (*moved_group) (struct task_struct *p);
  893. #endif
  894. };
  895. struct load_weight {
  896. unsigned long weight, inv_weight;
  897. };
  898. /*
  899. * CFS stats for a schedulable entity (task, task-group etc)
  900. *
  901. * Current field usage histogram:
  902. *
  903. * 4 se->block_start
  904. * 4 se->run_node
  905. * 4 se->sleep_start
  906. * 6 se->load.weight
  907. */
  908. struct sched_entity {
  909. struct load_weight load; /* for load-balancing */
  910. struct rb_node run_node;
  911. struct list_head group_node;
  912. unsigned int on_rq;
  913. u64 exec_start;
  914. u64 sum_exec_runtime;
  915. u64 vruntime;
  916. u64 prev_sum_exec_runtime;
  917. u64 last_wakeup;
  918. u64 avg_overlap;
  919. u64 nr_migrations;
  920. u64 start_runtime;
  921. u64 avg_wakeup;
  922. #ifdef CONFIG_SCHEDSTATS
  923. u64 wait_start;
  924. u64 wait_max;
  925. u64 wait_count;
  926. u64 wait_sum;
  927. u64 sleep_start;
  928. u64 sleep_max;
  929. s64 sum_sleep_runtime;
  930. u64 block_start;
  931. u64 block_max;
  932. u64 exec_max;
  933. u64 slice_max;
  934. u64 nr_migrations_cold;
  935. u64 nr_failed_migrations_affine;
  936. u64 nr_failed_migrations_running;
  937. u64 nr_failed_migrations_hot;
  938. u64 nr_forced_migrations;
  939. u64 nr_forced2_migrations;
  940. u64 nr_wakeups;
  941. u64 nr_wakeups_sync;
  942. u64 nr_wakeups_migrate;
  943. u64 nr_wakeups_local;
  944. u64 nr_wakeups_remote;
  945. u64 nr_wakeups_affine;
  946. u64 nr_wakeups_affine_attempts;
  947. u64 nr_wakeups_passive;
  948. u64 nr_wakeups_idle;
  949. #endif
  950. #ifdef CONFIG_FAIR_GROUP_SCHED
  951. struct sched_entity *parent;
  952. /* rq on which this entity is (to be) queued: */
  953. struct cfs_rq *cfs_rq;
  954. /* rq "owned" by this entity/group: */
  955. struct cfs_rq *my_q;
  956. #endif
  957. };
  958. struct sched_rt_entity {
  959. struct list_head run_list;
  960. unsigned long timeout;
  961. unsigned int time_slice;
  962. int nr_cpus_allowed;
  963. struct sched_rt_entity *back;
  964. #ifdef CONFIG_RT_GROUP_SCHED
  965. struct sched_rt_entity *parent;
  966. /* rq on which this entity is (to be) queued: */
  967. struct rt_rq *rt_rq;
  968. /* rq "owned" by this entity/group: */
  969. struct rt_rq *my_q;
  970. #endif
  971. };
  972. struct task_struct {
  973. volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
  974. void *stack;
  975. atomic_t usage;
  976. unsigned int flags; /* per process flags, defined below */
  977. unsigned int ptrace;
  978. int lock_depth; /* BKL lock depth */
  979. #ifdef CONFIG_SMP
  980. #ifdef __ARCH_WANT_UNLOCKED_CTXSW
  981. int oncpu;
  982. #endif
  983. #endif
  984. int prio, static_prio, normal_prio;
  985. unsigned int rt_priority;
  986. const struct sched_class *sched_class;
  987. struct sched_entity se;
  988. struct sched_rt_entity rt;
  989. #ifdef CONFIG_PREEMPT_NOTIFIERS
  990. /* list of struct preempt_notifier: */
  991. struct hlist_head preempt_notifiers;
  992. #endif
  993. /*
  994. * fpu_counter contains the number of consecutive context switches
  995. * that the FPU is used. If this is over a threshold, the lazy fpu
  996. * saving becomes unlazy to save the trap. This is an unsigned char
  997. * so that after 256 times the counter wraps and the behavior turns
  998. * lazy again; this to deal with bursty apps that only use FPU for
  999. * a short time
  1000. */
  1001. unsigned char fpu_counter;
  1002. s8 oomkilladj; /* OOM kill score adjustment (bit shift). */
  1003. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1004. unsigned int btrace_seq;
  1005. #endif
  1006. unsigned int policy;
  1007. cpumask_t cpus_allowed;
  1008. #ifdef CONFIG_PREEMPT_RCU
  1009. int rcu_read_lock_nesting;
  1010. int rcu_flipctr_idx;
  1011. #endif /* #ifdef CONFIG_PREEMPT_RCU */
  1012. #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
  1013. struct sched_info sched_info;
  1014. #endif
  1015. struct list_head tasks;
  1016. struct plist_node pushable_tasks;
  1017. struct mm_struct *mm, *active_mm;
  1018. /* task state */
  1019. struct linux_binfmt *binfmt;
  1020. int exit_state;
  1021. int exit_code, exit_signal;
  1022. int pdeath_signal; /* The signal sent when the parent dies */
  1023. /* ??? */
  1024. unsigned int personality;
  1025. unsigned did_exec:1;
  1026. unsigned in_execve:1; /* Tell the LSMs that the process is doing an
  1027. * execve */
  1028. /* Revert to default priority/policy when forking */
  1029. unsigned sched_reset_on_fork:1;
  1030. pid_t pid;
  1031. pid_t tgid;
  1032. /* Canary value for the -fstack-protector gcc feature */
  1033. unsigned long stack_canary;
  1034. /*
  1035. * pointers to (original) parent process, youngest child, younger sibling,
  1036. * older sibling, respectively. (p->father can be replaced with
  1037. * p->real_parent->pid)
  1038. */
  1039. struct task_struct *real_parent; /* real parent process */
  1040. struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */
  1041. /*
  1042. * children/sibling forms the list of my natural children
  1043. */
  1044. struct list_head children; /* list of my children */
  1045. struct list_head sibling; /* linkage in my parent's children list */
  1046. struct task_struct *group_leader; /* threadgroup leader */
  1047. /*
  1048. * ptraced is the list of tasks this task is using ptrace on.
  1049. * This includes both natural children and PTRACE_ATTACH targets.
  1050. * p->ptrace_entry is p's link on the p->parent->ptraced list.
  1051. */
  1052. struct list_head ptraced;
  1053. struct list_head ptrace_entry;
  1054. /*
  1055. * This is the tracer handle for the ptrace BTS extension.
  1056. * This field actually belongs to the ptracer task.
  1057. */
  1058. struct bts_context *bts;
  1059. /* PID/PID hash table linkage. */
  1060. struct pid_link pids[PIDTYPE_MAX];
  1061. struct list_head thread_group;
  1062. struct completion *vfork_done; /* for vfork() */
  1063. int __user *set_child_tid; /* CLONE_CHILD_SETTID */
  1064. int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
  1065. cputime_t utime, stime, utimescaled, stimescaled;
  1066. cputime_t gtime;
  1067. cputime_t prev_utime, prev_stime;
  1068. unsigned long nvcsw, nivcsw; /* context switch counts */
  1069. struct timespec start_time; /* monotonic time */
  1070. struct timespec real_start_time; /* boot based time */
  1071. /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
  1072. unsigned long min_flt, maj_flt;
  1073. struct task_cputime cputime_expires;
  1074. struct list_head cpu_timers[3];
  1075. /* process credentials */
  1076. const struct cred *real_cred; /* objective and real subjective task
  1077. * credentials (COW) */
  1078. const struct cred *cred; /* effective (overridable) subjective task
  1079. * credentials (COW) */
  1080. struct mutex cred_guard_mutex; /* guard against foreign influences on
  1081. * credential calculations
  1082. * (notably. ptrace) */
  1083. char comm[TASK_COMM_LEN]; /* executable name excluding path
  1084. - access with [gs]et_task_comm (which lock
  1085. it with task_lock())
  1086. - initialized normally by flush_old_exec */
  1087. /* file system info */
  1088. int link_count, total_link_count;
  1089. #ifdef CONFIG_SYSVIPC
  1090. /* ipc stuff */
  1091. struct sysv_sem sysvsem;
  1092. #endif
  1093. #ifdef CONFIG_DETECT_HUNG_TASK
  1094. /* hung task detection */
  1095. unsigned long last_switch_count;
  1096. #endif
  1097. /* CPU-specific state of this task */
  1098. struct thread_struct thread;
  1099. /* filesystem information */
  1100. struct fs_struct *fs;
  1101. /* open file information */
  1102. struct files_struct *files;
  1103. /* namespaces */
  1104. struct nsproxy *nsproxy;
  1105. /* signal handlers */
  1106. struct signal_struct *signal;
  1107. struct sighand_struct *sighand;
  1108. sigset_t blocked, real_blocked;
  1109. sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
  1110. struct sigpending pending;
  1111. unsigned long sas_ss_sp;
  1112. size_t sas_ss_size;
  1113. int (*notifier)(void *priv);
  1114. void *notifier_data;
  1115. sigset_t *notifier_mask;
  1116. struct audit_context *audit_context;
  1117. #ifdef CONFIG_AUDITSYSCALL
  1118. uid_t loginuid;
  1119. unsigned int sessionid;
  1120. #endif
  1121. seccomp_t seccomp;
  1122. /* Thread group tracking */
  1123. u32 parent_exec_id;
  1124. u32 self_exec_id;
  1125. /* Protection of (de-)allocation: mm, files, fs, tty, keyrings */
  1126. spinlock_t alloc_lock;
  1127. #ifdef CONFIG_GENERIC_HARDIRQS
  1128. /* IRQ handler threads */
  1129. struct irqaction *irqaction;
  1130. #endif
  1131. /* Protection of the PI data structures: */
  1132. spinlock_t pi_lock;
  1133. #ifdef CONFIG_RT_MUTEXES
  1134. /* PI waiters blocked on a rt_mutex held by this task */
  1135. struct plist_head pi_waiters;
  1136. /* Deadlock detection and priority inheritance handling */
  1137. struct rt_mutex_waiter *pi_blocked_on;
  1138. #endif
  1139. #ifdef CONFIG_DEBUG_MUTEXES
  1140. /* mutex deadlock detection */
  1141. struct mutex_waiter *blocked_on;
  1142. #endif
  1143. #ifdef CONFIG_TRACE_IRQFLAGS
  1144. unsigned int irq_events;
  1145. int hardirqs_enabled;
  1146. unsigned long hardirq_enable_ip;
  1147. unsigned int hardirq_enable_event;
  1148. unsigned long hardirq_disable_ip;
  1149. unsigned int hardirq_disable_event;
  1150. int softirqs_enabled;
  1151. unsigned long softirq_disable_ip;
  1152. unsigned int softirq_disable_event;
  1153. unsigned long softirq_enable_ip;
  1154. unsigned int softirq_enable_event;
  1155. int hardirq_context;
  1156. int softirq_context;
  1157. #endif
  1158. #ifdef CONFIG_LOCKDEP
  1159. # define MAX_LOCK_DEPTH 48UL
  1160. u64 curr_chain_key;
  1161. int lockdep_depth;
  1162. unsigned int lockdep_recursion;
  1163. struct held_lock held_locks[MAX_LOCK_DEPTH];
  1164. gfp_t lockdep_reclaim_gfp;
  1165. #endif
  1166. /* journalling filesystem info */
  1167. void *journal_info;
  1168. /* stacked block device info */
  1169. struct bio *bio_list, **bio_tail;
  1170. /* VM state */
  1171. struct reclaim_state *reclaim_state;
  1172. struct backing_dev_info *backing_dev_info;
  1173. struct io_context *io_context;
  1174. unsigned long ptrace_message;
  1175. siginfo_t *last_siginfo; /* For ptrace use. */
  1176. struct task_io_accounting ioac;
  1177. #if defined(CONFIG_TASK_XACCT)
  1178. u64 acct_rss_mem1; /* accumulated rss usage */
  1179. u64 acct_vm_mem1; /* accumulated virtual memory usage */
  1180. cputime_t acct_timexpd; /* stime + utime since last update */
  1181. #endif
  1182. #ifdef CONFIG_CPUSETS
  1183. nodemask_t mems_allowed;
  1184. int cpuset_mems_generation;
  1185. int cpuset_mem_spread_rotor;
  1186. #endif
  1187. #ifdef CONFIG_CGROUPS
  1188. /* Control Group info protected by css_set_lock */
  1189. struct css_set *cgroups;
  1190. /* cg_list protected by css_set_lock and tsk->alloc_lock */
  1191. struct list_head cg_list;
  1192. #endif
  1193. #ifdef CONFIG_FUTEX
  1194. struct robust_list_head __user *robust_list;
  1195. #ifdef CONFIG_COMPAT
  1196. struct compat_robust_list_head __user *compat_robust_list;
  1197. #endif
  1198. struct list_head pi_state_list;
  1199. struct futex_pi_state *pi_state_cache;
  1200. #endif
  1201. #ifdef CONFIG_PERF_COUNTERS
  1202. struct perf_counter_context *perf_counter_ctxp;
  1203. struct mutex perf_counter_mutex;
  1204. struct list_head perf_counter_list;
  1205. #endif
  1206. #ifdef CONFIG_NUMA
  1207. struct mempolicy *mempolicy;
  1208. short il_next;
  1209. #endif
  1210. atomic_t fs_excl; /* holding fs exclusive resources */
  1211. struct rcu_head rcu;
  1212. /*
  1213. * cache last used pipe for splice
  1214. */
  1215. struct pipe_inode_info *splice_pipe;
  1216. #ifdef CONFIG_TASK_DELAY_ACCT
  1217. struct task_delay_info *delays;
  1218. #endif
  1219. #ifdef CONFIG_FAULT_INJECTION
  1220. int make_it_fail;
  1221. #endif
  1222. struct prop_local_single dirties;
  1223. #ifdef CONFIG_LATENCYTOP
  1224. int latency_record_count;
  1225. struct latency_record latency_record[LT_SAVECOUNT];
  1226. #endif
  1227. /*
  1228. * time slack values; these are used to round up poll() and
  1229. * select() etc timeout values. These are in nanoseconds.
  1230. */
  1231. unsigned long timer_slack_ns;
  1232. unsigned long default_timer_slack_ns;
  1233. struct list_head *scm_work_list;
  1234. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1235. /* Index of current stored adress in ret_stack */
  1236. int curr_ret_stack;
  1237. /* Stack of return addresses for return function tracing */
  1238. struct ftrace_ret_stack *ret_stack;
  1239. /* time stamp for last schedule */
  1240. unsigned long long ftrace_timestamp;
  1241. /*
  1242. * Number of functions that haven't been traced
  1243. * because of depth overrun.
  1244. */
  1245. atomic_t trace_overrun;
  1246. /* Pause for the tracing */
  1247. atomic_t tracing_graph_pause;
  1248. #endif
  1249. #ifdef CONFIG_TRACING
  1250. /* state flags for use by tracers */
  1251. unsigned long trace;
  1252. /* bitmask of trace recursion */
  1253. unsigned long trace_recursion;
  1254. #endif /* CONFIG_TRACING */
  1255. };
  1256. /* Future-safe accessor for struct task_struct's cpus_allowed. */
  1257. #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
  1258. /*
  1259. * Priority of a process goes from 0..MAX_PRIO-1, valid RT
  1260. * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
  1261. * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
  1262. * values are inverted: lower p->prio value means higher priority.
  1263. *
  1264. * The MAX_USER_RT_PRIO value allows the actual maximum
  1265. * RT priority to be separate from the value exported to
  1266. * user-space. This allows kernel threads to set their
  1267. * priority to a value higher than any user task. Note:
  1268. * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
  1269. */
  1270. #define MAX_USER_RT_PRIO 100
  1271. #define MAX_RT_PRIO MAX_USER_RT_PRIO
  1272. #define MAX_PRIO (MAX_RT_PRIO + 40)
  1273. #define DEFAULT_PRIO (MAX_RT_PRIO + 20)
  1274. static inline int rt_prio(int prio)
  1275. {
  1276. if (unlikely(prio < MAX_RT_PRIO))
  1277. return 1;
  1278. return 0;
  1279. }
  1280. static inline int rt_task(struct task_struct *p)
  1281. {
  1282. return rt_prio(p->prio);
  1283. }
  1284. static inline struct pid *task_pid(struct task_struct *task)
  1285. {
  1286. return task->pids[PIDTYPE_PID].pid;
  1287. }
  1288. static inline struct pid *task_tgid(struct task_struct *task)
  1289. {
  1290. return task->group_leader->pids[PIDTYPE_PID].pid;
  1291. }
  1292. /*
  1293. * Without tasklist or rcu lock it is not safe to dereference
  1294. * the result of task_pgrp/task_session even if task == current,
  1295. * we can race with another thread doing sys_setsid/sys_setpgid.
  1296. */
  1297. static inline struct pid *task_pgrp(struct task_struct *task)
  1298. {
  1299. return task->group_leader->pids[PIDTYPE_PGID].pid;
  1300. }
  1301. static inline struct pid *task_session(struct task_struct *task)
  1302. {
  1303. return task->group_leader->pids[PIDTYPE_SID].pid;
  1304. }
  1305. struct pid_namespace;
  1306. /*
  1307. * the helpers to get the task's different pids as they are seen
  1308. * from various namespaces
  1309. *
  1310. * task_xid_nr() : global id, i.e. the id seen from the init namespace;
  1311. * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of
  1312. * current.
  1313. * task_xid_nr_ns() : id seen from the ns specified;
  1314. *
  1315. * set_task_vxid() : assigns a virtual id to a task;
  1316. *
  1317. * see also pid_nr() etc in include/linux/pid.h
  1318. */
  1319. pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
  1320. struct pid_namespace *ns);
  1321. static inline pid_t task_pid_nr(struct task_struct *tsk)
  1322. {
  1323. return tsk->pid;
  1324. }
  1325. static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
  1326. struct pid_namespace *ns)
  1327. {
  1328. return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
  1329. }
  1330. static inline pid_t task_pid_vnr(struct task_struct *tsk)
  1331. {
  1332. return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
  1333. }
  1334. static inline pid_t task_tgid_nr(struct task_struct *tsk)
  1335. {
  1336. return tsk->tgid;
  1337. }
  1338. pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
  1339. static inline pid_t task_tgid_vnr(struct task_struct *tsk)
  1340. {
  1341. return pid_vnr(task_tgid(tsk));
  1342. }
  1343. static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
  1344. struct pid_namespace *ns)
  1345. {
  1346. return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
  1347. }
  1348. static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
  1349. {
  1350. return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
  1351. }
  1352. static inline pid_t task_session_nr_ns(struct task_struct *tsk,
  1353. struct pid_namespace *ns)
  1354. {
  1355. return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
  1356. }
  1357. static inline pid_t task_session_vnr(struct task_struct *tsk)
  1358. {
  1359. return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
  1360. }
  1361. /* obsolete, do not use */
  1362. static inline pid_t task_pgrp_nr(struct task_struct *tsk)
  1363. {
  1364. return task_pgrp_nr_ns(tsk, &init_pid_ns);
  1365. }
  1366. /**
  1367. * pid_alive - check that a task structure is not stale
  1368. * @p: Task structure to be checked.
  1369. *
  1370. * Test if a process is not yet dead (at most zombie state)
  1371. * If pid_alive fails, then pointers within the task structure
  1372. * can be stale and must not be dereferenced.
  1373. */
  1374. static inline int pid_alive(struct task_struct *p)
  1375. {
  1376. return p->pids[PIDTYPE_PID].pid != NULL;
  1377. }
  1378. /**
  1379. * is_global_init - check if a task structure is init
  1380. * @tsk: Task structure to be checked.
  1381. *
  1382. * Check if a task structure is the first user space task the kernel created.
  1383. */
  1384. static inline int is_global_init(struct task_struct *tsk)
  1385. {
  1386. return tsk->pid == 1;
  1387. }
  1388. /*
  1389. * is_container_init:
  1390. * check whether in the task is init in its own pid namespace.
  1391. */
  1392. extern int is_container_init(struct task_struct *tsk);
  1393. extern struct pid *cad_pid;
  1394. extern void free_task(struct task_struct *tsk);
  1395. #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  1396. extern void __put_task_struct(struct task_struct *t);
  1397. static inline void put_task_struct(struct task_struct *t)
  1398. {
  1399. if (atomic_dec_and_test(&t->usage))
  1400. __put_task_struct(t);
  1401. }
  1402. extern cputime_t task_utime(struct task_struct *p);
  1403. extern cputime_t task_stime(struct task_struct *p);
  1404. extern cputime_t task_gtime(struct task_struct *p);
  1405. /*
  1406. * Per process flags
  1407. */
  1408. #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
  1409. /* Not implemented yet, only for 486*/
  1410. #define PF_STARTING 0x00000002 /* being created */
  1411. #define PF_EXITING 0x00000004 /* getting shut down */
  1412. #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */
  1413. #define PF_VCPU 0x00000010 /* I'm a virtual CPU */
  1414. #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
  1415. #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
  1416. #define PF_DUMPCORE 0x00000200 /* dumped core */
  1417. #define PF_SIGNALED 0x00000400 /* killed by a signal */
  1418. #define PF_MEMALLOC 0x00000800 /* Allocating memory */
  1419. #define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
  1420. #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
  1421. #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
  1422. #define PF_FROZEN 0x00010000 /* frozen for system suspend */
  1423. #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */
  1424. #define PF_KSWAPD 0x00040000 /* I am kswapd */
  1425. #define PF_SWAPOFF 0x00080000 /* I am in swapoff */
  1426. #define PF_LESS_THROTTLE 0x00100000 /* Throttle me less: I clean memory */
  1427. #define PF_KTHREAD 0x00200000 /* I am a kernel thread */
  1428. #define PF_RANDOMIZE 0x00400000 /* randomize virtual address space */
  1429. #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */
  1430. #define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */
  1431. #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */
  1432. #define PF_THREAD_BOUND 0x04000000 /* Thread bound to specific cpu */
  1433. #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */
  1434. #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */
  1435. #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezeable */
  1436. #define PF_FREEZER_NOSIG 0x80000000 /* Freezer won't send signals to it */
  1437. /*
  1438. * Only the _current_ task can read/write to tsk->flags, but other
  1439. * tasks can access tsk->flags in readonly mode for example
  1440. * with tsk_used_math (like during threaded core dumping).
  1441. * There is however an exception to this rule during ptrace
  1442. * or during fork: the ptracer task is allowed to write to the
  1443. * child->flags of its traced child (same goes for fork, the parent
  1444. * can write to the child->flags), because we're guaranteed the
  1445. * child is not running and in turn not changing child->flags
  1446. * at the same time the parent does it.
  1447. */
  1448. #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
  1449. #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
  1450. #define clear_used_math() clear_stopped_child_used_math(current)
  1451. #define set_used_math() set_stopped_child_used_math(current)
  1452. #define conditional_stopped_child_used_math(condition, child) \
  1453. do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
  1454. #define conditional_used_math(condition) \
  1455. conditional_stopped_child_used_math(condition, current)
  1456. #define copy_to_stopped_child_used_math(child) \
  1457. do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
  1458. /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
  1459. #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
  1460. #define used_math() tsk_used_math(current)
  1461. #ifdef CONFIG_SMP
  1462. extern int set_cpus_allowed_ptr(struct task_struct *p,
  1463. const struct cpumask *new_mask);
  1464. #else
  1465. static inline int set_cpus_allowed_ptr(struct task_struct *p,
  1466. const struct cpumask *new_mask)
  1467. {
  1468. if (!cpumask_test_cpu(0, new_mask))
  1469. return -EINVAL;
  1470. return 0;
  1471. }
  1472. #endif
  1473. static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
  1474. {
  1475. return set_cpus_allowed_ptr(p, &new_mask);
  1476. }
  1477. /*
  1478. * Architectures can set this to 1 if they have specified
  1479. * CONFIG_HAVE_UNSTABLE_SCHED_CLOCK in their arch Kconfig,
  1480. * but then during bootup it turns out that sched_clock()
  1481. * is reliable after all:
  1482. */
  1483. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  1484. extern int sched_clock_stable;
  1485. #endif
  1486. extern unsigned long long sched_clock(void);
  1487. extern void sched_clock_init(void);
  1488. extern u64 sched_clock_cpu(int cpu);
  1489. #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  1490. static inline void sched_clock_tick(void)
  1491. {
  1492. }
  1493. static inline void sched_clock_idle_sleep_event(void)
  1494. {
  1495. }
  1496. static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
  1497. {
  1498. }
  1499. #else
  1500. extern void sched_clock_tick(void);
  1501. extern void sched_clock_idle_sleep_event(void);
  1502. extern void sched_clock_idle_wakeup_event(u64 delta_ns);
  1503. #endif
  1504. /*
  1505. * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
  1506. * clock constructed from sched_clock():
  1507. */
  1508. extern unsigned long long cpu_clock(int cpu);
  1509. extern unsigned long long
  1510. task_sched_runtime(struct task_struct *task);
  1511. extern unsigned long long thread_group_sched_runtime(struct task_struct *task);
  1512. /* sched_exec is called by processes performing an exec */
  1513. #ifdef CONFIG_SMP
  1514. extern void sched_exec(void);
  1515. #else
  1516. #define sched_exec() {}
  1517. #endif
  1518. extern void sched_clock_idle_sleep_event(void);
  1519. extern void sched_clock_idle_wakeup_event(u64 delta_ns);
  1520. #ifdef CONFIG_HOTPLUG_CPU
  1521. extern void idle_task_exit(void);
  1522. #else
  1523. static inline void idle_task_exit(void) {}
  1524. #endif
  1525. extern void sched_idle_next(void);
  1526. #if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
  1527. extern void wake_up_idle_cpu(int cpu);
  1528. #else
  1529. static inline void wake_up_idle_cpu(int cpu) { }
  1530. #endif
  1531. extern unsigned int sysctl_sched_latency;
  1532. extern unsigned int sysctl_sched_min_granularity;
  1533. extern unsigned int sysctl_sched_wakeup_granularity;
  1534. extern unsigned int sysctl_sched_shares_ratelimit;
  1535. extern unsigned int sysctl_sched_shares_thresh;
  1536. #ifdef CONFIG_SCHED_DEBUG
  1537. extern unsigned int sysctl_sched_child_runs_first;
  1538. extern unsigned int sysctl_sched_features;
  1539. extern unsigned int sysctl_sched_migration_cost;
  1540. extern unsigned int sysctl_sched_nr_migrate;
  1541. int sched_nr_latency_handler(struct ctl_table *table, int write,
  1542. struct file *file, void __user *buffer, size_t *length,
  1543. loff_t *ppos);
  1544. #endif
  1545. extern unsigned int sysctl_sched_rt_period;
  1546. extern int sysctl_sched_rt_runtime;
  1547. int sched_rt_handler(struct ctl_table *table, int write,
  1548. struct file *filp, void __user *buffer, size_t *lenp,
  1549. loff_t *ppos);
  1550. extern unsigned int sysctl_sched_compat_yield;
  1551. #ifdef CONFIG_RT_MUTEXES
  1552. extern int rt_mutex_getprio(struct task_struct *p);
  1553. extern void rt_mutex_setprio(struct task_struct *p, int prio);
  1554. extern void rt_mutex_adjust_pi(struct task_struct *p);
  1555. #else
  1556. static inline int rt_mutex_getprio(struct task_struct *p)
  1557. {
  1558. return p->normal_prio;
  1559. }
  1560. # define rt_mutex_adjust_pi(p) do { } while (0)
  1561. #endif
  1562. extern void set_user_nice(struct task_struct *p, long nice);
  1563. extern int task_prio(const struct task_struct *p);
  1564. extern int task_nice(const struct task_struct *p);
  1565. extern int can_nice(const struct task_struct *p, const int nice);
  1566. extern int task_curr(const struct task_struct *p);
  1567. extern int idle_cpu(int cpu);
  1568. extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
  1569. extern int sched_setscheduler_nocheck(struct task_struct *, int,
  1570. struct sched_param *);
  1571. extern struct task_struct *idle_task(int cpu);
  1572. extern struct task_struct *curr_task(int cpu);
  1573. extern void set_curr_task(int cpu, struct task_struct *p);
  1574. void yield(void);
  1575. /*
  1576. * The default (Linux) execution domain.
  1577. */
  1578. extern struct exec_domain default_exec_domain;
  1579. union thread_union {
  1580. struct thread_info thread_info;
  1581. unsigned long stack[THREAD_SIZE/sizeof(long)];
  1582. };
  1583. #ifndef __HAVE_ARCH_KSTACK_END
  1584. static inline int kstack_end(void *addr)
  1585. {
  1586. /* Reliable end of stack detection:
  1587. * Some APM bios versions misalign the stack
  1588. */
  1589. return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
  1590. }
  1591. #endif
  1592. extern union thread_union init_thread_union;
  1593. extern struct task_struct init_task;
  1594. extern struct mm_struct init_mm;
  1595. extern struct pid_namespace init_pid_ns;
  1596. /*
  1597. * find a task by one of its numerical ids
  1598. *
  1599. * find_task_by_pid_type_ns():
  1600. * it is the most generic call - it finds a task by all id,
  1601. * type and namespace specified
  1602. * find_task_by_pid_ns():
  1603. * finds a task by its pid in the specified namespace
  1604. * find_task_by_vpid():
  1605. * finds a task by its virtual pid
  1606. *
  1607. * see also find_vpid() etc in include/linux/pid.h
  1608. */
  1609. extern struct task_struct *find_task_by_pid_type_ns(int type, int pid,
  1610. struct pid_namespace *ns);
  1611. extern struct task_struct *find_task_by_vpid(pid_t nr);
  1612. extern struct task_struct *find_task_by_pid_ns(pid_t nr,
  1613. struct pid_namespace *ns);
  1614. extern void __set_special_pids(struct pid *pid);
  1615. /* per-UID process charging. */
  1616. extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
  1617. static inline struct user_struct *get_uid(struct user_struct *u)
  1618. {
  1619. atomic_inc(&u->__count);
  1620. return u;
  1621. }
  1622. extern void free_uid(struct user_struct *);
  1623. extern void release_uids(struct user_namespace *ns);
  1624. #include <asm/current.h>
  1625. extern void do_timer(unsigned long ticks);
  1626. extern int wake_up_state(struct task_struct *tsk, unsigned int state);
  1627. extern int wake_up_process(struct task_struct *tsk);
  1628. extern void wake_up_new_task(struct task_struct *tsk,
  1629. unsigned long clone_flags);
  1630. #ifdef CONFIG_SMP
  1631. extern void kick_process(struct task_struct *tsk);
  1632. #else
  1633. static inline void kick_process(struct task_struct *tsk) { }
  1634. #endif
  1635. extern void sched_fork(struct task_struct *p, int clone_flags);
  1636. extern void sched_dead(struct task_struct *p);
  1637. extern void proc_caches_init(void);
  1638. extern void flush_signals(struct task_struct *);
  1639. extern void __flush_signals(struct task_struct *);
  1640. extern void ignore_signals(struct task_struct *);
  1641. extern void flush_signal_handlers(struct task_struct *, int force_default);
  1642. extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
  1643. static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
  1644. {
  1645. unsigned long flags;
  1646. int ret;
  1647. spin_lock_irqsave(&tsk->sighand->siglock, flags);
  1648. ret = dequeue_signal(tsk, mask, info);
  1649. spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
  1650. return ret;
  1651. }
  1652. extern void block_all_signals(int (*notifier)(void *priv), void *priv,
  1653. sigset_t *mask);
  1654. extern void unblock_all_signals(void);
  1655. extern void release_task(struct task_struct * p);
  1656. extern int send_sig_info(int, struct siginfo *, struct task_struct *);
  1657. extern int force_sigsegv(int, struct task_struct *);
  1658. extern int force_sig_info(int, struct siginfo *, struct task_struct *);
  1659. extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
  1660. extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
  1661. extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32);
  1662. extern int kill_pgrp(struct pid *pid, int sig, int priv);
  1663. extern int kill_pid(struct pid *pid, int sig, int priv);
  1664. extern int kill_proc_info(int, struct siginfo *, pid_t);
  1665. extern int do_notify_parent(struct task_struct *, int);
  1666. extern void force_sig(int, struct task_struct *);
  1667. extern void force_sig_specific(int, struct task_struct *);
  1668. extern int send_sig(int, struct task_struct *, int);
  1669. extern void zap_other_threads(struct task_struct *p);
  1670. extern struct sigqueue *sigqueue_alloc(void);
  1671. extern void sigqueue_free(struct sigqueue *);
  1672. extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
  1673. extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
  1674. extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
  1675. static inline int kill_cad_pid(int sig, int priv)
  1676. {
  1677. return kill_pid(cad_pid, sig, priv);
  1678. }
  1679. /* These can be the second arg to send_sig_info/send_group_sig_info. */
  1680. #define SEND_SIG_NOINFO ((struct siginfo *) 0)
  1681. #define SEND_SIG_PRIV ((struct siginfo *) 1)
  1682. #define SEND_SIG_FORCED ((struct siginfo *) 2)
  1683. static inline int is_si_special(const struct siginfo *info)
  1684. {
  1685. return info <= SEND_SIG_FORCED;
  1686. }
  1687. /* True if we are on the alternate signal stack. */
  1688. static inline int on_sig_stack(unsigned long sp)
  1689. {
  1690. return (sp - current->sas_ss_sp < current->sas_ss_size);
  1691. }
  1692. static inline int sas_ss_flags(unsigned long sp)
  1693. {
  1694. return (current->sas_ss_size == 0 ? SS_DISABLE
  1695. : on_sig_stack(sp) ? SS_ONSTACK : 0);
  1696. }
  1697. /*
  1698. * Routines for handling mm_structs
  1699. */
  1700. extern struct mm_struct * mm_alloc(void);
  1701. /* mmdrop drops the mm and the page tables */
  1702. extern void __mmdrop(struct mm_struct *);
  1703. static inline void mmdrop(struct mm_struct * mm)
  1704. {
  1705. if (unlikely(atomic_dec_and_test(&mm->mm_count)))
  1706. __mmdrop(mm);
  1707. }
  1708. /* mmput gets rid of the mappings and all user-space */
  1709. extern void mmput(struct mm_struct *);
  1710. /* Grab a reference to a task's mm, if it is not already going away */
  1711. extern struct mm_struct *get_task_mm(struct task_struct *task);
  1712. /* Remove the current tasks stale references to the old mm_struct */
  1713. extern void mm_release(struct task_struct *, struct mm_struct *);
  1714. /* Allocate a new mm structure and copy contents from tsk->mm */
  1715. extern struct mm_struct *dup_mm(struct task_struct *tsk);
  1716. extern int copy_thread(unsigned long, unsigned long, unsigned long,
  1717. struct task_struct *, struct pt_regs *);
  1718. extern void flush_thread(void);
  1719. extern void exit_thread(void);
  1720. extern void exit_files(struct task_struct *);
  1721. extern void __cleanup_signal(struct signal_struct *);
  1722. extern void __cleanup_sighand(struct sighand_struct *);
  1723. extern void exit_itimers(struct signal_struct *);
  1724. extern void flush_itimer_signals(void);
  1725. extern NORET_TYPE void do_group_exit(int);
  1726. extern void daemonize(const char *, ...);
  1727. extern int allow_signal(int);
  1728. extern int disallow_signal(int);
  1729. extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
  1730. extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
  1731. struct task_struct *fork_idle(int);
  1732. extern void set_task_comm(struct task_struct *tsk, char *from);
  1733. extern char *get_task_comm(char *to, struct task_struct *tsk);
  1734. #ifdef CONFIG_SMP
  1735. extern void wait_task_context_switch(struct task_struct *p);
  1736. extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
  1737. #else
  1738. static inline void wait_task_context_switch(struct task_struct *p) {}
  1739. static inline unsigned long wait_task_inactive(struct task_struct *p,
  1740. long match_state)
  1741. {
  1742. return 1;
  1743. }
  1744. #endif
  1745. #define next_task(p) \
  1746. list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
  1747. #define for_each_process(p) \
  1748. for (p = &init_task ; (p = next_task(p)) != &init_task ; )
  1749. extern bool is_single_threaded(struct task_struct *);
  1750. /*
  1751. * Careful: do_each_thread/while_each_thread is a double loop so
  1752. * 'break' will not work as expected - use goto instead.
  1753. */
  1754. #define do_each_thread(g, t) \
  1755. for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
  1756. #define while_each_thread(g, t) \
  1757. while ((t = next_thread(t)) != g)
  1758. /* de_thread depends on thread_group_leader not being a pid based check */
  1759. #define thread_group_leader(p) (p == p->group_leader)
  1760. /* Do to the insanities of de_thread it is possible for a process
  1761. * to have the pid of the thread group leader without actually being
  1762. * the thread group leader. For iteration through the pids in proc
  1763. * all we care about is that we have a task with the appropriate
  1764. * pid, we don't actually care if we have the right task.
  1765. */
  1766. static inline int has_group_leader_pid(struct task_struct *p)
  1767. {
  1768. return p->pid == p->tgid;
  1769. }
  1770. static inline
  1771. int same_thread_group(struct task_struct *p1, struct task_struct *p2)
  1772. {
  1773. return p1->tgid == p2->tgid;
  1774. }
  1775. static inline struct task_struct *next_thread(const struct task_struct *p)
  1776. {
  1777. return list_entry_rcu(p->thread_group.next,
  1778. struct task_struct, thread_group);
  1779. }
  1780. static inline int thread_group_empty(struct task_struct *p)
  1781. {
  1782. return list_empty(&p->thread_group);
  1783. }
  1784. #define delay_group_leader(p) \
  1785. (thread_group_leader(p) && !thread_group_empty(p))
  1786. static inline int task_detached(struct task_struct *p)
  1787. {
  1788. return p->exit_signal == -1;
  1789. }
  1790. /*
  1791. * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
  1792. * subscriptions and synchronises with wait4(). Also used in procfs. Also
  1793. * pins the final release of task.io_context. Also protects ->cpuset and
  1794. * ->cgroup.subsys[].
  1795. *
  1796. * Nests both inside and outside of read_lock(&tasklist_lock).
  1797. * It must not be nested with write_lock_irq(&tasklist_lock),
  1798. * neither inside nor outside.
  1799. */
  1800. static inline void task_lock(struct task_struct *p)
  1801. {
  1802. spin_lock(&p->alloc_lock);
  1803. }
  1804. static inline void task_unlock(struct task_struct *p)
  1805. {
  1806. spin_unlock(&p->alloc_lock);
  1807. }
  1808. extern struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
  1809. unsigned long *flags);
  1810. static inline void unlock_task_sighand(struct task_struct *tsk,
  1811. unsigned long *flags)
  1812. {
  1813. spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
  1814. }
  1815. #ifndef __HAVE_THREAD_FUNCTIONS
  1816. #define task_thread_info(task) ((struct thread_info *)(task)->stack)
  1817. #define task_stack_page(task) ((task)->stack)
  1818. static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
  1819. {
  1820. *task_thread_info(p) = *task_thread_info(org);
  1821. task_thread_info(p)->task = p;
  1822. }
  1823. static inline unsigned long *end_of_stack(struct task_struct *p)
  1824. {
  1825. return (unsigned long *)(task_thread_info(p) + 1);
  1826. }
  1827. #endif
  1828. static inline int object_is_on_stack(void *obj)
  1829. {
  1830. void *stack = task_stack_page(current);
  1831. return (obj >= stack) && (obj < (stack + THREAD_SIZE));
  1832. }
  1833. extern void thread_info_cache_init(void);
  1834. #ifdef CONFIG_DEBUG_STACK_USAGE
  1835. static inline unsigned long stack_not_used(struct task_struct *p)
  1836. {
  1837. unsigned long *n = end_of_stack(p);
  1838. do { /* Skip over canary */
  1839. n++;
  1840. } while (!*n);
  1841. return (unsigned long)n - (unsigned long)end_of_stack(p);
  1842. }
  1843. #endif
  1844. /* set thread flags in other task's structures
  1845. * - see asm/thread_info.h for TIF_xxxx flags available
  1846. */
  1847. static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
  1848. {
  1849. set_ti_thread_flag(task_thread_info(tsk), flag);
  1850. }
  1851. static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
  1852. {
  1853. clear_ti_thread_flag(task_thread_info(tsk), flag);
  1854. }
  1855. static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
  1856. {
  1857. return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
  1858. }
  1859. static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
  1860. {
  1861. return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
  1862. }
  1863. static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
  1864. {
  1865. return test_ti_thread_flag(task_thread_info(tsk), flag);
  1866. }
  1867. static inline void set_tsk_need_resched(struct task_struct *tsk)
  1868. {
  1869. set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
  1870. }
  1871. static inline void clear_tsk_need_resched(struct task_struct *tsk)
  1872. {
  1873. clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
  1874. }
  1875. static inline int test_tsk_need_resched(struct task_struct *tsk)
  1876. {
  1877. return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
  1878. }
  1879. static inline int signal_pending(struct task_struct *p)
  1880. {
  1881. return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
  1882. }
  1883. extern int __fatal_signal_pending(struct task_struct *p);
  1884. static inline int fatal_signal_pending(struct task_struct *p)
  1885. {
  1886. return signal_pending(p) && __fatal_signal_pending(p);
  1887. }
  1888. static inline int signal_pending_state(long state, struct task_struct *p)
  1889. {
  1890. if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
  1891. return 0;
  1892. if (!signal_pending(p))
  1893. return 0;
  1894. return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  1895. }
  1896. static inline int need_resched(void)
  1897. {
  1898. return unlikely(test_thread_flag(TIF_NEED_RESCHED));
  1899. }
  1900. /*
  1901. * cond_resched() and cond_resched_lock(): latency reduction via
  1902. * explicit rescheduling in places that are safe. The return
  1903. * value indicates whether a reschedule was done in fact.
  1904. * cond_resched_lock() will drop the spinlock before scheduling,
  1905. * cond_resched_softirq() will enable bhs before scheduling.
  1906. */
  1907. extern int _cond_resched(void);
  1908. #ifdef CONFIG_PREEMPT_BKL
  1909. static inline int cond_resched(void)
  1910. {
  1911. return 0;
  1912. }
  1913. #else
  1914. static inline int cond_resched(void)
  1915. {
  1916. return _cond_resched();
  1917. }
  1918. #endif
  1919. extern int cond_resched_lock(spinlock_t * lock);
  1920. extern int cond_resched_softirq(void);
  1921. static inline int cond_resched_bkl(void)
  1922. {
  1923. return _cond_resched();
  1924. }
  1925. /*
  1926. * Does a critical section need to be broken due to another
  1927. * task waiting?: (technically does not depend on CONFIG_PREEMPT,
  1928. * but a general need for low latency)
  1929. */
  1930. static inline int spin_needbreak(spinlock_t *lock)
  1931. {
  1932. #ifdef CONFIG_PREEMPT
  1933. return spin_is_contended(lock);
  1934. #else
  1935. return 0;
  1936. #endif
  1937. }
  1938. /*
  1939. * Thread group CPU time accounting.
  1940. */
  1941. void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
  1942. void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
  1943. static inline void thread_group_cputime_init(struct signal_struct *sig)
  1944. {
  1945. sig->cputimer.cputime = INIT_CPUTIME;
  1946. spin_lock_init(&sig->cputimer.lock);
  1947. sig->cputimer.running = 0;
  1948. }
  1949. static inline void thread_group_cputime_free(struct signal_struct *sig)
  1950. {
  1951. }
  1952. /*
  1953. * Reevaluate whether the task has signals pending delivery.
  1954. * Wake the task if so.
  1955. * This is required every time the blocked sigset_t changes.
  1956. * callers must hold sighand->siglock.
  1957. */
  1958. extern void recalc_sigpending_and_wake(struct task_struct *t);
  1959. extern void recalc_sigpending(void);
  1960. extern void signal_wake_up(struct task_struct *t, int resume_stopped);
  1961. /*
  1962. * Wrappers for p->thread_info->cpu access. No-op on UP.
  1963. */
  1964. #ifdef CONFIG_SMP
  1965. static inline unsigned int task_cpu(const struct task_struct *p)
  1966. {
  1967. return task_thread_info(p)->cpu;
  1968. }
  1969. extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
  1970. #else
  1971. static inline unsigned int task_cpu(const struct task_struct *p)
  1972. {
  1973. return 0;
  1974. }
  1975. static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
  1976. {
  1977. }
  1978. #endif /* CONFIG_SMP */
  1979. extern void arch_pick_mmap_layout(struct mm_struct *mm);
  1980. #ifdef CONFIG_TRACING
  1981. extern void
  1982. __trace_special(void *__tr, void *__data,
  1983. unsigned long arg1, unsigned long arg2, unsigned long arg3);
  1984. #else
  1985. static inline void
  1986. __trace_special(void *__tr, void *__data,
  1987. unsigned long arg1, unsigned long arg2, unsigned long arg3)
  1988. {
  1989. }
  1990. #endif
  1991. extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
  1992. extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
  1993. extern void normalize_rt_tasks(void);
  1994. #ifdef CONFIG_GROUP_SCHED
  1995. extern struct task_group init_task_group;
  1996. #ifdef CONFIG_USER_SCHED
  1997. extern struct task_group root_task_group;
  1998. extern void set_tg_uid(struct user_struct *user);
  1999. #endif
  2000. extern struct task_group *sched_create_group(struct task_group *parent);
  2001. extern void sched_destroy_group(struct task_group *tg);
  2002. extern void sched_move_task(struct task_struct *tsk);
  2003. #ifdef CONFIG_FAIR_GROUP_SCHED
  2004. extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
  2005. extern unsigned long sched_group_shares(struct task_group *tg);
  2006. #endif
  2007. #ifdef CONFIG_RT_GROUP_SCHED
  2008. extern int sched_group_set_rt_runtime(struct task_group *tg,
  2009. long rt_runtime_us);
  2010. extern long sched_group_rt_runtime(struct task_group *tg);
  2011. extern int sched_group_set_rt_period(struct task_group *tg,
  2012. long rt_period_us);
  2013. extern long sched_group_rt_period(struct task_group *tg);
  2014. extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk);
  2015. #endif
  2016. #endif
  2017. extern int task_can_switch_user(struct user_struct *up,
  2018. struct task_struct *tsk);
  2019. #ifdef CONFIG_TASK_XACCT
  2020. static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
  2021. {
  2022. tsk->ioac.rchar += amt;
  2023. }
  2024. static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
  2025. {
  2026. tsk->ioac.wchar += amt;
  2027. }
  2028. static inline void inc_syscr(struct task_struct *tsk)
  2029. {
  2030. tsk->ioac.syscr++;
  2031. }
  2032. static inline void inc_syscw(struct task_struct *tsk)
  2033. {
  2034. tsk->ioac.syscw++;
  2035. }
  2036. #else
  2037. static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
  2038. {
  2039. }
  2040. static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
  2041. {
  2042. }
  2043. static inline void inc_syscr(struct task_struct *tsk)
  2044. {
  2045. }
  2046. static inline void inc_syscw(struct task_struct *tsk)
  2047. {
  2048. }
  2049. #endif
  2050. #ifndef TASK_SIZE_OF
  2051. #define TASK_SIZE_OF(tsk) TASK_SIZE
  2052. #endif
  2053. /*
  2054. * Call the function if the target task is executing on a CPU right now:
  2055. */
  2056. extern void task_oncpu_function_call(struct task_struct *p,
  2057. void (*func) (void *info), void *info);
  2058. #ifdef CONFIG_MM_OWNER
  2059. extern void mm_update_next_owner(struct mm_struct *mm);
  2060. extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p);
  2061. #else
  2062. static inline void mm_update_next_owner(struct mm_struct *mm)
  2063. {
  2064. }
  2065. static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
  2066. {
  2067. }
  2068. #endif /* CONFIG_MM_OWNER */
  2069. #define TASK_STATE_TO_CHAR_STR "RSDTtZX"
  2070. #endif /* __KERNEL__ */
  2071. #endif