- 論壇徽章:
- 0
|
最近剛入門linux。主要是看驅動相關的,目前在看網(wǎng)卡收包的過程。也看了napi模式的收包。但是現(xiàn)在比較疑惑napi結構體和設備的對應關系是什么。渴且粋napi_struct對應一個網(wǎng)卡,還是一個napi_struct對應一個隊列?
以及在do_IRQ中:
irq_enter()和irq_exit()的作用就是為了進入和退出硬中斷上下文嗎?(進入硬中斷上下文其他中斷就沒辦法搶占了,linux新版本禁止內核搶占?)
unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
{
struct pt_regs *old_regs = set_irq_regs(regs);
/* high bit used in ret_from_ code */
unsigned vector = ~regs->orig_ax;
unsigned irq;
exit_idle();
irq_enter();
irq = __this_cpu_read(vector_irq[vector]);
//省略了中間的代碼
irq_exit();
set_irq_regs(old_regs);
return 1;
}
在軟中斷處理函數(shù)net_rx_action中:
幾處local_irq_disable和local_irq_enable的作用是什么啊?我看書上說這兩個函數(shù)的功能是禁止/激活cpu本地中斷的傳遞?那他會影響網(wǎng)卡中斷嗎?
static void net_rx_action(struct softirq_action *h)
{
struct softnet_data *sd = &__get_cpu_var(softnet_data);
unsigned long time_limit = jiffies + 2;
int budget = netdev_budget;
void *have;
local_irq_disable();
while (!list_empty(&sd->poll_list)) {
struct napi_struct *n;
int work, weight;
if (unlikely(budget <= 0 || time_after(jiffies, time_limit)))
goto softnet_break;
local_irq_enable();
n = list_first_entry(&sd->poll_list, struct napi_struct, poll_list);
have = netpoll_poll_lock(n);
weight = n->weight;
work = 0;
if (test_bit(NAPI_STATE_SCHED, &n->state)) {
work = n->poll(n, weight);
trace_napi_poll(n);
}
WARN_ON_ONCE(work > weight);
budget -= work;
local_irq_disable();
if (unlikely(work == weight)) {
if (unlikely(napi_disable_pending(n))) {
local_irq_enable();
napi_complete(n);
local_irq_disable();
} else
list_move_tail(&n->poll_list, &sd->poll_list);
}
netpoll_poll_unlock(have);
}
out:
net_rps_action_and_irq_enable(sd);
#ifdef CONFIG_NET_DMA
dma_issue_pending_all();
#endif
return;
softnet_break:
sd->time_squeeze++;
__raise_softirq_irqoff(NET_RX_SOFTIRQ);
goto out;
}
以及在e1000注冊的軟中斷處理函數(shù)中為什么當一個napi的work<weight的時候,移除了napi之后,就可以重新打開網(wǎng)卡中斷呢?
那其他napi結構體的處理不就是在開中斷的環(huán)境下執(zhí)行了嗎?還是說一個napi結構體就對應一個網(wǎng)卡?
|
|