Stronger CONFIG_DEBUG_SPINLOCK_SLEEP without CONFIG_PREEMPT
Subsystems (3)
CONFIG_DEBUG_SPINLOCK_SLEEP without CONFIG_PREEMPT
When CONFIG_DEBUG_SPINLOCK_SLEEP is enabled, I think it would make sense to have preempt_disable() increment the preempt count in order to be able to display debug messages if someone attempts to sleep from within a critical region.
This change defines PREEMPT_LOCK_OFFSET to be the value by which preempt_disable() increment the preempt count - 1 if CONFIG_PREEMPT and/or CONFIG_DEBUG_SPINLOCK_SLEEP are set, and 0 otherwise.
If CONFIG_PREEMPT is not set, preempt_disable() should add PREEMPT_LOCK_OFFSET to the preempt count but it is allowed to skip the optimization barriers since we are not, in the non-preempt case, worried about the preempt count value being tested from within interrupt handlers.
include/linux/hardirq.h +5 -7
@@ -2,7 +2,7 @@#define LINUX_HARDIRQ_H #include <linux/preempt.h> -#ifdef CONFIG_PREEMPT +#if PREEMPT_LOCK_OFFSET #include <linux/smp_lock.h> #endif #include <linux/lockdep.h>
@@ -92,12 +92,10 @@*/ #define in_nmi () (preempt_count() & NMI_MASK) -#if defined(CONFIG_PREEMPT ) +#if PREEMPT_LOCK_OFFSET # define PREEMPT_INATOMIC_BASE kernel_locked() -# define PREEMPT_CHECK_OFFSET 1#else # define PREEMPT_INATOMIC_BASE 0 -# define PREEMPT_CHECK_OFFSET 0#endif /*
@@ -114,16 +112,16 @@* (used by the scheduler, *after* releasing the kernel lock) */ #define in_atomic_preempt_off () \ - ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_CHECK_OFFSET) + ((preempt_count() & ~PREEMPT_ACTIVE) != PREEMPT_LOCK_OFFSET)#ifdef CONFIG_PREEMPT # define preemptible () (preempt_count() == 0 && !irqs_disabled()) -# define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET-1)#else # define preemptible () 0 -# define IRQ_EXIT_OFFSET HARDIRQ_OFFSET#endif +#define IRQ_EXIT_OFFSET (HARDIRQ_OFFSET - PREEMPT_LOCK_OFFSET) +#if defined(CONFIG_SMP ) || defined(CONFIG_GENERIC_HARDIRQS )extern void synchronize_irq (unsigned int irq);#else
include/linux/pagemap.h +2 -6
@@ -133,9 +133,7 @@ static inline int page_cache_get_speculative(struct page *page)VM_BUG_ON (in_interrupt ());#if !defined(CONFIG_SMP ) && defined(CONFIG_TREE_RCU ) -# ifdef CONFIG_PREEMPT -VM_BUG_ON (!in_atomic ()); -# endif +VM_BUG_ON (PREEMPT_LOCK_OFFSET && !in_atomic ());/* * Preempt must be disabled here - we rely on rcu_read_lock doing * this for us.
@@ -171,9 +169,7 @@ static inline int page_cache_add_speculative(struct page *page, int count)VM_BUG_ON (in_interrupt ());#if !defined(CONFIG_SMP ) && defined(CONFIG_TREE_RCU ) -# ifdef CONFIG_PREEMPT -VM_BUG_ON (!in_atomic ()); -# endif +VM_BUG_ON (PREEMPT_LOCK_OFFSET && !in_atomic ());VM_BUG_ON (page_count (page) ==0 );atomic_add (count, &page->_count);
include/linux/preempt.h +34 -35
112 lines not on this page · raw message
include/linux/sched.h +0 -6
@@ -2354,12 +2354,6 @@ extern int _cond_resched(void);extern int __cond_resched_lock (spinlock_t *lock); -#ifdef CONFIG_PREEMPT -#define PREEMPT_LOCK_OFFSET PREEMPT_OFFSET -#else -#define PREEMPT_LOCK_OFFSET 0 -#endif -#define cond_resched_lock (lock) ({ \ __might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET); \ __cond_resched_lock(lock); \
kernel/sched.c +4 -7
@@ -2641,9 +2641,9 @@ void sched_fork(struct task_struct *p, int clone_flags)#if defined(CONFIG_SMP ) && defined(__ARCH_WANT_UNLOCKED_CTXSW) p->oncpu =0 ;#endif -#ifdef CONFIG_PREEMPT +#if PREEMPT_LOCK_OFFSET /* Want to start with kernel preemption disabled. */ -task_thread_info (p)->preempt_count =1 ; +task_thread_info (p)->preempt_count =PREEMPT_LOCK_OFFSET ;#endif plist_node_init (&p->pushable_tasks,MAX_PRIO );
@@ -5266,11 +5266,8 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)raw_spin_unlock_irqrestore (&rq->lock, flags);/* Set the preempt count _outside_ the spinlocks! */ -#if defined(CONFIG_PREEMPT ) -task_thread_info (idle)->preempt_count = (idle->lock_depth >=0 ); -#else -task_thread_info (idle)->preempt_count =0 ; -#endif +task_thread_info (idle)->preempt_count = + (idle->lock_depth >=0 ) ?PREEMPT_LOCK_OFFSET :0 ;/* * The idle tasks have their own, simple scheduling class: */
lib/kernel_lock.c +1 -0
@@ -96,6 +96,7 @@ static inline void __lock_kernel(void)*/ static inline void __lock_kernel (void ) { +preempt_disable ();do_raw_spin_lock (&kernel_flag); }#endif
Signature · 2 lines
Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.