1#ifndef _LINUX_SCHED_H
2#define _LINUX_SCHED_H
3
4#include <uapi/linux/sched.h>
5
6
7struct sched_param {
8 int sched_priority;
9};
10
11#include <asm/param.h>
12
13#include <linux/capability.h>
14#include <linux/threads.h>
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/timex.h>
18#include <linux/jiffies.h>
19#include <linux/rbtree.h>
20#include <linux/thread_info.h>
21#include <linux/cpumask.h>
22#include <linux/errno.h>
23#include <linux/nodemask.h>
24#include <linux/mm_types.h>
25
26#include <asm/page.h>
27#include <asm/ptrace.h>
28#include <asm/cputime.h>
29
30#include <linux/smp.h>
31#include <linux/sem.h>
32#include <linux/signal.h>
33#include <linux/compiler.h>
34#include <linux/completion.h>
35#include <linux/pid.h>
36#include <linux/percpu.h>
37#include <linux/topology.h>
38#include <linux/proportions.h>
39#include <linux/seccomp.h>
40#include <linux/rcupdate.h>
41#include <linux/rculist.h>
42#include <linux/rtmutex.h>
43
44#include <linux/time.h>
45#include <linux/param.h>
46#include <linux/resource.h>
47#include <linux/timer.h>
48#include <linux/hrtimer.h>
49#include <linux/task_io_accounting.h>
50#include <linux/latencytop.h>
51#include <linux/cred.h>
52#include <linux/llist.h>
53#include <linux/uidgid.h>
54
55#include <asm/processor.h>
56
57struct exec_domain;
58struct futex_pi_state;
59struct robust_list_head;
60struct bio_list;
61struct fs_struct;
62struct perf_event_context;
63struct blk_plug;
64
65
66
67
68
69#define CLONE_KERNEL (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
70
71
72
73
74
75
76
77
78
79
80
81extern unsigned long avenrun[];
82extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
83
84#define FSHIFT 11
85#define FIXED_1 (1<<FSHIFT)
86#define LOAD_FREQ (5*HZ+1)
87#define EXP_1 1884
88#define EXP_5 2014
89#define EXP_15 2037
90
91#define CALC_LOAD(load,exp,n) \
92 load *= exp; \
93 load += n*(FIXED_1-exp); \
94 load >>= FSHIFT;
95
96extern unsigned long total_forks;
97extern int nr_threads;
98DECLARE_PER_CPU(unsigned long, process_counts);
99extern int nr_processes(void);
100extern unsigned long nr_running(void);
101extern unsigned long nr_uninterruptible(void);
102extern unsigned long nr_iowait(void);
103extern unsigned long nr_iowait_cpu(int cpu);
104extern unsigned long this_cpu_load(void);
105
106
107extern void calc_global_load(unsigned long ticks);
108extern void update_cpu_load_nohz(void);
109
110extern unsigned long get_parent_ip(unsigned long addr);
111
112struct seq_file;
113struct cfs_rq;
114struct task_group;
115#ifdef CONFIG_SCHED_DEBUG
116extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
117extern void proc_sched_set_task(struct task_struct *p);
118extern void
119print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
120#else
121static inline void
122proc_sched_show_task(struct task_struct *p, struct seq_file *m)
123{
124}
125static inline void proc_sched_set_task(struct task_struct *p)
126{
127}
128static inline void
129print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
130{
131}
132#endif
133
134
135
136
137
138
139
140
141
142
143
144#define TASK_RUNNING 0
145#define TASK_INTERRUPTIBLE 1
146#define TASK_UNINTERRUPTIBLE 2
147#define __TASK_STOPPED 4
148#define __TASK_TRACED 8
149
150#define EXIT_ZOMBIE 16
151#define EXIT_DEAD 32
152
153#define TASK_DEAD 64
154#define TASK_WAKEKILL 128
155#define TASK_WAKING 256
156#define TASK_STATE_MAX 512
157
158#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKW"
159
160extern char ___assert_task_state[1 - 2*!!(
161 sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)];
162
163
164#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
165#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
166#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)
167
168
169#define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
170#define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
171
172
173#define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \
174 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
175 __TASK_TRACED)
176
177#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
178#define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
179#define task_is_dead(task) ((task)->exit_state != 0)
180#define task_is_stopped_or_traced(task) \
181 ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
182#define task_contributes_to_load(task) \
183 ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
184 (task->flags & PF_FROZEN) == 0)
185
186#define __set_task_state(tsk, state_value) \
187 do { (tsk)->state = (state_value); } while (0)
188#define set_task_state(tsk, state_value) \
189 set_mb((tsk)->state, (state_value))
190
191
192
193
194
195
196
197
198
199
200
201
202#define __set_current_state(state_value) \
203 do { current->state = (state_value); } while (0)
204#define set_current_state(state_value) \
205 set_mb(current->state, (state_value))
206
207
208#define TASK_COMM_LEN 16
209
210#include <linux/spinlock.h>
211
212
213
214
215
216
217
218extern rwlock_t tasklist_lock;
219extern spinlock_t mmlist_lock;
220
221struct task_struct;
222
223#ifdef CONFIG_PROVE_RCU
224extern int lockdep_tasklist_lock_is_held(void);
225#endif
226
227extern void sched_init(void);
228extern void sched_init_smp(void);
229extern asmlinkage void schedule_tail(struct task_struct *prev);
230extern void init_idle(struct task_struct *idle, int cpu);
231extern void init_idle_bootup_task(struct task_struct *idle);
232
233extern int runqueue_is_locked(int cpu);
234
235#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
236extern void nohz_balance_enter_idle(int cpu);
237extern void set_cpu_sd_state_idle(void);
238extern int get_nohz_timer_target(void);
239#else
240static inline void nohz_balance_enter_idle(int cpu) { }
241static inline void set_cpu_sd_state_idle(void) { }
242#endif
243
244
245
246
247extern void show_state_filter(unsigned long state_filter);
248
249static inline void show_state(void)
250{
251 show_state_filter(0);
252}
253
254extern void show_regs(struct pt_regs *);
255
256
257
258
259
260
261extern void show_stack(struct task_struct *task, unsigned long *sp);
262
263void io_schedule(void);
264long io_schedule_timeout(long timeout);
265
266extern void cpu_init (void);
267extern void trap_init(void);
268extern void update_process_times(int user);
269extern void scheduler_tick(void);
270
271extern void sched_show_task(struct task_struct *p);
272
273#ifdef CONFIG_LOCKUP_DETECTOR
274extern void touch_softlockup_watchdog(void);
275extern void touch_softlockup_watchdog_sync(void);
276extern void touch_all_softlockup_watchdogs(void);
277extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
278 void __user *buffer,
279 size_t *lenp, loff_t *ppos);
280extern unsigned int softlockup_panic;
281void lockup_detector_init(void);
282#else
283static inline void touch_softlockup_watchdog(void)
284{
285}
286static inline void touch_softlockup_watchdog_sync(void)
287{
288}
289static inline void touch_all_softlockup_watchdogs(void)
290{
291}
292static inline void lockup_detector_init(void)
293{
294}
295#endif
296
297#ifdef CONFIG_DETECT_HUNG_TASK
298extern unsigned int sysctl_hung_task_panic;
299extern unsigned long sysctl_hung_task_check_count;
300extern unsigned long sysctl_hung_task_timeout_secs;
301extern unsigned long sysctl_hung_task_warnings;
302extern int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
303 void __user *buffer,
304 size_t *lenp, loff_t *ppos);
305#else
306
307enum { sysctl_hung_task_timeout_secs = 0 };
308#endif
309
310
311#define __sched __attribute__((__section__(".sched.text")))
312
313
314extern char __sched_text_start[], __sched_text_end[];
315
316
317extern int in_sched_functions(unsigned long addr);
318
319#define MAX_SCHEDULE_TIMEOUT LONG_MAX
320extern signed long schedule_timeout(signed long timeout);
321extern signed long schedule_timeout_interruptible(signed long timeout);
322extern signed long schedule_timeout_killable(signed long timeout);
323extern signed long schedule_timeout_uninterruptible(signed long timeout);
324asmlinkage void schedule(void);
325extern void schedule_preempt_disabled(void);
326extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
327
328struct nsproxy;
329struct user_namespace;
330
331
332
333
334
335
336
337
338
339
340
341
342
343#define MAPCOUNT_ELF_CORE_MARGIN (5)
344#define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
345
346extern int sysctl_max_map_count;
347
348#include <linux/aio.h>
349
350#ifdef CONFIG_MMU
351extern void arch_pick_mmap_layout(struct mm_struct *mm);
352extern unsigned long
353arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
354 unsigned long, unsigned long);
355extern unsigned long
356arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
357 unsigned long len, unsigned long pgoff,
358 unsigned long flags);
359extern void arch_unmap_area(struct mm_struct *, unsigned long);
360extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
361#else
362static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
363#endif
364
365
366extern void set_dumpable(struct mm_struct *mm, int value);
367extern int get_dumpable(struct mm_struct *mm);
368
369
370#define SUID_DUMPABLE_DISABLED 0
371#define SUID_DUMPABLE_ENABLED 1
372#define SUID_DUMPABLE_SAFE 2
373
374
375
376#define MMF_DUMPABLE 0
377#define MMF_DUMP_SECURELY 1
378
379#define MMF_DUMPABLE_BITS 2
380#define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1)
381
382
383#define MMF_DUMP_ANON_PRIVATE 2
384#define MMF_DUMP_ANON_SHARED 3
385#define MMF_DUMP_MAPPED_PRIVATE 4
386#define MMF_DUMP_MAPPED_SHARED 5
387#define MMF_DUMP_ELF_HEADERS 6
388#define MMF_DUMP_HUGETLB_PRIVATE 7
389#define MMF_DUMP_HUGETLB_SHARED 8
390
391#define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS
392#define MMF_DUMP_FILTER_BITS 7
393#define MMF_DUMP_FILTER_MASK \
394 (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT)
395#define MMF_DUMP_FILTER_DEFAULT \
396 ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\
397 (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF)
398
399#ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
400# define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS)
401#else
402# define MMF_DUMP_MASK_DEFAULT_ELF 0
403#endif
404
405#define MMF_VM_MERGEABLE 16
406#define MMF_VM_HUGEPAGE 17
407#define MMF_EXE_FILE_CHANGED 18
408
409#define MMF_HAS_UPROBES 19
410#define MMF_RECALC_UPROBES 20
411
412#define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
413
414struct sighand_struct {
415 atomic_t count;
416 struct k_sigaction action[_NSIG];
417 spinlock_t siglock;
418 wait_queue_head_t signalfd_wqh;
419};
420
421struct pacct_struct {
422 int ac_flag;
423 long ac_exitcode;
424 unsigned long ac_mem;
425 cputime_t ac_utime, ac_stime;
426 unsigned long ac_minflt, ac_majflt;
427};
428
429struct cpu_itimer {
430 cputime_t expires;
431 cputime_t incr;
432 u32 error;
433 u32 incr_error;
434};
435
436
437
438
439
440
441
442
443
444
445
446
447struct task_cputime {
448 cputime_t utime;
449 cputime_t stime;
450 unsigned long long sum_exec_runtime;
451};
452
453#define prof_exp stime
454#define virt_exp utime
455#define sched_exp sum_exec_runtime
456
457#define INIT_CPUTIME \
458 (struct task_cputime) { \
459 .utime = 0, \
460 .stime = 0, \
461 .sum_exec_runtime = 0, \
462 }
463
464
465
466
467
468
469
470
471#define INIT_PREEMPT_COUNT (1 + PREEMPT_ACTIVE)
472
473
474
475
476
477
478
479
480
481
482
483struct thread_group_cputimer {
484 struct task_cputime cputime;
485 int running;
486 raw_spinlock_t lock;
487};
488
489#include <linux/rwsem.h>
490struct autogroup;
491
492
493
494
495
496
497
498
499struct signal_struct {
500 atomic_t sigcnt;
501 atomic_t live;
502 int nr_threads;
503
504 wait_queue_head_t wait_chldexit;
505
506
507 struct task_struct *curr_target;
508
509
510 struct sigpending shared_pending;
511
512
513 int group_exit_code;
514
515
516
517
518
519 int notify_count;
520 struct task_struct *group_exit_task;
521
522
523 int group_stop_count;
524 unsigned int flags;
525
526
527
528
529
530
531
532
533
534
535 unsigned int is_child_subreaper:1;
536 unsigned int has_child_subreaper:1;
537
538
539 struct list_head posix_timers;
540
541
542 struct hrtimer real_timer;
543 struct pid *leader_pid;
544 ktime_t it_real_incr;
545
546
547
548
549
550
551 struct cpu_itimer it[2];
552
553
554
555
556
557 struct thread_group_cputimer cputimer;
558
559
560 struct task_cputime cputime_expires;
561
562 struct list_head cpu_timers[3];
563
564 struct pid *tty_old_pgrp;
565
566
567 int leader;
568
569 struct tty_struct *tty;
570
571#ifdef CONFIG_SCHED_AUTOGROUP
572 struct autogroup *autogroup;
573#endif
574
575
576
577
578
579
580 cputime_t utime, stime, cutime, cstime;
581 cputime_t gtime;
582 cputime_t cgtime;
583#ifndef CONFIG_VIRT_CPU_ACCOUNTING
584 cputime_t prev_utime, prev_stime;
585#endif
586 unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
587 unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
588 unsigned long inblock, oublock, cinblock, coublock;
589 unsigned long maxrss, cmaxrss;
590 struct task_io_accounting ioac;
591
592
593
594
595
596
597
598 unsigned long long sum_sched_runtime;
599
600
601
602
603
604
605
606
607
608
609 struct rlimit rlim[RLIM_NLIMITS];
610
611#ifdef CONFIG_BSD_PROCESS_ACCT
612 struct pacct_struct pacct;
613#endif
614#ifdef CONFIG_TASKSTATS
615 struct taskstats *stats;
616#endif
617#ifdef CONFIG_AUDIT
618 unsigned audit_tty;
619 struct tty_audit_buf *tty_audit_buf;
620#endif
621#ifdef CONFIG_CGROUPS
622
623
624
625
626
627
628
629
630
631 struct rw_semaphore group_rwsem;
632#endif
633
634 int oom_score_adj;
635 int oom_score_adj_min;
636
637
638 struct mutex cred_guard_mutex;
639
640
641};
642
643
644
645
646#define SIGNAL_STOP_STOPPED 0x00000001
647#define SIGNAL_STOP_CONTINUED 0x00000002
648#define SIGNAL_GROUP_EXIT 0x00000004
649
650
651
652#define SIGNAL_CLD_STOPPED 0x00000010
653#define SIGNAL_CLD_CONTINUED 0x00000020
654#define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
655
656#define SIGNAL_UNKILLABLE 0x00000040
657
658
659static inline int signal_group_exit(const struct signal_struct *sig)
660{
661 return (sig->flags & SIGNAL_GROUP_EXIT) ||
662 (sig->group_exit_task != NULL);
663}
664
665
666
667
668struct user_struct {
669 atomic_t __count;
670 atomic_t processes;
671 atomic_t files;
672 atomic_t sigpending;
673#ifdef CONFIG_INOTIFY_USER
674 atomic_t inotify_watches;
675 atomic_t inotify_devs;
676#endif
677#ifdef CONFIG_FANOTIFY
678 atomic_t fanotify_listeners;
679#endif
680#ifdef CONFIG_EPOLL
681 atomic_long_t epoll_watches;
682#endif
683#ifdef CONFIG_POSIX_MQUEUE
684
685 unsigned long mq_bytes;
686#endif
687 unsigned long locked_shm;
688
689#ifdef CONFIG_KEYS
690 struct key *uid_keyring;
691 struct key *session_keyring;
692#endif
693
694
695 struct hlist_node uidhash_node;
696 kuid_t uid;
697
698#ifdef CONFIG_PERF_EVENTS
699 atomic_long_t locked_vm;
700#endif
701};
702
703extern int uids_sysfs_init(void);
704
705extern struct user_struct *find_user(kuid_t);
706
707extern struct user_struct root_user;
708#define INIT_USER (&root_user)
709
710
711struct backing_dev_info;
712struct reclaim_state;
713
714#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
715struct sched_info {
716
717 unsigned long pcount;
718 unsigned long long run_delay;
719
720
721 unsigned long long last_arrival,
722 last_queued;
723};
724#endif
725
726#ifdef CONFIG_TASK_DELAY_ACCT
727struct task_delay_info {
728 spinlock_t lock;
729 unsigned int flags;
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746 struct timespec blkio_start, blkio_end;
747 u64 blkio_delay;
748 u64 swapin_delay;
749 u32 blkio_count;
750
751 u32 swapin_count;
752
753
754 struct timespec freepages_start, freepages_end;
755 u64 freepages_delay;
756 u32 freepages_count;
757};
758#endif
759
760static inline int sched_info_on(void)
761{
762#ifdef CONFIG_SCHEDSTATS
763 return 1;
764#elif defined(CONFIG_TASK_DELAY_ACCT)
765 extern int delayacct_on;
766 return delayacct_on;
767#else
768 return 0;
769#endif
770}
771
772enum cpu_idle_type {
773 CPU_IDLE,
774 CPU_NOT_IDLE,
775 CPU_NEWLY_IDLE,
776 CPU_MAX_IDLE_TYPES
777};
778
779
780
781
782
783
784
785
786
787
788
789
790
791#if 0
792# define SCHED_LOAD_RESOLUTION 10
793# define scale_load(w) ((w) << SCHED_LOAD_RESOLUTION)
794# define scale_load_down(w) ((w) >> SCHED_LOAD_RESOLUTION)
795#else
796# define SCHED_LOAD_RESOLUTION 0
797# define scale_load(w) (w)
798# define scale_load_down(w) (w)
799#endif
800
801#define SCHED_LOAD_SHIFT (10 + SCHED_LOAD_RESOLUTION)
802#define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
803
804
805
806
807#define SCHED_POWER_SHIFT 10
808#define SCHED_POWER_SCALE (1L << SCHED_POWER_SHIFT)
809
810
811
812
813#ifdef CONFIG_SMP
814#define SD_LOAD_BALANCE 0x0001
815#define SD_BALANCE_NEWIDLE 0x0002
816#define SD_BALANCE_EXEC 0x0004
817#define SD_BALANCE_FORK 0x0008
818#define SD_BALANCE_WAKE 0x0010
819#define SD_WAKE_AFFINE 0x0020
820#define SD_SHARE_CPUPOWER 0x0080
821#define SD_SHARE_PKG_RESOURCES 0x0200
822#define SD_SERIALIZE 0x0400
823#define SD_ASYM_PACKING 0x0800
824#define SD_PREFER_SIBLING 0x1000
825#define SD_OVERLAP 0x2000
826
827extern int __weak arch_sd_sibiling_asym_packing(void);
828
829struct sched_group_power {
830 atomic_t ref;
831
832
833
834
835 unsigned int power, power_orig;
836 unsigned long next_update;
837
838
839
840 atomic_t nr_busy_cpus;
841
842 unsigned long cpumask[0];
843};
844
845struct sched_group {
846 struct sched_group *next;
847 atomic_t ref;
848
849 unsigned int group_weight;
850 struct sched_group_power *sgp;
851
852
853
854
855
856
857
858
859 unsigned long cpumask[0];
860};
861
862static inline struct cpumask *sched_group_cpus(struct sched_group *sg)
863{
864 return to_cpumask(sg->cpumask);
865}
866
867
868
869
870
871static inline struct cpumask *sched_group_mask(struct sched_group *sg)
872{
873 return to_cpumask(sg->sgp->cpumask);
874}
875
876
877
878
879
880static inline unsigned int group_first_cpu(struct sched_group *group)
881{
882 return cpumask_first(sched_group_cpus(group));
883}
884
885struct sched_domain_attr {
886 int relax_domain_level;
887};
888
889#define SD_ATTR_INIT (struct sched_domain_attr) { \
890 .relax_domain_level = -1, \
891}
892
893extern int sched_domain_level_max;
894
895struct sched_domain {
896
897 struct sched_domain *parent;
898 struct sched_domain *child;
899 struct sched_group *groups;
900 unsigned long min_interval;
901 unsigned long max_interval;
902 unsigned int busy_factor;
903 unsigned int imbalance_pct;
904 unsigned int cache_nice_tries;
905 unsigned int busy_idx;
906 unsigned int idle_idx;
907 unsigned int newidle_idx;
908 unsigned int wake_idx;
909 unsigned int forkexec_idx;
910 unsigned int smt_gain;
911 int flags;
912 int level;
913
914
915 unsigned long last_balance;
916 unsigned int balance_interval;
917 unsigned int nr_balance_failed;
918
919 u64 last_update;
920
921#ifdef CONFIG_SCHEDSTATS
922
923 unsigned int lb_count[CPU_MAX_IDLE_TYPES];
924 unsigned int lb_failed[CPU_MAX_IDLE_TYPES];
925 unsigned int lb_balanced[CPU_MAX_IDLE_TYPES];
926 unsigned int lb_imbalance[CPU_MAX_IDLE_TYPES];
927 unsigned int lb_gained[CPU_MAX_IDLE_TYPES];
928 unsigned int lb_hot_gained[CPU_MAX_IDLE_TYPES];
929 unsigned int lb_nobusyg[CPU_MAX_IDLE_TYPES];
930 unsigned int lb_nobusyq[CPU_MAX_IDLE_TYPES];
931
932
933 unsigned int alb_count;
934 unsigned int alb_failed;
935 unsigned int alb_pushed;
936
937
938 unsigned int sbe_count;
939 unsigned int sbe_balanced;
940 unsigned int sbe_pushed;
941
942
943 unsigned int sbf_count;
944 unsigned int sbf_balanced;
945 unsigned int sbf_pushed;
946
947
948 unsigned int ttwu_wake_remote;
949 unsigned int ttwu_move_affine;
950 unsigned int ttwu_move_balance;
951#endif
952#ifdef CONFIG_SCHED_DEBUG
953 char *name;
954#endif
955 union {
956 void *private;
957 struct rcu_head rcu;
958 };
959
960 unsigned int span_weight;
961
962
963
964
965
966
967
968 unsigned long span[0];
969};
970
971static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
972{
973 return to_cpumask(sd->span);
974}
975
976extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
977 struct sched_domain_attr *dattr_new);
978
979
980cpumask_var_t *alloc_sched_domains(unsigned int ndoms);
981void free_sched_domains(cpumask_var_t doms[], unsigned int ndoms);
982
983
984static inline int test_sd_parent(struct sched_domain *sd, int flag)
985{
986 if (sd->parent && (sd->parent->flags & flag))
987 return 1;
988
989 return 0;
990}
991
992unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu);
993unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu);
994
995bool cpus_share_cache(int this_cpu, int that_cpu);
996
997#else
998
999struct sched_domain_attr;
1000
1001static inline void
1002partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
1003 struct sched_domain_attr *dattr_new)
1004{
1005}
1006
1007static inline bool cpus_share_cache(int this_cpu, int that_cpu)
1008{
1009 return true;
1010}
1011
1012#endif
1013
1014
1015struct io_context;
1016
1017
1018#ifdef ARCH_HAS_PREFETCH_SWITCH_STACK
1019extern void prefetch_stack(struct task_struct *t);
1020#else
1021static inline void prefetch_stack(struct task_struct *t) { }
1022#endif
1023
1024struct audit_context;
1025struct mempolicy;
1026struct pipe_inode_info;
1027struct uts_namespace;
1028
1029struct rq;
1030struct sched_domain;
1031
1032
1033
1034
1035#define WF_SYNC 0x01
1036#define WF_FORK 0x02
1037#define WF_MIGRATED 0x04
1038
1039#define ENQUEUE_WAKEUP 1
1040#define ENQUEUE_HEAD 2
1041#ifdef CONFIG_SMP
1042#define ENQUEUE_WAKING 4
1043#else
1044#define ENQUEUE_WAKING 0
1045#endif
1046
1047#define DEQUEUE_SLEEP 1
1048
1049struct sched_class {
1050 const struct sched_class *next;
1051
1052 void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
1053 void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
1054 void (*yield_task) (struct rq *rq);
1055 bool (*yield_to_task) (struct rq *rq, struct task_struct *p, bool preempt);
1056
1057 void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
1058
1059 struct task_struct * (*pick_next_task) (struct rq *rq);
1060 void (*put_prev_task) (struct rq *rq, struct task_struct *p);
1061
1062#ifdef CONFIG_SMP
1063 int (*select_task_rq)(struct task_struct *p, int sd_flag, int flags);
1064
1065 void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
1066 void (*post_schedule) (struct rq *this_rq);
1067 void (*task_waking) (struct task_struct *task);
1068 void (*task_woken) (struct rq *this_rq, struct task_struct *task);
1069
1070 void (*set_cpus_allowed)(struct task_struct *p,
1071 const struct cpumask *newmask);
1072
1073 void (*rq_online)(struct rq *rq);
1074 void (*rq_offline)(struct rq *rq);
1075#endif
1076
1077 void (*set_curr_task) (struct rq *rq);
1078 void (*task_tick) (struct rq *rq, struct task_struct *p, int queued);
1079 void (*task_fork) (struct task_struct *p);
1080
1081 void (*switched_from) (struct rq *this_rq, struct task_struct *task);
1082 void (*switched_to) (struct rq *this_rq, struct task_struct *task);
1083 void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1084 int oldprio);
1085
1086 unsigned int (*get_rr_interval) (struct rq *rq,
1087 struct task_struct *task);
1088
1089#ifdef CONFIG_FAIR_GROUP_SCHED
1090 void (*task_move_group) (struct task_struct *p, int on_rq);
1091#endif
1092};
1093
1094struct load_weight {
1095 unsigned long weight, inv_weight;
1096};
1097
1098#ifdef CONFIG_SCHEDSTATS
1099struct sched_statistics {
1100 u64 wait_start;
1101 u64 wait_max;
1102 u64 wait_count;
1103 u64 wait_sum;
1104 u64 iowait_count;
1105 u64 iowait_sum;
1106
1107 u64 sleep_start;
1108 u64 sleep_max;
1109 s64 sum_sleep_runtime;
1110
1111 u64 block_start;
1112 u64 block_max;
1113 u64 exec_max;
1114 u64 slice_max;
1115
1116 u64 nr_migrations_cold;
1117 u64 nr_failed_migrations_affine;
1118 u64 nr_failed_migrations_running;
1119 u64 nr_failed_migrations_hot;
1120 u64 nr_forced_migrations;
1121
1122 u64 nr_wakeups;
1123 u64 nr_wakeups_sync;
1124 u64 nr_wakeups_migrate;
1125 u64 nr_wakeups_local;
1126 u64 nr_wakeups_remote;
1127 u64 nr_wakeups_affine;
1128 u64 nr_wakeups_affine_attempts;
1129 u64 nr_wakeups_passive;
1130 u64 nr_wakeups_idle;
1131};
1132#endif
1133
1134struct sched_entity {
1135 struct load_weight load;
1136 struct rb_node run_node;
1137 struct list_head group_node;
1138 unsigned int on_rq;
1139
1140 u64 exec_start;
1141 u64 sum_exec_runtime;
1142 u64 vruntime;
1143 u64 prev_sum_exec_runtime;
1144
1145 u64 nr_migrations;
1146
1147#ifdef CONFIG_SCHEDSTATS
1148 struct sched_statistics statistics;
1149#endif
1150
1151#ifdef CONFIG_FAIR_GROUP_SCHED
1152 struct sched_entity *parent;
1153
1154 struct cfs_rq *cfs_rq;
1155
1156 struct cfs_rq *my_q;
1157#endif
1158};
1159
1160struct sched_rt_entity {
1161 struct list_head run_list;
1162 unsigned long timeout;
1163 unsigned int time_slice;
1164
1165 struct sched_rt_entity *back;
1166#ifdef CONFIG_RT_GROUP_SCHED
1167 struct sched_rt_entity *parent;
1168
1169 struct rt_rq *rt_rq;
1170
1171 struct rt_rq *my_q;
1172#endif
1173};
1174
1175
1176
1177
1178
1179#define RR_TIMESLICE (100 * HZ / 1000)
1180
1181struct rcu_node;
1182
1183enum perf_event_task_context {
1184 perf_invalid_context = -1,
1185 perf_hw_context = 0,
1186 perf_sw_context,
1187 perf_nr_task_contexts,
1188};
1189
1190struct task_struct {
1191 volatile long state;
1192 void *stack;
1193 atomic_t usage;
1194 unsigned int flags;
1195 unsigned int ptrace;
1196
1197#ifdef CONFIG_SMP
1198 struct llist_node wake_entry;
1199 int on_cpu;
1200#endif
1201 int on_rq;
1202
1203 int prio, static_prio, normal_prio;
1204 unsigned int rt_priority;
1205 const struct sched_class *sched_class;
1206 struct sched_entity se;
1207 struct sched_rt_entity rt;
1208#ifdef CONFIG_CGROUP_SCHED
1209 struct task_group *sched_task_group;
1210#endif
1211
1212#ifdef CONFIG_PREEMPT_NOTIFIERS
1213
1214 struct hlist_head preempt_notifiers;
1215#endif
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225 unsigned char fpu_counter;
1226#ifdef CONFIG_BLK_DEV_IO_TRACE
1227 unsigned int btrace_seq;
1228#endif
1229
1230 unsigned int policy;
1231 int nr_cpus_allowed;
1232 cpumask_t cpus_allowed;
1233
1234#ifdef CONFIG_PREEMPT_RCU
1235 int rcu_read_lock_nesting;
1236 char rcu_read_unlock_special;
1237 struct list_head rcu_node_entry;
1238#endif
1239#ifdef CONFIG_TREE_PREEMPT_RCU
1240 struct rcu_node *rcu_blocked_node;
1241#endif
1242#ifdef CONFIG_RCU_BOOST
1243 struct rt_mutex *rcu_boost_mutex;
1244#endif
1245
1246#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
1247 struct sched_info sched_info;
1248#endif
1249
1250 struct list_head tasks;
1251#ifdef CONFIG_SMP
1252 struct plist_node pushable_tasks;
1253#endif
1254
1255 struct mm_struct *mm, *active_mm;
1256#ifdef CONFIG_COMPAT_BRK
1257 unsigned brk_randomized:1;
1258#endif
1259#if defined(SPLIT_RSS_COUNTING)
1260 struct task_rss_stat rss_stat;
1261#endif
1262
1263 int exit_state;
1264 int exit_code, exit_signal;
1265 int pdeath_signal;
1266 unsigned int jobctl;
1267
1268 unsigned int personality;
1269 unsigned did_exec:1;
1270 unsigned in_execve:1;
1271
1272 unsigned in_iowait:1;
1273
1274
1275 unsigned no_new_privs:1;
1276
1277
1278 unsigned sched_reset_on_fork:1;
1279 unsigned sched_contributes_to_load:1;
1280
1281 pid_t pid;
1282 pid_t tgid;
1283
1284#ifdef CONFIG_CC_STACKPROTECTOR
1285
1286 unsigned long stack_canary;
1287#endif
1288
1289
1290
1291
1292
1293 struct task_struct __rcu *real_parent;
1294 struct task_struct __rcu *parent;
1295
1296
1297
1298 struct list_head children;
1299 struct list_head sibling;
1300 struct task_struct *group_leader;
1301
1302
1303
1304
1305
1306
1307 struct list_head ptraced;
1308 struct list_head ptrace_entry;
1309
1310
1311 struct pid_link pids[PIDTYPE_MAX];
1312 struct list_head thread_group;
1313
1314 struct completion *vfork_done;
1315 int __user *set_child_tid;
1316 int __user *clear_child_tid;
1317
1318 cputime_t utime, stime, utimescaled, stimescaled;
1319 cputime_t gtime;
1320#ifndef CONFIG_VIRT_CPU_ACCOUNTING
1321 cputime_t prev_utime, prev_stime;
1322#endif
1323 unsigned long nvcsw, nivcsw;
1324 struct timespec start_time;
1325 struct timespec real_start_time;
1326
1327 unsigned long min_flt, maj_flt;
1328
1329 struct task_cputime cputime_expires;
1330 struct list_head cpu_timers[3];
1331
1332
1333 const struct cred __rcu *real_cred;
1334
1335 const struct cred __rcu *cred;
1336
1337 char comm[TASK_COMM_LEN];
1338
1339
1340
1341
1342 int link_count, total_link_count;
1343#ifdef CONFIG_SYSVIPC
1344
1345 struct sysv_sem sysvsem;
1346#endif
1347#ifdef CONFIG_DETECT_HUNG_TASK
1348
1349 unsigned long last_switch_count;
1350#endif
1351
1352 struct thread_struct thread;
1353
1354 struct fs_struct *fs;
1355
1356 struct files_struct *files;
1357
1358 struct nsproxy *nsproxy;
1359
1360 struct signal_struct *signal;
1361 struct sighand_struct *sighand;
1362
1363 sigset_t blocked, real_blocked;
1364 sigset_t saved_sigmask;
1365 struct sigpending pending;
1366
1367 unsigned long sas_ss_sp;
1368 size_t sas_ss_size;
1369 int (*notifier)(void *priv);
1370 void *notifier_data;
1371 sigset_t *notifier_mask;
1372 struct callback_head *task_works;
1373
1374 struct audit_context *audit_context;
1375#ifdef CONFIG_AUDITSYSCALL
1376 kuid_t loginuid;
1377 unsigned int sessionid;
1378#endif
1379 struct seccomp seccomp;
1380
1381
1382 u32 parent_exec_id;
1383 u32 self_exec_id;
1384
1385
1386 spinlock_t alloc_lock;
1387
1388
1389 raw_spinlock_t pi_lock;
1390
1391#ifdef CONFIG_RT_MUTEXES
1392
1393 struct plist_head pi_waiters;
1394
1395 struct rt_mutex_waiter *pi_blocked_on;
1396#endif
1397
1398#ifdef CONFIG_DEBUG_MUTEXES
1399
1400 struct mutex_waiter *blocked_on;
1401#endif
1402#ifdef CONFIG_TRACE_IRQFLAGS
1403 unsigned int irq_events;
1404 unsigned long hardirq_enable_ip;
1405 unsigned long hardirq_disable_ip;
1406 unsigned int hardirq_enable_event;
1407 unsigned int hardirq_disable_event;
1408 int hardirqs_enabled;
1409 int hardirq_context;
1410 unsigned long softirq_disable_ip;
1411 unsigned long softirq_enable_ip;
1412 unsigned int softirq_disable_event;
1413 unsigned int softirq_enable_event;
1414 int softirqs_enabled;
1415 int softirq_context;
1416#endif
1417#ifdef CONFIG_LOCKDEP
1418# define MAX_LOCK_DEPTH 48UL
1419 u64 curr_chain_key;
1420 int lockdep_depth;
1421 unsigned int lockdep_recursion;
1422 struct held_lock held_locks[MAX_LOCK_DEPTH];
1423 gfp_t lockdep_reclaim_gfp;
1424#endif
1425
1426
1427 void *journal_info;
1428
1429
1430 struct bio_list *bio_list;
1431
1432#ifdef CONFIG_BLOCK
1433
1434 struct blk_plug *plug;
1435#endif
1436
1437
1438 struct reclaim_state *reclaim_state;
1439
1440 struct backing_dev_info *backing_dev_info;
1441
1442 struct io_context *io_context;
1443
1444 unsigned long ptrace_message;
1445 siginfo_t *last_siginfo;
1446 struct task_io_accounting ioac;
1447#if defined(CONFIG_TASK_XACCT)
1448 u64 acct_rss_mem1;
1449 u64 acct_vm_mem1;
1450 cputime_t acct_timexpd;
1451#endif
1452#ifdef CONFIG_CPUSETS
1453 nodemask_t mems_allowed;
1454 seqcount_t mems_allowed_seq;
1455 int cpuset_mem_spread_rotor;
1456 int cpuset_slab_spread_rotor;
1457#endif
1458#ifdef CONFIG_CGROUPS
1459
1460 struct css_set __rcu *cgroups;
1461
1462 struct list_head cg_list;
1463#endif
1464#ifdef CONFIG_FUTEX
1465 struct robust_list_head __user *robust_list;
1466#ifdef CONFIG_COMPAT
1467 struct compat_robust_list_head __user *compat_robust_list;
1468#endif
1469 struct list_head pi_state_list;
1470 struct futex_pi_state *pi_state_cache;
1471#endif
1472#ifdef CONFIG_PERF_EVENTS
1473 struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
1474 struct mutex perf_event_mutex;
1475 struct list_head perf_event_list;
1476#endif
1477#ifdef CONFIG_NUMA
1478 struct mempolicy *mempolicy;
1479 short il_next;
1480 short pref_node_fork;
1481#endif
1482 struct rcu_head rcu;
1483
1484
1485
1486
1487 struct pipe_inode_info *splice_pipe;
1488
1489 struct page_frag task_frag;
1490
1491#ifdef CONFIG_TASK_DELAY_ACCT
1492 struct task_delay_info *delays;
1493#endif
1494#ifdef CONFIG_FAULT_INJECTION
1495 int make_it_fail;
1496#endif
1497
1498
1499
1500
1501 int nr_dirtied;
1502 int nr_dirtied_pause;
1503 unsigned long dirty_paused_when;
1504
1505#ifdef CONFIG_LATENCYTOP
1506 int latency_record_count;
1507 struct latency_record latency_record[LT_SAVECOUNT];
1508#endif
1509
1510
1511
1512
1513 unsigned long timer_slack_ns;
1514 unsigned long default_timer_slack_ns;
1515
1516#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1517
1518 int curr_ret_stack;
1519
1520 struct ftrace_ret_stack *ret_stack;
1521
1522 unsigned long long ftrace_timestamp;
1523
1524
1525
1526
1527 atomic_t trace_overrun;
1528
1529 atomic_t tracing_graph_pause;
1530#endif
1531#ifdef CONFIG_TRACING
1532
1533 unsigned long trace;
1534
1535 unsigned long trace_recursion;
1536#endif
1537#ifdef CONFIG_MEMCG
1538 struct memcg_batch_info {
1539 int do_batch;
1540 struct mem_cgroup *memcg;
1541 unsigned long nr_pages;
1542 unsigned long memsw_nr_pages;
1543 } memcg_batch;
1544#endif
1545#ifdef CONFIG_HAVE_HW_BREAKPOINT
1546 atomic_t ptrace_bp_refcnt;
1547#endif
1548#ifdef CONFIG_UPROBES
1549 struct uprobe_task *utask;
1550#endif
1551};
1552
1553
1554#define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569#define MAX_USER_RT_PRIO 100
1570#define MAX_RT_PRIO MAX_USER_RT_PRIO
1571
1572#define MAX_PRIO (MAX_RT_PRIO + 40)
1573#define DEFAULT_PRIO (MAX_RT_PRIO + 20)
1574
1575static inline int rt_prio(int prio)
1576{
1577 if (unlikely(prio < MAX_RT_PRIO))
1578 return 1;
1579 return 0;
1580}
1581
1582static inline int rt_task(struct task_struct *p)
1583{
1584 return rt_prio(p->prio);
1585}
1586
1587static inline struct pid *task_pid(struct task_struct *task)
1588{
1589 return task->pids[PIDTYPE_PID].pid;
1590}
1591
1592static inline struct pid *task_tgid(struct task_struct *task)
1593{
1594 return task->group_leader->pids[PIDTYPE_PID].pid;
1595}
1596
1597
1598
1599
1600
1601
1602static inline struct pid *task_pgrp(struct task_struct *task)
1603{
1604 return task->group_leader->pids[PIDTYPE_PGID].pid;
1605}
1606
1607static inline struct pid *task_session(struct task_struct *task)
1608{
1609 return task->group_leader->pids[PIDTYPE_SID].pid;
1610}
1611
1612struct pid_namespace;
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
1628 struct pid_namespace *ns);
1629
1630static inline pid_t task_pid_nr(struct task_struct *tsk)
1631{
1632 return tsk->pid;
1633}
1634
1635static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
1636 struct pid_namespace *ns)
1637{
1638 return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
1639}
1640
1641static inline pid_t task_pid_vnr(struct task_struct *tsk)
1642{
1643 return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
1644}
1645
1646
1647static inline pid_t task_tgid_nr(struct task_struct *tsk)
1648{
1649 return tsk->tgid;
1650}
1651
1652pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns);
1653
1654static inline pid_t task_tgid_vnr(struct task_struct *tsk)
1655{
1656 return pid_vnr(task_tgid(tsk));
1657}
1658
1659
1660static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
1661 struct pid_namespace *ns)
1662{
1663 return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
1664}
1665
1666static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
1667{
1668 return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
1669}
1670
1671
1672static inline pid_t task_session_nr_ns(struct task_struct *tsk,
1673 struct pid_namespace *ns)
1674{
1675 return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
1676}
1677
1678static inline pid_t task_session_vnr(struct task_struct *tsk)
1679{
1680 return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
1681}
1682
1683
1684static inline pid_t task_pgrp_nr(struct task_struct *tsk)
1685{
1686 return task_pgrp_nr_ns(tsk, &init_pid_ns);
1687}
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697static inline int pid_alive(struct task_struct *p)
1698{
1699 return p->pids[PIDTYPE_PID].pid != NULL;
1700}
1701
1702
1703
1704
1705
1706
1707
1708static inline int is_global_init(struct task_struct *tsk)
1709{
1710 return tsk->pid == 1;
1711}
1712
1713
1714
1715
1716
1717extern int is_container_init(struct task_struct *tsk);
1718
1719extern struct pid *cad_pid;
1720
1721extern void free_task(struct task_struct *tsk);
1722#define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
1723
1724extern void __put_task_struct(struct task_struct *t);
1725
1726static inline void put_task_struct(struct task_struct *t)
1727{
1728 if (atomic_dec_and_test(&t->usage))
1729 __put_task_struct(t);
1730}
1731
1732extern void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st);
1733extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st);
1734
1735
1736
1737
1738#define PF_EXITING 0x00000004
1739#define PF_EXITPIDONE 0x00000008
1740#define PF_VCPU 0x00000010
1741#define PF_WQ_WORKER 0x00000020
1742#define PF_FORKNOEXEC 0x00000040
1743#define PF_MCE_PROCESS 0x00000080
1744#define PF_SUPERPRIV 0x00000100
1745#define PF_DUMPCORE 0x00000200
1746#define PF_SIGNALED 0x00000400
1747#define PF_MEMALLOC 0x00000800
1748#define PF_NPROC_EXCEEDED 0x00001000
1749#define PF_USED_MATH 0x00002000
1750#define PF_NOFREEZE 0x00008000
1751#define PF_FROZEN 0x00010000
1752#define PF_FSTRANS 0x00020000
1753#define PF_KSWAPD 0x00040000
1754#define PF_LESS_THROTTLE 0x00100000
1755#define PF_KTHREAD 0x00200000
1756#define PF_RANDOMIZE 0x00400000
1757#define PF_SWAPWRITE 0x00800000
1758#define PF_SPREAD_PAGE 0x01000000
1759#define PF_SPREAD_SLAB 0x02000000
1760#define PF_THREAD_BOUND 0x04000000
1761#define PF_MCE_EARLY 0x08000000
1762#define PF_MEMPOLICY 0x10000000
1763#define PF_MUTEX_TESTER 0x20000000
1764#define PF_FREEZER_SKIP 0x40000000
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777#define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
1778#define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
1779#define clear_used_math() clear_stopped_child_used_math(current)
1780#define set_used_math() set_stopped_child_used_math(current)
1781#define conditional_stopped_child_used_math(condition, child) \
1782 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
1783#define conditional_used_math(condition) \
1784 conditional_stopped_child_used_math(condition, current)
1785#define copy_to_stopped_child_used_math(child) \
1786 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
1787
1788#define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
1789#define used_math() tsk_used_math(current)
1790
1791
1792
1793
1794#define JOBCTL_STOP_SIGMASK 0xffff
1795
1796#define JOBCTL_STOP_DEQUEUED_BIT 16
1797#define JOBCTL_STOP_PENDING_BIT 17
1798#define JOBCTL_STOP_CONSUME_BIT 18
1799#define JOBCTL_TRAP_STOP_BIT 19
1800#define JOBCTL_TRAP_NOTIFY_BIT 20
1801#define JOBCTL_TRAPPING_BIT 21
1802#define JOBCTL_LISTENING_BIT 22
1803
1804#define JOBCTL_STOP_DEQUEUED (1 << JOBCTL_STOP_DEQUEUED_BIT)
1805#define JOBCTL_STOP_PENDING (1 << JOBCTL_STOP_PENDING_BIT)
1806#define JOBCTL_STOP_CONSUME (1 << JOBCTL_STOP_CONSUME_BIT)
1807#define JOBCTL_TRAP_STOP (1 << JOBCTL_TRAP_STOP_BIT)
1808#define JOBCTL_TRAP_NOTIFY (1 << JOBCTL_TRAP_NOTIFY_BIT)
1809#define JOBCTL_TRAPPING (1 << JOBCTL_TRAPPING_BIT)
1810#define JOBCTL_LISTENING (1 << JOBCTL_LISTENING_BIT)
1811
1812#define JOBCTL_TRAP_MASK (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY)
1813#define JOBCTL_PENDING_MASK (JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK)
1814
1815extern bool task_set_jobctl_pending(struct task_struct *task,
1816 unsigned int mask);
1817extern void task_clear_jobctl_trapping(struct task_struct *task);
1818extern void task_clear_jobctl_pending(struct task_struct *task,
1819 unsigned int mask);
1820
1821#ifdef CONFIG_PREEMPT_RCU
1822
1823#define RCU_READ_UNLOCK_BLOCKED (1 << 0)
1824#define RCU_READ_UNLOCK_NEED_QS (1 << 1)
1825
1826static inline void rcu_copy_process(struct task_struct *p)
1827{
1828 p->rcu_read_lock_nesting = 0;
1829 p->rcu_read_unlock_special = 0;
1830#ifdef CONFIG_TREE_PREEMPT_RCU
1831 p->rcu_blocked_node = NULL;
1832#endif
1833#ifdef CONFIG_RCU_BOOST
1834 p->rcu_boost_mutex = NULL;
1835#endif
1836 INIT_LIST_HEAD(&p->rcu_node_entry);
1837}
1838
1839#else
1840
1841static inline void rcu_copy_process(struct task_struct *p)
1842{
1843}
1844
1845#endif
1846
1847static inline void rcu_switch(struct task_struct *prev,
1848 struct task_struct *next)
1849{
1850#ifdef CONFIG_RCU_USER_QS
1851 rcu_user_hooks_switch(prev, next);
1852#endif
1853}
1854
1855static inline void tsk_restore_flags(struct task_struct *task,
1856 unsigned long orig_flags, unsigned long flags)
1857{
1858 task->flags &= ~flags;
1859 task->flags |= orig_flags & flags;
1860}
1861
1862#ifdef CONFIG_SMP
1863extern void do_set_cpus_allowed(struct task_struct *p,
1864 const struct cpumask *new_mask);
1865
1866extern int set_cpus_allowed_ptr(struct task_struct *p,
1867 const struct cpumask *new_mask);
1868#else
1869static inline void do_set_cpus_allowed(struct task_struct *p,
1870 const struct cpumask *new_mask)
1871{
1872}
1873static inline int set_cpus_allowed_ptr(struct task_struct *p,
1874 const struct cpumask *new_mask)
1875{
1876 if (!cpumask_test_cpu(0, new_mask))
1877 return -EINVAL;
1878 return 0;
1879}
1880#endif
1881
1882#ifdef CONFIG_NO_HZ
1883void calc_load_enter_idle(void);
1884void calc_load_exit_idle(void);
1885#else
1886static inline void calc_load_enter_idle(void) { }
1887static inline void calc_load_exit_idle(void) { }
1888#endif
1889
1890#ifndef CONFIG_CPUMASK_OFFSTACK
1891static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
1892{
1893 return set_cpus_allowed_ptr(p, &new_mask);
1894}
1895#endif
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905extern unsigned long long notrace sched_clock(void);
1906
1907
1908
1909extern u64 cpu_clock(int cpu);
1910extern u64 local_clock(void);
1911extern u64 sched_clock_cpu(int cpu);
1912
1913
1914extern void sched_clock_init(void);
1915
1916#ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
1917static inline void sched_clock_tick(void)
1918{
1919}
1920
1921static inline void sched_clock_idle_sleep_event(void)
1922{
1923}
1924
1925static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
1926{
1927}
1928#else
1929
1930
1931
1932
1933
1934
1935extern int sched_clock_stable;
1936
1937extern void sched_clock_tick(void);
1938extern void sched_clock_idle_sleep_event(void);
1939extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1940#endif
1941
1942#ifdef CONFIG_IRQ_TIME_ACCOUNTING
1943
1944
1945
1946
1947
1948extern void enable_sched_clock_irqtime(void);
1949extern void disable_sched_clock_irqtime(void);
1950#else
1951static inline void enable_sched_clock_irqtime(void) {}
1952static inline void disable_sched_clock_irqtime(void) {}
1953#endif
1954
1955extern unsigned long long
1956task_sched_runtime(struct task_struct *task);
1957
1958
1959#ifdef CONFIG_SMP
1960extern void sched_exec(void);
1961#else
1962#define sched_exec() {}
1963#endif
1964
1965extern void sched_clock_idle_sleep_event(void);
1966extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1967
1968#ifdef CONFIG_HOTPLUG_CPU
1969extern void idle_task_exit(void);
1970#else
1971static inline void idle_task_exit(void) {}
1972#endif
1973
1974#if defined(CONFIG_NO_HZ) && defined(CONFIG_SMP)
1975extern void wake_up_idle_cpu(int cpu);
1976#else
1977static inline void wake_up_idle_cpu(int cpu) { }
1978#endif
1979
1980extern unsigned int sysctl_sched_latency;
1981extern unsigned int sysctl_sched_min_granularity;
1982extern unsigned int sysctl_sched_wakeup_granularity;
1983extern unsigned int sysctl_sched_child_runs_first;
1984
1985enum sched_tunable_scaling {
1986 SCHED_TUNABLESCALING_NONE,
1987 SCHED_TUNABLESCALING_LOG,
1988 SCHED_TUNABLESCALING_LINEAR,
1989 SCHED_TUNABLESCALING_END,
1990};
1991extern enum sched_tunable_scaling sysctl_sched_tunable_scaling;
1992
1993#ifdef CONFIG_SCHED_DEBUG
1994extern unsigned int sysctl_sched_migration_cost;
1995extern unsigned int sysctl_sched_nr_migrate;
1996extern unsigned int sysctl_sched_time_avg;
1997extern unsigned int sysctl_timer_migration;
1998extern unsigned int sysctl_sched_shares_window;
1999
2000int sched_proc_update_handler(struct ctl_table *table, int write,
2001 void __user *buffer, size_t *length,
2002 loff_t *ppos);
2003#endif
2004#ifdef CONFIG_SCHED_DEBUG
2005static inline unsigned int get_sysctl_timer_migration(void)
2006{
2007 return sysctl_timer_migration;
2008}
2009#else
2010static inline unsigned int get_sysctl_timer_migration(void)
2011{
2012 return 1;
2013}
2014#endif
2015extern unsigned int sysctl_sched_rt_period;
2016extern int sysctl_sched_rt_runtime;
2017
2018int sched_rt_handler(struct ctl_table *table, int write,
2019 void __user *buffer, size_t *lenp,
2020 loff_t *ppos);
2021
2022#ifdef CONFIG_SCHED_AUTOGROUP
2023extern unsigned int sysctl_sched_autogroup_enabled;
2024
2025extern void sched_autogroup_create_attach(struct task_struct *p);
2026extern void sched_autogroup_detach(struct task_struct *p);
2027extern void sched_autogroup_fork(struct signal_struct *sig);
2028extern void sched_autogroup_exit(struct signal_struct *sig);
2029#ifdef CONFIG_PROC_FS
2030extern void proc_sched_autogroup_show_task(struct task_struct *p, struct seq_file *m);
2031extern int proc_sched_autogroup_set_nice(struct task_struct *p, int nice);
2032#endif
2033#else
2034static inline void sched_autogroup_create_attach(struct task_struct *p) { }
2035static inline void sched_autogroup_detach(struct task_struct *p) { }
2036static inline void sched_autogroup_fork(struct signal_struct *sig) { }
2037static inline void sched_autogroup_exit(struct signal_struct *sig) { }
2038#endif
2039
2040#ifdef CONFIG_CFS_BANDWIDTH
2041extern unsigned int sysctl_sched_cfs_bandwidth_slice;
2042#endif
2043
2044#ifdef CONFIG_RT_MUTEXES
2045extern int rt_mutex_getprio(struct task_struct *p);
2046extern void rt_mutex_setprio(struct task_struct *p, int prio);
2047extern void rt_mutex_adjust_pi(struct task_struct *p);
2048static inline bool tsk_is_pi_blocked(struct task_struct *tsk)
2049{
2050 return tsk->pi_blocked_on != NULL;
2051}
2052#else
2053static inline int rt_mutex_getprio(struct task_struct *p)
2054{
2055 return p->normal_prio;
2056}
2057# define rt_mutex_adjust_pi(p) do { } while (0)
2058static inline bool tsk_is_pi_blocked(struct task_struct *tsk)
2059{
2060 return false;
2061}
2062#endif
2063
2064extern bool yield_to(struct task_struct *p, bool preempt);
2065extern void set_user_nice(struct task_struct *p, long nice);
2066extern int task_prio(const struct task_struct *p);
2067extern int task_nice(const struct task_struct *p);
2068extern int can_nice(const struct task_struct *p, const int nice);
2069extern int task_curr(const struct task_struct *p);
2070extern int idle_cpu(int cpu);
2071extern int sched_setscheduler(struct task_struct *, int,
2072 const struct sched_param *);
2073extern int sched_setscheduler_nocheck(struct task_struct *, int,
2074 const struct sched_param *);
2075extern struct task_struct *idle_task(int cpu);
2076
2077
2078
2079
2080static inline bool is_idle_task(const struct task_struct *p)
2081{
2082 return p->pid == 0;
2083}
2084extern struct task_struct *curr_task(int cpu);
2085extern void set_curr_task(int cpu, struct task_struct *p);
2086
2087void yield(void);
2088
2089
2090
2091
2092extern struct exec_domain default_exec_domain;
2093
2094union thread_union {
2095 struct thread_info thread_info;
2096 unsigned long stack[THREAD_SIZE/sizeof(long)];
2097};
2098
2099#ifndef __HAVE_ARCH_KSTACK_END
2100static inline int kstack_end(void *addr)
2101{
2102
2103
2104
2105 return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
2106}
2107#endif
2108
2109extern union thread_union init_thread_union;
2110extern struct task_struct init_task;
2111
2112extern struct mm_struct init_mm;
2113
2114extern struct pid_namespace init_pid_ns;
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127extern struct task_struct *find_task_by_vpid(pid_t nr);
2128extern struct task_struct *find_task_by_pid_ns(pid_t nr,
2129 struct pid_namespace *ns);
2130
2131extern void __set_special_pids(struct pid *pid);
2132
2133
2134extern struct user_struct * alloc_uid(kuid_t);
2135static inline struct user_struct *get_uid(struct user_struct *u)
2136{
2137 atomic_inc(&u->__count);
2138 return u;
2139}
2140extern void free_uid(struct user_struct *);
2141
2142#include <asm/current.h>
2143
2144extern void xtime_update(unsigned long ticks);
2145
2146extern int wake_up_state(struct task_struct *tsk, unsigned int state);
2147extern int wake_up_process(struct task_struct *tsk);
2148extern void wake_up_new_task(struct task_struct *tsk);
2149#ifdef CONFIG_SMP
2150 extern void kick_process(struct task_struct *tsk);
2151#else
2152 static inline void kick_process(struct task_struct *tsk) { }
2153#endif
2154extern void sched_fork(struct task_struct *p);
2155extern void sched_dead(struct task_struct *p);
2156
2157extern void proc_caches_init(void);
2158extern void flush_signals(struct task_struct *);
2159extern void __flush_signals(struct task_struct *);
2160extern void ignore_signals(struct task_struct *);
2161extern void flush_signal_handlers(struct task_struct *, int force_default);
2162extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
2163
2164static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
2165{
2166 unsigned long flags;
2167 int ret;
2168
2169 spin_lock_irqsave(&tsk->sighand->siglock, flags);
2170 ret = dequeue_signal(tsk, mask, info);
2171 spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
2172
2173 return ret;
2174}
2175
2176extern void block_all_signals(int (*notifier)(void *priv), void *priv,
2177 sigset_t *mask);
2178extern void unblock_all_signals(void);
2179extern void release_task(struct task_struct * p);
2180extern int send_sig_info(int, struct siginfo *, struct task_struct *);
2181extern int force_sigsegv(int, struct task_struct *);
2182extern int force_sig_info(int, struct siginfo *, struct task_struct *);
2183extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
2184extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
2185extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *,
2186 const struct cred *, u32);
2187extern int kill_pgrp(struct pid *pid, int sig, int priv);
2188extern int kill_pid(struct pid *pid, int sig, int priv);
2189extern int kill_proc_info(int, struct siginfo *, pid_t);
2190extern __must_check bool do_notify_parent(struct task_struct *, int);
2191extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
2192extern void force_sig(int, struct task_struct *);
2193extern int send_sig(int, struct task_struct *, int);
2194extern int zap_other_threads(struct task_struct *p);
2195extern struct sigqueue *sigqueue_alloc(void);
2196extern void sigqueue_free(struct sigqueue *);
2197extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
2198extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
2199extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
2200
2201static inline void restore_saved_sigmask(void)
2202{
2203 if (test_and_clear_restore_sigmask())
2204 __set_current_blocked(¤t->saved_sigmask);
2205}
2206
2207static inline sigset_t *sigmask_to_save(void)
2208{
2209 sigset_t *res = ¤t->blocked;
2210 if (unlikely(test_restore_sigmask()))
2211 res = ¤t->saved_sigmask;
2212 return res;
2213}
2214
2215static inline int kill_cad_pid(int sig, int priv)
2216{
2217 return kill_pid(cad_pid, sig, priv);
2218}
2219
2220
2221#define SEND_SIG_NOINFO ((struct siginfo *) 0)
2222#define SEND_SIG_PRIV ((struct siginfo *) 1)
2223#define SEND_SIG_FORCED ((struct siginfo *) 2)
2224
2225
2226
2227
2228static inline int on_sig_stack(unsigned long sp)
2229{
2230#ifdef CONFIG_STACK_GROWSUP
2231 return sp >= current->sas_ss_sp &&
2232 sp - current->sas_ss_sp < current->sas_ss_size;
2233#else
2234 return sp > current->sas_ss_sp &&
2235 sp - current->sas_ss_sp <= current->sas_ss_size;
2236#endif
2237}
2238
2239static inline int sas_ss_flags(unsigned long sp)
2240{
2241 return (current->sas_ss_size == 0 ? SS_DISABLE
2242 : on_sig_stack(sp) ? SS_ONSTACK : 0);
2243}
2244
2245
2246
2247
2248extern struct mm_struct * mm_alloc(void);
2249
2250
2251extern void __mmdrop(struct mm_struct *);
2252static inline void mmdrop(struct mm_struct * mm)
2253{
2254 if (unlikely(atomic_dec_and_test(&mm->mm_count)))
2255 __mmdrop(mm);
2256}
2257
2258
2259extern void mmput(struct mm_struct *);
2260
2261extern struct mm_struct *get_task_mm(struct task_struct *task);
2262
2263
2264
2265
2266
2267extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
2268
2269extern void mm_release(struct task_struct *, struct mm_struct *);
2270
2271extern struct mm_struct *dup_mm(struct task_struct *tsk);
2272
2273extern int copy_thread(unsigned long, unsigned long, unsigned long,
2274 struct task_struct *, struct pt_regs *);
2275extern void flush_thread(void);
2276extern void exit_thread(void);
2277
2278extern void exit_files(struct task_struct *);
2279extern void __cleanup_sighand(struct sighand_struct *);
2280
2281extern void exit_itimers(struct signal_struct *);
2282extern void flush_itimer_signals(void);
2283
2284extern void do_group_exit(int);
2285
2286extern void daemonize(const char *, ...);
2287extern int allow_signal(int);
2288extern int disallow_signal(int);
2289
2290extern int do_execve(const char *,
2291 const char __user * const __user *,
2292 const char __user * const __user *, struct pt_regs *);
2293extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
2294struct task_struct *fork_idle(int);
2295#ifdef CONFIG_GENERIC_KERNEL_THREAD
2296extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
2297#endif
2298
2299extern void set_task_comm(struct task_struct *tsk, char *from);
2300extern char *get_task_comm(char *to, struct task_struct *tsk);
2301
2302#ifdef CONFIG_SMP
2303void scheduler_ipi(void);
2304extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
2305#else
2306static inline void scheduler_ipi(void) { }
2307static inline unsigned long wait_task_inactive(struct task_struct *p,
2308 long match_state)
2309{
2310 return 1;
2311}
2312#endif
2313
2314#define next_task(p) \
2315 list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
2316
2317#define for_each_process(p) \
2318 for (p = &init_task ; (p = next_task(p)) != &init_task ; )
2319
2320extern bool current_is_single_threaded(void);
2321
2322
2323
2324
2325
2326#define do_each_thread(g, t) \
2327 for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
2328
2329#define while_each_thread(g, t) \
2330 while ((t = next_thread(t)) != g)
2331
2332static inline int get_nr_threads(struct task_struct *tsk)
2333{
2334 return tsk->signal->nr_threads;
2335}
2336
2337static inline bool thread_group_leader(struct task_struct *p)
2338{
2339 return p->exit_signal >= 0;
2340}
2341
2342
2343
2344
2345
2346
2347
2348static inline int has_group_leader_pid(struct task_struct *p)
2349{
2350 return p->pid == p->tgid;
2351}
2352
2353static inline
2354int same_thread_group(struct task_struct *p1, struct task_struct *p2)
2355{
2356 return p1->tgid == p2->tgid;
2357}
2358
2359static inline struct task_struct *next_thread(const struct task_struct *p)
2360{
2361 return list_entry_rcu(p->thread_group.next,
2362 struct task_struct, thread_group);
2363}
2364
2365static inline int thread_group_empty(struct task_struct *p)
2366{
2367 return list_empty(&p->thread_group);
2368}
2369
2370#define delay_group_leader(p) \
2371 (thread_group_leader(p) && !thread_group_empty(p))
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383static inline void task_lock(struct task_struct *p)
2384{
2385 spin_lock(&p->alloc_lock);
2386}
2387
2388static inline void task_unlock(struct task_struct *p)
2389{
2390 spin_unlock(&p->alloc_lock);
2391}
2392
2393extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
2394 unsigned long *flags);
2395
2396static inline struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
2397 unsigned long *flags)
2398{
2399 struct sighand_struct *ret;
2400
2401 ret = __lock_task_sighand(tsk, flags);
2402 (void)__cond_lock(&tsk->sighand->siglock, ret);
2403 return ret;
2404}
2405
2406static inline void unlock_task_sighand(struct task_struct *tsk,
2407 unsigned long *flags)
2408{
2409 spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
2410}
2411
2412#ifdef CONFIG_CGROUPS
2413static inline void threadgroup_change_begin(struct task_struct *tsk)
2414{
2415 down_read(&tsk->signal->group_rwsem);
2416}
2417static inline void threadgroup_change_end(struct task_struct *tsk)
2418{
2419 up_read(&tsk->signal->group_rwsem);
2420}
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442static inline void threadgroup_lock(struct task_struct *tsk)
2443{
2444
2445
2446
2447
2448 mutex_lock(&tsk->signal->cred_guard_mutex);
2449 down_write(&tsk->signal->group_rwsem);
2450}
2451
2452
2453
2454
2455
2456
2457
2458static inline void threadgroup_unlock(struct task_struct *tsk)
2459{
2460 up_write(&tsk->signal->group_rwsem);
2461 mutex_unlock(&tsk->signal->cred_guard_mutex);
2462}
2463#else
2464static inline void threadgroup_change_begin(struct task_struct *tsk) {}
2465static inline void threadgroup_change_end(struct task_struct *tsk) {}
2466static inline void threadgroup_lock(struct task_struct *tsk) {}
2467static inline void threadgroup_unlock(struct task_struct *tsk) {}
2468#endif
2469
2470#ifndef __HAVE_THREAD_FUNCTIONS
2471
2472#define task_thread_info(task) ((struct thread_info *)(task)->stack)
2473#define task_stack_page(task) ((task)->stack)
2474
2475static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
2476{
2477 *task_thread_info(p) = *task_thread_info(org);
2478 task_thread_info(p)->task = p;
2479}
2480
2481static inline unsigned long *end_of_stack(struct task_struct *p)
2482{
2483 return (unsigned long *)(task_thread_info(p) + 1);
2484}
2485
2486#endif
2487
2488static inline int object_is_on_stack(void *obj)
2489{
2490 void *stack = task_stack_page(current);
2491
2492 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
2493}
2494
2495extern void thread_info_cache_init(void);
2496
2497#ifdef CONFIG_DEBUG_STACK_USAGE
2498static inline unsigned long stack_not_used(struct task_struct *p)
2499{
2500 unsigned long *n = end_of_stack(p);
2501
2502 do {
2503 n++;
2504 } while (!*n);
2505
2506 return (unsigned long)n - (unsigned long)end_of_stack(p);
2507}
2508#endif
2509
2510
2511
2512
2513static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
2514{
2515 set_ti_thread_flag(task_thread_info(tsk), flag);
2516}
2517
2518static inline void clear_tsk_thread_flag(struct task_struct *tsk, int flag)
2519{
2520 clear_ti_thread_flag(task_thread_info(tsk), flag);
2521}
2522
2523static inline int test_and_set_tsk_thread_flag(struct task_struct *tsk, int flag)
2524{
2525 return test_and_set_ti_thread_flag(task_thread_info(tsk), flag);
2526}
2527
2528static inline int test_and_clear_tsk_thread_flag(struct task_struct *tsk, int flag)
2529{
2530 return test_and_clear_ti_thread_flag(task_thread_info(tsk), flag);
2531}
2532
2533static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
2534{
2535 return test_ti_thread_flag(task_thread_info(tsk), flag);
2536}
2537
2538static inline void set_tsk_need_resched(struct task_struct *tsk)
2539{
2540 set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
2541}
2542
2543static inline void clear_tsk_need_resched(struct task_struct *tsk)
2544{
2545 clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
2546}
2547
2548static inline int test_tsk_need_resched(struct task_struct *tsk)
2549{
2550 return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
2551}
2552
2553static inline int restart_syscall(void)
2554{
2555 set_tsk_thread_flag(current, TIF_SIGPENDING);
2556 return -ERESTARTNOINTR;
2557}
2558
2559static inline int signal_pending(struct task_struct *p)
2560{
2561 return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
2562}
2563
2564static inline int __fatal_signal_pending(struct task_struct *p)
2565{
2566 return unlikely(sigismember(&p->pending.signal, SIGKILL));
2567}
2568
2569static inline int fatal_signal_pending(struct task_struct *p)
2570{
2571 return signal_pending(p) && __fatal_signal_pending(p);
2572}
2573
2574static inline int signal_pending_state(long state, struct task_struct *p)
2575{
2576 if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
2577 return 0;
2578 if (!signal_pending(p))
2579 return 0;
2580
2581 return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
2582}
2583
2584static inline int need_resched(void)
2585{
2586 return unlikely(test_thread_flag(TIF_NEED_RESCHED));
2587}
2588
2589
2590
2591
2592
2593
2594
2595
2596extern int _cond_resched(void);
2597
2598#define cond_resched() ({ \
2599 __might_sleep(__FILE__, __LINE__, 0); \
2600 _cond_resched(); \
2601})
2602
2603extern int __cond_resched_lock(spinlock_t *lock);
2604
2605#ifdef CONFIG_PREEMPT_COUNT
2606#define PREEMPT_LOCK_OFFSET PREEMPT_OFFSET
2607#else
2608#define PREEMPT_LOCK_OFFSET 0
2609#endif
2610
2611#define cond_resched_lock(lock) ({ \
2612 __might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET); \
2613 __cond_resched_lock(lock); \
2614})
2615
2616extern int __cond_resched_softirq(void);
2617
2618#define cond_resched_softirq() ({ \
2619 __might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET); \
2620 __cond_resched_softirq(); \
2621})
2622
2623
2624
2625
2626
2627
2628static inline int spin_needbreak(spinlock_t *lock)
2629{
2630#ifdef CONFIG_PREEMPT
2631 return spin_is_contended(lock);
2632#else
2633 return 0;
2634#endif
2635}
2636
2637
2638
2639
2640void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
2641void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
2642
2643static inline void thread_group_cputime_init(struct signal_struct *sig)
2644{
2645 raw_spin_lock_init(&sig->cputimer.lock);
2646}
2647
2648
2649
2650
2651
2652
2653
2654extern void recalc_sigpending_and_wake(struct task_struct *t);
2655extern void recalc_sigpending(void);
2656
2657extern void signal_wake_up_state(struct task_struct *t, unsigned int state);
2658
2659static inline void signal_wake_up(struct task_struct *t, bool resume)
2660{
2661 signal_wake_up_state(t, resume ? TASK_WAKEKILL : 0);
2662}
2663static inline void ptrace_signal_wake_up(struct task_struct *t, bool resume)
2664{
2665 signal_wake_up_state(t, resume ? __TASK_TRACED : 0);
2666}
2667
2668
2669
2670
2671#ifdef CONFIG_SMP
2672
2673static inline unsigned int task_cpu(const struct task_struct *p)
2674{
2675 return task_thread_info(p)->cpu;
2676}
2677
2678extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
2679
2680#else
2681
2682static inline unsigned int task_cpu(const struct task_struct *p)
2683{
2684 return 0;
2685}
2686
2687static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
2688{
2689}
2690
2691#endif
2692
2693extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
2694extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
2695
2696extern void normalize_rt_tasks(void);
2697
2698#ifdef CONFIG_CGROUP_SCHED
2699
2700extern struct task_group root_task_group;
2701
2702extern struct task_group *sched_create_group(struct task_group *parent);
2703extern void sched_destroy_group(struct task_group *tg);
2704extern void sched_move_task(struct task_struct *tsk);
2705#ifdef CONFIG_FAIR_GROUP_SCHED
2706extern int sched_group_set_shares(struct task_group *tg, unsigned long shares);
2707extern unsigned long sched_group_shares(struct task_group *tg);
2708#endif
2709#ifdef CONFIG_RT_GROUP_SCHED
2710extern int sched_group_set_rt_runtime(struct task_group *tg,
2711 long rt_runtime_us);
2712extern long sched_group_rt_runtime(struct task_group *tg);
2713extern int sched_group_set_rt_period(struct task_group *tg,
2714 long rt_period_us);
2715extern long sched_group_rt_period(struct task_group *tg);
2716extern int sched_rt_can_attach(struct task_group *tg, struct task_struct *tsk);
2717#endif
2718#endif
2719
2720extern int task_can_switch_user(struct user_struct *up,
2721 struct task_struct *tsk);
2722
2723#ifdef CONFIG_TASK_XACCT
2724static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
2725{
2726 tsk->ioac.rchar += amt;
2727}
2728
2729static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
2730{
2731 tsk->ioac.wchar += amt;
2732}
2733
2734static inline void inc_syscr(struct task_struct *tsk)
2735{
2736 tsk->ioac.syscr++;
2737}
2738
2739static inline void inc_syscw(struct task_struct *tsk)
2740{
2741 tsk->ioac.syscw++;
2742}
2743#else
2744static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
2745{
2746}
2747
2748static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
2749{
2750}
2751
2752static inline void inc_syscr(struct task_struct *tsk)
2753{
2754}
2755
2756static inline void inc_syscw(struct task_struct *tsk)
2757{
2758}
2759#endif
2760
2761#ifndef TASK_SIZE_OF
2762#define TASK_SIZE_OF(tsk) TASK_SIZE
2763#endif
2764
2765#ifdef CONFIG_MM_OWNER
2766extern void mm_update_next_owner(struct mm_struct *mm);
2767extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p);
2768#else
2769static inline void mm_update_next_owner(struct mm_struct *mm)
2770{
2771}
2772
2773static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
2774{
2775}
2776#endif
2777
2778static inline unsigned long task_rlimit(const struct task_struct *tsk,
2779 unsigned int limit)
2780{
2781 return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur);
2782}
2783
2784static inline unsigned long task_rlimit_max(const struct task_struct *tsk,
2785 unsigned int limit)
2786{
2787 return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_max);
2788}
2789
2790static inline unsigned long rlimit(unsigned int limit)
2791{
2792 return task_rlimit(current, limit);
2793}
2794
2795static inline unsigned long rlimit_max(unsigned int limit)
2796{
2797 return task_rlimit_max(current, limit);
2798}
2799
2800#endif
2801