Skip to contentSkip to conversation

even more spinlock.h cleanup

PATCH New Robert Love 1 participant 1 message Jul 30, 2002 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 even more spinlock.h cleanup

Quoted 1 line · Linus Torvalds

Last comment, then I promise to shut up..

Yah, sure, right...

Quoted 5 lines

How about making those #define spin_lock_xxx() things be fully expanded, ie including the preempt disabling?
[...]
so that there aren't two levels of #define expansion? Especially since at some point we may make the irq versions not do the preempt_disable at all.

Good idea.

This patch, against 2.5 BK, includes the previous cleanups with your suggestion above sans the compiler workaround.

Changes:

- cleanup #defines: I do not follow the rationale behind the odd line-wrapped defines at the beginning of the file. If we have to use multiple lines, then we might as well do so cleanly and according to normal practice...

- Remove a level of indirection: do not have spin_lock_foo use spin_lock - just explicitly call what is needed.

- we do not need to define the spin_lock functions twice, once for CONFIG_PREEMPT and once for !CONFIG_PREEMPT. Defining them once with the preempt macros will optimize away fine.

- other misc. cleanup, improved comments, reordering, etc.

The net result is we define each method once, with no extra levels of indirection or conditional statements. The various methods include each needed piece and those pieces are nops in the case they are not needed.

The patch is probably fairly confusing to look at since I reordered everything, but I suspect you will like the resulting spinlock.h. If so, please apply.

Robert Love

include/linux/preempt.h +11 -7
diff -urN linux-2.5.29-bk/include/linux/preempt.h linux/include/linux/preempt.h
@@ -1,9 +1,14 @@
 #ifndef __LINUX_PREEMPT_H
 #define __LINUX_PREEMPT_H
 
+/*
+ * include/linux/preempt.h - macros for accessing and manipulating
+ * preempt_count (used for kernel preemption, interrupt count, etc.)
+ */
+
 #include <linux/config.h>
 
-#define preempt_count() (current_thread_info()->preempt_count)
+#define preempt_count()	(current_thread_info()->preempt_count)
 
 #ifdef CONFIG_PREEMPT
 
@@ -21,23 +26,22 @@
 	barrier(); \
 } while (0)
 
-#define preempt_enable() \
+#define preempt_check_resched() \
 do { \
-	preempt_enable_no_resched(); \
 	if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
 		preempt_schedule(); \
 } while (0)
 
-#define preempt_check_resched() \
+#define preempt_enable() \
 do { \
-	if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
-		preempt_schedule(); \
+	preempt_enable_no_resched(); \
+	preempt_check_resched(); \
 } while (0)
 
 #else
 
 #define preempt_disable()		do { } while (0)
-#define preempt_enable_no_resched()	do {} while(0)
+#define preempt_enable_no_resched()	do { } while (0)
 #define preempt_enable()		do { } while (0)
 #define preempt_check_resched()		do { } while (0)
 
include/linux/spinlock.h +191 -83

340 lines not on this page · raw message