Skip to content

Commit 92cf211

Browse files
fweisbecIngo Molnar
authored andcommitted
sched/preempt: Merge preempt_mask.h into preempt.h
preempt_mask.h defines all the preempt_count semantics and related symbols: preempt, softirq, hardirq, nmi, preempt active, need resched, etc... preempt.h defines the accessors and mutators of preempt_count. But there is a messy dependency game around those two header files: * preempt_mask.h includes preempt.h in order to access preempt_count() * preempt_mask.h defines all preempt_count semantic and symbols except PREEMPT_NEED_RESCHED that is needed by asm/preempt.h Thus we need to define it from preempt.h, right before including asm/preempt.h, instead of defining it to preempt_mask.h with the other preempt_count symbols. Therefore the preempt_count semantics happen to be spread out. * We plan to introduce preempt_active_[enter,exit]() to consolidate preempt_schedule*() code. But we'll need to access both preempt_count mutators (preempt_count_add()) and preempt_count symbols (PREEMPT_ACTIVE, PREEMPT_OFFSET). The usual place to define preempt operations is in preempt.h but then we'll need symbols in preempt_mask.h which already includes preempt.h. So we end up with a ressource circle dependency. Lets merge preempt_mask.h into preempt.h to solve these dependency issues. This way we gather semantic symbols and operation definition of preempt_count in a single file. This is a dumb copy-paste merge. Further merge re-arrangments are performed in a subsequent patch to ease review. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1431441711-29753-2-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent a22ae71 commit 92cf211

File tree

7 files changed

+114
-124
lines changed

7 files changed

+114
-124
lines changed

arch/m68k/include/asm/irqflags.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#define _M68K_IRQFLAGS_H
33

44
#include <linux/types.h>
5-
#ifdef CONFIG_MMU
6-
#include <linux/preempt_mask.h>
7-
#endif
85
#include <linux/preempt.h>
96
#include <asm/thread_info.h>
107
#include <asm/entry.h>

include/linux/bottom_half.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define _LINUX_BH_H
33

44
#include <linux/preempt.h>
5-
#include <linux/preempt_mask.h>
65

76
#ifdef CONFIG_TRACE_IRQFLAGS
87
extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);

include/linux/hardirq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef LINUX_HARDIRQ_H
22
#define LINUX_HARDIRQ_H
33

4-
#include <linux/preempt_mask.h>
4+
#include <linux/preempt.h>
55
#include <linux/lockdep.h>
66
#include <linux/ftrace_irq.h>
77
#include <linux/vtime.h>

include/linux/preempt.h

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,117 @@
1717

1818
#include <asm/preempt.h>
1919

20+
/*
21+
* We put the hardirq and softirq counter into the preemption
22+
* counter. The bitmask has the following meaning:
23+
*
24+
* - bits 0-7 are the preemption count (max preemption depth: 256)
25+
* - bits 8-15 are the softirq count (max # of softirqs: 256)
26+
*
27+
* The hardirq count could in theory be the same as the number of
28+
* interrupts in the system, but we run all interrupt handlers with
29+
* interrupts disabled, so we cannot have nesting interrupts. Though
30+
* there are a few palaeontologic drivers which reenable interrupts in
31+
* the handler, so we need more than one bit here.
32+
*
33+
* PREEMPT_MASK: 0x000000ff
34+
* SOFTIRQ_MASK: 0x0000ff00
35+
* HARDIRQ_MASK: 0x000f0000
36+
* NMI_MASK: 0x00100000
37+
* PREEMPT_ACTIVE: 0x00200000
38+
*/
39+
#define PREEMPT_BITS 8
40+
#define SOFTIRQ_BITS 8
41+
#define HARDIRQ_BITS 4
42+
#define NMI_BITS 1
43+
44+
#define PREEMPT_SHIFT 0
45+
#define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
46+
#define HARDIRQ_SHIFT (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
47+
#define NMI_SHIFT (HARDIRQ_SHIFT + HARDIRQ_BITS)
48+
49+
#define __IRQ_MASK(x) ((1UL << (x))-1)
50+
51+
#define PREEMPT_MASK (__IRQ_MASK(PREEMPT_BITS) << PREEMPT_SHIFT)
52+
#define SOFTIRQ_MASK (__IRQ_MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT)
53+
#define HARDIRQ_MASK (__IRQ_MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT)
54+
#define NMI_MASK (__IRQ_MASK(NMI_BITS) << NMI_SHIFT)
55+
56+
#define PREEMPT_OFFSET (1UL << PREEMPT_SHIFT)
57+
#define SOFTIRQ_OFFSET (1UL << SOFTIRQ_SHIFT)
58+
#define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
59+
#define NMI_OFFSET (1UL << NMI_SHIFT)
60+
61+
#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
62+
63+
#define PREEMPT_ACTIVE_BITS 1
64+
#define PREEMPT_ACTIVE_SHIFT (NMI_SHIFT + NMI_BITS)
65+
#define PREEMPT_ACTIVE (__IRQ_MASK(PREEMPT_ACTIVE_BITS) << PREEMPT_ACTIVE_SHIFT)
66+
67+
#define hardirq_count() (preempt_count() & HARDIRQ_MASK)
68+
#define softirq_count() (preempt_count() & SOFTIRQ_MASK)
69+
#define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK \
70+
| NMI_MASK))
71+
72+
/*
73+
* Are we doing bottom half or hardware interrupt processing?
74+
* Are we in a softirq context? Interrupt context?
75+
* in_softirq - Are we currently processing softirq or have bh disabled?
76+
* in_serving_softirq - Are we currently processing softirq?
77+
*/
78+
#define in_irq() (hardirq_count())
79+
#define in_softirq() (softirq_count())
80+
#define in_interrupt() (irq_count())
81+
#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
82+
83+
/*
84+
* Are we in NMI context?
85+
*/
86+
#define in_nmi() (preempt_count() & NMI_MASK)
87+
88+
#if defined(CONFIG_PREEMPT_COUNT)
89+
# define PREEMPT_CHECK_OFFSET 1
90+
#else
91+
# define PREEMPT_CHECK_OFFSET 0
92+
#endif
93+
94+
/*
95+
* The preempt_count offset needed for things like:
96+
*
97+
* spin_lock_bh()
98+
*
99+
* Which need to disable both preemption (CONFIG_PREEMPT_COUNT) and
100+
* softirqs, such that unlock sequences of:
101+
*
102+
* spin_unlock();
103+
* local_bh_enable();
104+
*
105+
* Work as expected.
106+
*/
107+
#define SOFTIRQ_LOCK_OFFSET (SOFTIRQ_DISABLE_OFFSET + PREEMPT_CHECK_OFFSET)
108+
109+
/*
110+
* Are we running in atomic context? WARNING: this macro cannot
111+
* always detect atomic context; in particular, it cannot know about
112+
* held spinlocks in non-preemptible kernels. Thus it should not be
113+
* used in the general case to determine whether sleeping is possible.
114+
* Do not use in_atomic() in driver code.
115+
*/
116+
#define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
117+
118+
/*
119+
* Check whether we were atomic before we did preempt_disable():
120+
* (used by the scheduler, *after* releasing the kernel lock)
121+
*/
122+
#define in_atomic_preempt_off() \
123+
((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
124+
125+
#ifdef CONFIG_PREEMPT_COUNT
126+
# define preemptible() (preempt_count() == 0 && !irqs_disabled())
127+
#else
128+
# define preemptible() 0
129+
#endif
130+
20131
#if defined(CONFIG_DEBUG_PREEMPT) || defined(CONFIG_PREEMPT_TRACER)
21132
extern void preempt_count_add(int val);
22133
extern void preempt_count_sub(int val);

include/linux/preempt_mask.h

Lines changed: 0 additions & 117 deletions
This file was deleted.

include/linux/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct sched_param {
2525
#include <linux/errno.h>
2626
#include <linux/nodemask.h>
2727
#include <linux/mm_types.h>
28-
#include <linux/preempt_mask.h>
28+
#include <linux/preempt.h>
2929

3030
#include <asm/page.h>
3131
#include <asm/ptrace.h>

lib/radix-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <linux/string.h>
3434
#include <linux/bitops.h>
3535
#include <linux/rcupdate.h>
36-
#include <linux/preempt_mask.h> /* in_interrupt() */
36+
#include <linux/preempt.h> /* in_interrupt() */
3737

3838

3939
/*

0 commit comments

Comments
 (0)