views:

72

answers:

3

Hi,

Got some doubts with bottom half.Here, I consider tasklets only. Also , I consider non-preemptible kernel only.

Suppose consider a ethernet driver in which rx interrupt processing is doing some 10 functions calls.(bad programming :) )

Now, looking at performance perspective if 9 function calls can be moved to a tasklet and only 1 needs to be called in interrupt handling , Can I really get some good performance in a tcp read application.

Or in other words, when there is switch to user space application all the 9 function calls for the tasklets scheduled will be called, in effective the user space application will be able to get the packet cum data only after "all the taskets scheduled" are completed ? correct?

I understand that by having bottom half , we are enabling all interrupts .. but I have a doubt whether the application that relies on the interrupt actually gain anything by having the entire 10 functions in interrupt handler itself or in the bottom half.

In Short, by having tasklet do I gain performance improvement in user space application ,here ?

+1  A: 

Since tasklets are not queued but scheduled, i.e. several hardware interrupts posting the same tasklet might result in a single tasklet function invocation, you would be able to save up to 90% of the processing in extreme cases.

On the other hand there's already a high-priority soft IRQ for net-rx.

Nikolai N Fetissov
Do you mean to say different hardware interrupts schedule the same tasklet.hmm...may be the same tasklet but with different parameters..so everything is a different function ...I mean different functions with different params are getting called for every tasklet scheduled...Am i correct?
kumar
The single argument to the tasklet function is usually a pointer to a device that interrupted, not the data from the device.
Nikolai N Fetissov
What Nikolai is saying is that the tasklet function should be written to process the data from multiple interrupts in one go - all the data that is available when it runs.
caf
Thanks Caf got it :)
kumar
A: 

In my experience on fast machines, moving work from the handler to the tasklet does not make the machine run faster. I've added macros in the handler that can turn my schedule_tasklet() call into a call to the tasklet function itself, and it's easy to benchmark both ways and see the difference.

But it's important that interrupt handlers finish quickly. As Nikolai mentioned, you might benefit if your device likes to interrupt a lot, but most high-bandwidth devices have interrupt mitigation hardware that makes this a less serious problem.

Using tasklets is the way that core kernel people are going to do things, so all else being equal, it's probably best to follow their lead, especially if you ever want to see your driver accepted into the mainline kernel.

I would also note that calling lots of functions isn't necessarily bad practice; modern branch predictors can make branch-heavy code run just as fast as non-branch-heavy code. Far more important in my opinion are the potential cache effects of having to do half the job now, and then half the job later.

Eric Seppanen
A: 

A tasklet does not run in context of the user process. If your ISR schedules a tasklet, it will run immediately after your isr is done, but with interrupts enabled. The benefit of this is that your packet processing is not preventing additional interrupts.

In your TCP example, the hardware hands off the packet to the network stack and your driver is done -- the net stack handles waking up the process etc. so there really no way for the hw's driver to execute in the process context of the data's recipient, because the hw doesn't even know who that is.

Andy Grover

related questions