public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] reduce code in generic spinlock.h
@ 2002-07-23 16:28 Dave Hansen
  2002-07-23 16:38 ` Robert Love
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Hansen @ 2002-07-23 16:28 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, Adam G Litke, Robert Love

[-- Attachment #1: Type: text/plain, Size: 1087 bytes --]

The last time lockmeter was ported to 2.5, it was getting a little
messy.  There were separate declarations for spin_*lock() for each
combination of lockmeter and preemption, which made four, plus the
no-smp definition.  While lockmeter's mess isn't the kernel's fault, 
we noticed some some simplifications which could be made to the 
generic spinlock code.  This patch uses a single definition for each 
of the macros, eliminating some redundant code.

In the preemption-off case, spin lock is changed from this:
_raw_spin_lock(lock)
to this:
do {
	preempt_disable();
	_raw_spin_lock(lock)
} while (0)
The preemption-on case is unchanged.

Since preempt_disable() is a do{}while(0) with preemption off anyway,
it gets back to the same effective result as before, with a little
extra work from the compiler.  The preempt_disable() macro just had to
be moved up in the file a bit.

Thanks to Adam Litke <aglitke@us.ibm.com>, who has been doing the
lockmeter port and who initially wrote this patch.

Compiles in all combinations of SMP and preempt.
-- 
Dave Hansen
haveblue@us.ibm.com



[-- Attachment #2: spinlock-cleanup-2.5.27-2.diff --]
[-- Type: text/plain, Size: 1691 bytes --]

diff -ur linux-2.5.27-clean/include/linux/spinlock.h linux-2.5.27/include/linux/spinlock.h
--- linux-2.5.27-clean/include/linux/spinlock.h	Tue Jul 23 09:19:51 2002
+++ linux-2.5.27/include/linux/spinlock.h	Tue Jul 23 09:26:16 2002
@@ -150,6 +150,14 @@
 		preempt_schedule(); \
 } while (0)
 
+#else /* !CONFIG_PREEMPT */
+#define preempt_get_count()		(0)
+#define preempt_disable()		do { } while(0)
+#define preempt_enable_no_resched()	do { } while(0)
+#define preempt_enable()		do { } while(0)
+#define preempt_check_resched()		do { } while(0)
+#endif /* !CONFIG_PREEMPT */
+
 #define spin_lock(lock)	\
 do { \
 	preempt_disable(); \
@@ -176,26 +184,6 @@
 #define write_unlock(lock)	({_raw_write_unlock(lock); preempt_enable();})
 #define write_trylock(lock)	({preempt_disable();_raw_write_trylock(lock) ? \
 				1 : ({preempt_enable(); 0;});})
-
-#else
-
-#define preempt_get_count()		(0)
-#define preempt_disable()		do { } while (0)
-#define preempt_enable_no_resched()	do {} while(0)
-#define preempt_enable()		do { } while (0)
-#define preempt_check_resched()		do { } while (0)
-
-#define spin_lock(lock)			_raw_spin_lock(lock)
-#define spin_trylock(lock)		_raw_spin_trylock(lock)
-#define spin_unlock(lock)		_raw_spin_unlock(lock)
-#define spin_unlock_no_resched(lock)	_raw_spin_unlock(lock)
-
-#define read_lock(lock)			_raw_read_lock(lock)
-#define read_unlock(lock)		_raw_read_unlock(lock)
-#define write_lock(lock)		_raw_write_lock(lock)
-#define write_unlock(lock)		_raw_write_unlock(lock)
-#define write_trylock(lock)		_raw_write_trylock(lock)
-#endif
 
 /* "lock on reference count zero" */
 #ifndef ATOMIC_DEC_AND_LOCK
Only in linux-2.5.27-clean/include/linux: spinlock.h.orig

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] reduce code in generic spinlock.h
  2002-07-23 16:28 [PATCH] reduce code in generic spinlock.h Dave Hansen
@ 2002-07-23 16:38 ` Robert Love
  2002-07-23 16:41   ` Dave Hansen
  2002-07-23 19:41   ` Dave Hansen
  0 siblings, 2 replies; 4+ messages in thread
From: Robert Love @ 2002-07-23 16:38 UTC (permalink / raw)
  To: Dave Hansen; +Cc: Linus Torvalds, linux-kernel, Adam G Litke

On Tue, 2002-07-23 at 09:28, Dave Hansen wrote:

> The last time lockmeter was ported to 2.5, it was getting a little
> messy.  There were separate declarations for spin_*lock() for each
> combination of lockmeter and preemption, which made four, plus the
> no-smp definition.  While lockmeter's mess isn't the kernel's fault, 
> we noticed some some simplifications which could be made to the 
> generic spinlock code.  This patch uses a single definition for each 
> of the macros, eliminating some redundant code.

I have no problems with this (assuming it is right and it looks so on
first glance).

It will not apply to Linus's current tree, however, because of the IRQ
rewrite that is now applied.  If you pull his BK tree and diff against
that, you should be OK... most notably, the preemption code has moved to
preempt.h.

	Robert Love


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] reduce code in generic spinlock.h
  2002-07-23 16:38 ` Robert Love
@ 2002-07-23 16:41   ` Dave Hansen
  2002-07-23 19:41   ` Dave Hansen
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Hansen @ 2002-07-23 16:41 UTC (permalink / raw)
  To: Robert Love; +Cc: Linus Torvalds, linux-kernel, Adam G Litke

Robert Love wrote:
> On Tue, 2002-07-23 at 09:28, Dave Hansen wrote:
> 
>>The last time lockmeter was ported to 2.5, it was getting a little
>>messy.  There were separate declarations for spin_*lock() for each
>>combination of lockmeter and preemption, which made four, plus the
>>no-smp definition.  While lockmeter's mess isn't the kernel's fault, 
>>we noticed some some simplifications which could be made to the 
>>generic spinlock code.  This patch uses a single definition for each 
>>of the macros, eliminating some redundant code.
> 
> I have no problems with this (assuming it is right and it looks so on
> first glance).
> 
> It will not apply to Linus's current tree, however, because of the IRQ
> rewrite that is now applied.  If you pull his BK tree and diff against
> that, you should be OK... most notably, the preemption code has moved to
> preempt.h.

D'oh.  Bad timing, I guess.  I'll rediff against current BK.


-- 
Dave Hansen
haveblue@us.ibm.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] reduce code in generic spinlock.h
  2002-07-23 16:38 ` Robert Love
  2002-07-23 16:41   ` Dave Hansen
@ 2002-07-23 19:41   ` Dave Hansen
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Hansen @ 2002-07-23 19:41 UTC (permalink / raw)
  To: Robert Love; +Cc: Linus Torvalds, linux-kernel, Adam G Litke

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

Robert Love wrote:
> It will not apply to Linus's current tree, however, because of the IRQ
> rewrite that is now applied.  If you pull his BK tree and diff against
> that, you should be OK... most notably, the preemption code has moved to
> preempt.h.

OK, this just made it simpler.  Just remove the preempt ifdef and the 
extra spinlock calls.  Patch against latest BK attached.

-- 
Dave Hansen
haveblue@us.ibm.com

[-- Attachment #2: spinlock-cleanup-bk0723.diff --]
[-- Type: text/plain, Size: 1072 bytes --]

diff -Nru a/include/linux/spinlock.h b/include/linux/spinlock.h
--- a/include/linux/spinlock.h	Tue Jul 23 13:56:42 2002
+++ b/include/linux/spinlock.h	Tue Jul 23 13:56:42 2002
@@ -119,8 +119,6 @@
 
 #endif /* !SMP */
 
-#ifdef CONFIG_PREEMPT
-
 #define spin_lock(lock)	\
 do { \
 	preempt_disable(); \
@@ -147,20 +145,6 @@
 #define write_unlock(lock)	({_raw_write_unlock(lock); preempt_enable();})
 #define write_trylock(lock)	({preempt_disable();_raw_write_trylock(lock) ? \
 				1 : ({preempt_enable(); 0;});})
-
-#else
-
-#define spin_lock(lock)			_raw_spin_lock(lock)
-#define spin_trylock(lock)		_raw_spin_trylock(lock)
-#define spin_unlock(lock)		_raw_spin_unlock(lock)
-#define spin_unlock_no_resched(lock)	_raw_spin_unlock(lock)
-
-#define read_lock(lock)			_raw_read_lock(lock)
-#define read_unlock(lock)		_raw_read_unlock(lock)
-#define write_lock(lock)		_raw_write_lock(lock)
-#define write_unlock(lock)		_raw_write_unlock(lock)
-#define write_trylock(lock)		_raw_write_trylock(lock)
-#endif
 
 /* "lock on reference count zero" */
 #ifndef ATOMIC_DEC_AND_LOCK

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-07-23 19:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-23 16:28 [PATCH] reduce code in generic spinlock.h Dave Hansen
2002-07-23 16:38 ` Robert Love
2002-07-23 16:41   ` Dave Hansen
2002-07-23 19:41   ` Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox