aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2013-08-14 08:55:46 -0400
committerIngo Molnar <mingo@kernel.org>2013-09-25 08:07:52 -0400
commit01028747559ac6c6f642a7bbd2875cc4f66b2feb (patch)
tree3672a4ca3409cae40d5c7338ad9bfa590045dcbc
parenta787870924dbd6f321661e06d4ec1c7a408c9ccf (diff)
sched: Create more preempt_count accessors
We need a few special preempt_count accessors: - task_preempt_count() for when we're interested in the preemption count of another (non-running) task. - init_task_preempt_count() for properly initializing the preemption count. - init_idle_preempt_count() a special case of the above for the idle threads. With these no generic code ever touches thread_info::preempt_count anymore and architectures could choose to remove it. Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/n/tip-jf5swrio8l78j37d06fzmo4r@git.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--include/asm-generic/preempt.h14
-rw-r--r--include/trace/events/sched.h2
-rw-r--r--kernel/sched/core.c7
3 files changed, 18 insertions, 5 deletions
diff --git a/include/asm-generic/preempt.h b/include/asm-generic/preempt.h
index a1fc6590a743..8100b1ec1715 100644
--- a/include/asm-generic/preempt.h
+++ b/include/asm-generic/preempt.h
@@ -28,6 +28,20 @@ static __always_inline void preempt_count_set(int pc)
28} 28}
29 29
30/* 30/*
31 * must be macros to avoid header recursion hell
32 */
33#define task_preempt_count(p) \
34 (task_thread_info(p)->preempt_count & ~PREEMPT_NEED_RESCHED)
35
36#define init_task_preempt_count(p) do { \
37 task_thread_info(p)->preempt_count = PREEMPT_DISABLED; \
38} while (0)
39
40#define init_idle_preempt_count(p, cpu) do { \
41 task_thread_info(p)->preempt_count = PREEMPT_ENABLED; \
42} while (0)
43
44/*
31 * We fold the NEED_RESCHED bit into the preempt count such that 45 * We fold the NEED_RESCHED bit into the preempt count such that
32 * preempt_enable() can decrement and test for needing to reschedule with a 46 * preempt_enable() can decrement and test for needing to reschedule with a
33 * single instruction. 47 * single instruction.
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index 2e7d9947a10d..613381bcde40 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -100,7 +100,7 @@ static inline long __trace_sched_switch_state(struct task_struct *p)
100 /* 100 /*
101 * For all intents and purposes a preempted task is a running task. 101 * For all intents and purposes a preempted task is a running task.
102 */ 102 */
103 if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE) 103 if (task_preempt_count(p) & PREEMPT_ACTIVE)
104 state = TASK_RUNNING | TASK_STATE_MAX; 104 state = TASK_RUNNING | TASK_STATE_MAX;
105#endif 105#endif
106 106
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ee61f5affd20..0ba4e4192390 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -983,7 +983,7 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
983 * ttwu() will sort out the placement. 983 * ttwu() will sort out the placement.
984 */ 984 */
985 WARN_ON_ONCE(p->state != TASK_RUNNING && p->state != TASK_WAKING && 985 WARN_ON_ONCE(p->state != TASK_RUNNING && p->state != TASK_WAKING &&
986 !(task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)); 986 !(task_preempt_count(p) & PREEMPT_ACTIVE));
987 987
988#ifdef CONFIG_LOCKDEP 988#ifdef CONFIG_LOCKDEP
989 /* 989 /*
@@ -1723,8 +1723,7 @@ void sched_fork(struct task_struct *p)
1723 p->on_cpu = 0; 1723 p->on_cpu = 0;
1724#endif 1724#endif
1725#ifdef CONFIG_PREEMPT_COUNT 1725#ifdef CONFIG_PREEMPT_COUNT
1726 /* Want to start with kernel preemption disabled. */ 1726 init_task_preempt_count(p);
1727 task_thread_info(p)->preempt_count = PREEMPT_DISABLED;
1728#endif 1727#endif
1729#ifdef CONFIG_SMP 1728#ifdef CONFIG_SMP
1730 plist_node_init(&p->pushable_tasks, MAX_PRIO); 1729 plist_node_init(&p->pushable_tasks, MAX_PRIO);
@@ -4217,7 +4216,7 @@ void init_idle(struct task_struct *idle, int cpu)
4217 raw_spin_unlock_irqrestore(&rq->lock, flags); 4216 raw_spin_unlock_irqrestore(&rq->lock, flags);
4218 4217
4219 /* Set the preempt count _outside_ the spinlocks! */ 4218 /* Set the preempt count _outside_ the spinlocks! */
4220 task_thread_info(idle)->preempt_count = PREEMPT_ENABLED; 4219 init_idle_preempt_count(idle, cpu);
4221 4220
4222 /* 4221 /*
4223 * The idle tasks have their own, simple scheduling class: 4222 * The idle tasks have their own, simple scheduling class: