mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [patch] softirq-2.4.6-B2
@ 2001-06-05  9:09 Ingo Molnar
  2001-06-05  9:17 ` David S. Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ingo Molnar @ 2001-06-05  9:09 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, David S. Miller, Alexey Kuznetsov

[-- Attachment #1: Type: TEXT/PLAIN, Size: 778 bytes --]


the attached softirq-2.4.6-B2 patch against 2.4.6-pre1 includes additional
softirq fixes and cleanups:

 - David S. Miller noticed that 64-bit architectures are broken due to
   set_bit() on an int. Moved __cpu_raise_softirq into asm/softirq.h,
   every architecture can now define its fastest way of flipping a bit.

 - fixes module exports

 - got rid of softirq_mask, because it's completely unused currently, and
   just causes inlined overhead. There is a clear update path for other
   architectures: __softirq_mask, __softirq_active is replaced by a single
   __softirq_pending field. This change also simplified the do_softirq()
   code.

 - a small enable_local_bh() optimization

the patch compiles, boots & works just fine when applied to vanilla
2.4.6-pre1.

	Ingo

[-- Attachment #2: Type: TEXT/PLAIN, Size: 4544 bytes --]

--- linux/kernel/ksyms.c.orig	Tue Jun  5 09:59:44 2001
+++ linux/kernel/ksyms.c	Tue Jun  5 10:00:18 2001
@@ -535,6 +535,9 @@
 EXPORT_SYMBOL(tasklet_init);
 EXPORT_SYMBOL(tasklet_kill);
 EXPORT_SYMBOL(__run_task_queue);
+EXPORT_SYMBOL(do_softirq);
+EXPORT_SYMBOL(tasklet_schedule);
+EXPORT_SYMBOL(tasklet_hi_schedule);
 
 /* init task, for moving kthread roots - ought to export a function ?? */
 
--- linux/kernel/softirq.c.orig	Tue Jun  5 10:09:02 2001
+++ linux/kernel/softirq.c	Tue Jun  5 10:31:59 2001
@@ -50,7 +50,7 @@
 asmlinkage void do_softirq()
 {
 	int cpu = smp_processor_id();
-	__u32 active, mask;
+	__u32 pending;
 
 	local_irq_disable();
 	if (in_interrupt())
@@ -58,31 +58,30 @@
 
 	local_bh_disable();
 
-	mask = softirq_mask(cpu);
-	active = softirq_active(cpu) & mask;
+	pending = softirq_pending(cpu);
 
-	if (active) {
+	if (pending) {
 		struct softirq_action *h;
 
 restart:
-		/* Reset active bitmask before enabling irqs */
-		softirq_active(cpu) &= ~active;
+		/* Reset the pending bitmask before enabling irqs */
+		softirq_pending(cpu) = 0;
 
 		local_irq_enable();
 
 		h = softirq_vec;
 
 		do {
-			if (active & 1)
+			if (pending & 1)
 				h->action(h);
 			h++;
-			active >>= 1;
-		} while (active);
+			pending >>= 1;
+		} while (pending);
 
 		local_irq_disable();
 
-		active = softirq_active(cpu) & mask;
-		if (active)
+		pending = softirq_pending(cpu);
+		if (pending)
 			goto retry;
 	}
 
@@ -100,20 +99,10 @@
 }
 
 
-static spinlock_t softirq_mask_lock = SPIN_LOCK_UNLOCKED;
-
 void open_softirq(int nr, void (*action)(struct softirq_action*), void *data)
 {
-	unsigned long flags;
-	int i;
-
-	spin_lock_irqsave(&softirq_mask_lock, flags);
 	softirq_vec[nr].data = data;
 	softirq_vec[nr].action = action;
-
-	for (i=0; i<NR_CPUS; i++)
-		softirq_mask(i) |= (1<<nr);
-	spin_unlock_irqrestore(&softirq_mask_lock, flags);
 }
 
 
--- linux/include/linux/irq_cpustat.h.orig	Tue Jun  5 10:09:31 2001
+++ linux/include/linux/irq_cpustat.h	Tue Jun  5 10:21:16 2001
@@ -26,15 +26,11 @@
 #endif	
 
   /* arch independent irq_stat fields */
-#define softirq_active(cpu)	__IRQ_STAT((cpu), __softirq_active)
-#define softirq_mask(cpu)	__IRQ_STAT((cpu), __softirq_mask)
+#define softirq_pending(cpu)	__IRQ_STAT((cpu), __softirq_pending)
 #define local_irq_count(cpu)	__IRQ_STAT((cpu), __local_irq_count)
 #define local_bh_count(cpu)	__IRQ_STAT((cpu), __local_bh_count)
 #define syscall_count(cpu)	__IRQ_STAT((cpu), __syscall_count)
   /* arch dependent irq_stat fields */
 #define nmi_count(cpu)		__IRQ_STAT((cpu), __nmi_count)		/* i386, ia64 */
-
-#define softirq_pending(cpu) \
-	((softirq_active(cpu) & softirq_mask(cpu)))
 
 #endif	/* __irq_cpustat_h */
--- linux/include/linux/interrupt.h.orig	Tue Jun  5 10:11:02 2001
+++ linux/include/linux/interrupt.h	Tue Jun  5 10:33:16 2001
@@ -74,12 +74,6 @@
 asmlinkage void do_softirq(void);
 extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
 
-/* Locally cached atomic variables are cheaper than cli/sti */
-static inline void __cpu_raise_softirq(int cpu, int nr)
-{
-	set_bit(nr, &softirq_active(cpu));
-}
-
 static inline void raise_softirq(int nr)
 {
 	__cpu_raise_softirq(smp_processor_id(), nr);
--- linux/include/asm-i386/hardirq.h.orig	Tue Jun  5 10:10:35 2001
+++ linux/include/asm-i386/hardirq.h	Tue Jun  5 10:21:17 2001
@@ -7,8 +7,7 @@
 
 /* entry.S is sensitive to the offsets of these fields */
 typedef struct {
-	unsigned int __softirq_active;
-	unsigned int __softirq_mask;
+	unsigned int __softirq_pending;
 	unsigned int __local_irq_count;
 	unsigned int __local_bh_count;
 	unsigned int __syscall_count;
--- linux/include/asm-i386/softirq.h.orig	Tue Jun  5 10:16:53 2001
+++ linux/include/asm-i386/softirq.h	Tue Jun  5 10:33:19 2001
@@ -11,8 +11,8 @@
 
 #define local_bh_disable()	cpu_bh_disable(smp_processor_id())
 #define __local_bh_enable()	__cpu_bh_enable(smp_processor_id())
-#define local_bh_enable()	do { if (!--local_bh_count(smp_processor_id()) && softirq_pending(smp_processor_id())) { do_softirq(); __sti(); } } while (0)
-
+#define local_bh_enable()	do { int __cpu = smp_processor_id(); if (!--local_bh_count(__cpu) && softirq_pending(__cpu)) { do_softirq(); __sti(); } } while (0)
+#define __cpu_raise_softirq(cpu,nr) set_bit((nr), &softirq_pending(cpu));
 #define in_softirq() (local_bh_count(smp_processor_id()) != 0)
 
 #endif	/* __ASM_SOFTIRQ_H */

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

* Re: [patch] softirq-2.4.6-B2
  2001-06-05  9:09 [patch] softirq-2.4.6-B2 Ingo Molnar
@ 2001-06-05  9:17 ` David S. Miller
  2001-06-05  9:27 ` David S. Miller
  2001-06-05 10:34 ` [patch] softirq-2.4.6-B4 Ingo Molnar
  2 siblings, 0 replies; 8+ messages in thread
From: David S. Miller @ 2001-06-05  9:17 UTC (permalink / raw)
  To: mingo; +Cc: Linus Torvalds, linux-kernel, Alexey Kuznetsov


Ingo Molnar writes:
 >  - fixes module exports

Need to remove it from arch/ppc/kernel/ppc_ksyms.c too.

Later,
David S. Miller
davem@redhat.com

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

* Re: [patch] softirq-2.4.6-B2
  2001-06-05  9:09 [patch] softirq-2.4.6-B2 Ingo Molnar
  2001-06-05  9:17 ` David S. Miller
@ 2001-06-05  9:27 ` David S. Miller
  2001-06-05 10:34 ` [patch] softirq-2.4.6-B4 Ingo Molnar
  2 siblings, 0 replies; 8+ messages in thread
From: David S. Miller @ 2001-06-05  9:27 UTC (permalink / raw)
  To: mingo; +Cc: Linus Torvalds, linux-kernel, Alexey Kuznetsov


Ingo Molnar writes:
 >  - David S. Miller noticed that 64-bit architectures are broken due to
 >    set_bit() on an int. Moved __cpu_raise_softirq into asm/softirq.h,
 >    every architecture can now define its fastest way of flipping a bit.

You need to move raise_softirq() as well to the arch headers for this
to work Ingo.  Look at how the original code worked before you changed
it.

Later,
David S. Miller
davem@redhat.com

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

* [patch] softirq-2.4.6-B4
  2001-06-05  9:09 [patch] softirq-2.4.6-B2 Ingo Molnar
  2001-06-05  9:17 ` David S. Miller
  2001-06-05  9:27 ` David S. Miller
@ 2001-06-05 10:34 ` Ingo Molnar
  2001-06-06  1:53   ` Linus Torvalds
  2 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2001-06-05 10:34 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, David S. Miller, Alexey Kuznetsov

[-- Attachment #1: Type: TEXT/PLAIN, Size: 212 bytes --]


further updates, the patch is still against vanilla 2.4.6-pre1:

 - didnt include the necessery entry.S changes. (David S. Miller)

 - moved raise_softirq() to the arch headers as well. (David S. Miller)

	Ingo

[-- Attachment #2: Type: TEXT/PLAIN, Size: 5049 bytes --]

--- linux/kernel/ksyms.c.orig	Tue Jun  5 09:59:44 2001
+++ linux/kernel/ksyms.c	Tue Jun  5 10:00:18 2001
@@ -535,6 +535,9 @@
 EXPORT_SYMBOL(tasklet_init);
 EXPORT_SYMBOL(tasklet_kill);
 EXPORT_SYMBOL(__run_task_queue);
+EXPORT_SYMBOL(do_softirq);
+EXPORT_SYMBOL(tasklet_schedule);
+EXPORT_SYMBOL(tasklet_hi_schedule);
 
 /* init task, for moving kthread roots - ought to export a function ?? */
 
--- linux/kernel/softirq.c.orig	Tue Jun  5 10:09:02 2001
+++ linux/kernel/softirq.c	Tue Jun  5 10:31:59 2001
@@ -50,7 +50,7 @@
 asmlinkage void do_softirq()
 {
 	int cpu = smp_processor_id();
-	__u32 active, mask;
+	__u32 pending;
 
 	local_irq_disable();
 	if (in_interrupt())
@@ -58,31 +58,30 @@
 
 	local_bh_disable();
 
-	mask = softirq_mask(cpu);
-	active = softirq_active(cpu) & mask;
+	pending = softirq_pending(cpu);
 
-	if (active) {
+	if (pending) {
 		struct softirq_action *h;
 
 restart:
-		/* Reset active bitmask before enabling irqs */
-		softirq_active(cpu) &= ~active;
+		/* Reset the pending bitmask before enabling irqs */
+		softirq_pending(cpu) = 0;
 
 		local_irq_enable();
 
 		h = softirq_vec;
 
 		do {
-			if (active & 1)
+			if (pending & 1)
 				h->action(h);
 			h++;
-			active >>= 1;
-		} while (active);
+			pending >>= 1;
+		} while (pending);
 
 		local_irq_disable();
 
-		active = softirq_active(cpu) & mask;
-		if (active)
+		pending = softirq_pending(cpu);
+		if (pending)
 			goto retry;
 	}
 
@@ -100,20 +99,10 @@
 }
 
 
-static spinlock_t softirq_mask_lock = SPIN_LOCK_UNLOCKED;
-
 void open_softirq(int nr, void (*action)(struct softirq_action*), void *data)
 {
-	unsigned long flags;
-	int i;
-
-	spin_lock_irqsave(&softirq_mask_lock, flags);
 	softirq_vec[nr].data = data;
 	softirq_vec[nr].action = action;
-
-	for (i=0; i<NR_CPUS; i++)
-		softirq_mask(i) |= (1<<nr);
-	spin_unlock_irqrestore(&softirq_mask_lock, flags);
 }
 
 
--- linux/include/linux/irq_cpustat.h.orig	Tue Jun  5 10:09:31 2001
+++ linux/include/linux/irq_cpustat.h	Tue Jun  5 10:21:16 2001
@@ -26,15 +26,11 @@
 #endif	
 
   /* arch independent irq_stat fields */
-#define softirq_active(cpu)	__IRQ_STAT((cpu), __softirq_active)
-#define softirq_mask(cpu)	__IRQ_STAT((cpu), __softirq_mask)
+#define softirq_pending(cpu)	__IRQ_STAT((cpu), __softirq_pending)
 #define local_irq_count(cpu)	__IRQ_STAT((cpu), __local_irq_count)
 #define local_bh_count(cpu)	__IRQ_STAT((cpu), __local_bh_count)
 #define syscall_count(cpu)	__IRQ_STAT((cpu), __syscall_count)
   /* arch dependent irq_stat fields */
 #define nmi_count(cpu)		__IRQ_STAT((cpu), __nmi_count)		/* i386, ia64 */
-
-#define softirq_pending(cpu) \
-	((softirq_active(cpu) & softirq_mask(cpu)))
 
 #endif	/* __irq_cpustat_h */
--- linux/include/linux/interrupt.h.orig	Tue Jun  5 10:11:02 2001
+++ linux/include/linux/interrupt.h	Tue Jun  5 10:41:53 2001
@@ -74,12 +74,6 @@
 asmlinkage void do_softirq(void);
 extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
 
-/* Locally cached atomic variables are cheaper than cli/sti */
-static inline void __cpu_raise_softirq(int cpu, int nr)
-{
-	set_bit(nr, &softirq_active(cpu));
-}
-
 static inline void raise_softirq(int nr)
 {
 	__cpu_raise_softirq(smp_processor_id(), nr);
--- linux/include/asm-i386/hardirq.h.orig	Tue Jun  5 10:10:35 2001
+++ linux/include/asm-i386/hardirq.h	Tue Jun  5 10:21:17 2001
@@ -7,8 +7,7 @@
 
 /* entry.S is sensitive to the offsets of these fields */
 typedef struct {
-	unsigned int __softirq_active;
-	unsigned int __softirq_mask;
+	unsigned int __softirq_pending;
 	unsigned int __local_irq_count;
 	unsigned int __local_bh_count;
 	unsigned int __syscall_count;
--- linux/include/asm-i386/softirq.h.orig	Tue Jun  5 10:16:53 2001
+++ linux/include/asm-i386/softirq.h	Tue Jun  5 10:33:19 2001
@@ -11,8 +11,8 @@
 
 #define local_bh_disable()	cpu_bh_disable(smp_processor_id())
 #define __local_bh_enable()	__cpu_bh_enable(smp_processor_id())
-#define local_bh_enable()	do { if (!--local_bh_count(smp_processor_id()) && softirq_pending(smp_processor_id())) { do_softirq(); __sti(); } } while (0)
-
+#define local_bh_enable()	do { int __cpu = smp_processor_id(); if (!--local_bh_count(__cpu) && softirq_pending(__cpu)) { do_softirq(); __sti(); } } while (0)
+#define __cpu_raise_softirq(cpu,nr) set_bit((nr), &softirq_pending(cpu));
 #define in_softirq() (local_bh_count(smp_processor_id()) != 0)
 
 #endif	/* __ASM_SOFTIRQ_H */
--- linux/arch/i386/kernel/entry.S.orig	Tue Jun  5 11:55:38 2001
+++ linux/arch/i386/kernel/entry.S	Tue Jun  5 11:57:48 2001
@@ -137,11 +137,11 @@
 #define CHECK_SOFTIRQ \
 	movl processor(%ebx),%eax; \
 	shll $CONFIG_X86_L1_CACHE_SHIFT,%eax; \
-	movl SYMBOL_NAME(irq_stat)(,%eax),%ecx; \
+	xorl %ecx,%ecx; \
 	testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx
 #else
 #define CHECK_SOFTIRQ \
-	movl SYMBOL_NAME(irq_stat),%ecx; \
+	xorl %ecx,%ecx; \
 	testl SYMBOL_NAME(irq_stat)+4,%ecx
 #endif
 

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

* Re: [patch] softirq-2.4.6-B4
  2001-06-05 10:34 ` [patch] softirq-2.4.6-B4 Ingo Molnar
@ 2001-06-06  1:53   ` Linus Torvalds
  2001-06-06  8:06     ` Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Linus Torvalds @ 2001-06-06  1:53 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-kernel, David S. Miller, Alexey Kuznetsov


Ingo, what the heck are you up to?

entry.S:

+       xorl %ecx,%ecx; \
        testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx

That will always test as false. "testl" is an "and", not a "cmp". And a
binary "and" with zero always results in zero.

I would suggest:
 - remove the "cli". It only slow things down. If an interrupt comes in
   and causes a softirq, that interrupt routine will also run the softirq.

   (The "cli" may help the need_resched thing, but I doubt it matters, and
   if that's what you're trying to do then you should move it there,
   instead of having it at the softirq place).

 - fix the "testl"

 - send me a patch (relative to your B4 - I've applied it, but I want this
   fixed before I do a "pre2".

Thanks,

		Linus


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

* Re: [patch] softirq-2.4.6-B4
  2001-06-06  1:53   ` Linus Torvalds
@ 2001-06-06  8:06     ` Ingo Molnar
  2001-06-06  8:22       ` [patch] softirq-2.4.6-C3 Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2001-06-06  8:06 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, David S. Miller, Alexey Kuznetsov

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2006 bytes --]


On Tue, 5 Jun 2001, Linus Torvalds wrote:

> entry.S:
>
> +       xorl %ecx,%ecx; \
>         testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx

oops, bogus indeed.

the softirq checks in entry.S are now obsolete and i've removed them in
-C2 completely. (this also explains why this 'dummy' entry.S code had no
effect on performance and stability.) Any code that can somehow end up
delaying softirqs is supposed to restart them explicitly.

this should at least somewhat reduce the cost of having to add a cli to
the need_resched and sigpending checks.

we could avoid the cli in the syscall path by putting an additional check
into the IRQ path: we can check the interrupted EIP and fix up the return
EIP if we interrupted the 'critical path'. (since the window is small,
this check would be triggered rarely.) [the idea is not mine, i think it
came from Chris Evans, and the code is included in the lowlatency
patches.]

>    (The "cli" may help the need_resched thing, but I doubt it matters, and
>    if that's what you're trying to do then you should move it there,
>    instead of having it at the softirq place).

yes, it was there partly for need_resched and sigpending purposes as well,
so a cli before the need_resched and sigpending checks is still needed.

the attached softirq-2.4.6-C2 patch (relative to -B4) has another change
as well:

- to make the local_bh_enable() softirq-check even more lightweight, on
  x86 i've moved parts of it into asssembly, with the slow path moved into
  an offline section. The assembly code does not mark any register as
  clobbered to reduce the register-saving overhead, so it has to save
  %eax, %ecx and %edx prior calling do_softirq().

  in -C2 a softirq-restart check is straight fall-through code with two
  untaken forward-pointing branches, which should put the cost of the
  common softirq check on the order of 1-2 cycles. (plus the unavoidable
  icache footprint increase.)

(the patch has been sanity compiled & booted on both UP and SMP x86.)

	Ingo

[-- Attachment #2: Type: TEXT/PLAIN, Size: 3756 bytes --]

--- linux/include/asm-i386/softirq.h.orig	Wed Jun  6 08:51:54 2001
+++ linux/include/asm-i386/softirq.h	Wed Jun  6 09:16:26 2001
@@ -11,10 +11,39 @@
 
 #define local_bh_disable()	cpu_bh_disable(smp_processor_id())
 #define __local_bh_enable()	__cpu_bh_enable(smp_processor_id())
-#define local_bh_enable()	do { int __cpu = smp_processor_id(); if (!--local_bh_count(__cpu) && softirq_pending(__cpu)) { do_softirq(); __sti(); } } while (0)
 #define __cpu_raise_softirq(cpu,nr) set_bit((nr), &softirq_pending(cpu));
 #define raise_softirq(nr) __cpu_raise_softirq(smp_processor_id(), (nr))
 
 #define in_softirq() (local_bh_count(smp_processor_id()) != 0)
+
+/*
+ * NOTE: this assembly code assumes:
+ *
+ *    (char *)&local_bh_count - 8 == (char *)&softirq_pending
+ *
+ * If you change the offsets in irq_stat then you have to
+ * update this code as well.
+ */
+#define local_bh_enable()						\
+do {									\
+	unsigned int *ptr = &local_bh_count(smp_processor_id());	\
+									\
+	if (!--*ptr)							\
+		__asm__ __volatile__ (					\
+			"cmpl $0, -8(%0);"				\
+			"jnz 2f;"					\
+			"1:;"						\
+									\
+			".section .text.lock,\"ax\";"			\
+			"2: pushl %%eax; pushl %%ecx; pushl %%edx;"	\
+			"call do_softirq;"				\
+			"popl %%edx; popl %%ecx; popl %%eax;"		\
+			"jmp 1b;"					\
+			".previous;"					\
+									\
+		: /* no output */					\
+		: "r" (ptr)						\
+		/* no registers clobbered */ );				\
+} while (0)
 
 #endif	/* __ASM_SOFTIRQ_H */
--- linux/include/asm-i386/hardirq.h.orig	Wed Jun  6 09:04:59 2001
+++ linux/include/asm-i386/hardirq.h	Wed Jun  6 09:16:26 2001
@@ -5,7 +5,7 @@
 #include <linux/threads.h>
 #include <linux/irq.h>
 
-/* entry.S is sensitive to the offsets of these fields */
+/* assembly code in softirq.h is sensitive to the offsets of these fields */
 typedef struct {
 	unsigned int __softirq_pending;
 	unsigned int __local_irq_count;
--- linux/arch/i386/kernel/entry.S.orig	Wed Jun  6 08:48:09 2001
+++ linux/arch/i386/kernel/entry.S	Wed Jun  6 08:51:39 2001
@@ -133,18 +133,6 @@
 	movl $-8192, reg; \
 	andl %esp, reg
 
-#ifdef CONFIG_SMP
-#define CHECK_SOFTIRQ \
-	movl processor(%ebx),%eax; \
-	shll $CONFIG_X86_L1_CACHE_SHIFT,%eax; \
-	xorl %ecx,%ecx; \
-	testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx
-#else
-#define CHECK_SOFTIRQ \
-	xorl %ecx,%ecx; \
-	testl SYMBOL_NAME(irq_stat)+4,%ecx
-#endif
-
 ENTRY(lcall7)
 	pushfl			# We get a different stack layout with call gates,
 	pushl %eax		# which has to be cleaned up later..
@@ -215,9 +203,7 @@
 	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
 	movl %eax,EAX(%esp)		# save the return value
 ENTRY(ret_from_sys_call)
-	cli
-	CHECK_SOFTIRQ
-	jne handle_softirq
+	cli				# need_resched and signals atomic test
 	cmpl $0,need_resched(%ebx)
 	jne reschedule
 	cmpl $0,sigpending(%ebx)
@@ -233,13 +219,6 @@
 	jne v86_signal_return
 	xorl %edx,%edx
 	call SYMBOL_NAME(do_signal)
-#ifdef CONFIG_SMP
-	GET_CURRENT(%ebx)
-#endif
-	cli
-	CHECK_SOFTIRQ
-	je restore_all
-	call SYMBOL_NAME(do_softirq)
 	jmp restore_all
 
 	ALIGN
@@ -248,13 +227,6 @@
 	movl %eax,%esp
 	xorl %edx,%edx
 	call SYMBOL_NAME(do_signal)
-#ifdef CONFIG_SMP
-	GET_CURRENT(%ebx)
-#endif
-	cli
-	CHECK_SOFTIRQ
-	je restore_all
-	call SYMBOL_NAME(do_softirq)
 	jmp restore_all
 
 	ALIGN
@@ -276,8 +248,6 @@
 	ALIGN
 ret_from_exception:
 	cli
-	CHECK_SOFTIRQ
-	jne handle_softirq
 	cmpl $0,need_resched(%ebx)
 	jne reschedule
 	cmpl $0,sigpending(%ebx)
@@ -292,11 +262,6 @@
 	jne ret_from_sys_call
 	jmp restore_all
 
-	ALIGN
-handle_softirq:
-	call SYMBOL_NAME(do_softirq)
-	jmp ret_from_intr
-	
 	ALIGN
 reschedule:
 	call SYMBOL_NAME(schedule)    # test

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

* [patch] softirq-2.4.6-C3
  2001-06-06  8:06     ` Ingo Molnar
@ 2001-06-06  8:22       ` Ingo Molnar
  0 siblings, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2001-06-06  8:22 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, David S. Miller, Alexey Kuznetsov

[-- Attachment #1: Type: TEXT/PLAIN, Size: 532 bytes --]


a number of softirq.c updates (the patch is still relative to -B4 and
includes all -C2 changes as well):

- do_softirq() does not have to keep irqs disabled when returning.

- in do_softirq(), disable_local_bh() can be done after checking for
  pending softirqs.

- the goto retry thing has no effect on gcc's code, so it's an unnecessery
  complication of the code.

- ditto the in_interrupt() check, no point in doing a goto, gcc optimizes
  this already.

do_softirq() is now a very compact and straightforward function.

	Ingo

[-- Attachment #2: Type: TEXT/PLAIN, Size: 4722 bytes --]

--- linux/kernel/softirq.c.orig	Wed Jun  6 09:00:13 2001
+++ linux/kernel/softirq.c	Wed Jun  6 09:56:06 2001
@@ -52,17 +52,17 @@
 	int cpu = smp_processor_id();
 	__u32 pending;
 
-	local_irq_disable();
 	if (in_interrupt())
-		goto out;
+		return;
 
-	local_bh_disable();
+	local_irq_disable();
 
 	pending = softirq_pending(cpu);
 
 	if (pending) {
 		struct softirq_action *h;
 
+		local_bh_disable();
 restart:
 		/* Reset the pending bitmask before enabling irqs */
 		softirq_pending(cpu) = 0;
@@ -82,20 +82,11 @@
 
 		pending = softirq_pending(cpu);
 		if (pending)
-			goto retry;
+			goto restart;
+		__local_bh_enable();
 	}
 
-	__local_bh_enable();
-out:
-
-	/* Leave with locally disabled hard irqs. It is critical to close
-	 * window for infinite recursion, while we help local bh count,
-	 * it protected us. Now we are defenceless.
-	 */
-	return;
-
-retry:
-	goto restart;
+	local_irq_enable();
 }
 
 
--- linux/include/asm-i386/softirq.h.orig	Wed Jun  6 08:51:54 2001
+++ linux/include/asm-i386/softirq.h	Wed Jun  6 09:48:22 2001
@@ -11,10 +11,39 @@
 
 #define local_bh_disable()	cpu_bh_disable(smp_processor_id())
 #define __local_bh_enable()	__cpu_bh_enable(smp_processor_id())
-#define local_bh_enable()	do { int __cpu = smp_processor_id(); if (!--local_bh_count(__cpu) && softirq_pending(__cpu)) { do_softirq(); __sti(); } } while (0)
 #define __cpu_raise_softirq(cpu,nr) set_bit((nr), &softirq_pending(cpu));
 #define raise_softirq(nr) __cpu_raise_softirq(smp_processor_id(), (nr))
 
 #define in_softirq() (local_bh_count(smp_processor_id()) != 0)
+
+/*
+ * NOTE: this assembly code assumes:
+ *
+ *    (char *)&local_bh_count - 8 == (char *)&softirq_pending
+ *
+ * If you change the offsets in irq_stat then you have to
+ * update this code as well.
+ */
+#define local_bh_enable()						\
+do {									\
+	unsigned int *ptr = &local_bh_count(smp_processor_id());	\
+									\
+	if (!--*ptr)							\
+		__asm__ __volatile__ (					\
+			"cmpl $0, -8(%0);"				\
+			"jnz 2f;"					\
+			"1:;"						\
+									\
+			".section .text.lock,\"ax\";"			\
+			"2: pushl %%eax; pushl %%ecx; pushl %%edx;"	\
+			"call do_softirq;"				\
+			"popl %%edx; popl %%ecx; popl %%eax;"		\
+			"jmp 1b;"					\
+			".previous;"					\
+									\
+		: /* no output */					\
+		: "r" (ptr)						\
+		/* no registers clobbered */ );				\
+} while (0)
 
 #endif	/* __ASM_SOFTIRQ_H */
--- linux/include/asm-i386/hardirq.h.orig	Wed Jun  6 09:04:59 2001
+++ linux/include/asm-i386/hardirq.h	Wed Jun  6 09:16:26 2001
@@ -5,7 +5,7 @@
 #include <linux/threads.h>
 #include <linux/irq.h>
 
-/* entry.S is sensitive to the offsets of these fields */
+/* assembly code in softirq.h is sensitive to the offsets of these fields */
 typedef struct {
 	unsigned int __softirq_pending;
 	unsigned int __local_irq_count;
--- linux/arch/i386/kernel/entry.S.orig	Wed Jun  6 08:48:09 2001
+++ linux/arch/i386/kernel/entry.S	Wed Jun  6 08:51:39 2001
@@ -133,18 +133,6 @@
 	movl $-8192, reg; \
 	andl %esp, reg
 
-#ifdef CONFIG_SMP
-#define CHECK_SOFTIRQ \
-	movl processor(%ebx),%eax; \
-	shll $CONFIG_X86_L1_CACHE_SHIFT,%eax; \
-	xorl %ecx,%ecx; \
-	testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx
-#else
-#define CHECK_SOFTIRQ \
-	xorl %ecx,%ecx; \
-	testl SYMBOL_NAME(irq_stat)+4,%ecx
-#endif
-
 ENTRY(lcall7)
 	pushfl			# We get a different stack layout with call gates,
 	pushl %eax		# which has to be cleaned up later..
@@ -215,9 +203,7 @@
 	call *SYMBOL_NAME(sys_call_table)(,%eax,4)
 	movl %eax,EAX(%esp)		# save the return value
 ENTRY(ret_from_sys_call)
-	cli
-	CHECK_SOFTIRQ
-	jne handle_softirq
+	cli				# need_resched and signals atomic test
 	cmpl $0,need_resched(%ebx)
 	jne reschedule
 	cmpl $0,sigpending(%ebx)
@@ -233,13 +219,6 @@
 	jne v86_signal_return
 	xorl %edx,%edx
 	call SYMBOL_NAME(do_signal)
-#ifdef CONFIG_SMP
-	GET_CURRENT(%ebx)
-#endif
-	cli
-	CHECK_SOFTIRQ
-	je restore_all
-	call SYMBOL_NAME(do_softirq)
 	jmp restore_all
 
 	ALIGN
@@ -248,13 +227,6 @@
 	movl %eax,%esp
 	xorl %edx,%edx
 	call SYMBOL_NAME(do_signal)
-#ifdef CONFIG_SMP
-	GET_CURRENT(%ebx)
-#endif
-	cli
-	CHECK_SOFTIRQ
-	je restore_all
-	call SYMBOL_NAME(do_softirq)
 	jmp restore_all
 
 	ALIGN
@@ -276,8 +248,6 @@
 	ALIGN
 ret_from_exception:
 	cli
-	CHECK_SOFTIRQ
-	jne handle_softirq
 	cmpl $0,need_resched(%ebx)
 	jne reschedule
 	cmpl $0,sigpending(%ebx)
@@ -292,11 +262,6 @@
 	jne ret_from_sys_call
 	jmp restore_all
 
-	ALIGN
-handle_softirq:
-	call SYMBOL_NAME(do_softirq)
-	jmp ret_from_intr
-	
 	ALIGN
 reschedule:
 	call SYMBOL_NAME(schedule)    # test

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

* Re: [patch] softirq-2.4.6-B4
       [not found] <3B1CEDFF.E763DEB1@mandrakesoft.com>
@ 2001-06-05 16:53 ` Ingo Molnar
  0 siblings, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2001-06-05 16:53 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: Linus Torvalds, David S. Miller, Alexey Kuznetsov, linux-kernel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 162 bytes --]


On Tue, 5 Jun 2001, Jeff Garzik wrote:

> Ingo,
>
> You attached "B3" but your message says "B4".
> Was the latest one attached?

oops, -B4 attached now.

	Ingo

[-- Attachment #2: Type: TEXT/PLAIN, Size: 5139 bytes --]

--- linux/kernel/ksyms.c.orig	Tue Jun  5 09:59:44 2001
+++ linux/kernel/ksyms.c	Tue Jun  5 10:00:18 2001
@@ -535,6 +535,9 @@
 EXPORT_SYMBOL(tasklet_init);
 EXPORT_SYMBOL(tasklet_kill);
 EXPORT_SYMBOL(__run_task_queue);
+EXPORT_SYMBOL(do_softirq);
+EXPORT_SYMBOL(tasklet_schedule);
+EXPORT_SYMBOL(tasklet_hi_schedule);
 
 /* init task, for moving kthread roots - ought to export a function ?? */
 
--- linux/kernel/softirq.c.orig	Tue Jun  5 10:09:02 2001
+++ linux/kernel/softirq.c	Tue Jun  5 10:31:59 2001
@@ -50,7 +50,7 @@
 asmlinkage void do_softirq()
 {
 	int cpu = smp_processor_id();
-	__u32 active, mask;
+	__u32 pending;
 
 	local_irq_disable();
 	if (in_interrupt())
@@ -58,31 +58,30 @@
 
 	local_bh_disable();
 
-	mask = softirq_mask(cpu);
-	active = softirq_active(cpu) & mask;
+	pending = softirq_pending(cpu);
 
-	if (active) {
+	if (pending) {
 		struct softirq_action *h;
 
 restart:
-		/* Reset active bitmask before enabling irqs */
-		softirq_active(cpu) &= ~active;
+		/* Reset the pending bitmask before enabling irqs */
+		softirq_pending(cpu) = 0;
 
 		local_irq_enable();
 
 		h = softirq_vec;
 
 		do {
-			if (active & 1)
+			if (pending & 1)
 				h->action(h);
 			h++;
-			active >>= 1;
-		} while (active);
+			pending >>= 1;
+		} while (pending);
 
 		local_irq_disable();
 
-		active = softirq_active(cpu) & mask;
-		if (active)
+		pending = softirq_pending(cpu);
+		if (pending)
 			goto retry;
 	}
 
@@ -100,20 +99,10 @@
 }
 
 
-static spinlock_t softirq_mask_lock = SPIN_LOCK_UNLOCKED;
-
 void open_softirq(int nr, void (*action)(struct softirq_action*), void *data)
 {
-	unsigned long flags;
-	int i;
-
-	spin_lock_irqsave(&softirq_mask_lock, flags);
 	softirq_vec[nr].data = data;
 	softirq_vec[nr].action = action;
-
-	for (i=0; i<NR_CPUS; i++)
-		softirq_mask(i) |= (1<<nr);
-	spin_unlock_irqrestore(&softirq_mask_lock, flags);
 }
 
 
--- linux/include/linux/irq_cpustat.h.orig	Tue Jun  5 10:09:31 2001
+++ linux/include/linux/irq_cpustat.h	Tue Jun  5 10:21:16 2001
@@ -26,15 +26,11 @@
 #endif	
 
   /* arch independent irq_stat fields */
-#define softirq_active(cpu)	__IRQ_STAT((cpu), __softirq_active)
-#define softirq_mask(cpu)	__IRQ_STAT((cpu), __softirq_mask)
+#define softirq_pending(cpu)	__IRQ_STAT((cpu), __softirq_pending)
 #define local_irq_count(cpu)	__IRQ_STAT((cpu), __local_irq_count)
 #define local_bh_count(cpu)	__IRQ_STAT((cpu), __local_bh_count)
 #define syscall_count(cpu)	__IRQ_STAT((cpu), __syscall_count)
   /* arch dependent irq_stat fields */
 #define nmi_count(cpu)		__IRQ_STAT((cpu), __nmi_count)		/* i386, ia64 */
-
-#define softirq_pending(cpu) \
-	((softirq_active(cpu) & softirq_mask(cpu)))
 
 #endif	/* __irq_cpustat_h */
--- linux/include/linux/interrupt.h.orig	Tue Jun  5 10:11:02 2001
+++ linux/include/linux/interrupt.h	Tue Jun  5 12:03:58 2001
@@ -74,17 +74,6 @@
 asmlinkage void do_softirq(void);
 extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
 
-/* Locally cached atomic variables are cheaper than cli/sti */
-static inline void __cpu_raise_softirq(int cpu, int nr)
-{
-	set_bit(nr, &softirq_active(cpu));
-}
-
-static inline void raise_softirq(int nr)
-{
-	__cpu_raise_softirq(smp_processor_id(), nr);
-}
-
 extern void softirq_init(void);
 
 
--- linux/include/asm-i386/hardirq.h.orig	Tue Jun  5 10:10:35 2001
+++ linux/include/asm-i386/hardirq.h	Tue Jun  5 10:21:17 2001
@@ -7,8 +7,7 @@
 
 /* entry.S is sensitive to the offsets of these fields */
 typedef struct {
-	unsigned int __softirq_active;
-	unsigned int __softirq_mask;
+	unsigned int __softirq_pending;
 	unsigned int __local_irq_count;
 	unsigned int __local_bh_count;
 	unsigned int __syscall_count;
--- linux/include/asm-i386/softirq.h.orig	Tue Jun  5 10:16:53 2001
+++ linux/include/asm-i386/softirq.h	Tue Jun  5 12:04:22 2001
@@ -11,7 +11,9 @@
 
 #define local_bh_disable()	cpu_bh_disable(smp_processor_id())
 #define __local_bh_enable()	__cpu_bh_enable(smp_processor_id())
-#define local_bh_enable()	do { if (!--local_bh_count(smp_processor_id()) && softirq_pending(smp_processor_id())) { do_softirq(); __sti(); } } while (0)
+#define local_bh_enable()	do { int __cpu = smp_processor_id(); if (!--local_bh_count(__cpu) && softirq_pending(__cpu)) { do_softirq(); __sti(); } } while (0)
+#define __cpu_raise_softirq(cpu,nr) set_bit((nr), &softirq_pending(cpu));
+#define raise_softirq(nr) __cpu_raise_softirq(smp_processor_id(), (nr))
 
 #define in_softirq() (local_bh_count(smp_processor_id()) != 0)
 
--- linux/arch/i386/kernel/entry.S.orig	Tue Jun  5 11:55:38 2001
+++ linux/arch/i386/kernel/entry.S	Tue Jun  5 11:57:48 2001
@@ -137,11 +137,11 @@
 #define CHECK_SOFTIRQ \
 	movl processor(%ebx),%eax; \
 	shll $CONFIG_X86_L1_CACHE_SHIFT,%eax; \
-	movl SYMBOL_NAME(irq_stat)(,%eax),%ecx; \
+	xorl %ecx,%ecx; \
 	testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx
 #else
 #define CHECK_SOFTIRQ \
-	movl SYMBOL_NAME(irq_stat),%ecx; \
+	xorl %ecx,%ecx; \
 	testl SYMBOL_NAME(irq_stat)+4,%ecx
 #endif
 

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

end of thread, other threads:[~2001-06-06  8:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-05  9:09 [patch] softirq-2.4.6-B2 Ingo Molnar
2001-06-05  9:17 ` David S. Miller
2001-06-05  9:27 ` David S. Miller
2001-06-05 10:34 ` [patch] softirq-2.4.6-B4 Ingo Molnar
2001-06-06  1:53   ` Linus Torvalds
2001-06-06  8:06     ` Ingo Molnar
2001-06-06  8:22       ` [patch] softirq-2.4.6-C3 Ingo Molnar
     [not found] <3B1CEDFF.E763DEB1@mandrakesoft.com>
2001-06-05 16:53 ` [patch] softirq-2.4.6-B4 Ingo Molnar

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

all inboxes | Powered by JetHome®