aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sched.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/sched.h')
-rw-r--r--include/linux/sched.h262
1 files changed, 187 insertions, 75 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 693f0e6c54d4..731edaca8ffd 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -26,6 +26,7 @@
26#define CLONE_STOPPED 0x02000000 /* Start in stopped state */ 26#define CLONE_STOPPED 0x02000000 /* Start in stopped state */
27#define CLONE_NEWUTS 0x04000000 /* New utsname group? */ 27#define CLONE_NEWUTS 0x04000000 /* New utsname group? */
28#define CLONE_NEWIPC 0x08000000 /* New ipcs */ 28#define CLONE_NEWIPC 0x08000000 /* New ipcs */
29#define CLONE_NEWUSER 0x10000000 /* New user namespace */
29 30
30/* 31/*
31 * Scheduling policies 32 * Scheduling policies
@@ -34,6 +35,8 @@
34#define SCHED_FIFO 1 35#define SCHED_FIFO 1
35#define SCHED_RR 2 36#define SCHED_RR 2
36#define SCHED_BATCH 3 37#define SCHED_BATCH 3
38/* SCHED_ISO: reserved but not implemented yet */
39#define SCHED_IDLE 5
37 40
38#ifdef __KERNEL__ 41#ifdef __KERNEL__
39 42
@@ -130,6 +133,26 @@ extern unsigned long nr_active(void);
130extern unsigned long nr_iowait(void); 133extern unsigned long nr_iowait(void);
131extern unsigned long weighted_cpuload(const int cpu); 134extern unsigned long weighted_cpuload(const int cpu);
132 135
136struct seq_file;
137struct cfs_rq;
138#ifdef CONFIG_SCHED_DEBUG
139extern void proc_sched_show_task(struct task_struct *p, struct seq_file *m);
140extern void proc_sched_set_task(struct task_struct *p);
141extern void
142print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq, u64 now);
143#else
144static inline void
145proc_sched_show_task(struct task_struct *p, struct seq_file *m)
146{
147}
148static inline void proc_sched_set_task(struct task_struct *p)
149{
150}
151static inline void
152print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq, u64 now)
153{
154}
155#endif
133 156
134/* 157/*
135 * Task state bitmask. NOTE! These bits are also 158 * Task state bitmask. NOTE! These bits are also
@@ -193,6 +216,7 @@ struct task_struct;
193extern void sched_init(void); 216extern void sched_init(void);
194extern void sched_init_smp(void); 217extern void sched_init_smp(void);
195extern void init_idle(struct task_struct *idle, int cpu); 218extern void init_idle(struct task_struct *idle, int cpu);
219extern void init_idle_bootup_task(struct task_struct *idle);
196 220
197extern cpumask_t nohz_cpu_mask; 221extern cpumask_t nohz_cpu_mask;
198#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) 222#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
@@ -264,6 +288,7 @@ extern signed long schedule_timeout_uninterruptible(signed long timeout);
264asmlinkage void schedule(void); 288asmlinkage void schedule(void);
265 289
266struct nsproxy; 290struct nsproxy;
291struct user_namespace;
267 292
268/* Maximum number of active map areas.. This is a random (large) number */ 293/* Maximum number of active map areas.. This is a random (large) number */
269#define DEFAULT_MAX_MAP_COUNT 65536 294#define DEFAULT_MAX_MAP_COUNT 65536
@@ -479,7 +504,7 @@ struct signal_struct {
479 * from jiffies_to_ns(utime + stime) if sched_clock uses something 504 * from jiffies_to_ns(utime + stime) if sched_clock uses something
480 * other than jiffies.) 505 * other than jiffies.)
481 */ 506 */
482 unsigned long long sched_time; 507 unsigned long long sum_sched_runtime;
483 508
484 /* 509 /*
485 * We don't bother to synchronize most readers of this at all, 510 * We don't bother to synchronize most readers of this at all,
@@ -506,6 +531,10 @@ struct signal_struct {
506#ifdef CONFIG_TASKSTATS 531#ifdef CONFIG_TASKSTATS
507 struct taskstats *stats; 532 struct taskstats *stats;
508#endif 533#endif
534#ifdef CONFIG_AUDIT
535 unsigned audit_tty;
536 struct tty_audit_buf *tty_audit_buf;
537#endif
509}; 538};
510 539
511/* Context switch must be unlocked if interrupts are to be enabled */ 540/* Context switch must be unlocked if interrupts are to be enabled */
@@ -521,31 +550,6 @@ struct signal_struct {
521#define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */ 550#define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */
522#define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */ 551#define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */
523 552
524
525/*
526 * Priority of a process goes from 0..MAX_PRIO-1, valid RT
527 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
528 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
529 * values are inverted: lower p->prio value means higher priority.
530 *
531 * The MAX_USER_RT_PRIO value allows the actual maximum
532 * RT priority to be separate from the value exported to
533 * user-space. This allows kernel threads to set their
534 * priority to a value higher than any user task. Note:
535 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
536 */
537
538#define MAX_USER_RT_PRIO 100
539#define MAX_RT_PRIO MAX_USER_RT_PRIO
540
541#define MAX_PRIO (MAX_RT_PRIO + 40)
542
543#define rt_prio(prio) unlikely((prio) < MAX_RT_PRIO)
544#define rt_task(p) rt_prio((p)->prio)
545#define batch_task(p) (unlikely((p)->policy == SCHED_BATCH))
546#define is_rt_policy(p) ((p) != SCHED_NORMAL && (p) != SCHED_BATCH)
547#define has_rt_policy(p) unlikely(is_rt_policy((p)->policy))
548
549/* 553/*
550 * Some day this will be a full-fledged user tracking system.. 554 * Some day this will be a full-fledged user tracking system..
551 */ 555 */
@@ -583,13 +587,13 @@ struct reclaim_state;
583#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 587#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
584struct sched_info { 588struct sched_info {
585 /* cumulative counters */ 589 /* cumulative counters */
586 unsigned long cpu_time, /* time spent on the cpu */ 590 unsigned long pcnt; /* # of times run on this cpu */
587 run_delay, /* time spent waiting on a runqueue */ 591 unsigned long long cpu_time, /* time spent on the cpu */
588 pcnt; /* # of timeslices run on this cpu */ 592 run_delay; /* time spent waiting on a runqueue */
589 593
590 /* timestamps */ 594 /* timestamps */
591 unsigned long last_arrival, /* when we last ran on a cpu */ 595 unsigned long long last_arrival,/* when we last ran on a cpu */
592 last_queued; /* when we were last queued to run */ 596 last_queued; /* when we were last queued to run */
593}; 597};
594#endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */ 598#endif /* defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) */
595 599
@@ -639,18 +643,24 @@ static inline int sched_info_on(void)
639#endif 643#endif
640} 644}
641 645
642enum idle_type 646enum cpu_idle_type {
643{ 647 CPU_IDLE,
644 SCHED_IDLE, 648 CPU_NOT_IDLE,
645 NOT_IDLE, 649 CPU_NEWLY_IDLE,
646 NEWLY_IDLE, 650 CPU_MAX_IDLE_TYPES
647 MAX_IDLE_TYPES
648}; 651};
649 652
650/* 653/*
651 * sched-domains (multiprocessor balancing) declarations: 654 * sched-domains (multiprocessor balancing) declarations:
652 */ 655 */
653#define SCHED_LOAD_SCALE 128UL /* increase resolution of load */ 656
657/*
658 * Increase resolution of nice-level calculations:
659 */
660#define SCHED_LOAD_SHIFT 10
661#define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
662
663#define SCHED_LOAD_SCALE_FUZZ (SCHED_LOAD_SCALE >> 5)
654 664
655#ifdef CONFIG_SMP 665#ifdef CONFIG_SMP
656#define SD_LOAD_BALANCE 1 /* Do load balancing on this domain. */ 666#define SD_LOAD_BALANCE 1 /* Do load balancing on this domain. */
@@ -719,14 +729,14 @@ struct sched_domain {
719 729
720#ifdef CONFIG_SCHEDSTATS 730#ifdef CONFIG_SCHEDSTATS
721 /* load_balance() stats */ 731 /* load_balance() stats */
722 unsigned long lb_cnt[MAX_IDLE_TYPES]; 732 unsigned long lb_cnt[CPU_MAX_IDLE_TYPES];
723 unsigned long lb_failed[MAX_IDLE_TYPES]; 733 unsigned long lb_failed[CPU_MAX_IDLE_TYPES];
724 unsigned long lb_balanced[MAX_IDLE_TYPES]; 734 unsigned long lb_balanced[CPU_MAX_IDLE_TYPES];
725 unsigned long lb_imbalance[MAX_IDLE_TYPES]; 735 unsigned long lb_imbalance[CPU_MAX_IDLE_TYPES];
726 unsigned long lb_gained[MAX_IDLE_TYPES]; 736 unsigned long lb_gained[CPU_MAX_IDLE_TYPES];
727 unsigned long lb_hot_gained[MAX_IDLE_TYPES]; 737 unsigned long lb_hot_gained[CPU_MAX_IDLE_TYPES];
728 unsigned long lb_nobusyg[MAX_IDLE_TYPES]; 738 unsigned long lb_nobusyg[CPU_MAX_IDLE_TYPES];
729 unsigned long lb_nobusyq[MAX_IDLE_TYPES]; 739 unsigned long lb_nobusyq[CPU_MAX_IDLE_TYPES];
730 740
731 /* Active load balancing */ 741 /* Active load balancing */
732 unsigned long alb_cnt; 742 unsigned long alb_cnt;
@@ -753,12 +763,6 @@ struct sched_domain {
753extern int partition_sched_domains(cpumask_t *partition1, 763extern int partition_sched_domains(cpumask_t *partition1,
754 cpumask_t *partition2); 764 cpumask_t *partition2);
755 765
756/*
757 * Maximum cache size the migration-costs auto-tuning code will
758 * search from:
759 */
760extern unsigned int max_cache_size;
761
762#endif /* CONFIG_SMP */ 766#endif /* CONFIG_SMP */
763 767
764 768
@@ -809,14 +813,86 @@ struct mempolicy;
809struct pipe_inode_info; 813struct pipe_inode_info;
810struct uts_namespace; 814struct uts_namespace;
811 815
812enum sleep_type { 816struct rq;
813 SLEEP_NORMAL, 817struct sched_domain;
814 SLEEP_NONINTERACTIVE, 818
815 SLEEP_INTERACTIVE, 819struct sched_class {
816 SLEEP_INTERRUPTED, 820 struct sched_class *next;
821
822 void (*enqueue_task) (struct rq *rq, struct task_struct *p,
823 int wakeup, u64 now);
824 void (*dequeue_task) (struct rq *rq, struct task_struct *p,
825 int sleep, u64 now);
826 void (*yield_task) (struct rq *rq, struct task_struct *p);
827
828 void (*check_preempt_curr) (struct rq *rq, struct task_struct *p);
829
830 struct task_struct * (*pick_next_task) (struct rq *rq, u64 now);
831 void (*put_prev_task) (struct rq *rq, struct task_struct *p, u64 now);
832
833 int (*load_balance) (struct rq *this_rq, int this_cpu,
834 struct rq *busiest,
835 unsigned long max_nr_move, unsigned long max_load_move,
836 struct sched_domain *sd, enum cpu_idle_type idle,
837 int *all_pinned, unsigned long *total_load_moved);
838
839 void (*set_curr_task) (struct rq *rq);
840 void (*task_tick) (struct rq *rq, struct task_struct *p);
841 void (*task_new) (struct rq *rq, struct task_struct *p);
817}; 842};
818 843
819struct prio_array; 844struct load_weight {
845 unsigned long weight, inv_weight;
846};
847
848/*
849 * CFS stats for a schedulable entity (task, task-group etc)
850 *
851 * Current field usage histogram:
852 *
853 * 4 se->block_start
854 * 4 se->run_node
855 * 4 se->sleep_start
856 * 4 se->sleep_start_fair
857 * 6 se->load.weight
858 * 7 se->delta_fair
859 * 15 se->wait_runtime
860 */
861struct sched_entity {
862 long wait_runtime;
863 unsigned long delta_fair_run;
864 unsigned long delta_fair_sleep;
865 unsigned long delta_exec;
866 s64 fair_key;
867 struct load_weight load; /* for load-balancing */
868 struct rb_node run_node;
869 unsigned int on_rq;
870
871 u64 wait_start_fair;
872 u64 wait_start;
873 u64 exec_start;
874 u64 sleep_start;
875 u64 sleep_start_fair;
876 u64 block_start;
877 u64 sleep_max;
878 u64 block_max;
879 u64 exec_max;
880 u64 wait_max;
881 u64 last_ran;
882
883 u64 sum_exec_runtime;
884 s64 sum_wait_runtime;
885 s64 sum_sleep_runtime;
886 unsigned long wait_runtime_overruns;
887 unsigned long wait_runtime_underruns;
888#ifdef CONFIG_FAIR_GROUP_SCHED
889 struct sched_entity *parent;
890 /* rq on which this entity is (to be) queued: */
891 struct cfs_rq *cfs_rq;
892 /* rq "owned" by this entity/group: */
893 struct cfs_rq *my_q;
894#endif
895};
820 896
821struct task_struct { 897struct task_struct {
822 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ 898 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
@@ -832,23 +908,20 @@ struct task_struct {
832 int oncpu; 908 int oncpu;
833#endif 909#endif
834#endif 910#endif
835 int load_weight; /* for niceness load balancing purposes */ 911
836 int prio, static_prio, normal_prio; 912 int prio, static_prio, normal_prio;
837 struct list_head run_list; 913 struct list_head run_list;
838 struct prio_array *array; 914 struct sched_class *sched_class;
915 struct sched_entity se;
839 916
840 unsigned short ioprio; 917 unsigned short ioprio;
841#ifdef CONFIG_BLK_DEV_IO_TRACE 918#ifdef CONFIG_BLK_DEV_IO_TRACE
842 unsigned int btrace_seq; 919 unsigned int btrace_seq;
843#endif 920#endif
844 unsigned long sleep_avg;
845 unsigned long long timestamp, last_ran;
846 unsigned long long sched_time; /* sched_clock time spent running */
847 enum sleep_type sleep_type;
848 921
849 unsigned int policy; 922 unsigned int policy;
850 cpumask_t cpus_allowed; 923 cpumask_t cpus_allowed;
851 unsigned int time_slice, first_time_slice; 924 unsigned int time_slice;
852 925
853#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) 926#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
854 struct sched_info sched_info; 927 struct sched_info sched_info;
@@ -905,7 +978,8 @@ struct task_struct {
905 unsigned int rt_priority; 978 unsigned int rt_priority;
906 cputime_t utime, stime; 979 cputime_t utime, stime;
907 unsigned long nvcsw, nivcsw; /* context switch counts */ 980 unsigned long nvcsw, nivcsw; /* context switch counts */
908 struct timespec start_time; 981 struct timespec start_time; /* monotonic time */
982 struct timespec real_start_time; /* boot based time */
909/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ 983/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
910 unsigned long min_flt, maj_flt; 984 unsigned long min_flt, maj_flt;
911 985
@@ -1078,6 +1152,37 @@ struct task_struct {
1078#endif 1152#endif
1079}; 1153};
1080 1154
1155/*
1156 * Priority of a process goes from 0..MAX_PRIO-1, valid RT
1157 * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
1158 * tasks are in the range MAX_RT_PRIO..MAX_PRIO-1. Priority
1159 * values are inverted: lower p->prio value means higher priority.
1160 *
1161 * The MAX_USER_RT_PRIO value allows the actual maximum
1162 * RT priority to be separate from the value exported to
1163 * user-space. This allows kernel threads to set their
1164 * priority to a value higher than any user task. Note:
1165 * MAX_RT_PRIO must not be smaller than MAX_USER_RT_PRIO.
1166 */
1167
1168#define MAX_USER_RT_PRIO 100
1169#define MAX_RT_PRIO MAX_USER_RT_PRIO
1170
1171#define MAX_PRIO (MAX_RT_PRIO + 40)
1172#define DEFAULT_PRIO (MAX_RT_PRIO + 20)
1173
1174static inline int rt_prio(int prio)
1175{
1176 if (unlikely(prio < MAX_RT_PRIO))
1177 return 1;
1178 return 0;
1179}
1180
1181static inline int rt_task(struct task_struct *p)
1182{
1183 return rt_prio(p->prio);
1184}
1185
1081static inline pid_t process_group(struct task_struct *tsk) 1186static inline pid_t process_group(struct task_struct *tsk)
1082{ 1187{
1083 return tsk->signal->pgrp; 1188 return tsk->signal->pgrp;
@@ -1223,7 +1328,7 @@ static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
1223 1328
1224extern unsigned long long sched_clock(void); 1329extern unsigned long long sched_clock(void);
1225extern unsigned long long 1330extern unsigned long long
1226current_sched_time(const struct task_struct *current_task); 1331task_sched_runtime(struct task_struct *task);
1227 1332
1228/* sched_exec is called by processes performing an exec */ 1333/* sched_exec is called by processes performing an exec */
1229#ifdef CONFIG_SMP 1334#ifdef CONFIG_SMP
@@ -1232,6 +1337,8 @@ extern void sched_exec(void);
1232#define sched_exec() {} 1337#define sched_exec() {}
1233#endif 1338#endif
1234 1339
1340extern void sched_clock_unstable_event(void);
1341
1235#ifdef CONFIG_HOTPLUG_CPU 1342#ifdef CONFIG_HOTPLUG_CPU
1236extern void idle_task_exit(void); 1343extern void idle_task_exit(void);
1237#else 1344#else
@@ -1240,6 +1347,14 @@ static inline void idle_task_exit(void) {}
1240 1347
1241extern void sched_idle_next(void); 1348extern void sched_idle_next(void);
1242 1349
1350extern unsigned int sysctl_sched_granularity;
1351extern unsigned int sysctl_sched_wakeup_granularity;
1352extern unsigned int sysctl_sched_batch_wakeup_granularity;
1353extern unsigned int sysctl_sched_stat_granularity;
1354extern unsigned int sysctl_sched_runtime_limit;
1355extern unsigned int sysctl_sched_child_runs_first;
1356extern unsigned int sysctl_sched_features;
1357
1243#ifdef CONFIG_RT_MUTEXES 1358#ifdef CONFIG_RT_MUTEXES
1244extern int rt_mutex_getprio(struct task_struct *p); 1359extern int rt_mutex_getprio(struct task_struct *p);
1245extern void rt_mutex_setprio(struct task_struct *p, int prio); 1360extern void rt_mutex_setprio(struct task_struct *p, int prio);
@@ -1295,7 +1410,7 @@ extern struct task_struct *find_task_by_pid_type(int type, int pid);
1295extern void __set_special_pids(pid_t session, pid_t pgrp); 1410extern void __set_special_pids(pid_t session, pid_t pgrp);
1296 1411
1297/* per-UID process charging. */ 1412/* per-UID process charging. */
1298extern struct user_struct * alloc_uid(uid_t); 1413extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
1299static inline struct user_struct *get_uid(struct user_struct *u) 1414static inline struct user_struct *get_uid(struct user_struct *u)
1300{ 1415{
1301 atomic_inc(&u->__count); 1416 atomic_inc(&u->__count);
@@ -1317,8 +1432,8 @@ extern void FASTCALL(wake_up_new_task(struct task_struct * tsk,
1317#else 1432#else
1318 static inline void kick_process(struct task_struct *tsk) { } 1433 static inline void kick_process(struct task_struct *tsk) { }
1319#endif 1434#endif
1320extern void FASTCALL(sched_fork(struct task_struct * p, int clone_flags)); 1435extern void sched_fork(struct task_struct *p, int clone_flags);
1321extern void FASTCALL(sched_exit(struct task_struct * p)); 1436extern void sched_dead(struct task_struct *p);
1322 1437
1323extern int in_group_p(gid_t); 1438extern int in_group_p(gid_t);
1324extern int in_egroup_p(gid_t); 1439extern int in_egroup_p(gid_t);
@@ -1406,7 +1521,7 @@ extern struct mm_struct * mm_alloc(void);
1406extern void FASTCALL(__mmdrop(struct mm_struct *)); 1521extern void FASTCALL(__mmdrop(struct mm_struct *));
1407static inline void mmdrop(struct mm_struct * mm) 1522static inline void mmdrop(struct mm_struct * mm)
1408{ 1523{
1409 if (atomic_dec_and_test(&mm->mm_count)) 1524 if (unlikely(atomic_dec_and_test(&mm->mm_count)))
1410 __mmdrop(mm); 1525 __mmdrop(mm);
1411} 1526}
1412 1527
@@ -1638,10 +1753,7 @@ static inline unsigned int task_cpu(const struct task_struct *p)
1638 return task_thread_info(p)->cpu; 1753 return task_thread_info(p)->cpu;
1639} 1754}
1640 1755
1641static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) 1756extern void set_task_cpu(struct task_struct *p, unsigned int cpu);
1642{
1643 task_thread_info(p)->cpu = cpu;
1644}
1645 1757
1646#else 1758#else
1647 1759