: napi_struct V4
Subsystems (5)
David Miller
maintainerRFC PATCH 1/1 : napi_struct V4
We're getting there, slowly...
1) netif_napi_init() is added, the workqueue/requeue stuff as discussed is not needed so you won't see that here
2) all cases where netif_rx_complete() are invoked in contexts where cpu interrupts are known to be disabled are replaced with __netif_rx_complete()
Most drivers are in good shape, although some still have very questionable netif_rx_complete() handling, in that racy area that Rusty and myself were discussing today.
My inclination is to wrap those sequences around with an IRQ safe spinlock to fix the race provably, and then if driver authors want to optimize that away with techniques like those that tg3, bnx2, sky2, skge et al. use, that's fine but can be done later.
To some extent it's mechanical work if you know what to look for, so any relative patches for that stuff would be much appreciated and I'll integrate such patches rapidly and without delay.
Besides that the only major issue is netpoll and I have some ideas on how to handle that, which I'll try to implement tonight and tomorrow.
Another thing that's really apparent now is all the wacky napi->weight values various drivers use. Just grep for netif_napi_init() in the patch or a patched tree to see what I mean. So much of it doesn't make any sense and I'm tempted to just remove the argument and make everyone use 32 or 64 or something like that :-) Or, default to some value across the board, and let drivers override that on a case by case basis with a BIG FAT COMMENT above the override describing why the different value is being used and precisely what tests were performed to validate that different value.
Anyways, enjoy:
[NET]: Make NAPI polling independant of struct net_device objects.
Several devices have multiple independant RX queues per net device, and some have a single interrupt doorbell for several queues.
In either case, it's easier to support layouts like that if the structure representing the poll is independant from the net device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or the number of "NAPI credits" consumed if you want to get abstract). The callee no longer messes around bumping dev->quota, *budget, etc. because that is all handled in the caller upon return.
The napi_struct is to be embedded in the device driver private data structures.
Furthermore, it is the driver's responsibility to disable all NAPI instances in it's ->stop() device close handler. Since the napi_struct is privatized into the driver's private data structures, only the driver knows how to get at all the napi_struct instances it may have per-device.
With lots of help and suggestions from Rusty Russell.
[ Ported to current tree and more drivers converted. -DaveM ]
drivers/net/8139cp.c +16 -18
@@ -334,6 +334,8 @@ struct cp_private {spinlock_t lock;u32 msg_enable; +struct napi_struct napi; +struct pci_dev *pdev;u32 rx_config;u16 cpcmd;
@@ -501,12 +503,12 @@ static inline unsigned int cp_rx_csum_ok (u32 status)return 0 ; } -static int cp_rx_poll (struct net_device *dev,int *budget) +static int cp_rx_poll (struct napi_struct *napi,int budget) { -struct cp_private *cp =netdev_priv (dev); -unsigned rx_tail = cp->rx_tail; -unsigned rx_work = dev->quota; -unsigned rx; + struct cp_private *cp = container_of(napi, struct cp_private, napi); +struct net_device *dev = cp->dev; +unsigned int rx_tail = cp->rx_tail; +int rx; rx_status_loop: rx =0 ;
@@ -588,19 +590,16 @@ rx_next: desc->opts1 =cpu_to_le32 (DescOwn | cp->rx_buf_sz); rx_tail =NEXT_RX (rx_tail); -if (!rx_work--) +if (rx >= budget)break ; } cp->rx_tail = rx_tail; - dev->quota -= rx; - *budget -= rx; -/* if we did not reach work limit, then we're done with * this round of polling */ -if (rx_work) { +if (rx < budget) {unsigned long flags;if (cpr16 (IntrStatus) & cp_rx_intr_mask)
@@ -608,13 +607,11 @@ rx_next:local_irq_save (flags);cpw16_f (IntrMask, cp_intr_mask); -__netif_rx_complete (dev); +__netif_rx_complete (dev, napi);local_irq_restore (flags); - -return 0 ;/* done */ } -return 1 ;/* not done */ +return rx; }static irqreturn_t cp_interrupt (int irq,void *dev_instance)
@@ -647,9 +644,9 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance) }if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr)) -if (netif_rx_schedule_prep (dev)) { +if (netif_rx_schedule_prep (dev, &cp->napi)) {cpw16_f (IntrMask, cp_norx_intr_mask); -__netif_rx_schedule (dev); +__netif_rx_schedule (dev, &cp->napi); }if (status & (TxOK | TxErr | TxEmpty | SWInt))
@@ -1198,6 +1195,8 @@ static int cp_close (struct net_device *dev)struct cp_private *cp =netdev_priv (dev);unsigned long flags; +napi_disable (&cp->napi); +if (netif_msg_ifdown (cp))printk (KERN_DEBUG "%s: disabling interface\n" , dev->name);
@@ -1934,11 +1933,10 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) dev->hard_start_xmit = cp_start_xmit; dev->get_stats = cp_get_stats; dev->do_ioctl = cp_ioctl; - dev->poll = cp_rx_poll; +netif_napi_init (&cp->napi, cp_rx_poll,16 );#ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = cp_poll_controller;#endif - dev->weight =16 ;/* arbitrary? from NAPI_HOWTO.txt. */ #ifdef BROKEN dev->change_mtu = cp_change_mtu;#endif
drivers/net/8139too.c +19 -23
100 lines not on this page · raw message
drivers/net/amd8111e.c +11 -16
@@ -723,9 +723,10 @@ static int amd8111e_tx(struct net_device *dev)#ifdef CONFIG_AMD8111E_NAPI /* This function handles the driver receive operation in polling mode */ -static int amd8111e_rx_poll (struct net_device *dev,int * budget) +static int amd8111e_rx_poll (struct napi_struct *napi,int budget) { -struct amd8111e_priv *lp =netdev_priv (dev); + struct amd8111e_priv *lp = container_of(napi, struct amd8111e_priv, napi); +struct net_device *dev = lp->amd8111e_net_dev;int rx_index = lp->rx_idx &RX_RING_DR_MOD_MASK ;void __iomem *mmio = lp->mmio;struct sk_buff *skb,*new_skb;
@@ -737,7 +738,7 @@ static int amd8111e_rx_poll(struct net_device *dev, int * budget)#if AMD8111E_VLAN_TAG_USED short vtag;#endif -int rx_pkt_limit = dev->quota; +int rx_pkt_limit = budget;unsigned long flags; do{
@@ -838,21 +839,14 @@ static int amd8111e_rx_poll(struct net_device *dev, int * budget) } while(intr0 & RINT0);/* Receive descriptor is empty now */ - dev->quota -= num_rx_pkt; - *budget -= num_rx_pkt; -spin_lock_irqsave (&lp->lock, flags); -netif_rx_complete (dev); +__netif_rx_complete (dev, napi);writel (VAL0 |RINTEN0 , mmio +INTEN0 );writel (VAL2 |RDMD0 , mmio +CMD0 );spin_unlock_irqrestore (&lp->lock, flags); -return 0 ; rx_not_empty: -/* Do not call a netif_rx_complete */ - dev->quota -= num_rx_pkt; - *budget -= num_rx_pkt; -return 1 ; +return num_rx_pkt; }#else
@@ -1287,11 +1281,11 @@ static irqreturn_t amd8111e_interrupt(int irq, void *dev_id)/* Check if Receive Interrupt has occurred. */ #ifdef CONFIG_AMD8111E_NAPI if (intr0 &RINT0 ){ -if (netif_rx_schedule_prep (dev)){ +if (netif_rx_schedule_prep (dev, &lp->napi)){/* Disable receive interupts */ writel (RINTEN0 , mmio +INTEN0 );/* Schedule a polling routine */ -__netif_rx_schedule (dev); +__netif_rx_schedule (dev, &lp->napi); }else if (intren0 &RINTEN0 ) { printk("************Driver bug! \
@@ -1345,6 +1339,8 @@ static int amd8111e_close(struct net_device * dev)struct amd8111e_priv *lp =netdev_priv (dev);netif_stop_queue (dev); +napi_disable (&lp->napi); +spin_lock_irq (&lp->lock);amd8111e_disable_interrupt (lp);
@@ -2031,8 +2027,7 @@ static int __devinit amd8111e_probe_one(struct pci_dev *pdev, dev->tx_timeout = amd8111e_tx_timeout; dev->watchdog_timeo =AMD8111E_TX_TIMEOUT ;#ifdef CONFIG_AMD8111E_NAPI - dev->poll = amd8111e_rx_poll; - dev->weight =32 ; +netif_napi_init (&lp->napi, amd8111e_rx_poll,32 );#endif #ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = amd8111e_poll;
drivers/net/amd8111e.h +2 -0
@@ -763,6 +763,8 @@ struct amd8111e_priv{/* Reg memory mapped address */ void __iomem *mmio; +struct napi_struct napi; +spinlock_t lock;/* Guard lock */ unsigned long rx_idx, tx_idx;/* The next free ring entry */ unsigned long tx_complete_idx;
drivers/net/arm/ep93xx_eth.c +24 -36
135 lines not on this page · raw message
drivers/net/b44.c +16 -29
98 lines not on this page · raw message
drivers/net/b44.h +2 -0
@@ -423,6 +423,8 @@ struct b44 {struct ring_info *rx_buffers;struct ring_info *tx_buffers; +struct napi_struct napi; +u32 dma_offset;u32 flags;#define B44_FLAG_B0_ANDLATER 0x00000001
drivers/net/bnx2.c +17 -24
116 lines not on this page · raw message
drivers/net/bnx2.h +2 -0
@@ -6473,6 +6473,8 @@ struct bnx2 {struct net_device *dev;struct pci_dev *pdev; +struct napi_struct napi; +atomic_t intr_sem;struct status_block *status_blk;
drivers/net/cassini.c +14 -20
@@ -2485,7 +2485,7 @@ static irqreturn_t cas_interruptN(int irq, void *dev_id)if (status &INTR_RX_DONE_ALT ) {/* handle rx separately */ #ifdef USE_NAPI cas_mask_intr (cp); -netif_rx_schedule (dev); +netif_rx_schedule (dev, &cp->napi);#else cas_rx_ringN (cp, ring,0 );#endif
@@ -2536,7 +2536,7 @@ static irqreturn_t cas_interrupt1(int irq, void *dev_id)if (status &INTR_RX_DONE_ALT ) {/* handle rx separately */ #ifdef USE_NAPI cas_mask_intr (cp); -netif_rx_schedule (dev); +netif_rx_schedule (dev, &cp->napi);#else cas_rx_ringN (cp,1 ,0 );#endif
@@ -2592,7 +2592,7 @@ static irqreturn_t cas_interrupt(int irq, void *dev_id)if (status &INTR_RX_DONE ) {#ifdef USE_NAPI cas_mask_intr (cp); -netif_rx_schedule (dev); +netif_rx_schedule (dev, &cp->napi);#else cas_rx_ringN (cp,0 ,0 );#endif
@@ -2607,9 +2607,10 @@ static irqreturn_t cas_interrupt(int irq, void *dev_id)#ifdef USE_NAPI -static int cas_poll (struct net_device *dev,int *budget) +static int cas_poll (struct napi_struct *napi,int budget) { -struct cas *cp =netdev_priv (dev); + struct cas *cp = container_of(napi, struct cas, napi); +struct net_device *dev = cp->dev;int i, enable_intr, todo, credits;u32 status =readl (cp->regs +REG_INTR_STATUS );unsigned long flags;
@@ -2620,20 +2621,18 @@ static int cas_poll(struct net_device *dev, int *budget)/* NAPI rx packets. we spread the credits across all of the * rxc rings -*/ - todo =min (*budget, dev->quota); - -/* to make sure we're fair with the work we loop through each +* +* to make sure we're fair with the work we loop through each * ring N_RX_COMP_RING times with a request of -* todo / N_RX_COMP_RINGS +* budget / N_RX_COMP_RINGS */ enable_intr =1 ; credits =0 ;for (i =0 ; i <N_RX_COMP_RINGS ; i++) {int j;for (j =0 ; j <N_RX_COMP_RINGS ; j++) { - credits +=cas_rx_ringN (cp, j, todo /N_RX_COMP_RINGS ); -if (credits >= todo) { + credits +=cas_rx_ringN (cp, j, budget /N_RX_COMP_RINGS ); +if (credits >= budget) { enable_intr =0 ; goto rx_comp; }
@@ -2641,9 +2640,6 @@ static int cas_poll(struct net_device *dev, int *budget) } rx_comp: - *budget -= credits; - dev->quota -= credits; -/* final rx completion */ spin_lock_irqsave (&cp->lock, flags);if (status)
@@ -2674,11 +2670,10 @@ rx_comp:#endif spin_unlock_irqrestore (&cp->lock, flags);if (enable_intr) { -netif_rx_complete (dev); +netif_rx_complete (dev, napi);cas_unmask_intr (cp); -return 0 ; } - return 1; + return credits; }#endif
@@ -5062,8 +5057,7 @@ static int __devinit cas_init_one(struct pci_dev *pdev, dev->watchdog_timeo =CAS_TX_TIMEOUT ; dev->change_mtu = cas_change_mtu;#ifdef USE_NAPI - dev->poll = cas_poll; - dev->weight =64 ; +netif_napi_init (&cp->napi, cas_poll,64 );#endif #ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = cas_netpoll;
drivers/net/cassini.h +2 -0
@@ -4280,6 +4280,8 @@ struct cas {int rx_cur[N_RX_COMP_RINGS ], rx_new[N_RX_COMP_RINGS ];int rx_last[N_RX_DESC_RINGS ]; +struct napi_struct napi; +/* Set when chip is actually in operational state * (ie. not power managed) */ int hw_running;
drivers/net/chelsio/common.h +1 -0
@@ -278,6 +278,7 @@ struct adapter {struct peespi *espi;struct petp *tp; +struct napi_struct napi;struct port_info port[MAX_NPORTS ];struct delayed_work stats_update_task;struct timer_list stats_update_timer;
drivers/net/chelsio/cxgb2.c +2 -2
@@ -274,6 +274,7 @@ static int cxgb_close(struct net_device *dev)struct cmac *mac = p->mac;netif_stop_queue (dev); +napi_disable (&adapter->napi); mac->ops->disable (mac,MAC_DIRECTION_TX |MAC_DIRECTION_RX );netif_carrier_off (dev);
@@ -1113,8 +1114,7 @@ static int __devinit init_one(struct pci_dev *pdev, netdev->poll_controller = t1_netpoll;#endif #ifdef CONFIG_CHELSIO_T1_NAPI - netdev->weight =64 ; - netdev->poll = t1_poll; +netif_napi_init (&adapter->napi, t1_poll,64 );#endif SET_ETHTOOL_OPS (netdev, &t1_ethtool_ops);
drivers/net/chelsio/sge.c +13 -16
@@ -1620,23 +1620,20 @@ static int process_pure_responses(struct adapter *adapter)* or protection from interrupts as data interrupts are off at this point and * other adapter interrupts do not interfere. */ -int t1_poll (struct net_device *dev,int *budget) +int t1_poll (struct napi_struct *napi,int budget) { -struct adapter *adapter = dev->priv; + struct adapter *adapter = container_of(napi, struct adapter, napi); +struct net_device *dev = adapter->port[0 ].dev;int work_done; - work_done =process_responses (adapter,min (*budget, dev->quota)); - *budget -= work_done; - dev->quota -= work_done; - -if (unlikely (responses_pending (adapter))) -return 1 ; - -netif_rx_complete (dev); -writel (adapter->sge->respQ.cidx, adapter->regs +A_SG_SLEEPING ); - -return 0 ; + work_done =process_responses (adapter, budget); +if (likely (!responses_pending (adapter))) { +netif_rx_complete (dev, napi); +writel (adapter->sge->respQ.cidx, + adapter->regs +A_SG_SLEEPING ); + } +return work_done; }/*
@@ -1653,13 +1650,13 @@ irqreturn_t t1_interrupt(int irq, void *data)writel (F_PL_INTR_SGE_DATA , adapter->regs +A_PL_CAUSE ); -if (__netif_rx_schedule_prep (dev)) { +if (napi_schedule_prep (&adapter->napi)) {if (process_pure_responses (adapter)) -__netif_rx_schedule (dev); +__netif_rx_schedule (dev, &adapter->napi);else {/* no data, no NAPI needed */ writel (sge->respQ.cidx, adapter->regs +A_SG_SLEEPING ); -netif_poll_enable (dev);/* undo schedule_prep */ +napi_enable (&adapter->napi);/* undo schedule_prep */ } }return IRQ_HANDLED ;
drivers/net/chelsio/sge.h +1 -1
@@ -77,7 +77,7 @@ int t1_sge_configure(struct sge *, struct sge_params *);int t1_sge_set_coalesce_params (struct sge *,struct sge_params *);void t1_sge_destroy (struct sge *);irqreturn_t t1_interrupt (int irq,void *cookie); -int t1_poll (struct net_device *,int *); +int t1_poll (struct napi_struct *,int );int t1_start_xmit (struct sk_buff *skb,struct net_device *dev);void t1_set_vlan_accel (struct adapter *adapter,int on_off);
drivers/net/cxgb3/adapter.h +15 -13
@@ -50,7 +50,9 @@ typedef irqreturn_t(*intr_handler_t) (int, void *);struct vlan_group ; +struct adapter ;struct port_info { +struct adapter *adapter;struct vlan_group *vlan_grp;const struct port_type_info *port_type;u8 port_id;
@@ -170,11 +172,13 @@ enum { /* per port SGE statistics */SGE_PSTAT_MAX /* must be last */ }; +struct adapter_napi ;struct sge_qset {/* an SGE queue set */ struct sge_rspq rspq;struct sge_fl fl[SGE_RXQ_PER_SET ];struct sge_txq txq[SGE_TXQ_PER_SET ]; -struct net_device *netdev;/* associated net device */ +struct adapter_napi *anapi; +struct net_device *netdev;unsigned long txq_stopped;/* which Tx queues are stopped */ struct timer_list tx_reclaim_timer;/* reclaims TX buffers */ unsigned long port_stats[SGE_PSTAT_MAX ];
@@ -185,6 +189,13 @@ struct sge {spinlock_t reg_lock;/* guards non-atomic SGE registers (eg context) */ }; +struct adapter_napi { +struct napi_struct napi; +struct adapter *adapter; +int port; +int qset; +}; +struct adapter {struct t3cdev tdev;struct list_head adapter_list;
@@ -219,11 +230,7 @@ struct adapter {struct delayed_work adap_check_task;struct work_struct ext_intr_handler_task; -/* -* Dummy netdevices are needed when using multiple receive queues with -* NAPI as each netdevice can service only one queue. -*/ -struct net_device *dummy_netdev[SGE_QSETS -1 ]; +struct adapter_napi napi[SGE_QSETS ];struct dentry *debugfs_root;
@@ -251,12 +258,6 @@ static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)return netdev_priv (adap->port[idx]); } -/* -* We use the spare atalk_ptr to map a net device to its SGE queue set. -* This is a macro so it can be used as l-value. -*/ -#define dev2qset (netdev) ((netdev)->atalk_ptr) -#define OFFLOAD_DEVMAP_BIT 15#define tdev2adap (d) container_of(d, struct adapter, tdev)
@@ -282,7 +283,8 @@ int t3_mgmt_tx(struct adapter *adap, struct sk_buff *skb);void t3_update_qset_coalesce (struct sge_qset *qs,const struct qset_params *p);int t3_sge_alloc_qset (struct adapter *adapter,unsigned int id,int nports,int irq_vec_idx,const struct qset_params *p, -int ntxq,struct net_device *netdev); +int ntxq,struct adapter_napi *anapi, +struct net_device *dev);int t3_get_desc (const struct sge_qset *qs,unsigned int qnum,unsigned int idx,unsigned char *data);irqreturn_t t3_sge_intr_msix (int irq,void *cookie);
drivers/net/cxgb3/cxgb3_main.c +83 -104
456 lines not on this page · raw message
drivers/net/cxgb3/sge.c +76 -86
318 lines not on this page · raw message
drivers/net/e100.c +17 -20
@@ -539,6 +539,7 @@ struct nic {struct csr __iomem *csr;enum scb_cmd_lo cuc_cmd;unsigned int cbs_avail; +struct napi_struct napi;struct cb *cbs;struct cb *cb_to_use;struct cb *cb_to_send;
@@ -1974,35 +1975,31 @@ static irqreturn_t e100_intr(int irq, void *dev_id)if (stat_ack & stat_ack_rnr) nic->ru_running =RU_SUSPENDED ; -if (likely (netif_rx_schedule_prep (netdev))) { +if (likely (netif_rx_schedule_prep (netdev, &nic->napi))) {e100_disable_irq (nic); -__netif_rx_schedule (netdev); +__netif_rx_schedule (netdev, &nic->napi); }return IRQ_HANDLED ; } -static int e100_poll (struct net_device *netdev,int *budget) +static int e100_poll (struct napi_struct *napi,int budget) { -struct nic *nic =netdev_priv (netdev); -unsigned int work_to_do =min (netdev->quota, *budget); -unsigned int work_done =0 ; + struct nic *nic = container_of(napi, struct nic, napi); +struct net_device *netdev = nic->netdev; +int work_done =0 ;int tx_cleaned; -e100_rx_clean (nic, &work_done, work_to_do); +e100_rx_clean (nic, &work_done, budget); tx_cleaned =e100_tx_clean (nic);/* If no Rx and Tx cleanup work was done, exit polling mode. */ if ((!tx_cleaned && (work_done ==0 )) || !netif_running (netdev)) { -netif_rx_complete (netdev); +netif_rx_complete (netdev, napi);e100_enable_irq (nic); -return 0 ; } - *budget -= work_done; - netdev->quota -= work_done; - -return 1 ; +return work_done; }#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -2071,7 +2068,7 @@ static int e100_up(struct nic *nic) nic->netdev->name, nic->netdev))) goto err_no_irq;netif_wake_queue (nic->netdev); -netif_poll_enable (nic->netdev); +napi_enable (&nic->napi);/* enable ints _after_ enabling poll, preventing a race between * disable ints+schedule */ e100_enable_irq (nic);
@@ -2089,7 +2086,7 @@ err_rx_clean_list:static void e100_down (struct nic *nic) {/* wait here for poll to complete */ -netif_poll_disable (nic->netdev); +napi_disable (&nic->napi);netif_stop_queue (nic->netdev);e100_hw_reset (nic);free_irq (nic->pdev->irq, nic->netdev);
@@ -2573,14 +2570,13 @@ static int __devinit e100_probe(struct pci_dev *pdev,SET_ETHTOOL_OPS (netdev, &e100_ethtool_ops); netdev->tx_timeout = e100_tx_timeout; netdev->watchdog_timeo =E100_WATCHDOG_PERIOD ; - netdev->poll = e100_poll; - netdev->weight =E100_NAPI_WEIGHT ;#ifdef CONFIG_NET_POLL_CONTROLLER netdev->poll_controller = e100_netpoll;#endif strncpy (netdev->name,pci_name (pdev),sizeof (netdev->name) -1 ); nic =netdev_priv (netdev); +netif_napi_init (&nic->napi, e100_poll,E100_NAPI_WEIGHT ); nic->netdev = netdev; nic->pdev = pdev; nic->msg_enable = (1 << debug) -1 ;
@@ -2734,7 +2730,7 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)struct nic *nic =netdev_priv (netdev);if (netif_running (netdev)) -netif_poll_disable (nic->netdev); +napi_disable (&nic->napi);del_timer_sync (&nic->watchdog);netif_carrier_off (nic->netdev);netif_device_detach (netdev);
@@ -2780,7 +2776,7 @@ static void e100_shutdown(struct pci_dev *pdev)struct nic *nic =netdev_priv (netdev);if (netif_running (netdev)) -netif_poll_disable (nic->netdev); +napi_disable (&nic->napi);del_timer_sync (&nic->watchdog);netif_carrier_off (nic->netdev);
@@ -2805,12 +2801,13 @@ static void e100_shutdown(struct pci_dev *pdev)static pci_ers_result_t e100_io_error_detected (struct pci_dev *pdev,pci_channel_state_t state) {struct net_device *netdev =pci_get_drvdata (pdev); +struct nic *nic =netdev_priv (netdev);/* Similar to calling e100_down(), but avoids adpater I/O. */ netdev->stop (netdev);/* Detach; put netif into state similar to hotplug unplug. */ -netif_poll_enable (netdev); +napi_enable (&nic->napi);netif_device_detach (netdev);pci_disable_device (pdev);
drivers/net/e1000/e1000.h +1 -0
@@ -300,6 +300,7 @@ struct e1000_adapter { int cleaned_count);struct e1000_rx_ring *rx_ring;/* One per active queue */ #ifdef CONFIG_E1000_NAPI +struct napi_struct napi;struct net_device *polling_netdev;/* One per active queue */ #endif int num_tx_queues;
drivers/net/e1000/e1000_main.c +21 -24
135 lines not on this page · raw message
drivers/net/ehea/ehea.h +2 -1
@@ -351,6 +351,8 @@ struct ehea_q_skb_arr {* Port resources */ struct ehea_port_res { +spinlock_t poll_lock; +struct napi_struct napi;struct port_stats p_stats;struct ehea_mr send_mr;/* send memory region */ struct ehea_mr recv_mr;/* receive memory region */
@@ -362,7 +364,6 @@ struct ehea_port_res {struct ehea_cq *send_cq;struct ehea_cq *recv_cq;struct ehea_eq *eq; -struct net_device *d_netdev;struct ehea_q_skb_arr rq1_skba;struct ehea_q_skb_arr rq2_skba;struct ehea_q_skb_arr rq3_skba;
drivers/net/ehea/ehea_main.c +29 -40
184 lines not on this page · raw message
drivers/net/epic100.c +14 -17
@@ -262,6 +262,7 @@ struct epic_private {/* Ring pointers. */ spinlock_t lock;/* Group with Tx control cache line. */ spinlock_t napi_lock; +struct napi_struct napi;unsigned int reschedule_in_poll;unsigned int cur_tx, dirty_tx;
@@ -294,7 +295,7 @@ static void epic_tx_timeout(struct net_device *dev);static void epic_init_ring (struct net_device *dev);static int epic_start_xmit (struct sk_buff *skb,struct net_device *dev);static int epic_rx (struct net_device *dev,int budget); -static int epic_poll (struct net_device *dev,int *budget); +static int epic_poll (struct napi_struct *napi,int budget);static irqreturn_t epic_interrupt (int irq,void *dev_instance);static int netdev_ioctl (struct net_device *dev,struct ifreq *rq,int cmd);static const struct ethtool_ops netdev_ethtool_ops;
@@ -487,8 +488,7 @@ static int __devinit epic_init_one (struct pci_dev *pdev, dev->ethtool_ops = &netdev_ethtool_ops; dev->watchdog_timeo =TX_TIMEOUT ; dev->tx_timeout = &epic_tx_timeout; - dev->poll = epic_poll; - dev->weight =64 ; +netif_napi_init (&ep->napi, epic_poll,64 ); ret =register_netdev (dev);if (ret <0 )
@@ -1103,9 +1103,9 @@ static irqreturn_t epic_interrupt(int irq, void *dev_instance)if ((status & EpicNapiEvent) && !ep->reschedule_in_poll) {spin_lock (&ep->napi_lock); -if (netif_rx_schedule_prep (dev)) { +if (netif_rx_schedule_prep (dev, &ep->napi)) {epic_napi_irq_off (dev, ep); -__netif_rx_schedule (dev); +__netif_rx_schedule (dev, &ep->napi); }else ep->reschedule_in_poll++;spin_unlock (&ep->napi_lock);
@@ -1257,26 +1257,22 @@ static void epic_rx_err(struct net_device *dev, struct epic_private *ep)outw (RxQueued, ioaddr +COMMAND ); } -static int epic_poll (struct net_device *dev,int *budget) +static int epic_poll (struct napi_struct *napi,int budget) { -struct epic_private *ep = dev->priv; -int work_done =0 , orig_budget; + struct epic_private *ep = container_of(napi, struct epic_private, napi); +struct net_device *dev = ep->mii.dev; +int work_done =0 ;long ioaddr = dev->base_addr; - orig_budget = (*budget > dev->quota) ? dev->quota : *budget; - rx_action:epic_tx (dev, ep); - work_done +=epic_rx (dev, *budget); + work_done +=epic_rx (dev, budget);epic_rx_err (dev, ep); - *budget -= work_done; - dev->quota -= work_done; - -if (netif_running (dev) && (work_done < orig_budget)) { +if (netif_running (dev) && (work_done < budget)) {unsigned long flags;int more;
@@ -1286,7 +1282,7 @@ rx_action: more = ep->reschedule_in_poll;if (!more) { -__netif_rx_complete (dev); +__netif_rx_complete (dev, napi);outl (EpicNapiEvent, ioaddr +INTSTAT );epic_napi_irq_on (dev, ep); }else
@@ -1298,7 +1294,7 @@ rx_action: goto rx_action; } -return (work_done >= orig_budget); +return work_done; }static int epic_close (struct net_device *dev)
@@ -1309,6 +1305,7 @@ static int epic_close(struct net_device *dev)int i;netif_stop_queue (dev); +napi_disable (&ep->napi);if (debug >1 ) printk(KERN_DEBUG "%s: Shutting down ethercard, status was %2.2x.\n",
drivers/net/fec_8xx/fec_8xx.h +2 -0
@@ -105,6 +105,8 @@ struct fec;struct fec_enet_private {spinlock_t lock;/* during all ops except TX pckt processing */ spinlock_t tx_lock;/* during fec_start_xmit and fec_tx */ +struct net_device *dev; +struct napi_struct napi;int fecno;struct fec *fecp;const struct fec_platform_info *fpi;
drivers/net/fec_8xx/fec_main.c +25 -30
124 lines not on this page · raw message
drivers/net/forcedeth.c +25 -26
155 lines not on this page · raw message
drivers/net/fs_enet/fs_enet-main.c +18 -29
106 lines not on this page · raw message
drivers/net/fs_enet/fs_enet.h +1 -0
@@ -121,6 +121,7 @@ struct fs_enet_mii_bus { };struct fs_enet_private { +struct napi_struct napi;struct device *dev;/* pointer back to the device (must be initialized first) */ spinlock_t lock;/* during all ops except TX pckt processing */ spinlock_t tx_lock;/* during fs_start_xmit and fs_tx */
drivers/net/gianfar.c +16 -21
@@ -134,7 +134,7 @@ static void gfar_configure_serdes(struct net_device *dev);extern int gfar_local_mdio_write (struct gfar_mii *regs,int mii_id,int regnum,u16 value);extern int gfar_local_mdio_read (struct gfar_mii *regs,int mii_id,int regnum);#ifdef CONFIG_GFAR_NAPI -static int gfar_poll (struct net_device *dev,int *budget); +static int gfar_poll (struct napi_struct *napi,int budget);#endif #ifdef CONFIG_NET_POLL_CONTROLLER static void gfar_netpoll (struct net_device *dev);
@@ -188,6 +188,7 @@ static int gfar_probe(struct platform_device *pdev)return -ENOMEM ; priv =netdev_priv (dev); + priv->dev = dev;/* Set the info in the priv to the current info */ priv->einfo = einfo;
@@ -262,8 +263,7 @@ static int gfar_probe(struct platform_device *pdev) dev->tx_timeout = gfar_timeout; dev->watchdog_timeo =TX_TIMEOUT ;#ifdef CONFIG_GFAR_NAPI - dev->poll = gfar_poll; - dev->weight =GFAR_DEV_WEIGHT ; +netif_napi_init (&priv->napi, gfar_poll,GFAR_DEV_WEIGHT );#endif #ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = gfar_netpoll;
@@ -1102,6 +1102,9 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)static int gfar_close (struct net_device *dev) {struct gfar_private *priv =netdev_priv (dev); + +napi_disable (&priv->napi); +stop_gfar (dev);/* Disconnect from the PHY */
@@ -1318,7 +1321,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)return NULL ; alignamount =RXBUF_ALIGNMENT - - (((unsigned ) skb->data) & (RXBUF_ALIGNMENT -1 )); + (((unsigned long ) skb->data) & (RXBUF_ALIGNMENT -1 ));/* We need the data buffer to be aligned properly. We will reserve * as many bytes as needed to align the data properly
@@ -1390,12 +1393,12 @@ irqreturn_t gfar_receive(int irq, void *dev_id)/* support NAPI */ #ifdef CONFIG_GFAR_NAPI -if (netif_rx_schedule_prep (dev)) { +if (netif_rx_schedule_prep (dev, &priv->napi)) { tempval =gfar_read (&priv->regs->imask); tempval &=IMASK_RX_DISABLED ;gfar_write (&priv->regs->imask, tempval); -__netif_rx_schedule (dev); +__netif_rx_schedule (dev, &priv->napi); }else {if (netif_msg_rx_err (priv)) printk(KERN_DEBUG "%s: receive called twice (%x)[%x]\n",
@@ -1569,23 +1572,16 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit) }#ifdef CONFIG_GFAR_NAPI -static int gfar_poll (struct net_device *dev,int *budget) +static int gfar_poll (struct napi_struct *napi,int budget) { + struct gfar_private *priv = container_of(napi, struct gfar_private, napi); +struct net_device *dev = priv->dev;int howmany; -struct gfar_private *priv =netdev_priv (dev); -int rx_work_limit = *budget; -if (rx_work_limit > dev->quota) - rx_work_limit = dev->quota; + howmany =gfar_clean_rx_ring (dev, budget); - howmany =gfar_clean_rx_ring (dev, rx_work_limit); - - dev->quota -= howmany; - rx_work_limit -= howmany; - *budget -= howmany; - -if (rx_work_limit >0 ) { -netif_rx_complete (dev); +if (howmany < budget) { +netif_rx_complete (dev, napi);/* Clear the halt bit in RSTAT */ gfar_write (&priv->regs->rstat,RSTAT_CLEAR_RHALT );
@@ -1601,8 +1597,7 @@ static int gfar_poll(struct net_device *dev, int *budget) gfar_write(&priv->regs->rxic, 0); } -/* Return 1 if there's more work to do */ -return (rx_work_limit >0 ) ?0 :1 ; +return howmany; }#endif
drivers/net/gianfar.h +3 -0
@@ -691,6 +691,9 @@ struct gfar_private {/* RX Locked fields */ spinlock_t rxlock; +struct net_device *dev; +struct napi_struct napi; +/* skb array and index */ struct sk_buff ** rx_skbuff;u16 skb_currx;
drivers/net/ibmveth.c +51 -60
175 lines not on this page · raw message
drivers/net/ibmveth.h +2 -0
@@ -115,6 +115,8 @@ struct ibmveth_rx_q {struct ibmveth_adapter {struct vio_dev *vdev;struct net_device *netdev; +spinlock_t poll_lock; +struct napi_struct napi;struct net_device_stats stats;unsigned int mcastFilterSize;unsigned long mac_addr;
drivers/net/ixgb/ixgb.h +1 -0
@@ -184,6 +184,7 @@ struct ixgb_adapter {boolean_t rx_csum;/* OS defined structs */ +struct napi_struct napi;struct net_device *netdev;struct pci_dev *pdev;struct net_device_stats net_stats;
drivers/net/ixgb/ixgb_main.c +12 -17
@@ -97,7 +97,7 @@ static irqreturn_t ixgb_intr(int irq, void *data);static boolean_t ixgb_clean_tx_irq (struct ixgb_adapter *adapter);#ifdef CONFIG_IXGB_NAPI -static int ixgb_clean (struct net_device *netdev,int *budget); +static int ixgb_clean (struct napi_struct *napi,int budget);static boolean_t ixgb_clean_rx_irq (struct ixgb_adapter *adapter,int *work_done,int work_to_do);#else
@@ -288,7 +288,7 @@ ixgb_up(struct ixgb_adapter *adapter)mod_timer (&adapter->watchdog_timer, jiffies);#ifdef CONFIG_IXGB_NAPI -netif_poll_enable (netdev); +napi_enable (&adapter->napi);#endif ixgb_irq_enable (adapter);
@@ -309,7 +309,7 @@ ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)if (kill_watchdog)del_timer_sync (&adapter->watchdog_timer);#ifdef CONFIG_IXGB_NAPI -netif_poll_disable (netdev); +napi_disable (&adapter->napi);#endif adapter->link_speed =0 ; adapter->link_duplex =0 ;
@@ -421,8 +421,7 @@ ixgb_probe(struct pci_dev *pdev, netdev->tx_timeout = &ixgb_tx_timeout; netdev->watchdog_timeo =5 *HZ ;#ifdef CONFIG_IXGB_NAPI - netdev->poll = &ixgb_clean; - netdev->weight =64 ; +netif_napi_init (&adapter->napi, ixgb_clean,64 );#endif netdev->vlan_rx_register = ixgb_vlan_rx_register; netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
@@ -1746,7 +1745,7 @@ ixgb_intr(int irq, void *data) }#ifdef CONFIG_IXGB_NAPI -if (netif_rx_schedule_prep (netdev)) { +if (netif_rx_schedule_prep (netdev, &adapter->napi)) {/* Disable interrupts and register for poll. The flush of the posted write is intentionally left out.
@@ -1754,7 +1753,7 @@ ixgb_intr(int irq, void *data)atomic_inc (&adapter->irq_sem);IXGB_WRITE_REG (&adapter->hw,IMC , ~0 ); - __netif_rx_schedule(netdev); + __netif_rx_schedule(netdev, &adapter->napi); }#else /* yes, that is actually a & and it is meant to make sure that
@@ -1776,27 +1775,23 @@ ixgb_intr(int irq, void *data)**/ static int -ixgb_clean (struct net_device *netdev,int *budget) +ixgb_clean (struct napi_struct *napi,int budget) { -struct ixgb_adapter *adapter =netdev_priv (netdev); -int work_to_do =min (*budget, netdev->quota); + struct ixgb_adapter *adapter = container_of(napi, struct ixgb_adapter, napi); +struct net_device *netdev = adapter->netdev;int tx_cleaned;int work_done =0 ; tx_cleaned =ixgb_clean_tx_irq (adapter); -ixgb_clean_rx_irq (adapter, &work_done, work_to_do); - - *budget -= work_done; - netdev->quota -= work_done; +ixgb_clean_rx_irq (adapter, &work_done, budget);/* if no Tx and not enough Rx work done, exit the polling mode */ if ((!tx_cleaned && (work_done ==0 )) || !netif_running (netdev)) { -netif_rx_complete (netdev); +netif_rx_complete (netdev, napi);ixgb_irq_enable (adapter); -return 0 ; } -return 1 ; +return work_done; }#endif
drivers/net/ixp2000/ixpdev.c +23 -14
@@ -74,9 +74,9 @@ static int ixpdev_xmit(struct sk_buff *skb, struct net_device *dev) } -static int ixpdev_rx (struct net_device *dev,int *budget) +static int ixpdev_rx (struct net_device *dev,int processed,int budget) { -while (*budget >0 ) { +while (processed < budget) {struct ixpdev_rx_desc *desc;struct sk_buff *skb;void *buf;
@@ -122,29 +122,34 @@ static int ixpdev_rx(struct net_device *dev, int *budget) err:ixp2000_reg_write (RING_RX_PENDING , _desc); - dev->quota--; - (*budget)--; + processed++; } -return 1 ; +return processed; }
Lines of this file are not shown. View the raw message.
drivers/net/mv643xx_eth.c +17 -27
44 lines not on this page · raw message
drivers/net/pcnet32.c +37 -35
72 lines not on this page · raw message
drivers/net/ps3_gelic_net.c +18 -27
45 lines not on this page · raw message
drivers/net/r8169.c +23 -25
48 lines not on this page · raw message
drivers/net/skge.c +20 -24
44 lines not on this page · raw message
drivers/net/sky2.c +33 -48
81 lines not on this page · raw message
drivers/net/spider_net.c +26 -33
59 lines not on this page · raw message
drivers/net/starfire.c +23 -23
46 lines not on this page · raw message
drivers/net/sungem.c +22 -28
50 lines not on this page · raw message
drivers/net/tc35815.c +21 -22
43 lines not on this page · raw message
drivers/net/tg3.c +23 -33
56 lines not on this page · raw message
drivers/net/tulip/interrupt.c +23 -31
54 lines not on this page · raw message
drivers/net/typhoon.c +14 -27
41 lines not on this page · raw message
drivers/net/ucc_geth.c +17 -26
43 lines not on this page · raw message
include/linux/netdevice.h +99 -74
173 lines not on this page · raw message
include/linux/netpoll.h +0 -50
50 lines not on this page · raw message
net/core/dev.c +138 -84
222 lines not on this page · raw message
net/core/netpoll.c +17 -43
60 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 29 lines · On Wed, 25 Jul 2007 01:31:54 -0700 (PDT) David Miller <[email protected]>…
We're getting there, slowly...
1)
netif_napi_init()is added, the workqueue/requeue stuff as discussed is not needed so you won't see that here2) all cases where
netif_rx_complete()are invoked in contexts where cpu interrupts are known to be disabled are replaced with__netif_rx_complete()Most drivers are in good shape, although some still have very questionable
netif_rx_complete()handling, in that racy area that Rusty and myself were discussing today.My inclination is to wrap those sequences around with an IRQ safe spinlock to fix the race provably, and then if driver authors want to optimize that away with techniques like those that tg3, bnx2, sky2, skge et al. use, that's fine but can be done later.
To some extent it's mechanical work if you know what to look for, so any relative patches for that stuff would be much appreciated and I'll integrate such patches rapidly and without delay.
Besides that the only major issue is netpoll and I have some ideas on how to handle that, which I'll try to implement tonight and tomorrow.
Quoted 11 lines
Another thing that's really apparent now is all the wacky
napi->weightvalues various drivers use. Just grep fornetif_napi_init()in the patch or a patched tree to see what I mean. So much of it doesn't make any sense and I'm tempted to just remove the argument and make everyone use 32 or 64 or something like that :-) Or, default to some value across the board, and let drivers override that on a case by case basis with a BIG FAT COMMENT above the override describing why the different value is being used and precisely what tests were performed to validate that different value.
The usage of NAPI on 8139cp and 8139too seems dodgy; these drivers expect this to work:
local_irq_save(flags); cpw16_f(IntrMask, cp_intr_mask); __netif_rx_complete(dev); local_irq_restore(flags);
It works on SMP only because if poll races with IRQ, the IRQ is not masked or cleared so the IRQ will get restarted.
Better would be to change it to:
spin_lock_irqsave(&cp->lock, flags); cpw16_f(IntrMask, cp_intr_mask); __netif_rx_complete(dev); spin_unlock_irqrestore(&cp->lock, flags);
Which actually is same code on UP.
Quoted 4 lines · David Miller
We're getting there, slowly...
1)
netif_napi_init()is added, the workqueue/requeue stuff as discussed is not needed so you won't see that here
..
....
Quoted 10 lines
Another thing that's really apparent now is all the wacky
napi->weightvalues various drivers use. Just grep fornetif_napi_init()in the patch or a patched tree to see what I mean. So much of it doesn't make any sense and I'm tempted to just remove the argument and make everyone use 32 or 64 or something like that :-) Or, default to some value across the board, and let drivers override that on a case by case basis with a BIG FAT COMMENT above the override describing why the different value is being used and precisely what tests were performed to validate that different value.
Sounds reasonable.
32-64 for Gige seemed to work well as i recall. 10/100 was around 16. But that shouldnt matter i think: because the poll from the core is based on Varghese's DRR, it probably will be fine if you just gave all the same value and the "deficit" part will kick in when needed. Some testing maybe required but theoretically i dont see a problem.
BTW: The current kernel code has a "bug" - where if a driver forgot to set its weight it would be indeterminate, so even for this reason it will be a good idea to enforce a default.
Sorry, havent been following the thread - thanks for CCing me, will try to catch up at some point.
cheers,
jamal
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Wed, 25 Jul 2007 09:56:54 +0100
Quoted 11 lines
The usage of NAPI on 8139cp and 8139too seems dodgy; these drivers expect this to work:
local_irq_save(flags); cpw16_f(IntrMask, cp_intr_mask); __netif_rx_complete(dev); local_irq_restore(flags);It works on SMP only because if poll races with IRQ, the IRQ is not masked or cleared so the IRQ will get restarted.
Quoted 7 lines
Better would be to change it to:
spin_lock_irqsave(&cp->lock, flags); cpw16_f(IntrMask, cp_intr_mask); __netif_rx_complete(dev); spin_unlock_irqrestore(&cp->lock, flags);Which actually is same code on UP.
I've made these fixes to my tree, thanks Stephen.
Quoted 9 lines · Stephen Hemminger
The usage of NAPI on 8139cp and 8139too seems dodgy; these drivers expect this to work:
local_irq_save(flags); cpw16_f(IntrMask, cp_intr_mask); __netif_rx_complete(dev); local_irq_restore(flags);It works on SMP only because if poll races with IRQ, the IRQ is not masked or cleared so the IRQ will get restarted.
Expect? This _does_ work on both UP and SMP.
Quoted 7 lines
Better would be to change it to:
spin_lock_irqsave(&cp->lock, flags); cpw16_f(IntrMask, cp_intr_mask); __netif_rx_complete(dev); spin_unlock_irqrestore(&cp->lock, flags);Which actually is same code on UP.
I'm missing your point?
You claim local_irq_save() works only on SMP, then suggest a solution that you agree produces the same result?
I don't see any logic to your request, only added overhead for no reason.
Jeff
David Miller
maintainerFrom: Jeff Garzik <[email protected]>
Date: Wed, 25 Jul 2007 21:55:08 -0400
Quoted 1 line
I don't see any logic to your request, only added overhead for no reason.
There may be some flawed logic in what Stephen stated, but the change really is needed.
It must be atomic to execute the:
enable_interrupts(); netif_rx_complete();
sequence wrt. the same code path in the interrupt handler.
Quoted 8 lines · David Miller
From: Jeff Garzik <[email protected]>
Date: Wed, 25 Jul 2007 21:55:08 -0400Quoted 1 line
I don't see any logic to your request, only added overhead for no reason.
There may be some flawed logic in what Stephen stated, but the change really is needed.
Quoted 6 lines
It must be atomic to execute the:
enable_interrupts(); netif_rx_complete();sequence wrt. the same code path in the interrupt handler.
Sure. And how did the existing code fail to achieve that?
Jeff
David Miller
maintainerFrom: Jeff Garzik <[email protected]>
Date: Wed, 25 Jul 2007 22:00:31 -0400
Quoted 9 lines
Quoted 8 lines · David Miller
From: Jeff Garzik <[email protected]>
Date: Wed, 25 Jul 2007 21:55:08 -0400Quoted 1 line
I don't see any logic to your request, only added overhead for no reason.
There may be some flawed logic in what Stephen stated, but the change really is needed.
Quoted 8 lines
Quoted 6 lines
It must be atomic to execute the:
enable_interrupts(); netif_rx_complete();sequence wrt. the same code path in the interrupt handler.
Sure. And how did the existing code fail to achieve that?
The interrupt handler can run on another cpu in betwen those two statements, running the NAPI test-and-do-something operations in parallel with the netif_rx_complete() which causes problems as Rusty and I discussed yesterday.
David Miller
maintainerFrom: David Miller <[email protected]>
Date: Wed, 25 Jul 2007 01:31:54 -0700 (PDT)
Quoted 3 lines
Besides that the only major issue is netpoll and I have some ideas on how to handle that, which I'll try to implement tonight and tomorrow.
Ok, here is how I'm trying to crack this nut.
The way I'll solve this is to just change the problem space and therefore simplify things enough that it's actually sane and implementable.
None of the receive packet handling of netpoll is even needed, so we rip all of it out. Every use was out of tree, and now subsumed by another facility. Basically that was kdump, which is now done via kexec.
As a result there is no more messing around with fake NAPI polls and all that other crap, instead ->poll_controller() merely has to try to process TX queue acks to free up space and wake up the transmit queue(s) of the device.
The downside is that TX ack processing has to run with the netif_tx_lock() for this to work out. Basically, netpoll carefully grabs the TX lock first by disabling interrupts and using netif_tx_trylock(), if successful it does dev->poll_controller() and then tries to transmit the packet.
Non-NAPI driver should be able to continue functioning as-is, they just run their interrupt handler which doesn't schedule polls and will do the TX queue acking.
NAPI drivers do need to change their ->poll_controller() to do TX queue acking directly.
I wanted to do this in a way that didn't require touching non-NAPI drivers as this change is getting big enough as it is and the change is incomplete if it makes netconsole totally broken in the process.
Anyways, here are snippets of patch from my current tree that should show generally what is going on, with bnx2 and tg3 as two converted NAPI ->poll_controler() examples. I'm about to boot this up and play with netconsole to test out that it works properly.
drivers/net/bnx2.c +25 -36
@@ -428,7 +428,7 @@ bnx2_netif_stop(struct bnx2 *bp) {bnx2_disable_int_sync (bp);if (netif_running (bp->dev)) { -netif_poll_disable (bp->dev); +napi_disable (&bp->napi);netif_tx_disable (bp->dev); bp->dev->trans_start = jiffies;/* prevent tx timeout */ }
@@ -440,7 +440,7 @@ bnx2_netif_start(struct bnx2 *bp)if (atomic_dec_and_test (&bp->intr_sem)) {if (netif_running (bp->dev)) {netif_wake_queue (bp->dev); -netif_poll_enable (bp->dev); +napi_enable (&bp->napi);bnx2_enable_int (bp); } }
@@ -2268,7 +2268,7 @@ bnx2_phy_int(struct bnx2 *bp) }static void -bnx2_tx_int (struct bnx2 *bp) +__bnx2_tx_int (struct bnx2 *bp) {struct status_block *sblk = bp->status_blk;u16 hw_cons, sw_cons, sw_ring_cons;
@@ -2347,11 +2347,9 @@ bnx2_tx_int(struct bnx2 *bp)if (unlikely (netif_queue_stopped (bp->dev)) && (bnx2_tx_avail (bp) > bp->tx_wake_thresh)) { -netif_tx_lock (bp->dev);if ((netif_queue_stopped (bp->dev)) && (bnx2_tx_avail (bp) > bp->tx_wake_thresh))netif_wake_queue (bp->dev); -netif_tx_unlock (bp->dev); } }
@@ -2551,7 +2549,7 @@ bnx2_msi(int irq, void *dev_instance)if (unlikely (atomic_read (&bp->intr_sem) !=0 ))return IRQ_HANDLED ; -netif_rx_schedule (dev); +netif_rx_schedule (dev, &bp->napi);return IRQ_HANDLED ; }
@@ -2568,7 +2566,7 @@ bnx2_msi_1shot(int irq, void *dev_instance)if (unlikely (atomic_read (&bp->intr_sem) !=0 ))return IRQ_HANDLED ; -netif_rx_schedule (dev); +netif_rx_schedule (dev, &bp->napi);return IRQ_HANDLED ; }
@@ -2604,9 +2602,9 @@ bnx2_interrupt(int irq, void *dev_instance)if (unlikely (atomic_read (&bp->intr_sem) !=0 ))return IRQ_HANDLED ; -if (netif_rx_schedule_prep (dev)) { +if (netif_rx_schedule_prep (dev, &bp->napi)) { bp->last_status_idx = sblk->status_idx; -__netif_rx_schedule (dev); +__netif_rx_schedule (dev, &bp->napi); }return IRQ_HANDLED ;
@@ -2632,12 +2630,14 @@ bnx2_has_work(struct bnx2 *bp) }static int -bnx2_poll (struct net_device *dev,int *budget) +bnx2_poll (struct napi_struct *napi,int budget) { -struct bnx2 *bp =netdev_priv (dev); + struct bnx2 *bp = container_of(napi, struct bnx2, napi); +struct net_device *dev = bp->dev;struct status_block *sblk = bp->status_blk;u32 status_attn_bits = sblk->status_attn_bits;u32 status_attn_bits_ack = sblk->status_attn_bits_ack; +int work_done =0 ;if ((status_attn_bits &STATUS_ATTN_EVENTS ) != (status_attn_bits_ack &STATUS_ATTN_EVENTS )) {
@@ -2652,26 +2652,20 @@ bnx2_poll(struct net_device *dev, int *budget)REG_RD (bp,BNX2_HC_COMMAND ); } -if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons) -bnx2_tx_int (bp); - -if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) { -int orig_budget = *budget; -int work_done; - -if (orig_budget > dev->quota) - orig_budget = dev->quota; - - work_done =bnx2_rx_int (bp, orig_budget); - *budget -= work_done; - dev->quota -= work_done; +if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons) { +netif_tx_lock (dev); +__bnx2_tx_int (bp); +netif_tx_unlock (dev); } +if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) + work_done =bnx2_rx_int (bp, budget); + bp->last_status_idx = bp->status_blk->status_idx;rmb ();if (!bnx2_has_work (bp)) { -netif_rx_complete (dev); +netif_rx_complete (dev, napi);if (likely (bp->flags &USING_MSI_FLAG )) { REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
@@ -2686,10 +2680,9 @@ bnx2_poll(struct net_device *dev, int *budget)REG_WR (bp,BNX2_PCICFG_INT_ACK_CMD ,BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx); -return 0 ; } -return 1 ; +return work_done; }/* Called with rtnl_lock from vlan functions and also netif_tx_lock
@@ -5146,10 +5139,7 @@ bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp) }#endif -/* Called with netif_tx_lock. -* bnx2_tx_int() runs without netif_tx_lock unless it needs to call -* netif_wake_queue(). -*/ +/* Called with netif_tx_lock. */ static int bnx2_start_xmit (struct sk_buff *skb,struct net_device *dev) {
@@ -5292,6 +5282,8 @@ bnx2_close(struct net_device *dev)struct bnx2 *bp =netdev_priv (dev);u32 reset_code; +napi_disable (&bp->napi); +/* Calling flush_scheduled_work() may deadlock because * linkwatch_event() may be on the workqueue and it will try to get * the rtnl_lock which we are holding.
@@ -6370,9 +6362,7 @@ poll_bnx2(struct net_device *dev) {struct bnx2 *bp =netdev_priv (dev); -disable_irq (bp->pdev->irq); -bnx2_interrupt (bp->pdev->irq, dev); -enable_irq (bp->pdev->irq); +__bnx2_tx_int (bp); }#endif
@@ -6856,11 +6846,10 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)#ifdef BCM_VLAN dev->vlan_rx_register = bnx2_vlan_rx_register;#endif - dev->poll = bnx2_poll; dev->ethtool_ops = &bnx2_ethtool_ops; - dev->weight =64 ; bp =netdev_priv (dev); +netif_napi_init (&bp->napi, bnx2_poll,64 );#if defined(HAVE_POLL_CONTROLLER ) || defined(CONFIG_NET_POLL_CONTROLLER ) dev->poll_controller = poll_bnx2;
drivers/net/bnx2.h +2 -0
@@ -6473,6 +6473,8 @@ struct bnx2 {struct net_device *dev;struct pci_dev *pdev; +struct napi_struct napi; +atomic_t intr_sem;struct status_block *status_blk;
drivers/net/tg3.c +28 -38
191 lines not on this page · raw message
drivers/net/tg3.h +1 -0
@@ -2176,6 +2176,7 @@ struct tg3 {dma_addr_t tx_desc_mapping;/* begin "rx thread" cacheline section */ +struct napi_struct napi;void (*write32_rx_mbox) (struct tg3 *,u32 ,u32 );u32 rx_rcb_ptr;
include/linux/netdevice.h +81 -91
281 lines not on this page · raw message
include/linux/netpoll.h +0 -59
78 lines not on this page · raw message
net/core/dev.c +78 -90
267 lines not on this page · raw message
net/core/netpoll.c +3 -351
452 lines not on this page · raw message
drivers/net/tg3.c static int tg3_poll(struct net_device *netdev, int *budget) · line 3496
Quoted 7 lines · David Miller
drivers/net/tg3.c +3
-1/* run TX completion thread */ if (sblk->idx[0 ].tx_consumer != tp->tx_cons) { -tg3_tx (tp); +netif_tx_lock (netdev); +__tg3_tx (tp); +netif_tx_unlock (netdev);
This will lead to more and longer lock contentions between ->hard_start_xmit() and ->poll() in the normal fast path. Why do we need to widen the scope of netif_tx_lock() in this case?
By not taking the netif_tx_lock() during tx completions until the last moment and only when necessary improves the performance substantially.
David Miller
maintainerFrom: "Michael Chan" <[email protected]>
Date: Wed, 25 Jul 2007 23:33:03 -0700
Quoted 3 lines
This will lead to more and longer lock contentions between ->hard_start_xmit() and ->poll() in the normal fast path. Why do we need to widen the scope of
netif_tx_lock()in this case?
So that ->poll_controller() can process TX acks by just having the TX lock and interrupts disabled.
Can you think of another way to process TX acks from absolutely any execution context whatsoever? That's what we need and preferably in some generic way, and the above is what I came up with.
To be honest I don't think the TX lock contention will matter, and even if there were a small cost, the simplicity of the netpoll implementation is worth it given how problematic and hard to debug netpoll has been in the past.
Quoted 5 lines · David Miller
As a result there is no more messing around with fake NAPI polls and all that other crap, instead ->poll_controller() merely has to try to process TX queue acks to free up space and wake up the transmit queue(s) of the device.
I think we also need to take care of link change interrupts as well.
David Miller
maintainerFrom: "Michael Chan" <[email protected]>
Date: Wed, 25 Jul 2007 23:39:18 -0700
Quoted 9 lines
Quoted 5 lines · David Miller
As a result there is no more messing around with fake NAPI polls and all that other crap, instead ->poll_controller() merely has to try to process TX queue acks to free up space and wake up the transmit queue(s) of the device.
I think we also need to take care of link change interrupts as well.
Since netpoll is best-effort, we can elide that I think. The more requirements you put into this ->poll_controller() handler, the more complicated it gets.
Furthermore, this should work out. If the link is down, the top level poll loop will timeout waiting for the TX queue to open up, which will kick the netpoll processing into a work queue, the link handling will be allowed to occur meanwhile.
Quoted 7 lines · David Miller
So that ->poll_controller() can process TX acks by just having the TX lock and interrupts disabled.
Can you think of another way to process TX acks from absolutely any execution context whatsoever? That's what we need and preferably in some generic way, and the above is what I came up with.
What are we trying to protect against by taking the TX lock before calling ->poll_controller()?
Quoted 7 lines
To be honest I don't think the TX lock contention will matter, and even if there were a small cost, the simplicity of the netpoll implementation is worth it given how problematic and hard to debug netpoll has been in the past.
There is a measurable difference in oprofile. When passing small packets, there's a non-trivial difference in throughput.
David Miller
maintainerFrom: "Michael Chan" <[email protected]>
Date: Thu, 26 Jul 2007 00:05:47 -0700
Quoted 5 lines
Quoted 3 lines · David Miller
So that ->poll_controller() can process TX acks by just having the TX lock and interrupts disabled.
Quoted 7 lines
Quoted 4 lines
Can you think of another way to process TX acks from absolutely any execution context whatsoever? That's what we need and preferably in some generic way, and the above is what I came up with.
What are we trying to protect against by taking the TX lock before calling ->poll_controller()?
The netpoll code has to take that anyways in order to call into ->hard_start_xmit() to send out the packet it has pending, I'm leveraging that as a synchronization mechanism in the drivers because the locking options are limited given that netpoll can try to do this in any context whatsoever.
Quoted 2 lines
There is a measurable difference in oprofile. When passing small packets, there's a non-trivial difference in throughput.
Then please help come up with an alternate scheme, because these NAPI changes fix real limitations and bugs in the current code and unless we fix netpoll too we can't move forward.
Thanks.
Quoted 6 lines · David Miller
The netpoll code has to take that anyways in order to call into ->hard_start_xmit() to send out the packet it has pending, I'm leveraging that as a synchronization mechanism in the drivers because the locking options are limited given that netpoll can try to do this in any context whatsoever.
Quoted 7 lines
Quoted 2 lines
There is a measurable difference in oprofile. When passing small packets, there's a non-trivial difference in throughput.
Then please help come up with an alternate scheme, because these NAPI changes fix real limitations and bugs in the current code and unless we fix netpoll too we can't move forward.
I'm not very familiar with netpoll, but I am guessing that we need to prevent concurrent calls to the TX cleanup code. For maximum flexibility, we should let ->poll_controller() handle the locking as the driver knows what kind of locking is best.
If the driver wants a simple solution, it can do what you did in the
patch: wrap the tx cleanup code with netif_tx_lock() and netif_tx_unlock().
If a NAPI driver wants to be more clever, it can do something such as this in tg3's poll_controller:
if (netif_rx_schedule_prep(dev, &tp->napi)) {
tg3_tx(tp);
netif_poll_enable(tp->napi);
}Quoted 9 lines
Most drivers are in good shape, although some still have very questionable
netif_rx_complete()handling, in that racy area that Rusty and myself were discussing today.My inclination is to wrap those sequences around with an IRQ safe spinlock to fix the race provably, and then if driver authors want to optimize that away with techniques like those that tg3, bnx2, sky2, skge et al. use, that's fine but can be done later.
Ouch... that extra lock seems pretty expensive. Also I'm having a hard time understanding how the techniques you're alluding to apply to devices that may miss events when enabling interrupts; the drivers you mention all seem to be for devices that didn't have the race and didn't use netif_rx_reschedule() in the old NAPI world. Can you provide a little more detail on how the lock could be optimized away?
Thanks,
Roland
Quoted 16 lines · David Miller
From: Jeff Garzik <[email protected]>
Date: Wed, 25 Jul 2007 22:00:31 -0400Quoted 13 lines
Quoted 12 lines · David Miller
From: Jeff Garzik <[email protected]>
Date: Wed, 25 Jul 2007 21:55:08 -0400Quoted 1 line
I don't see any logic to your request, only added overhead for no reason.
There may be some flawed logic in what Stephen stated, but the change really is needed.
It must be atomic to execute the:
enable_interrupts(); netif_rx_complete();
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
sequence wrt. the same code path in the interrupt handler.
Sure. And how did the existing code fail to achieve that?
The interrupt handler can run on another cpu in betwen those two statements, running the NAPI test-and-do-something operations in parallel with the
netif_rx_complete()which causes problems as Rusty and I discussed yesterday.
That's a performance/parallelization regression from current NAPI :(
Jeff
David Miller
maintainerFrom: Roland Dreier <[email protected]>
Date: Sat, 28 Jul 2007 08:27:18 -0700
Quoted 10 lines
Quoted 9 lines
Most drivers are in good shape, although some still have very questionable
netif_rx_complete()handling, in that racy area that Rusty and myself were discussing today.My inclination is to wrap those sequences around with an IRQ safe spinlock to fix the race provably, and then if driver authors want to optimize that away with techniques like those that tg3, bnx2, sky2, skge et al. use, that's fine but can be done later.
Quoted 6 lines
Ouch... that extra lock seems pretty expensive. Also I'm having a hard time understanding how the techniques you're alluding to apply to devices that may miss events when enabling interrupts; the drivers you mention all seem to be for devices that didn't have the race and didn't use
netif_rx_reschedule()in the old NAPI world. Can you provide a little more detail on how the lock could be optimized away?
If you have a means in the device (like tg3, bnx2, e1000, and a score of others do) to force the device to trigger a HW interrupt, that's what you do if you detect that events are pending after re-enabling interrupt in the ->poll() handler.
Frankly I don't think the lock is a big deal and you need something like it anyways typically.
David Miller
maintainerFrom: Jeff Garzik <[email protected]>
Date: Sat, 28 Jul 2007 14:08:44 -0400
Quoted 1 line
That's a performance/parallelization regression from current NAPI :(
That's not true since current NAPI will only run on one cpu, the one that the interrupt triggers on.
The existing cases that are not guarding the sequence to be atomic are racy, and in a way which is very hard to debug when it triggers and the device just appears dead.
Quoted 4 lines
If you have a means in the device (like tg3, bnx2, e1000, and a score of others do) to force the device to trigger a HW interrupt, that's what you do if you detect that events are pending after re-enabling interrupt in the ->poll() handler.
It is possible to trigger an interrupt for IPoIB I think but it will lead to a fair bit of code, since one would have to do something like a dummy send operation to generate an event that leads to the interrupt. I think this will be rather complex/ugly to implement because we have to make sure we have space in the send queue to post the send operation, etc.
Quoted 2 lines
Frankly I don't think the lock is a big deal and you need something like it anyways typically.
If I understand this correctly, you're suggesting a spin_lock_irqsave() around the netif_rx_complete() in the poll routine, and a corresponding lock in the interrupt handler. That seems like a pretty big step backwards for performance to me. Especially since in my experience, fast machines handling full-MTU traffic often end up being basically interrupt driven because they drain the RX ring too quickly to stay in NAPI polling. Yes, it's "only one more lock" but look at the tricky smp_mb() usage that tg3, bnx2, etc have to avoid using a spinlock...
IPoIB can cope but it really seems like an unfortunate feature of these changes that we can't do something like what we have today, which imposes no overhead unless an event actually lands in the race window.
- R.
David Miller
maintainerFrom: Roland Dreier <[email protected]>
Date: Mon, 30 Jul 2007 08:04:24 -0700
Quoted 4 lines
IPoIB can cope but it really seems like an unfortunate feature of these changes that we can't do something like what we have today, which imposes no overhead unless an event actually lands in the race window.
It is not a feature of these changes.
These races exist in the current code, it is a bug fix.
David Miller
maintainerFrom: "Michael Chan" <[email protected]>
Date: Thu, 26 Jul 2007 14:38:09 -0700
Quoted 11 lines
If the driver wants a simple solution, it can do what you did in the
patch: wrap the tx cleanup code withnetif_tx_lock()andnetif_tx_unlock().If a NAPI driver wants to be more clever, it can do something such as this in tg3's
poll_controller:if (netif_rx_schedule_prep(dev, &tp->napi)) { tg3_tx(tp); netif_poll_enable(tp->napi); }
Thanks Michael, that's a good suggestion and would work.
In thinking about this some more over the weekend I've decided that my plan to rip out RX support from netpoll is a bit too ambitious.
Therefore, for the time being, I'm going to add a special driver function for netpoll that will allow it to ask the driver to invoke ->poll() over all the NAPI structs assosciated with the netdev.
Quoted 3 lines
It is not a feature of these changes.
These races exist in the current code, it is a bug fix.
Not sure I follow. What is the race in the current code? Are you saying that netif_rx_reschedule() itself is racy? Otherwise the code in ipoib looks OK to me.
- R.
David Miller
maintainerFrom: Roland Dreier <[email protected]>
Date: Mon, 30 Jul 2007 19:01:55 -0700
Quoted 1 line
Are you saying that
netif_rx_reschedule()itself is racy?
Nevermind, you're right.
I'll see if I can resurrect something akin to netif_rx_reschedule() when I get back to the NAPI patches. Probably what I'll do is let the ->poll() handler make sure to accumulate 'rx' work counts if it loops again on netif_rx_reschedule() instead of dorking with the quota and budget in that helper function.