Skip to content

Commit bdd4e85

Browse files
committed
sched: Isolate preempt counting in its own config option
Create a new CONFIG_PREEMPT_COUNT that handles the inc/dec of preempt count offset independently. So that the offset can be updated by preempt_disable() and preempt_enable() even without the need for CONFIG_PREEMPT beeing set. This prepares to make CONFIG_DEBUG_SPINLOCK_SLEEP working with !CONFIG_PREEMPT where it currently doesn't detect code that sleeps inside explicit preemption disabled sections. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
1 parent 2da8c8b commit bdd4e85

8 files changed

Lines changed: 33 additions & 22 deletions

File tree

‎include/linux/bit_spinlock.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static inline int bit_spin_is_locked(int bitnum, unsigned long *addr)
8888
{
8989
#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
9090
return test_bit(bitnum, addr);
91-
#elif defined CONFIG_PREEMPT
91+
#elif defined CONFIG_PREEMPT_COUNT
9292
return preempt_count();
9393
#else
9494
return 1;

‎include/linux/hardirq.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
*/
9494
#define in_nmi() (preempt_count() & NMI_MASK)
9595

96-
#if defined(CONFIG_PREEMPT)
96+
#if defined(CONFIG_PREEMPT_COUNT)
9797
# define PREEMPT_CHECK_OFFSET 1
9898
#else
9999
# define PREEMPT_CHECK_OFFSET 0
@@ -115,7 +115,7 @@
115115
#define in_atomic_preempt_off() \
116116
((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET)
117117

118-
#ifdef CONFIG_PREEMPT
118+
#ifdef CONFIG_PREEMPT_COUNT
119119
# define preemptible() (preempt_count() == 0 && !irqs_disabled())
120120
# define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)
121121
#else

‎include/linux/pagemap.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static inline int page_cache_get_speculative(struct page *page)
134134
VM_BUG_ON(in_interrupt());
135135

136136
#if !defined(CONFIG_SMP) && defined(CONFIG_TREE_RCU)
137-
# ifdef CONFIG_PREEMPT
137+
# ifdef CONFIG_PREEMPT_COUNT
138138
VM_BUG_ON(!in_atomic());
139139
# endif
140140
/*
@@ -172,7 +172,7 @@ static inline int page_cache_add_speculative(struct page *page, int count)
172172
VM_BUG_ON(in_interrupt());
173173

174174
#if !defined(CONFIG_SMP) && defined(CONFIG_TREE_RCU)
175-
# ifdef CONFIG_PREEMPT
175+
# ifdef CONFIG_PREEMPT_COUNT
176176
VM_BUG_ON(!in_atomic());
177177
# endif
178178
VM_BUG_ON(page_count(page) == 0);

‎include/linux/preempt.h‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727

2828
asmlinkage void preempt_schedule(void);
2929

30+
#define preempt_check_resched() \
31+
do { \
32+
if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
33+
preempt_schedule(); \
34+
} while (0)
35+
36+
#else /* !CONFIG_PREEMPT */
37+
38+
#define preempt_check_resched() do { } while (0)
39+
40+
#endif /* CONFIG_PREEMPT */
41+
42+
43+
#ifdef CONFIG_PREEMPT_COUNT
44+
3045
#define preempt_disable() \
3146
do { \
3247
inc_preempt_count(); \
@@ -39,12 +54,6 @@ do { \
3954
dec_preempt_count(); \
4055
} while (0)
4156

42-
#define preempt_check_resched() \
43-
do { \
44-
if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
45-
preempt_schedule(); \
46-
} while (0)
47-
4857
#define preempt_enable() \
4958
do { \
5059
preempt_enable_no_resched(); \
@@ -80,18 +89,17 @@ do { \
8089
preempt_check_resched(); \
8190
} while (0)
8291

83-
#else
92+
#else /* !CONFIG_PREEMPT_COUNT */
8493

8594
#define preempt_disable() do { } while (0)
8695
#define preempt_enable_no_resched() do { } while (0)
8796
#define preempt_enable() do { } while (0)
88-
#define preempt_check_resched() do { } while (0)
8997

9098
#define preempt_disable_notrace() do { } while (0)
9199
#define preempt_enable_no_resched_notrace() do { } while (0)
92100
#define preempt_enable_notrace() do { } while (0)
93101

94-
#endif
102+
#endif /* CONFIG_PREEMPT_COUNT */
95103

96104
#ifdef CONFIG_PREEMPT_NOTIFIERS
97105

‎include/linux/rcupdate.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ extern int rcu_read_lock_bh_held(void);
239239
* Check debug_lockdep_rcu_enabled() to prevent false positives during boot
240240
* and while lockdep is disabled.
241241
*/
242-
#ifdef CONFIG_PREEMPT
242+
#ifdef CONFIG_PREEMPT_COUNT
243243
static inline int rcu_read_lock_sched_held(void)
244244
{
245245
int lockdep_opinion = 0;
@@ -250,12 +250,12 @@ static inline int rcu_read_lock_sched_held(void)
250250
lockdep_opinion = lock_is_held(&rcu_sched_lock_map);
251251
return lockdep_opinion || preempt_count() != 0 || irqs_disabled();
252252
}
253-
#else /* #ifdef CONFIG_PREEMPT */
253+
#else /* #ifdef CONFIG_PREEMPT_COUNT */
254254
static inline int rcu_read_lock_sched_held(void)
255255
{
256256
return 1;
257257
}
258-
#endif /* #else #ifdef CONFIG_PREEMPT */
258+
#endif /* #else #ifdef CONFIG_PREEMPT_COUNT */
259259

260260
#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
261261

@@ -276,17 +276,17 @@ static inline int rcu_read_lock_bh_held(void)
276276
return 1;
277277
}
278278

279-
#ifdef CONFIG_PREEMPT
279+
#ifdef CONFIG_PREEMPT_COUNT
280280
static inline int rcu_read_lock_sched_held(void)
281281
{
282282
return preempt_count() != 0 || irqs_disabled();
283283
}
284-
#else /* #ifdef CONFIG_PREEMPT */
284+
#else /* #ifdef CONFIG_PREEMPT_COUNT */
285285
static inline int rcu_read_lock_sched_held(void)
286286
{
287287
return 1;
288288
}
289-
#endif /* #else #ifdef CONFIG_PREEMPT */
289+
#endif /* #else #ifdef CONFIG_PREEMPT_COUNT */
290290

291291
#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
292292

‎include/linux/sched.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ extern int _cond_resched(void);
25022502

25032503
extern int __cond_resched_lock(spinlock_t *lock);
25042504

2505-
#ifdef CONFIG_PREEMPT
2505+
#ifdef CONFIG_PREEMPT_COUNT
25062506
#define PREEMPT_LOCK_OFFSET PREEMPT_OFFSET
25072507
#else
25082508
#define PREEMPT_LOCK_OFFSET 0

‎kernel/Kconfig.preempt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config PREEMPT_VOLUNTARY
3535

3636
config PREEMPT
3737
bool "Preemptible Kernel (Low-Latency Desktop)"
38+
select PREEMPT_COUNT
3839
help
3940
This option reduces the latency of the kernel by making
4041
all kernel code (that is not executing in a critical section)
@@ -52,3 +53,5 @@ config PREEMPT
5253

5354
endchoice
5455

56+
config PREEMPT_COUNT
57+
bool

‎kernel/sched.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2843,7 +2843,7 @@ void sched_fork(struct task_struct *p)
28432843
#if defined(CONFIG_SMP)
28442844
p->on_cpu = 0;
28452845
#endif
2846-
#ifdef CONFIG_PREEMPT
2846+
#ifdef CONFIG_PREEMPT_COUNT
28472847
/* Want to start with kernel preemption disabled. */
28482848
task_thread_info(p)->preempt_count = 1;
28492849
#endif

0 commit comments

Comments
 (0)