Search code examples
linuxtimerkernelisr

Can the same timer interrupt occur in parallel?


I implemented one timer interrupt handler in kernel module.

This timer interrupt handler requires about 1000us to run.

And I want this timer to trigger up every 10us.

(In doing so, I hope the same handler will be performed in parallel.)

(I know that this can create a tremendous amount of interrupt overhead, but I want to implement it for some testing.)

But this handler does not seem to run in parallel.

Timer interrupt seems to wait until the handler in progress is finished.

Can the same timer interrupt occur in parallel?

If not, is there a kernel mechanism that can run the same handler in parallel?


Solution

  • If the timer triggers every 10us, and requires 1000us (1ms) to complete, you would require 100 dedicated cpu's to barely keep up to the timers. The short answer is no, the interrupt system isn't going to support this. If an interrupt recursed, it would inevitably consume the interrupt handler stack.

    Interrupts typically work by having a short bit of code be directly invoked when the interrupt asserts. If more work is to be done, this short bit would schedule a slower bit to follow on, and inhibit this source of interrupt. This is to minimize the latency caused by disparate devices seeking cpu attention. The slower bit, when it determines it has satiated the device request, can re-enable interrupts from this source.

    [ In linux, the short bit is called the top half; the slower bit the bottom half. It is a bit confusing, because decades of kernel implementation pre-linux named it exactly the other way around. Best to avoid these terms. ]

    One of many ways to get the effect you desire is to have this slow handler release a semaphore then re-enable the interrupt. You could then have an appropriate number of threads sit in a loop acquiring the semaphore then performing your task.