NAPI

内核为网络设备提供了NAPI机制来代替tasklet等。

=======napi_struct结构体======

【位置】include/linux/netdevice.h
/*
  * 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;
 
 ____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;
____struct sk_buff______*gro_list;
 ____struct sk_buff______*skb;
};

【poll_list】用来将当前设备放置到内核维护的一个轮询列表中。

【weight】设置当前设备的权重,如果某一设备上长时间连续接收分组,不至于使系统中其他设备失去被轮询的机会。

【poll】函数指针,设备驱动程序需要实现这个函数,它将在内核对当前设备轮询时被调用。


=========操作函数==========

netif_napi_add

【原型】void netif_napi_add(struct net_device *dev, struct napi_struct *napi, int(*poll)(struct napi_struct *,int), int weight)

【作用】用于将napi指向的struct napi_struct对象进行初始化。将该napi_struct放入dev的napi_list列表中。将state设为NAPI_STATE_SCHED。

netif_napi_del

【原型】void netif_napi_del(struct napi_struct *napi)

【作用】netif_napi_add的反操作。

napi_enable

【作用】使能napi

【实现】将state的NAPI_STATE_SCHED位清0。

napi_disable

【作用】将napi不被轮询

napi_schedule_prep

【作用】测试napi能否被schedule。

napi_schedule

【作用】schedule NAPI poll

napi_complete

【作用】


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值