diff options
Diffstat (limited to 'include/linux/sched.h')
-rw-r--r-- | include/linux/sched.h | 186 |
1 files changed, 170 insertions, 16 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 53f97eb8dbc7..a781dec1cd0b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -16,6 +16,7 @@ struct sched_param { | |||
16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
17 | #include <linux/timex.h> | 17 | #include <linux/timex.h> |
18 | #include <linux/jiffies.h> | 18 | #include <linux/jiffies.h> |
19 | #include <linux/plist.h> | ||
19 | #include <linux/rbtree.h> | 20 | #include <linux/rbtree.h> |
20 | #include <linux/thread_info.h> | 21 | #include <linux/thread_info.h> |
21 | #include <linux/cpumask.h> | 22 | #include <linux/cpumask.h> |
@@ -56,6 +57,70 @@ struct sched_param { | |||
56 | 57 | ||
57 | #include <asm/processor.h> | 58 | #include <asm/processor.h> |
58 | 59 | ||
60 | #define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */ | ||
61 | |||
62 | /* | ||
63 | * Extended scheduling parameters data structure. | ||
64 | * | ||
65 | * This is needed because the original struct sched_param can not be | ||
66 | * altered without introducing ABI issues with legacy applications | ||
67 | * (e.g., in sched_getparam()). | ||
68 | * | ||
69 | * However, the possibility of specifying more than just a priority for | ||
70 | * the tasks may be useful for a wide variety of application fields, e.g., | ||
71 | * multimedia, streaming, automation and control, and many others. | ||
72 | * | ||
73 | * This variant (sched_attr) is meant at describing a so-called | ||
74 | * sporadic time-constrained task. In such model a task is specified by: | ||
75 | * - the activation period or minimum instance inter-arrival time; | ||
76 | * - the maximum (or average, depending on the actual scheduling | ||
77 | * discipline) computation time of all instances, a.k.a. runtime; | ||
78 | * - the deadline (relative to the actual activation time) of each | ||
79 | * instance. | ||
80 | * Very briefly, a periodic (sporadic) task asks for the execution of | ||
81 | * some specific computation --which is typically called an instance-- | ||
82 | * (at most) every period. Moreover, each instance typically lasts no more | ||
83 | * than the runtime and must be completed by time instant t equal to | ||
84 | * the instance activation time + the deadline. | ||
85 | * | ||
86 | * This is reflected by the actual fields of the sched_attr structure: | ||
87 | * | ||
88 | * @size size of the structure, for fwd/bwd compat. | ||
89 | * | ||
90 | * @sched_policy task's scheduling policy | ||
91 | * @sched_flags for customizing the scheduler behaviour | ||
92 | * @sched_nice task's nice value (SCHED_NORMAL/BATCH) | ||
93 | * @sched_priority task's static priority (SCHED_FIFO/RR) | ||
94 | * @sched_deadline representative of the task's deadline | ||
95 | * @sched_runtime representative of the task's runtime | ||
96 | * @sched_period representative of the task's period | ||
97 | * | ||
98 | * Given this task model, there are a multiplicity of scheduling algorithms | ||
99 | * and policies, that can be used to ensure all the tasks will make their | ||
100 | * timing constraints. | ||
101 | * | ||
102 | * As of now, the SCHED_DEADLINE policy (sched_dl scheduling class) is the | ||
103 | * only user of this new interface. More information about the algorithm | ||
104 | * available in the scheduling class file or in Documentation/. | ||
105 | */ | ||
106 | struct sched_attr { | ||
107 | u32 size; | ||
108 | |||
109 | u32 sched_policy; | ||
110 | u64 sched_flags; | ||
111 | |||
112 | /* SCHED_NORMAL, SCHED_BATCH */ | ||
113 | s32 sched_nice; | ||
114 | |||
115 | /* SCHED_FIFO, SCHED_RR */ | ||
116 | u32 sched_priority; | ||
117 | |||
118 | /* SCHED_DEADLINE */ | ||
119 | u64 sched_runtime; | ||
120 | u64 sched_deadline; | ||
121 | u64 sched_period; | ||
122 | }; | ||
123 | |||
59 | struct exec_domain; | 124 | struct exec_domain; |
60 | struct futex_pi_state; | 125 | struct futex_pi_state; |
61 | struct robust_list_head; | 126 | struct robust_list_head; |
@@ -63,6 +128,7 @@ struct bio_list; | |||
63 | struct fs_struct; | 128 | struct fs_struct; |
64 | struct perf_event_context; | 129 | struct perf_event_context; |
65 | struct blk_plug; | 130 | struct blk_plug; |
131 | struct filename; | ||
66 | 132 | ||
67 | /* | 133 | /* |
68 | * List of flags we want to share for kernel threads, | 134 | * List of flags we want to share for kernel threads, |
@@ -164,11 +230,10 @@ extern char ___assert_task_state[1 - 2*!!( | |||
164 | /* get_task_state() */ | 230 | /* get_task_state() */ |
165 | #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \ | 231 | #define TASK_REPORT (TASK_RUNNING | TASK_INTERRUPTIBLE | \ |
166 | TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \ | 232 | TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \ |
167 | __TASK_TRACED) | 233 | __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD) |
168 | 234 | ||
169 | #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) | 235 | #define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) |
170 | #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) | 236 | #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) |
171 | #define task_is_dead(task) ((task)->exit_state != 0) | ||
172 | #define task_is_stopped_or_traced(task) \ | 237 | #define task_is_stopped_or_traced(task) \ |
173 | ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) | 238 | ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) |
174 | #define task_contributes_to_load(task) \ | 239 | #define task_contributes_to_load(task) \ |
@@ -327,22 +392,33 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, | |||
327 | static inline void arch_pick_mmap_layout(struct mm_struct *mm) {} | 392 | static inline void arch_pick_mmap_layout(struct mm_struct *mm) {} |
328 | #endif | 393 | #endif |
329 | 394 | ||
330 | |||
331 | extern void set_dumpable(struct mm_struct *mm, int value); | ||
332 | extern int get_dumpable(struct mm_struct *mm); | ||
333 | |||
334 | #define SUID_DUMP_DISABLE 0 /* No setuid dumping */ | 395 | #define SUID_DUMP_DISABLE 0 /* No setuid dumping */ |
335 | #define SUID_DUMP_USER 1 /* Dump as user of process */ | 396 | #define SUID_DUMP_USER 1 /* Dump as user of process */ |
336 | #define SUID_DUMP_ROOT 2 /* Dump as root */ | 397 | #define SUID_DUMP_ROOT 2 /* Dump as root */ |
337 | 398 | ||
338 | /* mm flags */ | 399 | /* mm flags */ |
339 | /* dumpable bits */ | ||
340 | #define MMF_DUMPABLE 0 /* core dump is permitted */ | ||
341 | #define MMF_DUMP_SECURELY 1 /* core file is readable only by root */ | ||
342 | 400 | ||
401 | /* for SUID_DUMP_* above */ | ||
343 | #define MMF_DUMPABLE_BITS 2 | 402 | #define MMF_DUMPABLE_BITS 2 |
344 | #define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1) | 403 | #define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1) |
345 | 404 | ||
405 | extern void set_dumpable(struct mm_struct *mm, int value); | ||
406 | /* | ||
407 | * This returns the actual value of the suid_dumpable flag. For things | ||
408 | * that are using this for checking for privilege transitions, it must | ||
409 | * test against SUID_DUMP_USER rather than treating it as a boolean | ||
410 | * value. | ||
411 | */ | ||
412 | static inline int __get_dumpable(unsigned long mm_flags) | ||
413 | { | ||
414 | return mm_flags & MMF_DUMPABLE_MASK; | ||
415 | } | ||
416 | |||
417 | static inline int get_dumpable(struct mm_struct *mm) | ||
418 | { | ||
419 | return __get_dumpable(mm->flags); | ||
420 | } | ||
421 | |||
346 | /* coredump filter bits */ | 422 | /* coredump filter bits */ |
347 | #define MMF_DUMP_ANON_PRIVATE 2 | 423 | #define MMF_DUMP_ANON_PRIVATE 2 |
348 | #define MMF_DUMP_ANON_SHARED 3 | 424 | #define MMF_DUMP_ANON_SHARED 3 |
@@ -485,6 +561,7 @@ struct signal_struct { | |||
485 | atomic_t sigcnt; | 561 | atomic_t sigcnt; |
486 | atomic_t live; | 562 | atomic_t live; |
487 | int nr_threads; | 563 | int nr_threads; |
564 | struct list_head thread_head; | ||
488 | 565 | ||
489 | wait_queue_head_t wait_chldexit; /* for wait4() */ | 566 | wait_queue_head_t wait_chldexit; /* for wait4() */ |
490 | 567 | ||
@@ -1029,6 +1106,51 @@ struct sched_rt_entity { | |||
1029 | #endif | 1106 | #endif |
1030 | }; | 1107 | }; |
1031 | 1108 | ||
1109 | struct sched_dl_entity { | ||
1110 | struct rb_node rb_node; | ||
1111 | |||
1112 | /* | ||
1113 | * Original scheduling parameters. Copied here from sched_attr | ||
1114 | * during sched_setscheduler2(), they will remain the same until | ||
1115 | * the next sched_setscheduler2(). | ||
1116 | */ | ||
1117 | u64 dl_runtime; /* maximum runtime for each instance */ | ||
1118 | u64 dl_deadline; /* relative deadline of each instance */ | ||
1119 | u64 dl_period; /* separation of two instances (period) */ | ||
1120 | u64 dl_bw; /* dl_runtime / dl_deadline */ | ||
1121 | |||
1122 | /* | ||
1123 | * Actual scheduling parameters. Initialized with the values above, | ||
1124 | * they are continously updated during task execution. Note that | ||
1125 | * the remaining runtime could be < 0 in case we are in overrun. | ||
1126 | */ | ||
1127 | s64 runtime; /* remaining runtime for this instance */ | ||
1128 | u64 deadline; /* absolute deadline for this instance */ | ||
1129 | unsigned int flags; /* specifying the scheduler behaviour */ | ||
1130 | |||
1131 | /* | ||
1132 | * Some bool flags: | ||
1133 | * | ||
1134 | * @dl_throttled tells if we exhausted the runtime. If so, the | ||
1135 | * task has to wait for a replenishment to be performed at the | ||
1136 | * next firing of dl_timer. | ||
1137 | * | ||
1138 | * @dl_new tells if a new instance arrived. If so we must | ||
1139 | * start executing it with full runtime and reset its absolute | ||
1140 | * deadline; | ||
1141 | * | ||
1142 | * @dl_boosted tells if we are boosted due to DI. If so we are | ||
1143 | * outside bandwidth enforcement mechanism (but only until we | ||
1144 | * exit the critical section). | ||
1145 | */ | ||
1146 | int dl_throttled, dl_new, dl_boosted; | ||
1147 | |||
1148 | /* | ||
1149 | * Bandwidth enforcement timer. Each -deadline task has its | ||
1150 | * own bandwidth to be enforced, thus we need one timer per task. | ||
1151 | */ | ||
1152 | struct hrtimer dl_timer; | ||
1153 | }; | ||
1032 | 1154 | ||
1033 | struct rcu_node; | 1155 | struct rcu_node; |
1034 | 1156 | ||
@@ -1065,6 +1187,7 @@ struct task_struct { | |||
1065 | #ifdef CONFIG_CGROUP_SCHED | 1187 | #ifdef CONFIG_CGROUP_SCHED |
1066 | struct task_group *sched_task_group; | 1188 | struct task_group *sched_task_group; |
1067 | #endif | 1189 | #endif |
1190 | struct sched_dl_entity dl; | ||
1068 | 1191 | ||
1069 | #ifdef CONFIG_PREEMPT_NOTIFIERS | 1192 | #ifdef CONFIG_PREEMPT_NOTIFIERS |
1070 | /* list of struct preempt_notifier: */ | 1193 | /* list of struct preempt_notifier: */ |
@@ -1098,6 +1221,7 @@ struct task_struct { | |||
1098 | struct list_head tasks; | 1221 | struct list_head tasks; |
1099 | #ifdef CONFIG_SMP | 1222 | #ifdef CONFIG_SMP |
1100 | struct plist_node pushable_tasks; | 1223 | struct plist_node pushable_tasks; |
1224 | struct rb_node pushable_dl_tasks; | ||
1101 | #endif | 1225 | #endif |
1102 | 1226 | ||
1103 | struct mm_struct *mm, *active_mm; | 1227 | struct mm_struct *mm, *active_mm; |
@@ -1116,7 +1240,6 @@ struct task_struct { | |||
1116 | /* Used for emulating ABI behavior of previous Linux versions */ | 1240 | /* Used for emulating ABI behavior of previous Linux versions */ |
1117 | unsigned int personality; | 1241 | unsigned int personality; |
1118 | 1242 | ||
1119 | unsigned did_exec:1; | ||
1120 | unsigned in_execve:1; /* Tell the LSMs that the process is doing an | 1243 | unsigned in_execve:1; /* Tell the LSMs that the process is doing an |
1121 | * execve */ | 1244 | * execve */ |
1122 | unsigned in_iowait:1; | 1245 | unsigned in_iowait:1; |
@@ -1160,6 +1283,7 @@ struct task_struct { | |||
1160 | /* PID/PID hash table linkage. */ | 1283 | /* PID/PID hash table linkage. */ |
1161 | struct pid_link pids[PIDTYPE_MAX]; | 1284 | struct pid_link pids[PIDTYPE_MAX]; |
1162 | struct list_head thread_group; | 1285 | struct list_head thread_group; |
1286 | struct list_head thread_node; | ||
1163 | 1287 | ||
1164 | struct completion *vfork_done; /* for vfork() */ | 1288 | struct completion *vfork_done; /* for vfork() */ |
1165 | int __user *set_child_tid; /* CLONE_CHILD_SETTID */ | 1289 | int __user *set_child_tid; /* CLONE_CHILD_SETTID */ |
@@ -1249,9 +1373,12 @@ struct task_struct { | |||
1249 | 1373 | ||
1250 | #ifdef CONFIG_RT_MUTEXES | 1374 | #ifdef CONFIG_RT_MUTEXES |
1251 | /* PI waiters blocked on a rt_mutex held by this task */ | 1375 | /* PI waiters blocked on a rt_mutex held by this task */ |
1252 | struct plist_head pi_waiters; | 1376 | struct rb_root pi_waiters; |
1377 | struct rb_node *pi_waiters_leftmost; | ||
1253 | /* Deadlock detection and priority inheritance handling */ | 1378 | /* Deadlock detection and priority inheritance handling */ |
1254 | struct rt_mutex_waiter *pi_blocked_on; | 1379 | struct rt_mutex_waiter *pi_blocked_on; |
1380 | /* Top pi_waiters task */ | ||
1381 | struct task_struct *pi_top_task; | ||
1255 | #endif | 1382 | #endif |
1256 | 1383 | ||
1257 | #ifdef CONFIG_DEBUG_MUTEXES | 1384 | #ifdef CONFIG_DEBUG_MUTEXES |
@@ -1880,7 +2007,9 @@ static inline void sched_clock_idle_wakeup_event(u64 delta_ns) | |||
1880 | * but then during bootup it turns out that sched_clock() | 2007 | * but then during bootup it turns out that sched_clock() |
1881 | * is reliable after all: | 2008 | * is reliable after all: |
1882 | */ | 2009 | */ |
1883 | extern int sched_clock_stable; | 2010 | extern int sched_clock_stable(void); |
2011 | extern void set_sched_clock_stable(void); | ||
2012 | extern void clear_sched_clock_stable(void); | ||
1884 | 2013 | ||
1885 | extern void sched_clock_tick(void); | 2014 | extern void sched_clock_tick(void); |
1886 | extern void sched_clock_idle_sleep_event(void); | 2015 | extern void sched_clock_idle_sleep_event(void); |
@@ -1959,6 +2088,8 @@ extern int sched_setscheduler(struct task_struct *, int, | |||
1959 | const struct sched_param *); | 2088 | const struct sched_param *); |
1960 | extern int sched_setscheduler_nocheck(struct task_struct *, int, | 2089 | extern int sched_setscheduler_nocheck(struct task_struct *, int, |
1961 | const struct sched_param *); | 2090 | const struct sched_param *); |
2091 | extern int sched_setattr(struct task_struct *, | ||
2092 | const struct sched_attr *); | ||
1962 | extern struct task_struct *idle_task(int cpu); | 2093 | extern struct task_struct *idle_task(int cpu); |
1963 | /** | 2094 | /** |
1964 | * is_idle_task - is the specified task an idle task? | 2095 | * is_idle_task - is the specified task an idle task? |
@@ -2038,7 +2169,7 @@ extern void wake_up_new_task(struct task_struct *tsk); | |||
2038 | #else | 2169 | #else |
2039 | static inline void kick_process(struct task_struct *tsk) { } | 2170 | static inline void kick_process(struct task_struct *tsk) { } |
2040 | #endif | 2171 | #endif |
2041 | extern void sched_fork(unsigned long clone_flags, struct task_struct *p); | 2172 | extern int sched_fork(unsigned long clone_flags, struct task_struct *p); |
2042 | extern void sched_dead(struct task_struct *p); | 2173 | extern void sched_dead(struct task_struct *p); |
2043 | 2174 | ||
2044 | extern void proc_caches_init(void); | 2175 | extern void proc_caches_init(void); |
@@ -2164,8 +2295,6 @@ extern struct mm_struct *get_task_mm(struct task_struct *task); | |||
2164 | extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode); | 2295 | extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode); |
2165 | /* Remove the current tasks stale references to the old mm_struct */ | 2296 | /* Remove the current tasks stale references to the old mm_struct */ |
2166 | extern void mm_release(struct task_struct *, struct mm_struct *); | 2297 | extern void mm_release(struct task_struct *, struct mm_struct *); |
2167 | /* Allocate a new mm structure and copy contents from tsk->mm */ | ||
2168 | extern struct mm_struct *dup_mm(struct task_struct *tsk); | ||
2169 | 2298 | ||
2170 | extern int copy_thread(unsigned long, unsigned long, unsigned long, | 2299 | extern int copy_thread(unsigned long, unsigned long, unsigned long, |
2171 | struct task_struct *); | 2300 | struct task_struct *); |
@@ -2183,7 +2312,7 @@ extern void do_group_exit(int); | |||
2183 | extern int allow_signal(int); | 2312 | extern int allow_signal(int); |
2184 | extern int disallow_signal(int); | 2313 | extern int disallow_signal(int); |
2185 | 2314 | ||
2186 | extern int do_execve(const char *, | 2315 | extern int do_execve(struct filename *, |
2187 | const char __user * const __user *, | 2316 | const char __user * const __user *, |
2188 | const char __user * const __user *); | 2317 | const char __user * const __user *); |
2189 | extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *); | 2318 | extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *); |
@@ -2223,6 +2352,16 @@ extern bool current_is_single_threaded(void); | |||
2223 | #define while_each_thread(g, t) \ | 2352 | #define while_each_thread(g, t) \ |
2224 | while ((t = next_thread(t)) != g) | 2353 | while ((t = next_thread(t)) != g) |
2225 | 2354 | ||
2355 | #define __for_each_thread(signal, t) \ | ||
2356 | list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node) | ||
2357 | |||
2358 | #define for_each_thread(p, t) \ | ||
2359 | __for_each_thread((p)->signal, t) | ||
2360 | |||
2361 | /* Careful: this is a double loop, 'break' won't work as expected. */ | ||
2362 | #define for_each_process_thread(p, t) \ | ||
2363 | for_each_process(p) for_each_thread(p, t) | ||
2364 | |||
2226 | static inline int get_nr_threads(struct task_struct *tsk) | 2365 | static inline int get_nr_threads(struct task_struct *tsk) |
2227 | { | 2366 | { |
2228 | return tsk->signal->nr_threads; | 2367 | return tsk->signal->nr_threads; |
@@ -2627,6 +2766,21 @@ static inline bool __must_check current_clr_polling_and_test(void) | |||
2627 | } | 2766 | } |
2628 | #endif | 2767 | #endif |
2629 | 2768 | ||
2769 | static inline void current_clr_polling(void) | ||
2770 | { | ||
2771 | __current_clr_polling(); | ||
2772 | |||
2773 | /* | ||
2774 | * Ensure we check TIF_NEED_RESCHED after we clear the polling bit. | ||
2775 | * Once the bit is cleared, we'll get IPIs with every new | ||
2776 | * TIF_NEED_RESCHED and the IPI handler, scheduler_ipi(), will also | ||
2777 | * fold. | ||
2778 | */ | ||
2779 | smp_mb(); /* paired with resched_task() */ | ||
2780 | |||
2781 | preempt_fold_need_resched(); | ||
2782 | } | ||
2783 | |||
2630 | static __always_inline bool need_resched(void) | 2784 | static __always_inline bool need_resched(void) |
2631 | { | 2785 | { |
2632 | return unlikely(tif_need_resched()); | 2786 | return unlikely(tif_need_resched()); |