当有数据到达网卡的时候,网卡会触发一个硬中断。硬中断做了一些必要的操作,对于IGB网卡来说,该中断函数为igb_msix_ring
static irqreturn_t igb_msix_ring(int irq, void *data)
{
struct igb_q_vector *q_vector = data;
/* Write the ITR value calculated from the previous interrupt. */
igb_write_itr(q_vector);
napi_schedule(&q_vector->napi);
return IRQ_HANDLED;
}
igb_write_itr中记录了硬中断的次数,简单的累加过程。最主要的是napi_schedule函数,该函数将网卡的polling方法添加到CPU变量softnet_data中。
该函数最终调用__napi_schedule函数:
void __napi_schedule(struct napi_struct *n)
{
unsigned long flags;
local_irq_save(flags);
____napi_schedule(this_cpu_ptr(&softnet_data), n);
local_irq_restore(flags);
}
____napi_schedule函数将polling方法添加到softnet_data上。
为什么是polling方法呢,我们看一下这个函数的传参,struct napi_struct *n,通过napi_schedule(&q_vector->napi);传递过来,q_vector是一个igb_q_vector 结构体,是在网卡open方法中,通过注册中断函数来的。
adapter获取的是每个网卡的私有数据,其中网卡的私有数据中,就包含了该网卡polling方法的信息:
但是这里我有一点还没看明白,这个结构体的参数为什么是个数组?这个不是代表的中断向量?