From: Andrea Arcangeli <andrea@suse.de>
To: Maksim Krasnyanskiy <maxk@qualcomm.com>
Cc: kuznet@ms2.inr.ac.ru, linux-kernel@vger.kernel.org,
torvalds@transmeta.com, mingo@redhat.com
Subject: Re: [PATCH] [IMPORTANT] Re: 2.4.7 softirq incorrectness.
Date: Sat, 28 Jul 2001 21:17:03 +0200 [thread overview]
Message-ID: <20010728211703.A11441@athlon.random> (raw)
In-Reply-To: <4.3.1.0.20010727121014.055d4c90@mail1> <200107271935.XAA27068@ms2.inr.ac.ru> <4.3.1.0.20010727141716.05651ac0@mail1> <20010728195404.D12090@athlon.random>
In-Reply-To: <20010728195404.D12090@athlon.random>; from andrea@suse.de on Sat, Jul 28, 2001 at 07:54:04PM +0200
On Sat, Jul 28, 2001 at 07:54:04PM +0200, Andrea Arcangeli wrote:
> On Fri, Jul 27, 2001 at 05:52:01PM -0700, Maksim Krasnyanskiy wrote:
> > tasklet_schedule calls tasklet_unlock after it schedules tasklet, which is _totaly_ wrong.
>
> yes, it was a leftover from 2.4.6. Your diff -u 2.4.7 2.4.5 is correct
> and I also suggest it for for mainline inclusion, thanks.
I did some minor further improvement to it while merging it into my tree
and then I rediffed it. This one also adds the debug check for
local_bh_enable in a clied region. (note for other archs:
__cpu_raise_softirq is required to be atomic with respect to irqs but it
doesn't need to be atomic with respect to smp, in x86 it is implemented
as a non locked bts for example)
diff -urN 2.4.7/include/asm-i386/softirq.h softirq/include/asm-i386/softirq.h
--- 2.4.7/include/asm-i386/softirq.h Wed Jul 25 22:38:08 2001
+++ softirq/include/asm-i386/softirq.h Sat Jul 28 21:11:35 2001
@@ -25,7 +25,11 @@
#define local_bh_enable() \
do { \
unsigned int *ptr = &local_bh_count(smp_processor_id()); \
+ unsigned long flags; \
\
+ __save_flags(flags); \
+ if (!(flags & (1 << 9))) \
+ BUG(); \
barrier(); \
if (!--*ptr) \
__asm__ __volatile__ ( \
diff -urN 2.4.7/include/linux/interrupt.h softirq/include/linux/interrupt.h
--- 2.4.7/include/linux/interrupt.h Sun Jul 22 01:16:45 2001
+++ softirq/include/linux/interrupt.h Sat Jul 28 21:09:15 2001
@@ -118,7 +118,7 @@
enum
{
TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
- TASKLET_STATE_RUN /* Tasklet is running */
+ TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
};
struct tasklet_head
@@ -129,34 +129,80 @@
extern struct tasklet_head tasklet_vec[NR_CPUS];
extern struct tasklet_head tasklet_hi_vec[NR_CPUS];
-#define tasklet_trylock(t) (!test_and_set_bit(TASKLET_STATE_RUN, &(t)->state))
-#define tasklet_unlock(t) do { smp_mb__before_clear_bit(); clear_bit(TASKLET_STATE_RUN, &(t)->state); } while(0)
-#define tasklet_unlock_wait(t) while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
+#ifdef CONFIG_SMP
+static inline int tasklet_trylock(struct tasklet_struct *t)
+{
+ return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
+}
+
+static inline void tasklet_unlock(struct tasklet_struct *t)
+{
+ smp_mb__before_clear_bit();
+ clear_bit(TASKLET_STATE_RUN, &(t)->state);
+}
+
+static inline void tasklet_unlock_wait(struct tasklet_struct *t)
+{
+ while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
+}
+#else
+#define tasklet_trylock(t) 1
+#define tasklet_unlock_wait(t) do { } while (0)
+#define tasklet_unlock(t) do { } while (0)
+#endif
+
+static inline void tasklet_schedule(struct tasklet_struct *t)
+{
+ if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
+ int cpu = smp_processor_id();
+ unsigned long flags;
+
+ local_irq_save(flags);
+ t->next = tasklet_vec[cpu].list;
+ tasklet_vec[cpu].list = t;
+ cpu_raise_softirq(cpu, TASKLET_SOFTIRQ);
+ local_irq_restore(flags);
+ }
+}
+
+static inline void tasklet_hi_schedule(struct tasklet_struct *t)
+{
+ if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
+ int cpu = smp_processor_id();
+ unsigned long flags;
+
+ local_irq_save(flags);
+ t->next = tasklet_hi_vec[cpu].list;
+ tasklet_hi_vec[cpu].list = t;
+ cpu_raise_softirq(cpu, HI_SOFTIRQ);
+ local_irq_restore(flags);
+ }
+}
-extern void tasklet_schedule(struct tasklet_struct *t);
-extern void tasklet_hi_schedule(struct tasklet_struct *t);
static inline void tasklet_disable_nosync(struct tasklet_struct *t)
{
atomic_inc(&t->count);
+ smp_mb__after_atomic_inc();
}
static inline void tasklet_disable(struct tasklet_struct *t)
{
tasklet_disable_nosync(t);
tasklet_unlock_wait(t);
+ smp_mb();
}
static inline void tasklet_enable(struct tasklet_struct *t)
{
- if (atomic_dec_and_test(&t->count))
- tasklet_schedule(t);
+ smp_mb__before_atomic_dec();
+ atomic_dec(&t->count);
}
static inline void tasklet_hi_enable(struct tasklet_struct *t)
{
- if (atomic_dec_and_test(&t->count))
- tasklet_hi_schedule(t);
+ smp_mb__before_atomic_dec();
+ atomic_dec(&t->count);
}
extern void tasklet_kill(struct tasklet_struct *t);
diff -urN 2.4.7/kernel/softirq.c softirq/kernel/softirq.c
--- 2.4.7/kernel/softirq.c Sat Jul 21 00:04:34 2001
+++ softirq/kernel/softirq.c Sat Jul 28 21:09:46 2001
@@ -143,43 +143,7 @@
/* Tasklets */
struct tasklet_head tasklet_vec[NR_CPUS] __cacheline_aligned;
-
-void tasklet_schedule(struct tasklet_struct *t)
-{
- unsigned long flags;
- int cpu;
-
- cpu = smp_processor_id();
- local_irq_save(flags);
- /*
- * If nobody is running it then add it to this CPU's
- * tasklet queue.
- */
- if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
- t->next = tasklet_vec[cpu].list;
- tasklet_vec[cpu].list = t;
- cpu_raise_softirq(cpu, TASKLET_SOFTIRQ);
- tasklet_unlock(t);
- }
- local_irq_restore(flags);
-}
-
-void tasklet_hi_schedule(struct tasklet_struct *t)
-{
- unsigned long flags;
- int cpu;
-
- cpu = smp_processor_id();
- local_irq_save(flags);
-
- if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
- t->next = tasklet_hi_vec[cpu].list;
- tasklet_hi_vec[cpu].list = t;
- cpu_raise_softirq(cpu, HI_SOFTIRQ);
- tasklet_unlock(t);
- }
- local_irq_restore(flags);
-}
+struct tasklet_head tasklet_hi_vec[NR_CPUS] __cacheline_aligned;
static void tasklet_action(struct softirq_action *a)
{
@@ -196,29 +160,25 @@
list = list->next;
- if (!tasklet_trylock(t))
- BUG();
- if (!atomic_read(&t->count)) {
- if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
- BUG();
- t->func(t->data);
+ if (tasklet_trylock(t)) {
+ if (!atomic_read(&t->count)) {
+ if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
+ BUG();
+ t->func(t->data);
+ tasklet_unlock(t);
+ continue;
+ }
tasklet_unlock(t);
- continue;
}
- tasklet_unlock(t);
local_irq_disable();
t->next = tasklet_vec[cpu].list;
tasklet_vec[cpu].list = t;
- cpu_raise_softirq(cpu, TASKLET_SOFTIRQ);
local_irq_enable();
+ __cpu_raise_softirq(cpu, TASKLET_SOFTIRQ);
}
}
-
-
-struct tasklet_head tasklet_hi_vec[NR_CPUS] __cacheline_aligned;
-
static void tasklet_hi_action(struct softirq_action *a)
{
int cpu = smp_processor_id();
@@ -234,22 +194,22 @@
list = list->next;
- if (!tasklet_trylock(t))
- BUG();
- if (!atomic_read(&t->count)) {
- if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
- BUG();
- t->func(t->data);
+ if (tasklet_trylock(t)) {
+ if (!atomic_read(&t->count)) {
+ if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
+ BUG();
+ t->func(t->data);
+ tasklet_unlock(t);
+ continue;
+ }
tasklet_unlock(t);
- continue;
}
- tasklet_unlock(t);
local_irq_disable();
t->next = tasklet_hi_vec[cpu].list;
tasklet_hi_vec[cpu].list = t;
- cpu_raise_softirq(cpu, HI_SOFTIRQ);
local_irq_enable();
+ __cpu_raise_softirq(cpu, HI_SOFTIRQ);
}
}
diff -urN 2.4.7/net/core/dev.c softirq/net/core/dev.c
--- 2.4.7/net/core/dev.c Sat Jul 21 00:04:34 2001
+++ softirq/net/core/dev.c Sat Jul 28 21:10:20 2001
@@ -1217,10 +1217,10 @@
enqueue:
dev_hold(skb->dev);
__skb_queue_tail(&queue->input_pkt_queue,skb);
+ local_irq_restore(flags);
/* Runs from irqs or BH's, no need to wake BH */
__cpu_raise_softirq(this_cpu, NET_RX_SOFTIRQ);
- local_irq_restore(flags);
#ifndef OFFLINE_SAMPLE
get_sample_stats(this_cpu);
#endif
@@ -1529,10 +1529,10 @@
local_irq_disable();
netdev_rx_stat[this_cpu].time_squeeze++;
+ local_irq_enable();
/* This already runs in BH context, no need to wake up BH's */
__cpu_raise_softirq(this_cpu, NET_RX_SOFTIRQ);
- local_irq_enable();
NET_PROFILE_LEAVE(softnet_process);
return;
Andrea
next prev parent reply other threads:[~2001-07-28 19:16 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-22 20:44 2.4.7 softirq incorrectness Rusty Russell
2001-07-22 23:34 ` Andrea Arcangeli
2001-07-23 9:06 ` Rusty Russell
2001-07-23 12:05 ` David S. Miller
2001-07-23 14:31 ` Andrea Arcangeli
2001-07-23 14:29 ` Andrea Arcangeli
2001-07-24 9:35 ` Rusty Russell
2001-07-25 19:33 ` Andrea Arcangeli
2001-07-26 20:26 ` Rusty Russell
2001-07-23 9:25 ` Kai Germaschewski
2001-07-23 11:12 ` Jeff Garzik
2001-07-23 14:18 ` Andrea Arcangeli
2001-07-23 22:24 ` Alexey Kuznetsov
2001-07-25 22:23 ` Andrea Arcangeli
2001-07-26 17:46 ` kuznet
2001-07-26 18:03 ` Jeff Garzik
2001-07-26 18:29 ` Andrea Arcangeli
2001-07-27 16:48 ` kuznet
2001-07-27 0:47 ` Maksim Krasnyanskiy
2001-07-27 15:01 ` Andrea Arcangeli
2001-07-27 18:31 ` Maksim Krasnyanskiy
2001-07-27 18:59 ` kuznet
2001-07-27 19:21 ` Maksim Krasnyanskiy
2001-07-27 19:35 ` kuznet
2001-07-28 0:52 ` [PATCH] [IMPORTANT] " Maksim Krasnyanskiy
2001-07-28 17:41 ` kuznet
2001-07-28 18:02 ` Andrea Arcangeli
2001-07-28 19:02 ` kuznet
2001-07-28 19:32 ` Andrea Arcangeli
2001-07-28 23:28 ` Alexey Kuznetsov
2001-07-29 17:07 ` Linus Torvalds
2001-07-29 17:52 ` kuznet
2001-07-30 18:50 ` Ingo Molnar
2001-07-30 22:47 ` Nigel Gamble
2001-07-30 22:56 ` Christoph Hellwig
2001-07-31 18:08 ` kuznet
2001-07-28 17:54 ` Andrea Arcangeli
2001-07-28 19:17 ` Andrea Arcangeli [this message]
2001-07-30 18:32 ` Maksim Krasnyanskiy
2001-07-27 9:34 ` David S. Miller
2001-07-27 17:01 ` kuznet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010728211703.A11441@athlon.random \
--to=andrea@suse.de \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=maxk@qualcomm.com \
--cc=mingo@redhat.com \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.