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.h118
1 files changed, 91 insertions, 27 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 26a2e6122734..7de815c6fa78 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -25,7 +25,7 @@ struct sched_param {
25#include <linux/errno.h> 25#include <linux/errno.h>
26#include <linux/nodemask.h> 26#include <linux/nodemask.h>
27#include <linux/mm_types.h> 27#include <linux/mm_types.h>
28#include <linux/preempt_mask.h> 28#include <linux/preempt.h>
29 29
30#include <asm/page.h> 30#include <asm/page.h>
31#include <asm/ptrace.h> 31#include <asm/ptrace.h>
@@ -173,7 +173,12 @@ extern unsigned long nr_iowait_cpu(int cpu);
173extern void get_iowait_load(unsigned long *nr_waiters, unsigned long *load); 173extern void get_iowait_load(unsigned long *nr_waiters, unsigned long *load);
174 174
175extern void calc_global_load(unsigned long ticks); 175extern void calc_global_load(unsigned long ticks);
176
177#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
176extern void update_cpu_load_nohz(void); 178extern void update_cpu_load_nohz(void);
179#else
180static inline void update_cpu_load_nohz(void) { }
181#endif
177 182
178extern unsigned long get_parent_ip(unsigned long addr); 183extern unsigned long get_parent_ip(unsigned long addr);
179 184
@@ -213,9 +218,10 @@ print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
213#define TASK_WAKEKILL 128 218#define TASK_WAKEKILL 128
214#define TASK_WAKING 256 219#define TASK_WAKING 256
215#define TASK_PARKED 512 220#define TASK_PARKED 512
216#define TASK_STATE_MAX 1024 221#define TASK_NOLOAD 1024
222#define TASK_STATE_MAX 2048
217 223
218#define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWP" 224#define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPN"
219 225
220extern char ___assert_task_state[1 - 2*!!( 226extern char ___assert_task_state[1 - 2*!!(
221 sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)]; 227 sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)];
@@ -225,6 +231,8 @@ extern char ___assert_task_state[1 - 2*!!(
225#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) 231#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
226#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) 232#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)
227 233
234#define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
235
228/* Convenience macros for the sake of wake_up */ 236/* Convenience macros for the sake of wake_up */
229#define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) 237#define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
230#define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED) 238#define TASK_ALL (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
@@ -240,7 +248,8 @@ extern char ___assert_task_state[1 - 2*!!(
240 ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) 248 ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
241#define task_contributes_to_load(task) \ 249#define task_contributes_to_load(task) \
242 ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \ 250 ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
243 (task->flags & PF_FROZEN) == 0) 251 (task->flags & PF_FROZEN) == 0 && \
252 (task->state & TASK_NOLOAD) == 0)
244 253
245#ifdef CONFIG_DEBUG_ATOMIC_SLEEP 254#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
246 255
@@ -567,6 +576,23 @@ struct task_cputime {
567 .sum_exec_runtime = 0, \ 576 .sum_exec_runtime = 0, \
568 } 577 }
569 578
579/*
580 * This is the atomic variant of task_cputime, which can be used for
581 * storing and updating task_cputime statistics without locking.
582 */
583struct task_cputime_atomic {
584 atomic64_t utime;
585 atomic64_t stime;
586 atomic64_t sum_exec_runtime;
587};
588
589#define INIT_CPUTIME_ATOMIC \
590 (struct task_cputime_atomic) { \
591 .utime = ATOMIC64_INIT(0), \
592 .stime = ATOMIC64_INIT(0), \
593 .sum_exec_runtime = ATOMIC64_INIT(0), \
594 }
595
570#ifdef CONFIG_PREEMPT_COUNT 596#ifdef CONFIG_PREEMPT_COUNT
571#define PREEMPT_DISABLED (1 + PREEMPT_ENABLED) 597#define PREEMPT_DISABLED (1 + PREEMPT_ENABLED)
572#else 598#else
@@ -584,18 +610,16 @@ struct task_cputime {
584 610
585/** 611/**
586 * struct thread_group_cputimer - thread group interval timer counts 612 * struct thread_group_cputimer - thread group interval timer counts
587 * @cputime: thread group interval timers. 613 * @cputime_atomic: atomic thread group interval timers.
588 * @running: non-zero when there are timers running and 614 * @running: non-zero when there are timers running and
589 * @cputime receives updates. 615 * @cputime receives updates.
590 * @lock: lock for fields in this struct.
591 * 616 *
592 * This structure contains the version of task_cputime, above, that is 617 * This structure contains the version of task_cputime, above, that is
593 * used for thread group CPU timer calculations. 618 * used for thread group CPU timer calculations.
594 */ 619 */
595struct thread_group_cputimer { 620struct thread_group_cputimer {
596 struct task_cputime cputime; 621 struct task_cputime_atomic cputime_atomic;
597 int running; 622 int running;
598 raw_spinlock_t lock;
599}; 623};
600 624
601#include <linux/rwsem.h> 625#include <linux/rwsem.h>
@@ -900,6 +924,50 @@ enum cpu_idle_type {
900#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT) 924#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
901 925
902/* 926/*
927 * Wake-queues are lists of tasks with a pending wakeup, whose
928 * callers have already marked the task as woken internally,
929 * and can thus carry on. A common use case is being able to
930 * do the wakeups once the corresponding user lock as been
931 * released.
932 *
933 * We hold reference to each task in the list across the wakeup,
934 * thus guaranteeing that the memory is still valid by the time
935 * the actual wakeups are performed in wake_up_q().
936 *
937 * One per task suffices, because there's never a need for a task to be
938 * in two wake queues simultaneously; it is forbidden to abandon a task
939 * in a wake queue (a call to wake_up_q() _must_ follow), so if a task is
940 * already in a wake queue, the wakeup will happen soon and the second
941 * waker can just skip it.
942 *
943 * The WAKE_Q macro declares and initializes the list head.
944 * wake_up_q() does NOT reinitialize the list; it's expected to be
945 * called near the end of a function, where the fact that the queue is
946 * not used again will be easy to see by inspection.
947 *
948 * Note that this can cause spurious wakeups. schedule() callers
949 * must ensure the call is done inside a loop, confirming that the
950 * wakeup condition has in fact occurred.
951 */
952struct wake_q_node {
953 struct wake_q_node *next;
954};
955
956struct wake_q_head {
957 struct wake_q_node *first;
958 struct wake_q_node **lastp;
959};
960
961#define WAKE_Q_TAIL ((struct wake_q_node *) 0x01)
962
963#define WAKE_Q(name) \
964 struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
965
966extern void wake_q_add(struct wake_q_head *head,
967 struct task_struct *task);
968extern void wake_up_q(struct wake_q_head *head);
969
970/*
903 * sched-domains (multiprocessor balancing) declarations: 971 * sched-domains (multiprocessor balancing) declarations:
904 */ 972 */
905#ifdef CONFIG_SMP 973#ifdef CONFIG_SMP
@@ -1334,8 +1402,6 @@ struct task_struct {
1334 int rcu_read_lock_nesting; 1402 int rcu_read_lock_nesting;
1335 union rcu_special rcu_read_unlock_special; 1403 union rcu_special rcu_read_unlock_special;
1336 struct list_head rcu_node_entry; 1404 struct list_head rcu_node_entry;
1337#endif /* #ifdef CONFIG_PREEMPT_RCU */
1338#ifdef CONFIG_PREEMPT_RCU
1339 struct rcu_node *rcu_blocked_node; 1405 struct rcu_node *rcu_blocked_node;
1340#endif /* #ifdef CONFIG_PREEMPT_RCU */ 1406#endif /* #ifdef CONFIG_PREEMPT_RCU */
1341#ifdef CONFIG_TASKS_RCU 1407#ifdef CONFIG_TASKS_RCU
@@ -1369,7 +1435,7 @@ struct task_struct {
1369 int exit_state; 1435 int exit_state;
1370 int exit_code, exit_signal; 1436 int exit_code, exit_signal;
1371 int pdeath_signal; /* The signal sent when the parent dies */ 1437 int pdeath_signal; /* The signal sent when the parent dies */
1372 unsigned int jobctl; /* JOBCTL_*, siglock protected */ 1438 unsigned long jobctl; /* JOBCTL_*, siglock protected */
1373 1439
1374 /* Used for emulating ABI behavior of previous Linux versions */ 1440 /* Used for emulating ABI behavior of previous Linux versions */
1375 unsigned int personality; 1441 unsigned int personality;
@@ -1511,6 +1577,8 @@ struct task_struct {
1511 /* Protection of the PI data structures: */ 1577 /* Protection of the PI data structures: */
1512 raw_spinlock_t pi_lock; 1578 raw_spinlock_t pi_lock;
1513 1579
1580 struct wake_q_node wake_q;
1581
1514#ifdef CONFIG_RT_MUTEXES 1582#ifdef CONFIG_RT_MUTEXES
1515 /* PI waiters blocked on a rt_mutex held by this task */ 1583 /* PI waiters blocked on a rt_mutex held by this task */
1516 struct rb_root pi_waiters; 1584 struct rb_root pi_waiters;
@@ -1724,6 +1792,7 @@ struct task_struct {
1724#ifdef CONFIG_DEBUG_ATOMIC_SLEEP 1792#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
1725 unsigned long task_state_change; 1793 unsigned long task_state_change;
1726#endif 1794#endif
1795 int pagefault_disabled;
1727}; 1796};
1728 1797
1729/* Future-safe accessor for struct task_struct's cpus_allowed. */ 1798/* Future-safe accessor for struct task_struct's cpus_allowed. */
@@ -2077,22 +2146,22 @@ TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)
2077#define JOBCTL_TRAPPING_BIT 21 /* switching to TRACED */ 2146#define JOBCTL_TRAPPING_BIT 21 /* switching to TRACED */
2078#define JOBCTL_LISTENING_BIT 22 /* ptracer is listening for events */ 2147#define JOBCTL_LISTENING_BIT 22 /* ptracer is listening for events */
2079 2148
2080#define JOBCTL_STOP_DEQUEUED (1 << JOBCTL_STOP_DEQUEUED_BIT) 2149#define JOBCTL_STOP_DEQUEUED (1UL << JOBCTL_STOP_DEQUEUED_BIT)
2081#define JOBCTL_STOP_PENDING (1 << JOBCTL_STOP_PENDING_BIT) 2150#define JOBCTL_STOP_PENDING (1UL << JOBCTL_STOP_PENDING_BIT)
2082#define JOBCTL_STOP_CONSUME (1 << JOBCTL_STOP_CONSUME_BIT) 2151#define JOBCTL_STOP_CONSUME (1UL << JOBCTL_STOP_CONSUME_BIT)
2083#define JOBCTL_TRAP_STOP (1 << JOBCTL_TRAP_STOP_BIT) 2152#define JOBCTL_TRAP_STOP (1UL << JOBCTL_TRAP_STOP_BIT)
2084#define JOBCTL_TRAP_NOTIFY (1 << JOBCTL_TRAP_NOTIFY_BIT) 2153#define JOBCTL_TRAP_NOTIFY (1UL << JOBCTL_TRAP_NOTIFY_BIT)
2085#define JOBCTL_TRAPPING (1 << JOBCTL_TRAPPING_BIT) 2154#define JOBCTL_TRAPPING (1UL << JOBCTL_TRAPPING_BIT)
2086#define JOBCTL_LISTENING (1 << JOBCTL_LISTENING_BIT) 2155#define JOBCTL_LISTENING (1UL << JOBCTL_LISTENING_BIT)
2087 2156
2088#define JOBCTL_TRAP_MASK (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY) 2157#define JOBCTL_TRAP_MASK (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY)
2089#define JOBCTL_PENDING_MASK (JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK) 2158#define JOBCTL_PENDING_MASK (JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK)
2090 2159
2091extern bool task_set_jobctl_pending(struct task_struct *task, 2160extern bool task_set_jobctl_pending(struct task_struct *task,
2092 unsigned int mask); 2161 unsigned long mask);
2093extern void task_clear_jobctl_trapping(struct task_struct *task); 2162extern void task_clear_jobctl_trapping(struct task_struct *task);
2094extern void task_clear_jobctl_pending(struct task_struct *task, 2163extern void task_clear_jobctl_pending(struct task_struct *task,
2095 unsigned int mask); 2164 unsigned long mask);
2096 2165
2097static inline void rcu_copy_process(struct task_struct *p) 2166static inline void rcu_copy_process(struct task_struct *p)
2098{ 2167{
@@ -2962,11 +3031,6 @@ static __always_inline bool need_resched(void)
2962void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times); 3031void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
2963void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times); 3032void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
2964 3033
2965static inline void thread_group_cputime_init(struct signal_struct *sig)
2966{
2967 raw_spin_lock_init(&sig->cputimer.lock);
2968}
2969
2970/* 3034/*
2971 * Reevaluate whether the task has signals pending delivery. 3035 * Reevaluate whether the task has signals pending delivery.
2972 * Wake the task if so. 3036 * Wake the task if so.
@@ -3080,13 +3144,13 @@ static inline void mm_update_next_owner(struct mm_struct *mm)
3080static inline unsigned long task_rlimit(const struct task_struct *tsk, 3144static inline unsigned long task_rlimit(const struct task_struct *tsk,
3081 unsigned int limit) 3145 unsigned int limit)
3082{ 3146{
3083 return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_cur); 3147 return READ_ONCE(tsk->signal->rlim[limit].rlim_cur);
3084} 3148}
3085 3149
3086static inline unsigned long task_rlimit_max(const struct task_struct *tsk, 3150static inline unsigned long task_rlimit_max(const struct task_struct *tsk,
3087 unsigned int limit) 3151 unsigned int limit)
3088{ 3152{
3089 return ACCESS_ONCE(tsk->signal->rlim[limit].rlim_max); 3153 return READ_ONCE(tsk->signal->rlim[limit].rlim_max);
3090} 3154}
3091 3155
3092static inline unsigned long rlimit(unsigned int limit) 3156static inline unsigned long rlimit(unsigned int limit)