NAPI

来源:互联网 发布:中国电建华东院 知乎 编辑:程序博客网 时间:2024/06/05 20:32

内核为网络设备提供了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

【作用】


原创粉丝点击