2011年10月23日 星期日

CSE506: Networking Softirq and NAPI

Why top half and bottom half?
1. to minimize time in an interrupt handler with other interrupt disabled.
2. Give kernel more scheduling flexibility.
3. Simplify service routines.

Top half:
1. allocate skb, 2. copy into buffer, 3. initialize fields, 3. calling bottom half (for later processing)
Buffer preallocating using DMA:

In some cases, sk_buff can be pre-allocated, and network card can copy data in (DMA) before firing the interrupt. 

Softirqs:
- hardware irq is hardware interrupt line, calls the top half
- Soft IRQ is the associated software “interrupt” handler : the bottom half
- Kernel’s view: per-CPU work lists: Tuples of <function, data>
甚麼時候被執行:
1. return from exception, interrupt, and system call
2. each CPU has a kernel thread "ksoftirqd_CPU#" that processes pending requests
* softirq一定要run在同一個CPU, why? locking. (deadlock, code complexity, scale better!)

從programmer的角度:
1. Only one instance of a softirq function will run on a CPU at a time
2. Doesn’t need to be reentrant
3. If interrupted,won’t be called again by interrupt handler **Subsequent calls enqueued!**
4. One instance can run on each CPU concurrently, though Must use locks

Tasklet: Constrained to run one at a time on any CPU.

Softirq Priority:
HI_SOFTIRQ(high/first) 
TIMER
NET_TX
NET_RX
SCSI
TASKLET(low/last)
- Devices can decide whether their bottom half is higher or lower priority than network traffic (HI or TASKLET) 
- Transmit traffic prioritized above receive. Why? 
- The ability to send packets may stem the tide of incoming packets

Receive livelock

Reference:
1. cse506 course slide by Don Porter.

沒有留言:

張貼留言