LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
@ 2008-02-19 15:37 Ahmed S. Darwish
  2008-02-19 15:52 ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Ahmed S. Darwish @ 2008-02-19 15:37 UTC (permalink / raw)
  To: Andrew Morton, Ingo Molnar; +Cc: LKML

Hi all,

Avoid duplicating __tasklet_schedule() and __tasklet_hi_schedule()
code in tasklet_action() and tasklet_hi_action() respectively.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

This also saves a few bytes of image space:

   text	   data	    bss	    dec	    hex	filename
   3632	     12	    324	   3968	    f80	softirq.o.before
   3552	     12	    324	   3888	    f30	softirq.o.after

diff --git a/kernel/softirq.c b/kernel/softirq.c
index 5b3aea5..3068dc3 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -414,11 +414,8 @@ static void tasklet_action(struct softirq_action *a)
 			tasklet_unlock(t);
 		}
 
-		local_irq_disable();
-		t->next = __get_cpu_var(tasklet_vec).list;
-		__get_cpu_var(tasklet_vec).list = t;
-		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
-		local_irq_enable();
+		/* We were not lucky enough to run, reschedule. */
+		__tasklet_schedule(t);
 	}
 }
 
@@ -447,11 +444,8 @@ static void tasklet_hi_action(struct softirq_action *a)
 			tasklet_unlock(t);
 		}
 
-		local_irq_disable();
-		t->next = __get_cpu_var(tasklet_hi_vec).list;
-		__get_cpu_var(tasklet_hi_vec).list = t;
-		__raise_softirq_irqoff(HI_SOFTIRQ);
-		local_irq_enable();
+		/* We were not lucky enough to run, reschedule. */
+		__tasklet_hi_schedule(t);
 	}
 }
 

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


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

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  2008-02-19 15:37 [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code Ahmed S. Darwish
@ 2008-02-19 15:52 ` Ingo Molnar
  2008-02-19 16:27   ` Ahmed S. Darwish
  0 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2008-02-19 15:52 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Andrew Morton, Ingo Molnar, LKML


* Ahmed S. Darwish <darwish.07@gmail.com> wrote:

> -		local_irq_disable();
> -		t->next = __get_cpu_var(tasklet_vec).list;
> -		__get_cpu_var(tasklet_vec).list = t;
> -		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
> -		local_irq_enable();
> +		/* We were not lucky enough to run, reschedule. */
> +		__tasklet_schedule(t);

i think there's a subtle difference that you missed: this one does 
__raise_softirq_irqoff(), while __tasklet_schedule() does a 
raise_softirq_irqoff(). (note the lack of undescores)

the reason is to avoid infinitely self-activating tasklets.

	Ingo

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

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  2008-02-19 15:52 ` Ingo Molnar
@ 2008-02-19 16:27   ` Ahmed S. Darwish
  2008-02-20 10:41     ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Ahmed S. Darwish @ 2008-02-19 16:27 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, Ingo Molnar, LKML

On Tue, Feb 19, 2008 at 04:52:52PM +0100, Ingo Molnar wrote:
> 
> * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> 
> > -		local_irq_disable();
> > -		t->next = __get_cpu_var(tasklet_vec).list;
> > -		__get_cpu_var(tasklet_vec).list = t;
> > -		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > -		local_irq_enable();
> > +		/* We were not lucky enough to run, reschedule. */
> > +		__tasklet_schedule(t);
> 
> i think there's a subtle difference that you missed: this one does 
> __raise_softirq_irqoff(), while __tasklet_schedule() does a 
> raise_softirq_irqoff(). (note the lack of undescores)
> 
> the reason is to avoid infinitely self-activating tasklets.
> 

Indeed, thanks a lot for the explanation. (maybe it's time to check
for new eyeglasses ;)).

Regards

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


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

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  2008-02-19 16:27   ` Ahmed S. Darwish
@ 2008-02-20 10:41     ` Ingo Molnar
  2008-02-20 13:37       ` Ahmed S. Darwish
  0 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2008-02-20 10:41 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Andrew Morton, Ingo Molnar, LKML


* Ahmed S. Darwish <darwish.07@gmail.com> wrote:

> > > -		local_irq_disable();
> > > -		t->next = __get_cpu_var(tasklet_vec).list;
> > > -		__get_cpu_var(tasklet_vec).list = t;
> > > -		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > > -		local_irq_enable();
> > > +		/* We were not lucky enough to run, reschedule. */
> > > +		__tasklet_schedule(t);
> > 
> > i think there's a subtle difference that you missed: this one does 
> > __raise_softirq_irqoff(), while __tasklet_schedule() does a 
> > raise_softirq_irqoff(). (note the lack of undescores)
> > 
> > the reason is to avoid infinitely self-activating tasklets.
> 
> Indeed, thanks a lot for the explanation. (maybe it's time to check 
> for new eyeglasses ;)).

nah, it's rather subtle and the code looked good to me at first but i 
remembered that there was some small detail here to watch out for.

i really dont like tasklets due to their many, arbitrary scheduling 
limitations, we should really use the "turn tasklets into kthreads" 
patch i posted last year.

	Ingo

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

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  2008-02-20 10:41     ` Ingo Molnar
@ 2008-02-20 13:37       ` Ahmed S. Darwish
  2008-02-20 14:20         ` Dmitry Adamushko
  0 siblings, 1 reply; 7+ messages in thread
From: Ahmed S. Darwish @ 2008-02-20 13:37 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, Ingo Molnar, LKML

On Wed, Feb 20, 2008 at 11:41:13AM +0100, Ingo Molnar wrote:
> 
> * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> 
> > > > -		local_irq_disable();
> > > > -		t->next = __get_cpu_var(tasklet_vec).list;
> > > > -		__get_cpu_var(tasklet_vec).list = t;
> > > > -		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > > > -		local_irq_enable();
> > > > +		/* We were not lucky enough to run, reschedule. */
> > > > +		__tasklet_schedule(t);
> > > 
> > > i think there's a subtle difference that you missed: this one does 
> > > __raise_softirq_irqoff(), while __tasklet_schedule() does a 
> > > raise_softirq_irqoff(). (note the lack of undescores)
> > > 
> > > the reason is to avoid infinitely self-activating tasklets.
> > 
> > Indeed, thanks a lot for the explanation. (maybe it's time to check 
> > for new eyeglasses ;)).
> 
> nah, it's rather subtle and the code looked good to me at first but i 
> remembered that there was some small detail here to watch out for.
> 
> i really dont like tasklets due to their many, arbitrary scheduling 
> limitations, we should really use the "turn tasklets into kthreads" 
> patch i posted last year.
> 

While we are at it, there's a small question that is bothering me
for a while (and I'm really thankful for help). 

I keep reading that softirqs (and naturally, tasklets) got executed 
in interrupt context at the return from hardirq code path.

Checking entry_32.S, I find no mentioning of softirqs on the return
path (beginning from ret_from_intr: to restore_all: )

The only invocation I'm able to find is from local_bh_enable() and
from ksoftirqd/n threads (by calling do_softirq()). AFAIK, both 
invocations occur in a _nont-interrupt_ context (exception context).

So, where does the interrupt-context tasklets invocation really 
occur ?

Thanks

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


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

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  2008-02-20 13:37       ` Ahmed S. Darwish
@ 2008-02-20 14:20         ` Dmitry Adamushko
  2008-02-20 19:39           ` Ahmed S. Darwish
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Adamushko @ 2008-02-20 14:20 UTC (permalink / raw)
  To: Ahmed S. Darwish; +Cc: Ingo Molnar, LKML

On 20/02/2008, Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> On Wed, Feb 20, 2008 at 11:41:13AM +0100, Ingo Molnar wrote:
> >
> > * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> >
> > > > > -               local_irq_disable();
> > > > > -               t->next = __get_cpu_var(tasklet_vec).list;
> > > > > -               __get_cpu_var(tasklet_vec).list = t;
> > > > > -               __raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > > > > -               local_irq_enable();
> > > > > +               /* We were not lucky enough to run, reschedule. */
> > > > > +               __tasklet_schedule(t);
> > > >
> > > > i think there's a subtle difference that you missed: this one does
> > > > __raise_softirq_irqoff(), while __tasklet_schedule() does a
> > > > raise_softirq_irqoff(). (note the lack of undescores)
> > > >
> > > > the reason is to avoid infinitely self-activating tasklets.
> > >
> > > Indeed, thanks a lot for the explanation. (maybe it's time to check
> > > for new eyeglasses ;)).
> >
> > nah, it's rather subtle and the code looked good to me at first but i
> > remembered that there was some small detail here to watch out for.
> >
> > i really dont like tasklets due to their many, arbitrary scheduling
> > limitations, we should really use the "turn tasklets into kthreads"
> > patch i posted last year.
> >
>
> While we are at it, there's a small question that is bothering me
> for a while (and I'm really thankful for help).
>
> I keep reading that softirqs (and naturally, tasklets) got executed
> in interrupt context at the return from hardirq code path.
>
> Checking entry_32.S, I find no mentioning of softirqs on the return
> path (beginning from ret_from_intr: to restore_all: )
>
> The only invocation I'm able to find is from local_bh_enable() and
> from ksoftirqd/n threads (by calling do_softirq()). AFAIK, both
> invocations occur in a _nont-interrupt_ context (exception context).
>
> So, where does the interrupt-context tasklets invocation really
> occur ?

Look at irq_exit() in softirq.c.

The common sequence is ... -> do_IRQ() --> irq_exit() --> invoke_softirq()


-- 
Best regards,
Dmitry Adamushko

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

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  2008-02-20 14:20         ` Dmitry Adamushko
@ 2008-02-20 19:39           ` Ahmed S. Darwish
  0 siblings, 0 replies; 7+ messages in thread
From: Ahmed S. Darwish @ 2008-02-20 19:39 UTC (permalink / raw)
  To: Dmitry Adamushko; +Cc: Ingo Molnar, LKML, Andrew Morton

On Wed, Feb 20, 2008 at 03:20:52PM +0100, Dmitry Adamushko wrote:
> On 20/02/2008, Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> > On Wed, Feb 20, 2008 at 11:41:13AM +0100, Ingo Molnar wrote:
> > >
> > > * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> > >
> > > > > > -               local_irq_disable();
> > > > > > -               t->next = __get_cpu_var(tasklet_vec).list;
> > > > > > -               __get_cpu_var(tasklet_vec).list = t;
> > > > > > -               __raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > > > > > -               local_irq_enable();
> > > > > > +               /* We were not lucky enough to run, reschedule. */
> > > > > > +               __tasklet_schedule(t);
> > > > >
> > > > > i think there's a subtle difference that you missed: this one does
> > > > > __raise_softirq_irqoff(), while __tasklet_schedule() does a
> > > > > raise_softirq_irqoff(). (note the lack of undescores)
> > > > >
> > > > > the reason is to avoid infinitely self-activating tasklets.
> > > >
> > > > Indeed, thanks a lot for the explanation. (maybe it's time to check
> > > > for new eyeglasses ;)).
> > >
> > > nah, it's rather subtle and the code looked good to me at first but i
> > > remembered that there was some small detail here to watch out for.
> > >
> > > i really dont like tasklets due to their many, arbitrary scheduling
> > > limitations, we should really use the "turn tasklets into kthreads"
> > > patch i posted last year.
> > >
> >
> > While we are at it, there's a small question that is bothering me
> > for a while (and I'm really thankful for help).
> >
> > I keep reading that softirqs (and naturally, tasklets) got executed
> > in interrupt context at the return from hardirq code path.
> >
> > Checking entry_32.S, I find no mentioning of softirqs on the return
> > path (beginning from ret_from_intr: to restore_all: )
> >
> > The only invocation I'm able to find is from local_bh_enable() and
> > from ksoftirqd/n threads (by calling do_softirq()). AFAIK, both
> > invocations occur in a _nont-interrupt_ context (exception context).
> >
> > So, where does the interrupt-context tasklets invocation really
> > occur ?
> 
> Look at irq_exit() in softirq.c.
> 
> The common sequence is ... -> do_IRQ() --> irq_exit() --> invoke_softirq()
> 
> 

Great, this was the last missing block in my understanding of softirqs :).
Thank you.

[btw, your MUA broke the CC list]

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


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

end of thread, other threads:[~2008-02-20 19:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-19 15:37 [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code Ahmed S. Darwish
2008-02-19 15:52 ` Ingo Molnar
2008-02-19 16:27   ` Ahmed S. Darwish
2008-02-20 10:41     ` Ingo Molnar
2008-02-20 13:37       ` Ahmed S. Darwish
2008-02-20 14:20         ` Dmitry Adamushko
2008-02-20 19:39           ` Ahmed S. Darwish

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).