Skip to contentSkip to conversation

preempt rcu: check for underflow

PATCH Applied Daniel Walker 6 participants 26 messages Jul 30, 2007 – Aug 8, 2007

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/9 preempt rcu: check for underflow

Simple WARN_ON to catch any underflow in rcu_read_lock_nesting.

---
 kernel/rcupreempt.c |    6 ++++++
 1 file changed, 6 insertions(+)
kernel/rcupreempt.c +6 -0
Index: linux-2.6.22/kernel/rcupreempt.c
===================================================================
@@ -157,6 +157,12 @@ void __rcu_read_unlock(void)
 	}
 
 	local_irq_restore(oldirq);
+
+	/*
+	 * If our rcu_read_lock_nesting went negative, likely
+	 * something is wrong..
+	 */
+	WARN_ON(current->rcu_read_lock_nesting < 0);
 }
 
 static void __rcu_advance_callbacks(void)
#4 lore raw

PATCH 3/9 Fix jiffies wrap issue in update_times

In prior -rt verisons the last_tick value was called wall_jiffies and was initialized in this same way as below. If this value isn't initialized the calc_load function gets skewed for several minutes right after boot up. Skewed meaning always zero.

---
 kernel/timer.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/timer.c +1 -1
Index: linux-2.6.22/kernel/timer.c
===================================================================
@@ -987,7 +987,7 @@ void run_local_timers(void)
  */
 static inline void update_times(void)
 {
-	static unsigned long last_tick;
+	static unsigned long last_tick = INITIAL_JIFFIES;
 	unsigned long ticks, flags;
 
 	/*
#6 lore raw

PATCH 4/9 ifdef raise_softirq_irqoff wakeup

In reply to Daniel Walker

raise_softirq is called every timer interrupt in run_local_timers(), which causes a thread wakeup to happen every timer interrupt. This happens in !CONFIG_PREEMPT_SOFTIRQS, which means the wakeup is most likely not needed. In addition it also fouls calc_load() since it's, agian, observing at least one thread running on every invocation.

---
 kernel/softirq.c |    2 ++
 1 file changed, 2 insertions(+)
kernel/softirq.c +2 -0
Index: linux-2.6.22/kernel/softirq.c
===================================================================
@@ -508,7 +508,9 @@ inline fastcall void raise_softirq_irqof
 {
 	__do_raise_softirq_irqoff(nr);
 
+#ifdef CONFIG_PREEMPT_SOFTIRQS
 	wakeup_softirqd(nr);
+#endif
 }
 
 EXPORT_SYMBOL(raise_softirq_irqoff);
#10 lore raw

PATCH 5/9 net: fix mis-merge in qdisc_restart

In reply to Daniel Walker

This mismerge caused my networking to malfunction. The interface would come up, but no traffic would make it in/out ..

---
 net/sched/sch_generic.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_generic.c +1 -1
Index: linux-2.6.22/net/sched/sch_generic.c
===================================================================
@@ -156,7 +156,7 @@ static inline int qdisc_restart(struct n
 #ifdef CONFIG_PREEMPT_RT
 		netif_tx_lock(dev);
 #else
-		if (netif_tx_trylock(dev))
+		if (!netif_tx_trylock(dev))
 			/* Another CPU grabbed the driver tx lock */
 			return handle_dev_cpu_collision(skb, dev, q);
 #endif
#12 lore raw

PATCH 6/9 spinlock/rt_lock random cleanups

In reply to Daniel Walker
---
 include/linux/rt_lock.h  |    6 ++++--
 include/linux/spinlock.h |    5 +++--
 2 files changed, 7 insertions(+), 4 deletions(-)
include/linux/rt_lock.h +4 -2
Index: linux-2.6.22/include/linux/rt_lock.h
===================================================================
@@ -128,12 +128,14 @@ struct semaphore name = \
  */
 #define DECLARE_MUTEX_LOCKED COMPAT_DECLARE_MUTEX_LOCKED
 
-extern void fastcall __sema_init(struct semaphore *sem, int val, char *name, char *file, int line);
+extern void fastcall
+__sema_init(struct semaphore *sem, int val, char *name, char *file, int line);
 
 #define rt_sema_init(sem, val) \
 		__sema_init(sem, val, #sem, __FILE__, __LINE__)
 
-extern void fastcall __init_MUTEX(struct semaphore *sem, char *name, char *file, int line);
+extern void fastcall
+__init_MUTEX(struct semaphore *sem, char *name, char *file, int line);
 #define rt_init_MUTEX(sem) \
 		__init_MUTEX(sem, #sem, __FILE__, __LINE__)
 
include/linux/spinlock.h +3 -2
Index: linux-2.6.22/include/linux/spinlock.h
===================================================================
@@ -126,7 +126,7 @@ extern int __lockfunc generic__raw_read_
 
 #ifdef CONFIG_DEBUG_SPINLOCK
  extern __lockfunc void _raw_spin_lock(raw_spinlock_t *lock);
-#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
+# define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
  extern __lockfunc int _raw_spin_trylock(raw_spinlock_t *lock);
  extern __lockfunc void _raw_spin_unlock(raw_spinlock_t *lock);
  extern __lockfunc void _raw_read_lock(raw_rwlock_t *lock);
@@ -325,7 +325,8 @@ do {							\
 
 # define _read_trylock(rwl)	rt_read_trylock(rwl)
 # define _write_trylock(rwl)	rt_write_trylock(rwl)
-#define _write_trylock_irqsave(rwl, flags)  rt_write_trylock_irqsave(rwl, flags)
+# define _write_trylock_irqsave(rwl, flags) \
+	rt_write_trylock_irqsave(rwl, flags)
 
 # define _read_lock(rwl)	rt_read_lock(rwl)
 # define _write_lock(rwl)	rt_write_lock(rwl)
#16 lore raw

PATCH 7/9 introduce PICK_FUNCTION

In reply to Daniel Walker

PICK_FUNCTION() is similar to the other PICK_OP style macros, and was created to replace them all. I used variable argument macros to handle PICK_FUNC_2ARG/PICK_FUNC_1ARG. Otherwise the marcos are similar to the original macros used for semaphores. The entire system is used to do a compile time switch between two different locking APIs. For example, real spinlocks (raw_spinlock_t) and mutexes (or sleeping spinlocks).

This new macro replaces all the duplication from lock type to lock type. The result of this patch, and the next two, is a fairly nice simplification, and consolidation. Although the seqlock changes are larger than the originals I think over all the patchset is worth while.

---
 include/linux/pickop.h  |   32 +++++++++++
 include/linux/rt_lock.h |  129 +++++++++++++++---------------------------------
 2 files changed, 73 insertions(+), 88 deletions(-)
include/linux/pickop.h new file +32 -0
Index: linux-2.6.22/include/linux/pickop.h
===================================================================
@@ -0,0 +1,32 @@
+#ifndef _LINUX_PICKOP_H
+#define _LINUX_PICKOP_H
+
+#undef TYPE_EQUAL
+#define TYPE_EQUAL(var, type) \
+		__builtin_types_compatible_p(typeof(var), type *)
+
+extern int __bad_func_type(void);
+
+#define PICK_FUNCTION(type1, type2, func1, func2, arg0, ...)		\
+do {									\
+	if (TYPE_EQUAL((arg0), type1))					\
+		func1((type1 *)(arg0), ##__VA_ARGS__);			\
+	else if (TYPE_EQUAL((arg0), type2))				\
+		func2((type2 *)(arg0), ##__VA_ARGS__);			\
+	else __bad_func_type();						\
+} while (0)
+
+#define PICK_FUNCTION_RET(type1, type2, func1, func2, arg0, ...)	\
+({									\
+	unsigned long __ret;						\
+									\
+	if (TYPE_EQUAL((arg0), type1))					\
+		__ret = func1((type1 *)(arg0), ##__VA_ARGS__);		\
+	else if (TYPE_EQUAL((arg0), type2))				\
+		__ret = func2((type2 *)(arg0), ##__VA_ARGS__);		\
+	else __ret = __bad_func_type();					\
+									\
+	__ret;								\
+})
+
+#endif /* _LINUX_PICKOP_H */
include/linux/rt_lock.h +41 -88

175 lines not on this page · raw message

#19 lore raw

PATCH 8/9 spinlocks/rwlocks: use PICK_FUNCTION()

In reply to Daniel Walker

Reaplace old PICK_OP style macros with the new PICK_FUNCTION macro.

---
 include/linux/sched.h    |   13 -
 include/linux/spinlock.h |  345 ++++++++++++++---------------------------------
 kernel/rtmutex.c         |    2 
 lib/dec_and_lock.c       |    2 
 4 files changed, 111 insertions(+), 251 deletions(-)
include/linux/sched.h +2 -11
Index: linux-2.6.22/include/linux/sched.h
===================================================================
@@ -1997,17 +1997,8 @@ extern int __cond_resched_raw_spinlock(r
 extern int __cond_resched_spinlock(spinlock_t *spinlock);
 
 #define cond_resched_lock(lock) \
-({								\
-	int __ret;						\
-								\
-	if (TYPE_EQUAL((lock), raw_spinlock_t))	 		\
-		__ret = __cond_resched_raw_spinlock((raw_spinlock_t *)lock);\
-	else if (TYPE_EQUAL(lock, spinlock_t))			\
-		__ret = __cond_resched_spinlock((spinlock_t *)lock); \
-	else __ret = __bad_spinlock_type();			\
-								\
-	__ret;							\
-})
+	PICK_SPIN_OP_RET(__cond_resched_raw_spinlock, __cond_resched_spinlock,\
+		 lock)
 
 extern int cond_resched_softirq(void);
 extern int cond_resched_softirq_context(void);
include/linux/spinlock.h +107 -238

470 lines not on this page · raw message

kernel/rtmutex.c +1 -1
Index: linux-2.6.22/kernel/rtmutex.c
===================================================================
@@ -857,7 +857,7 @@ int __lockfunc rt_spin_trylock_irqsave(s
 }
 EXPORT_SYMBOL(rt_spin_trylock_irqsave);
 
-int _atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock)
+int _atomic_dec_and_spin_lock(spinlock_t *lock, atomic_t *atomic)
 {
 	/* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
 	if (atomic_add_unless(atomic, -1, 1))
lib/dec_and_lock.c +1 -1
Index: linux-2.6.22/lib/dec_and_lock.c
===================================================================
@@ -17,7 +17,7 @@
  * because the spin-lock and the decrement must be
  * "atomic".
  */
-int __atomic_dec_and_spin_lock(atomic_t *atomic, raw_spinlock_t *lock)
+int __atomic_dec_and_spin_lock(raw_spinlock_t *lock, atomic_t *atomic)
 {
 #ifdef CONFIG_SMP
 	/* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
#20 lore raw

PATCH 9/9 seqlocks: use PICK_FUNCTION

In reply to Daniel Walker

Replace the old PICK_OP style macros with PICK_FUNCTION. Although, seqlocks has some alien code, which I also replaced as can be seen from the line count below.

---
 include/linux/seqlock.h |  234 +++++++++++++++++++++++++++---------------------
 1 file changed, 134 insertions(+), 100 deletions(-)
include/linux/seqlock.h +134 -100
Index: linux-2.6.22/include/linux/seqlock.h
===================================================================
@@ -90,6 +90,12 @@ static inline void __write_seqlock(seqlo
 	smp_wmb();
 }
 
+static __always_inline unsigned long __write_seqlock_irqsave(seqlock_t *sl)
+{
+	__write_seqlock(sl);
+	return 0;
+}
+
 static inline void __write_sequnlock(seqlock_t *sl)
 {
 	smp_wmb();
@@ -97,6 +103,8 @@ static inline void __write_sequnlock(seq
 	spin_unlock(&sl->lock);
 }
 
+#define __write_sequnlock_irqrestore(sl, flags)	__write_sequnlock(sl)
+
 static inline int __write_tryseqlock(seqlock_t *sl)
 {
 	int ret = spin_trylock(&sl->lock);
@@ -149,6 +157,28 @@ static __always_inline void __write_seql
 	smp_wmb();
 }
 
+static __always_inline unsigned long
+__write_seqlock_irqsave_raw(raw_seqlock_t *sl)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	__write_seqlock_raw(sl);
+	return flags;
+}
+
+static __always_inline void __write_seqlock_irq_raw(raw_seqlock_t *sl)
+{
+	local_irq_disable();
+	__write_seqlock_raw(sl);
+}
+
+static __always_inline void __write_seqlock_bh_raw(raw_seqlock_t *sl)
+{
+	local_bh_disable();
+	__write_seqlock_raw(sl);
+}
+
 static __always_inline void __write_sequnlock_raw(raw_seqlock_t *sl)
 {
 	smp_wmb();
@@ -156,6 +186,27 @@ static __always_inline void __write_sequ
 	spin_unlock(&sl->lock);
 }
 
+static __always_inline void
+__write_sequnlock_irqrestore_raw(raw_seqlock_t *sl, unsigned long flags)
+{
+	__write_sequnlock_raw(sl);
+	local_irq_restore(flags);
+	preempt_check_resched();
+}
+
+static __always_inline void __write_sequnlock_irq_raw(raw_seqlock_t *sl)
+{
+	__write_sequnlock_raw(sl);
+	local_irq_enable();
+	preempt_check_resched();
+}
+
+static __always_inline void __write_sequnlock_bh_raw(raw_seqlock_t *sl)
+{
+	__write_sequnlock_raw(sl);
+	local_bh_enable();
+}
+
 static __always_inline int __write_tryseqlock_raw(raw_seqlock_t *sl)
 {
 	int ret = spin_trylock(&sl->lock);
@@ -182,60 +233,92 @@ static __always_inline int __read_seqret
 
 extern int __bad_seqlock_type(void);
 
-#define PICK_SEQOP(op, lock)					\
+/*
+ * PICK_SEQ_OP() is a small redirector to allow less typing of the lock
+ * types raw_seqlock_t, seqlock_t, at the front of the PICK_FUNCTION
+ * macro.
+ */
+#define PICK_SEQ_OP(...) PICK_FUNCTION(raw_seqlock_t, seqlock_t, ##__VA_ARGS__)
+#define PICK_SEQ_OP_RET(...) \
+	PICK_FUNCTION_RET(raw_seqlock_t, seqlock_t, ##__VA_ARGS__)
+
+#define write_seqlock(sl) PICK_SEQ_OP(__write_seqlock_raw, __write_seqlock, sl)
+
+#define write_sequnlock(sl)	\
+	PICK_SEQ_OP(__write_sequnlock_raw, __write_sequnlock, sl)
+
+#define write_tryseqlock(sl)	\
+	PICK_SEQ_OP_RET(__write_tryseqlock_raw, __write_tryseqlock, sl)
+
+#define read_seqbegin(sl) 	\
+	PICK_SEQ_OP_RET(__read_seqbegin_raw, __read_seqbegin, sl)
+
+#define read_seqretry(sl, iv)	\
+	PICK_SEQ_OP_RET(__read_seqretry_raw, __read_seqretry, sl, iv)
+
+#define write_seqlock_irqsave(lock, flags)			\
 do {								\
-	if (TYPE_EQUAL((lock), raw_seqlock_t))			\
-		op##_raw((raw_seqlock_t *)(lock));		\
-	else if (TYPE_EQUAL((lock), seqlock_t))			\
-		op((seqlock_t *)(lock));			\
-	else __bad_seqlock_type();				\
+	flags = PICK_SEQ_OP_RET(__write_seqlock_irqsave_raw,	\
+		__write_seqlock_irqsave, lock);			\
 } while (0)
 
-#define PICK_SEQOP_RET(op, lock)				\
-({								\
-	unsigned long __ret;					\
-								\
-	if (TYPE_EQUAL((lock), raw_seqlock_t))			\
-		__ret = op##_raw((raw_seqlock_t *)(lock));	\
-	else if (TYPE_EQUAL((lock), seqlock_t))			\
-		__ret = op((seqlock_t *)(lock));		\
-	else __ret = __bad_seqlock_type();			\
-								\
-	__ret;							\
-})
-
-#define PICK_SEQOP_CONST_RET(op, lock)				\
-({								\
-	unsigned long __ret;					\
-								\
-	if (TYPE_EQUAL((lock), raw_seqlock_t))			\
-		__ret = op##_raw((const raw_seqlock_t *)(lock));\
-	else if (TYPE_EQUAL((lock), seqlock_t))			\
-		__ret = op((seqlock_t *)(lock));		\
-	else __ret = __bad_seqlock_type();			\
-								\
-	__ret;							\
-})
-
-#define PICK_SEQOP2_CONST_RET(op, lock, arg)				\
- ({									\
-	unsigned long __ret;						\
-									\
-	if (TYPE_EQUAL((lock), raw_seqlock_t))				\
-		__ret = op##_raw((const raw_seqlock_t *)(lock), (arg));	\
-	else if (TYPE_EQUAL((lock), seqlock_t))				\
-		__ret = op((seqlock_t *)(lock), (arg));			\
-	else __ret = __bad_seqlock_type();				\
-									\
-	__ret;								\
-})
-
-
-#define write_seqlock(sl)	PICK_SEQOP(__write_seqlock, sl)
-#define write_sequnlock(sl)	PICK_SEQOP(__write_sequnlock, sl)
-#define write_tryseqlock(sl)	PICK_SEQOP_RET(__write_tryseqlock, sl)
-#define read_seqbegin(sl)	PICK_SEQOP_CONST_RET(__read_seqbegin, sl)
-#define read_seqretry(sl, iv)	PICK_SEQOP2_CONST_RET(__read_seqretry, sl, iv)
+#define write_seqlock_irq(lock)	\
+	PICK_SEQ_OP(__write_seqlock_irq_raw, __write_seqlock, lock)
+
+#define write_seqlock_bh(lock)	\
+	PICK_SEQ_OP(__write_seqlock_bh_raw, __write_seqlock, lock)
+
+#define write_sequnlock_irqrestore(lock, flags)		\
+	PICK_SEQ_OP(__write_sequnlock_irqrestore_raw,	\
+		__write_sequnlock_irqrestore, lock, flags)
+
+#define write_sequnlock_bh(lock)	\
+	PICK_SEQ_OP(__write_sequnlock_bh_raw, __write_sequnlock, lock)
+
+#define write_sequnlock_irq(lock)	\
+	PICK_SEQ_OP(__write_sequnlock_irq_raw, __write_sequnlock, lock)
+
+static __always_inline
+unsigned long __read_seqbegin_irqsave_raw(raw_seqlock_t *sl)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	__read_seqbegin_raw(sl);
+	return flags;
+}
+
+static __always_inline unsigned long __read_seqbegin_irqsave(seqlock_t *sl)
+{
+	__read_seqbegin(sl);
+	return 0;
+}
+
+#define read_seqbegin_irqsave(lock, flags)			\
+do {								\
+	flags = PICK_SEQ_OP_RET(__read_seqbegin_irqsave_raw,	\
+		__read_seqbegin_irqsave, lock);			\
+} while (0)
+
+static __always_inline int
+__read_seqretry_irqrestore(seqlock_t *sl, unsigned iv, unsigned long flags)
+{
+	return __read_seqretry(sl, iv);
+}
+
+static __always_inline int
+__read_seqretry_irqrestore_raw(raw_seqlock_t *sl, unsigned iv,
+			       unsigned long flags)
+{
+	int ret = read_seqretry(sl, iv);
+	local_irq_restore(flags);
+	preempt_check_resched();
+	return ret;
+}
+
+#define read_seqretry_irqrestore(lock, iv, flags)			\
+	PICK_SEQ_OP_RET(__read_seqretry_irqrestore_raw, 		\
+		__read_seqretry_irqrestore, lock, iv, flags)
 
 /*
  * Version using sequence counter only.
@@ -286,53 +369,4 @@ static inline void write_seqcount_end(se
 	smp_wmb();
 	s->sequence++;
 }
-
-#define PICK_IRQOP(op, lock)					\
-do {								\
-	if (TYPE_EQUAL((lock), raw_seqlock_t))			\
-		op();						\
-	else if (TYPE_EQUAL((lock), seqlock_t))			\
-		{ /* nothing */ }				\
-	else __bad_seqlock_type();				\
-} while (0)
-
-#define PICK_IRQOP2(op, arg, lock)				\
-do {								\
-	if (TYPE_EQUAL((lock), raw_seqlock_t))			\
-		op(arg);					\
-	else if (TYPE_EQUAL(lock, seqlock_t))			\
-		{ /* nothing */ }				\
-	else __bad_seqlock_type();				\
-} while (0)
-
-
-
-/*
- * Possible sw/hw IRQ protected versions of the interfaces.
- */
-#define write_seqlock_irqsave(lock, flags)				\
-	do { PICK_IRQOP2(local_irq_save, flags, lock); write_seqlock(lock); } while (0)
-#define write_seqlock_irq(lock)						\
-	do { PICK_IRQOP(local_irq_disable, lock); write_seqlock(lock); } while (0)
-#define write_seqlock_bh(lock)						\
-        do { PICK_IRQOP(local_bh_disable, lock); write_seqlock(lock); } while (0)
-
-#define write_sequnlock_irqrestore(lock, flags)				\
-	do { write_sequnlock(lock); PICK_IRQOP2(local_irq_restore, flags, lock); preempt_check_resched(); } while(0)
-#define write_sequnlock_irq(lock)					\
-	do { write_sequnlock(lock); PICK_IRQOP(local_irq_enable, lock); preempt_check_resched(); } while(0)
-#define write_sequnlock_bh(lock)					\
-	do { write_sequnlock(lock); PICK_IRQOP(local_bh_enable, lock); } while(0)
-
-#define read_seqbegin_irqsave(lock, flags)				\
-	({ PICK_IRQOP2(local_irq_save, flags, lock); read_seqbegin(lock); })
-
-#define read_seqretry_irqrestore(lock, iv, flags)			\
-	({								\
-		int ret = read_seqretry(lock, iv);			\
-		PICK_IRQOP2(local_irq_restore, flags, lock);		\
-		preempt_check_resched(); 				\
-		ret;							\
-	})
-
 #endif /* __LINUX_SEQLOCK_H */
#1 lore raw

PATCH 2/9 Dont allow non-threaded softirqs and threaded hardirqs

In reply to Daniel Walker

From: Steven Rostedt <[email protected]>

Ingo,

I think this was sent before, and it did cause problems before. Would there be *any* reason to have non-threaded softirqs but threaded hardirqs. I can see lots of issues with that.

This patch has selecting hardirqs also select softirqs as threads.

---
 kernel/Kconfig.preempt |    1 +
 1 file changed, 1 insertion(+)
kernel/Kconfig.preempt +1 -0
Index: linux-2.6.22/kernel/Kconfig.preempt
===================================================================
@@ -106,6 +106,7 @@ config PREEMPT_HARDIRQS
 	bool "Thread Hardirqs"
 	default n
 	depends on !GENERIC_HARDIRQS_NO__DO_IRQ
+	select PREEMPT_SOFTIRQS
 	help
 	  This option reduces the latency of the kernel by 'threading'
           hardirqs. This means that all (or selected) hardirqs will run
#13 lore raw

Re: [PATCH -rt 6/9] spinlock/rt_lock random cleanups

In reply to Daniel Walker
Quoted 33 lines · Daniel Walker
---
 include/linux/rt_lock.h  |    6 ++++--
 include/linux/spinlock.h |    5 +++--
 2 files changed, 7 insertions(+), 4 deletions(-)

Index: linux-2.6.22/include/linux/rt_lock.h
===================================================================

include/linux/rt_lock.h +4 -2
@@ -128,12 +128,14 @@ struct semaphore name = \
  */
 #define DECLARE_MUTEX_LOCKED COMPAT_DECLARE_MUTEX_LOCKED
 
-extern void fastcall __sema_init(struct semaphore *sem, int val, char *name, char *file, int line);
+extern void fastcall
+__sema_init(struct semaphore *sem, int val, char *name, char *file, int line);
 
 #define rt_sema_init(sem, val) \
 		__sema_init(sem, val, #sem, __FILE__, __LINE__)
 
-extern void fastcall __init_MUTEX(struct semaphore *sem, char *name, char *file, int line);
+extern void fastcall
+__init_MUTEX(struct semaphore *sem, char *name, char *file, int line);
 #define rt_init_MUTEX(sem) \
 		__init_MUTEX(sem, #sem, __FILE__, __LINE__)
 

Index: linux-2.6.22/include/linux/spinlock.h
===================================================================

include/linux/spinlock.h extern int __lockfunc generic__raw_read_ · line 129

Quoted 5 lines
include/linux/spinlock.h +1 -1
@@ -126,7 +126,7 @@ extern int __lockfunc generic__raw_read_
 
 #ifdef CONFIG_DEBUG_SPINLOCK
  extern __lockfunc void _raw_spin_lock(raw_spinlock_t *lock);
-#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
+# define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)

Any reason behind including a space here?

Quoted 14 lines
include/linux/spinlock.h +2 -1
  extern __lockfunc int _raw_spin_trylock(raw_spinlock_t *lock);
  extern __lockfunc void _raw_spin_unlock(raw_spinlock_t *lock);
  extern __lockfunc void _raw_read_lock(raw_rwlock_t *lock);
@@ -325,7 +325,8 @@ do {							\
 
 # define _read_trylock(rwl)	rt_read_trylock(rwl)
 # define _write_trylock(rwl)	rt_write_trylock(rwl)
-#define _write_trylock_irqsave(rwl, flags)  rt_write_trylock_irqsave(rwl, flags)
+# define _write_trylock_irqsave(rwl, flags) \
+	rt_write_trylock_irqsave(rwl, flags)
 
 # define _read_lock(rwl)	rt_read_lock(rwl)
 # define _write_lock(rwl)	rt_write_lock(rwl)
Signature · 5 lines
Regards,
Ankita Garg ([email protected])
Linux Technology Center
IBM India Systems & Technology Labs, 
Bangalore, India   
Acked-by on v1 1/9
#23 lore raw
In reply to Daniel Walker
Quoted 3 lines · Daniel Walker

Simple WARN_ON to catch any underflow in rcu_read_lock_nesting.

Quoted 27 lines
---
 kernel/rcupreempt.c |    6 ++++++
 1 file changed, 6 insertions(+)

Index: linux-2.6.22/kernel/rcupreempt.c
===================================================================

kernel/rcupreempt.c +6 -0
@@ -157,6 +157,12 @@ void __rcu_read_unlock(void)
 	}
 
 	local_irq_restore(oldirq);
+
+	/*
+	 * If our rcu_read_lock_nesting went negative, likely
+	 * something is wrong..
+	 */
+	WARN_ON(current->rcu_read_lock_nesting < 0);
 }
 
 static void __rcu_advance_callbacks(void)
Signature · 5 lines
-- 
-
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#24 lore raw
In reply to Daniel Walker

kernel/rcupreempt.c void __rcu_read_unlock(void) · line 165

Quoted 5 lines · Daniel Walker
kernel/rcupreempt.c +5 -0
+	/*
+	 * If our rcu_read_lock_nesting went negative, likely
+	 * something is wrong..
+	 */
+	WARN_ON(current->rcu_read_lock_nesting < 0);

have you actually caught any rcu locking problem this way? Double unlocks should be caught by lockdep already, at a higher level.

in any case i've added a slightly different form of this change to the -rt queue that will also check for counter overflows. But i'm not sure we want to litter the code with trivial checks like this, so i'm keeping it separate and if it does not trigger anything real i'll remove it.

Ingo

#2 lore raw

Re: [PATCH -rt 2/9] Dont allow non-threaded softirqs and threaded hardirqs

In reply to Daniel Walker
Quoted 5 lines · Daniel Walker

From: Steven Rostedt <[email protected]>

I think this was sent before, and it did cause problems before. Would there be *any* reason to have non-threaded softirqs but threaded hardirqs. I can see lots of issues with that.

please elaborate in precise terms: what issues can you see?

Ingo

Applied
#5 lore raw

Re: [PATCH -rt 3/9] Fix jiffies wrap issue in update_times

In reply to Daniel Walker
Quoted 4 lines · Daniel Walker

In prior -rt verisons the last_tick value was called wall_jiffies and was initialized in this same way as below. If this value isn't initialized the calc_load function gets skewed for several minutes right after boot up. Skewed meaning always zero.

thanks, applied.

Ingo

Applied
#7 lore raw

Re: [PATCH -rt 4/9] ifdef raise_softirq_irqoff wakeup

In reply to Daniel Walker

kernel/softirq.c inline fastcall void raise_softirq_irqof · line 513

Quoted 7 lines · Daniel Walker
kernel/softirq.c +2 -0
@@ -508,7 +508,9 @@ inline fastcall void raise_softirq_irqof
 {
 	__do_raise_softirq_irqoff(nr);
 
+#ifdef CONFIG_PREEMPT_SOFTIRQS
 	wakeup_softirqd(nr);
+#endif

thanks, applied. People rarely run the -rt kernel just to turn off PREEMPT_RT, that's why this bug was there ;-)

Ingo

#11 lore raw

Re: [PATCH -rt 5/9] net: fix mis-merge in qdisc_restart

In reply to Daniel Walker
Quoted 2 lines · Daniel Walker

This mismerge caused my networking to malfunction. The interface would come up, but no traffic would make it in/out ..

your patch only affects the !CONFIG_PREEMPT_RT case, so with that qualification indeed that happened, and i've applied your fix.

Ingo

maintainer
#17 lore raw

Re: [PATCH -rt 7/9] introduce PICK_FUNCTION

In reply to Daniel Walker

include/linux/pickop.h line 7

Quoted 4 lines · Daniel Walker
include/linux/pickop.h new file +4 -0
+#undef TYPE_EQUAL
+#define TYPE_EQUAL(var, type) \
+		__builtin_types_compatible_p(typeof(var), type *)
+

If you're going to touch this code, could you perhaps change TYPE_EQUAL to do as it says and read like so:

__builtin_types_compatible_p(typeof(var), type)

#3 lore raw

Re: [PATCH -rt 2/9] Dont allow non-threaded softirqs and threaded hardirqs

In reply to Ingo Molnar

--

Quoted 8 lines · Ingo Molnar
Quoted 5 lines

From: Steven Rostedt <[email protected]>

I think this was sent before, and it did cause problems before. Would there be *any* reason to have non-threaded softirqs but threaded hardirqs. I can see lots of issues with that.

please elaborate in precise terms: what issues can you see?

Hi Ingo,

I don't remember the exact details, I can try to find the thread. But I remember someone was having their system lock up strangly. We later found that they had softirqs as normal softirqs and interrupts as threads. I think there was some driver that didn't expect the softirq to preempt the irq handler. Perhaps the softirq was using spin_lock_irq while the irq thread was just using spin_lock, which I can see as being something normal.

The standard Linux does not expect an interrupt to be preempted by a softirq, and with interrupts as threads but not softirqs, I can see that happening a lot.

-- Steve

#14 lore raw

Re: [PATCH -rt 6/9] spinlock/rt_lock random cleanups

In reply to Ankita Garg
Quoted 35 lines · Ankita Garg
Quoted 34 lines · Daniel Walker
---
 include/linux/rt_lock.h  |    6 ++++--
 include/linux/spinlock.h |    5 +++--
 2 files changed, 7 insertions(+), 4 deletions(-)

Index: linux-2.6.22/include/linux/rt_lock.h
===================================================================

include/linux/rt_lock.h +4 -2
@@ -128,12 +128,14 @@ struct semaphore name = \
  */
 #define DECLARE_MUTEX_LOCKED COMPAT_DECLARE_MUTEX_LOCKED
 
-extern void fastcall __sema_init(struct semaphore *sem, int val, char *name, char *file, int line);
+extern void fastcall
+__sema_init(struct semaphore *sem, int val, char *name, char *file, int line);
 
 #define rt_sema_init(sem, val) \
 		__sema_init(sem, val, #sem, __FILE__, __LINE__)
 
-extern void fastcall __init_MUTEX(struct semaphore *sem, char *name, char *file, int line);
+extern void fastcall
+__init_MUTEX(struct semaphore *sem, char *name, char *file, int line);
 #define rt_init_MUTEX(sem) \
 		__init_MUTEX(sem, #sem, __FILE__, __LINE__)
 

Index: linux-2.6.22/include/linux/spinlock.h
===================================================================

include/linux/spinlock.h +0 -0
@@ -126,7 +126,7 @@ extern int __lockfunc generic__raw_read_
 
Quoted 6 lines

include/linux/spinlock.h extern int __lockfunc generic__raw_read_ · line 129

Quoted 4 lines
include/linux/spinlock.h +1 -1
 #ifdef CONFIG_DEBUG_SPINLOCK
  extern __lockfunc void _raw_spin_lock(raw_spinlock_t *lock);
-#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
+# define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)

Any reason behind including a space here?

Yes . Sometimes a space is added when a define is embedded inside #ifdefs , example below.

#ifdef CONFIG_DEBUG_SPINLOCK

# define DEBUG_MACRO do_somedebug_here()
#endif

That's usually the method Ingo uses, and it matches the code surrounding it in this particular patch.

Daniel

#25 lore raw
In reply to Ingo Molnar
Quoted 11 lines · Ingo Molnar

kernel/rcupreempt.c void __rcu_read_unlock(void) · line 165

Quoted 5 lines · Daniel Walker
kernel/rcupreempt.c +5 -0
+	/*
+	 * If our rcu_read_lock_nesting went negative, likely
+	 * something is wrong..
+	 */
+	WARN_ON(current->rcu_read_lock_nesting < 0);

have you actually caught any rcu locking problem this way? Double unlocks should be caught by lockdep already, at a higher level.

Quoted 4 lines

in any case i've added a slightly different form of this change to the -rt queue that will also check for counter overflows. But i'm not sure we want to litter the code with trivial checks like this, so i'm keeping it separate and if it does not trigger anything real i'll remove it.

I haven't caught anything with it, but this code would have made it much easier to catch the single rcu unlock in sys_sched_yield() which was silent in PREEMPT_RT, and hung !PREEMPT_RT ..

It's fine with me, if you have another method.

Daniel

#8 lore raw

Re: [PATCH -rt 4/9] ifdef raise_softirq_irqoff wakeup

In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 4 lines · Daniel Walker
kernel/softirq.c +0 -0
@@ -508,7 +508,9 @@ inline fastcall void raise_softirq_irqof
 {
 	__do_raise_softirq_irqoff(nr);
 
Quoted 6 lines

kernel/softirq.c inline fastcall void raise_softirq_irqof · line 513

Quoted 3 lines
kernel/softirq.c +2 -0
+#ifdef CONFIG_PREEMPT_SOFTIRQS
 	wakeup_softirqd(nr);
+#endif

thanks, applied. People rarely run the -rt kernel just to turn off PREEMPT_RT, that's why this bug was there ;-)

Ultimately, all modes should function correctly right?

Daniel

#18 lore raw

Re: [PATCH -rt 7/9] introduce PICK_FUNCTION

In reply to Peter Zijlstra
Quoted 10 lines · Peter Zijlstra

include/linux/pickop.h line 7

Quoted 4 lines · Daniel Walker
include/linux/pickop.h new file +4 -0
+#undef TYPE_EQUAL
+#define TYPE_EQUAL(var, type) \
+		__builtin_types_compatible_p(typeof(var), type *)
+

If you're going to touch this code, could you perhaps change TYPE_EQUAL to do as it says and read like so:

Quoted 2 lines

__builtin_types_compatible_p(typeof(var), type)

Yeah that makes sense .. I'll add it to my tree ..

Daniel

#9 lore raw

Re: [PATCH -rt 4/9] ifdef raise_softirq_irqoff wakeup

In reply to Daniel Walker
Quoted 7 lines · Daniel Walker
Quoted 6 lines · Ingo Molnar
Quoted 4 lines · Daniel Walker
kernel/softirq.c +0 -0
@@ -508,7 +508,9 @@ inline fastcall void raise_softirq_irqof
 {
 	__do_raise_softirq_irqoff(nr);
 
Quoted 8 lines
Quoted 6 lines

kernel/softirq.c inline fastcall void raise_softirq_irqof · line 513

Quoted 3 lines
kernel/softirq.c +2 -0
+#ifdef CONFIG_PREEMPT_SOFTIRQS
 	wakeup_softirqd(nr);
+#endif

thanks, applied. People rarely run the -rt kernel just to turn off PREEMPT_RT, that's why this bug was there ;-)

Ultimately, all modes should function correctly right?

yes, of course - especially once any of the components nears upstream integration ;-)

Ingo

#21 lore raw

Re: [PATCH -rt 9/9] seqlocks: use PICK_FUNCTION

In reply to Daniel Walker
Quoted 3 lines · Daniel Walker

Replace the old PICK_OP style macros with PICK_FUNCTION. Although, seqlocks has some alien code, which I also replaced as can be seen from the line count below.

ok, i very much like the cleanup effects here, could you resend your latest version of this (with Peter's suggested cleanup) against -rc2-rt2 so that i can apply it?

Ingo

#22 lore raw

Re: [PATCH -rt 9/9] seqlocks: use PICK_FUNCTION

Quoted 9 lines · Ingo Molnar
Quoted 3 lines · Daniel Walker

Replace the old PICK_OP style macros with PICK_FUNCTION. Although, seqlocks has some alien code, which I also replaced as can be seen from the line count below.

ok, i very much like the cleanup effects here, could you resend your latest version of this (with Peter's suggested cleanup) against -rc2-rt2 so that i can apply it?

Ok, sent them privately. Updated to 2.6.23-rc2-rt2 w/ Peter's suggestion. You'll get two sets the first had some unrefreshed hunks in the 3/3 patch .

There is one thing I was wondering about in seqlock.h . There was a class of these macro's like below,

#define PICK_SEQOP_CONST_RET(op, lock)                          \
({                                                              \
        unsigned long __ret;                                    \
                                                                \
        if (TYPE_EQUAL((lock), raw_seqlock_t))                  \
                __ret = op##_raw((const raw_seqlock_t *)(lock));\
        else if (TYPE_EQUAL((lock), seqlock_t))                 \
                __ret = op((seqlock_t *)(lock));                \
        else __ret = __bad_seqlock_type();                      \
                                                                \
        __ret;                                                  \
})

Where the variable is specifically casted to "const raw_seqlock_t *".. I ended up dropping these all together, and I'm wonder what the adverse effects of that are .. The casting seems superfluous to me since you know already that the type are compatible at that point. Any thoughts?

Daniel