linux napi网卡驱动原理

转载地址:http://blog.chinaunix.net/uid-26902809-id-4100219.html

NAPI(New API) 将中断与轮讯结合在一起,避免频繁的中断造成的系统开销。
基本思路是:
中断到来--->关闭中断--->调度softirq--->在softirq里面多设备进行轮询,直到没有包为止--->开启中断

/*
 * Structure for NAPI scheduling similar to tasklet but with weighting
 */
struct napi_struct {
 /* The poll_list must only be managed by the entity which
  * changes the state of the NAPI_STATE_SCHED bit.  This means
  * whoever atomically sets that bit can add this napi_struct
  * to the per-cpu poll_list, and whoever clears that bit
  * can remove from the list right before clearing the bit.
  */
 struct list_head poll_list;  /* 用来链入softnet_data的poll_list  */

 unsigned long  state;
 int   weight;
 int   (*poll)(struct napi_struct *, int);
#ifdef CONFIG_NETPOLL
 spinlock_t  poll_lock;
 int   poll_owner;
#endif

 unsigned int  gro_count;

 struct net_device *dev;
 struct list_head dev_list;  /* 用来将NAPI 挂在net_device的napi_list  */
 struct sk_buff  *gro_list;
 struct sk_buff  *skb;
};

void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
      int (*poll)(struct napi_struct *, int), int weight)
{
 INIT_LIST_HEAD(&napi->poll_list);  /*  napi->poll_list 此时初始化为 prev next都指向自己, 等调用napi_schedule时,链入softnet_data的poll_list  */
 napi->gro_count = 0;
 napi->gro_list = NULL;
 napi->skb = NULL
  napi->poll = poll;
 napi->weight = weight;
 list_add(&napi->dev_list, &dev->napi_list); /*  napi->dev_list 挂在 dev->napi_list里面 */
 napi->dev = dev;
#ifdef CONFIG_NETPOLL
 spin_lock_init(&napi->poll_lock);
 napi->poll_owner = -1;
#endif
 set_bit(NAPI_STATE_SCHED, &napi->state);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值