Skip to contentSkip to conversation

: napi_struct V5

RFC PATCH In review David Miller 6 participants 22 messages Aug 6, 2007 – Aug 13, 2007 1 message not in the archive

Subsystems (7)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

RFC PATCH 1/1 : napi_struct V5

Changes since V4:

1) A usable version of netif_rx_reschedule() put back. Drivers that were using it are made to keep doing so.

2) Infiniband converted, sorry for missing that, that's what happens when you put a networking driver under drivers/something_not_net/ :-)

3) Attempt to bring NAPI howto as uptodate as is possible for such a rotting document. :)

4) NETPOLL put hopefully into a working state. Basically, for netpoll, the napi_struct has a backpointer to the netdevice (so we can check for dev->npinfo and thus whether the special NETPOLL locking sequence is necessary) and there is a list collecting all of the NAPI instances for a netdevice (dev->napi_list) so that NETPOLL can iterate over all of them trying to invoke ->poll() is that instance is scheduled and the necesarry locks can be obtained.

The ->poll_lock and ->poll_owner are put into the napi_struct when NETPOLL is enabled too.

5) Since, in the NETPOLL case, netif_napi_init() adds the NAPI struct to the per-device list I renamed it to netif_napi_add(). Currently no teardown is really necessary, anything that would need to be done would be driver internal, so I didn't create the corollary netif_napi_remove() for the time being. Let's not add it unless it really becomes necessary.

I've decided to leave the weight settings used by drivers alone for now. It's easy to handle in a follow-on patch if we still want to commonize or tweak that.

I don't anticipate making any more changes, just fixing bugs. So please help me with that so we can finalize this patch. I intend to cut a net-2.6.24 tree and stuff this patch into it by the end of the week.

[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 of 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 ]

Documentation/networking/NAPI_HOWTO.txt +83 -100
index 7907435..e39f763 100644
@@ -60,39 +60,39 @@ A) DMA ring or enough RAM to store packets in software devices.
 B) Ability to turn off interrupts or maybe events that send packets up 
 the stack.
 
-NAPI processes packet events in what is known as dev->poll() method.
-Typically, only packet receive events are processed in dev->poll(). 
+NAPI processes packet events in what is known as napi->poll() method.
+Typically, only packet receive events are processed in napi->poll(). 
 The rest of the events MAY be processed by the regular interrupt handler 
 to reduce processing latency (justified also because there are not that 
 many of them).
-Note, however, NAPI does not enforce that dev->poll() only processes 
+Note, however, NAPI does not enforce that napi->poll() only processes 
 receive events. 
 Tests with the tulip driver indicated slightly increased latency if
-all of the interrupt handler is moved to dev->poll(). Also MII handling
+all of the interrupt handler is moved to napi->poll(). Also MII handling
 gets a little trickier.
 The example used in this document is to move the receive processing only
-to dev->poll(); this is shown with the patch for the tulip driver.
+to napi->poll(); this is shown with the patch for the tulip driver.
 For an example of code that moves all the interrupt driver to 
-dev->poll() look at the ported e1000 code.
+napi->poll() look at the ported e1000 code.
 
 There are caveats that might force you to go with moving everything to 
-dev->poll(). Different NICs work differently depending on their status/event 
+napi->poll(). Different NICs work differently depending on their status/event 
 acknowledgement setup. 
 There are two types of event register ACK mechanisms.
 	I)  what is known as Clear-on-read (COR).
 	when you read the status/event register, it clears everything!
 	The natsemi and sunbmac NICs are known to do this.
-	In this case your only choice is to move all to dev->poll()
+	In this case your only choice is to move all to napi->poll()
 
 	II) Clear-on-write (COW)
 	 i) you clear the status by writing a 1 in the bit-location you want.
 		These are the majority of the NICs and work the best with NAPI.
-		Put only receive events in dev->poll(); leave the rest in
+		Put only receive events in napi->poll(); leave the rest in
 		the old interrupt handler.
 	 ii) whatever you write in the status register clears every thing ;->
 		Cant seem to find any supported by Linux which do this. If
 		someone knows such a chip email us please.
-		Move all to dev->poll()
+		Move all to napi->poll()
 
 C) Ability to detect new work correctly.
 NAPI works by shutting down event interrupts when there's work and
@@ -110,56 +110,64 @@ discussion.
 Locking rules and environmental guarantees
 ==========================================
 
--Guarantee: Only one CPU at any time can call dev->poll(); this is because
+-Guarantee: Only one CPU at any time can call napi->poll(); this is because
 only one CPU can pick the initial interrupt and hence the initial
-netif_rx_schedule(dev);
+netif_rx_schedule(dev, napi);
 - The core layer invokes devices to send packets in a round robin format.
 This implies receive is totally lockless because of the guarantee that only 
 one CPU is executing it.
 -  contention can only be the result of some other CPU accessing the rx
 ring. This happens only in close() and suspend() (when these methods
-try to clean the rx ring); 
-****guarantee: driver authors need not worry about this; synchronization 
-is taken care for them by the top net layer.
--local interrupts are enabled (if you dont move all to dev->poll()). For 
+try to clean the rx ring);  Therefore the close() and suspend() methods
+must take care to invoke napi_disable() on each NAPI instance assosciated
+with the driver.
+-local interrupts are enabled (if you dont move all to napi->poll()). For 
 example link/MII and txcomplete continue functioning just same old way. 
 This improves the latency of processing these events. It is also assumed that 
 the receive interrupt is the largest cause of noise. Note this might not 
 always be true. 
 [according to Manfred Spraul, the winbond insists on sending one 
 txmitcomplete interrupt for each packet (although this can be mitigated)].
-For these broken drivers, move all to dev->poll().
+For these broken drivers, move all to napi->poll().
 
-For the rest of this text, we'll assume that dev->poll() only
+For the rest of this text, we'll assume that napi->poll() only
 processes receive events.
 
 new methods introduce by NAPI
 =============================
 
-a) netif_rx_schedule(dev)
-Called by an IRQ handler to schedule a poll for device
+a) netif_rx_schedule(dev, napi)
+Called by an IRQ handler to schedule a poll on the given NAPI instance
+for device
 
-b) netif_rx_schedule_prep(dev)
-puts the device in a state which allows for it to be added to the
-CPU polling list if it is up and running. You can look at this as
-the first half of  netif_rx_schedule(dev) above; the second half
-being c) below.
+b) netif_rx_schedule_prep(dev, napi)
+puts given NAPI instance of the device in a state which allows for it
+to be added to the CPU polling list if the device is up and running.
+You can look at this as the first half of netif_rx_schedule(dev, napi)
+above; the second half being c) below.
 
-c) __netif_rx_schedule(dev)
-Add device to the poll list for this CPU; assuming that _prep above
-has already been called and returned 1.
+c) __netif_rx_schedule(dev, napi)
+Add NAPI instance of device to the poll list for this CPU; assuming
+that _prep above has already been called and returned 1.
 
-d) netif_rx_reschedule(dev, undo)
-Called to reschedule polling for device specifically for some
-deficient hardware. Read Appendix 2 for more details.
+d) netif_rx_reschedule(dev, napi)
+Called to reschedule polling for a NAPI instance of a device specifically
+for some deficient hardware. Read Appendix 2 for more details.
 
-e) netif_rx_complete(dev)
-
-Remove interface from the CPU poll list: it must be in the poll list
-on current cpu. This primitive is called by dev->poll(), when
+e) netif_rx_complete(dev, napi)
+Remove NAPI instance of device from the CPU poll list: it must be in the
+poll list on the current cpu. This primitive is called by napi->poll(), when
 it completes its work. The device cannot be out of poll list at this
 call, if it is then clearly it is a BUG(). You'll know ;->
 
+f) netif_napi_add(dev, napi, poll, weight)
+Register a NAPI instance for the given device, using the given
+'poll' handler and device weight 'weight'.  For most devices, a
+"struct napi_struct" will be embedded in the netdevice private
+structure, and given as the second argument here.  For more complicated
+devices with multiple receive queues, a seperate NAPI struct instance
+will be allocated and added for each such queue.
+
 All of the above methods are used below, so keep reading for clarity.
 
 Device driver changes to be made when porting NAPI
@@ -167,54 +175,49 @@ Device driver changes to be made when porting NAPI
 
 Below we describe what kind of changes are required for NAPI to work.
 
-1) introduction of dev->poll() method 
+1) introduction of napi->poll() method 
 =====================================
 
 This is the method that is invoked by the network core when it requests
-for new packets from the driver. A driver is allowed to send upto
-dev->quota packets by the current CPU before yielding to the network
-subsystem (so other devices can also get opportunity to send to the stack).
+for new packets from the driver for a specific NAPI instance. A driver
+is allowed to send upto 'budget' packets by the current CPU before yielding
+to the network subsystem (so other devices can also get opportunity to send
+to the stack).
 
-dev->poll() prototype looks as follows:
-int my_poll(struct net_device *dev, int *budget)
+napi->poll() prototype looks as follows:
+
+int my_poll(struct napi_struct *napi, int budget)
 
 budget is the remaining number of packets the network subsystem on the
 current CPU can send up the stack before yielding to other system tasks.
-*Each driver is responsible for decrementing budget by the total number of
-packets sent.
-	Total number of packets cannot exceed dev->quota.
 
-dev->poll() method is invoked by the top layer, the driver just sends if it 
-can to the stack the packet quantity requested.
+The napi->poll() method is invoked by the top layer, the driver just sends
+if it can to the stack the packet quantity requested.
 
-more on dev->poll() below after the interrupt changes are explained.
+more on napi->poll() below after the interrupt changes are explained.
 
-2) registering dev->poll() method
+2) registering napi->poll() method
 ===================================
 
-dev->poll should be set in the dev->probe() method. 
+napi->poll should be registered in the dev->probe() method via
+netif_napi_add() as explained above.
+
 e.g:
 dev->open = my_open;
 .
 .
-/* two new additions */
-/* first register my poll method */
-dev->poll = my_poll;
-/* next register my weight/quanta; can be overridden in /proc */
-dev->weight = 16;
+netif_napi_add(dev, &private->napi, my_poll, 16);
 .
 .
 dev->stop = my_close;
 
-
-
-3) scheduling dev->poll()
+3) scheduling napi->poll()
 =============================
 This involves modifying the interrupt handler and the code
 path which takes the packet off the NIC and sends them to the 
 stack.
 
-it's important at this point to introduce the classical D Becker 
+It's important at this point to introduce the classical D Becker 
 interrupt processor:
 
 ------------------
@@ -296,13 +299,13 @@ netdevice_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 		}
 /************************ start note *********************************/		
 		if (status & rx_interrupt || (status & rx_nobuffs)) {
-			if (netif_rx_schedule_prep(dev)) {
+			if (netif_rx_schedule_prep(dev, &tp->napi)) {
 
 				/* disable interrupts caused 
 			         *	by arriving packets */
 				disable_rx_and_rxnobuff_ints();
 				/* tell system we have work to be done. */
-				__netif_rx_schedule(dev);
+				__netif_rx_schedule(dev, &tp->napi);
 			} else {
 				printk("driver bug! interrupt while in poll\n");
 				/* FIX by disabling interrupts  */
@@ -344,10 +347,10 @@ register for those two items above; clearing is done in the place where
 proper work is done within NAPI; at the poll() and refill_rx_ring() 
 discussed further below.
 netif_rx_schedule_prep() returns 1 if device is in running state and
-gets successfully added to the core poll list. If we get a zero value
-we can _almost_ assume are already added to the list (instead of not running. 
-Logic based on the fact that you shouldn't get interrupt if not running)
-We rectify this by disabling rx and rxnobuf interrupts.
+the NAPI instance gets successfully added to the core poll list. If we get
+a zero value we can _almost_ assume are already added to the list (instead
+of not running.  Logic based on the fact that you shouldn't get interrupt
+if not running) We rectify this by disabling rx and rxnobuf interrupts.
 
 II) that receive_packets(dev) and make_rx_buffs_avail() may have disappeared.
 These functionalities are still around actually......
@@ -355,7 +358,7 @@ These functionalities are still around actually......
 infact, receive_packets(dev) is very close to my_poll() and 
 make_rx_buffs_avail() is invoked from my_poll()
 
-4) converting receive_packets() to dev->poll()
+4) converting receive_packets() to napi->poll()
 ===============================================
 
 We need to convert the classical D Becker receive_packets(dev) to my_poll()
@@ -430,18 +433,15 @@ the call.
 -------------------------------------------------------------------
 
 /* this is called by the network core */
-static int my_poll (struct net_device *dev, int *budget)
+static int my_poll (struct napi_struct *napi, int budget)
 {
-
-	struct my_private *tp = (struct my_private *)dev->priv;
+	struct my_private *tp = container_of(napi, struct my_private, napi);
+	struct net_device *dev = tp->dev;
 	rx_ring = tp->rx_ring;
 	cur_rx = tp->cur_rx;
 	int entry = cur_rx % RX_BUF_LEN;
-	/* maximum packets to send to the stack */
-/************************ note note *********************************/		
-	int rx_work_limit = dev->quota;
+	int work_done = 0;
 
-/************************ end note note *********************************/		
     do {  // outer beginning loop starts here
 
 	clear_rx_status_register_bit();
@@ -461,11 +461,11 @@ static int my_poll (struct net_device *dev, int *budget)
                 if ((rx_size > (MAX_ETH_FRAME_SIZE+4)) ||
                     (!(rx_status & RxStatusOK))) {
                         netdrv_rx_err (rx_status, dev, tp, ioaddr);
-                        return 1;
+                        return work_done;
                 }
 
 /************************ note note *********************************/		
-                if (--rx_work_limit < 0) { /* we got packets, but no quota */
+		if (work_done >= budget) { /* we got packets, but no quota */
 			/* store current ring pointer state */
 			tp->cur_rx = cur_rx;
 
@@ -492,7 +492,7 @@ static int my_poll (struct net_device *dev, int *budget)
 
 		/* move to the next skb on the ring */
 		entry = (++tp->cur_rx) % RX_RING_SIZE;
-		received++ ;
+		work_done++;
 
         }
 
@@ -518,17 +518,13 @@ static int my_poll (struct net_device *dev, int *budget)
 
 done:
 
-/************************ note note *********************************/		
-        dev->quota -= received;
-        *budget -= received;
-
         /* If RX ring is not full we are out of memory. */
         if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
                 goto oom;
 
 	/* we are happy/done, no more packets on ring; put us back
 	to where we can start processing interrupts again */
-        netif_rx_complete(dev);
+        netif_rx_complete(dev, napi);
 	enable_rx_and_rxnobuf_ints();
 
        /* The last op happens after poll completion. Which means the following:
@@ -544,20 +540,14 @@ done:
         * processed irqs. The good news: no events are ever lost.
         */
 
-        return 0;   /* done */
+        return work_done;   /* done */
 
 not_done:
         if (tp->cur_rx - tp->dirty_rx > RX_RING_SIZE/2 ||
             tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
                 refill_rx_ring(dev);
 
-        if (!received) {
-                printk("received==0\n");
-                received = 1;
-        }
-        dev->quota -= received;
-        *budget -= received;
-        return 1;  /* not_done */
+        return work_done;
 
 oom:
         /* Start timer, stop polling, but do not enable rx interrupts. */
@@ -569,7 +559,6 @@ oom:
 -------------------------------------------------------------------
 
 From above we note that:
-0) rx_work_limit = dev->quota 
 1) refill_rx_ring() is in charge of clearing the bit for rxnobuff when
 it does the work.
 2) We have a done and not_done state.
@@ -597,18 +586,12 @@ a)
         if (tp->rx_buffers[tp->dirty_rx % RX_RING_SIZE].skb == NULL)
                 restart_timer();
 
-	else netif_rx_schedule(dev);  /* we are back on the poll list */
+	else netif_rx_schedule(dev, napi);  /* we are back on the poll list */
 	
 5) dev->close() and dev->suspend() issues
 ==========================================
-The driver writer needn't worry about this; the top net layer takes
-care of it.
-
-6) Adding new Stats to /proc 
-=============================
-In order to debug some of the new features, we introduce new stats
-that need to be collected.
-TODO: Fill this later.
+These handlers should shut off all NAPI instances for a given device using
+napi_disable(napi)
 
 APPENDIX 1: discussion on using ethernet HW FC
 ==============================================
@@ -708,8 +691,8 @@ restart_poll:
 	.
 	.
 	enable_rx_interrupts()
-	netif_rx_complete(dev);
-	if (ring_has_new_packet() && netif_rx_reschedule(dev, received)) {
+	netif_rx_complete(dev, napi);
+	if (ring_has_new_packet() && netif_rx_reschedule(dev, napi)) {
 		disable_rx_and_rxnobufs()
 		goto restart_poll
 	} while (rx_status_is_set);
drivers/infiniband/ulp/ipoib/ipoib.h +3 -1
index 285c143..35f3ca4 100644
@@ -228,6 +228,8 @@ struct ipoib_dev_priv {
 
 	struct net_device *dev;
 
+	struct napi_struct napi;
+
 	unsigned long flags;
 
 	struct mutex mcast_mutex;
@@ -351,7 +353,7 @@ extern struct workqueue_struct *ipoib_workqueue;
 
 /* functions */
 
-int ipoib_poll(struct net_device *dev, int *budget);
+int ipoib_poll(struct napi_struct *napi, int budget);
 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
 
 struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
drivers/infiniband/ulp/ipoib/ipoib_ib.c +20 -25

97 lines not on this page · raw message

drivers/infiniband/ulp/ipoib/ipoib_main.c +4 -2
index 894b1dc..8d4dad4 100644
@@ -141,6 +141,8 @@ static int ipoib_stop(struct net_device *dev)
 
 	clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags);
 
+	napi_disable(&priv->napi);
+
 	netif_stop_queue(dev);
 
 	clear_bit(IPOIB_FLAG_NETIF_STOPPED, &priv->flags);
@@ -948,8 +950,8 @@ static void ipoib_setup(struct net_device *dev)
 	dev->hard_header 	 = ipoib_hard_header;
 	dev->set_multicast_list  = ipoib_set_mcast_list;
 	dev->neigh_setup         = ipoib_neigh_setup_dev;
-	dev->poll                = ipoib_poll;
-	dev->weight              = 100;
+
+	netif_napi_add(dev, &priv->napi, ipoib_poll, 100);
 
 	dev->watchdog_timeo 	 = HZ;
 
drivers/net/8139cp.c +18 -20
index a79f28c..923821d 100644
@@ -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,33 +590,28 @@ 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)
 			goto rx_status_loop;
 
-		local_irq_save(flags);
+		spin_lock_irqsave(&cp->lock, flags);
 		cpw16_f(IntrMask, cp_intr_mask);
-		__netif_rx_complete(dev);
-		local_irq_restore(flags);
-
-		return 0;	/* done */
+		__netif_rx_complete(dev, napi);
+		spin_unlock_irqrestore(&cp->lock, flags);
 	}
 
-	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);
 
@@ -1933,11 +1932,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;
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = cp_poll_controller;
 #endif
-	dev->weight = 16;	/* arbitrary? from NAPI_HOWTO.txt. */
+	netif_napi_add(dev, &cp->napi, cp_rx_poll, 16);
 #ifdef BROKEN
 	dev->change_mtu = cp_change_mtu;
 #endif
drivers/net/8139too.c +21 -25

106 lines not on this page · raw message

drivers/net/amd8111e.c +11 -16
index a61b2f8..2f7af7c 100644
@@ -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_add(dev, &lp->napi, amd8111e_rx_poll, 32);
 #endif
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = amd8111e_poll;
drivers/net/amd8111e.h +2 -0
index e65080a..612e653 100644
@@ -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 +29 -38

140 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
index e537e63..63c55a4 100644
@@ -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 +27 -41

168 lines not on this page · raw message

drivers/net/bnx2.h +2 -0
index 102adfe..fbae439 100644
@@ -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
index f6e4030..ffcefa2 100644
@@ -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_add(dev, &cp->napi, cas_poll, 64);
 #endif
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	dev->poll_controller = cas_netpoll;
drivers/net/cassini.h +2 -0
index a970804..2f93f83 100644
@@ -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
index 8ba702c..b5de445 100644
@@ -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
index 231ce43..66da0c7 100644
@@ -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_add(netdev, &adapter->napi, t1_poll, 64);
 #endif
 
 		SET_ETHTOOL_OPS(netdev, &t1_ethtool_ops);
drivers/net/chelsio/sge.c +13 -16
index e4f874a..0e5504d 100644
@@ -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
index d132a0e..713d9c5 100644
@@ -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
index ab72563..e723e7b 100644
@@ -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 +84 -104

457 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
index 280313b..e25f5ec 100644
@@ -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);
@@ -2572,14 +2569,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_add(netdev, &nic->napi, e100_poll, E100_NAPI_WEIGHT);
 	nic->netdev = netdev;
 	nic->pdev = pdev;
 	nic->msg_enable = (1 << debug) - 1;
@@ -2733,7 +2729,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);
@@ -2779,7 +2775,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);
 
@@ -2804,12 +2800,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
index 16a6edf..781ed99 100644
@@ -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 +1 -1
index 8ee2c2c..eb019c8 100644
@@ -351,6 +351,7 @@ struct ehea_q_skb_arr {
  * Port resources
  */
 struct ehea_port_res {
+	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 +363,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 +22 -37

176 lines not on this page · raw message

drivers/net/epic100.c +14 -17
index 1197784..211909d 100644
@@ -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_add(dev, &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
index 5af60b0..f3b1c6f 100644
@@ -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 +26 -30

125 lines not on this page · raw message

drivers/net/forcedeth.c +28 -29

106 lines not on this page · raw message

drivers/net/fs_enet/fs_enet-main.c +19 -29

48 lines not on this page · raw message

drivers/net/fs_enet/fs_enet.h +1 -0
index 569be22..46d0606 100644

Lines of this file are not shown. View the raw message.

drivers/net/gianfar.c +16 -21
index f926905..89c2fb4 100644

Lines of this file are not shown. View the raw message.

drivers/net/gianfar.h +3 -0
index d8e779c..b8714e0 100644

Lines of this file are not shown. View the raw message.

drivers/net/ibmveth.c +50 -59

109 lines not on this page · raw message

drivers/net/ibmveth.h +1 -0
index bb69cca..bb2e5e1 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixgb/ixgb.h +1 -0
index 3569d5b..1eee889 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixgb/ixgb_main.c +12 -17
index 991c883..e3f27c6 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixp2000/ixpdev.c +23 -14
index d9ce1ae..5148a92 100644

Lines of this file are not shown. View the raw message.

drivers/net/ixp2000/ixpdev.h +2 -0
index bd686cb..391ece6 100644

Lines of this file are not shown. View the raw message.

drivers/net/macb.c +15 -21
index a4bb026..0bd7d21 100644

Lines of this file are not shown. View the raw message.

drivers/net/macb.h +1 -0
index 4e3283e..57b85ac 100644

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/mv643xx_eth.h +2 -0
index 82f8c0c..6f2aaa6 100644

Lines of this file are not shown. View the raw message.

drivers/net/myri10ge/myri10ge.c +17 -23
index deca653..3cd7921 100644

Lines of this file are not shown. View the raw message.

drivers/net/natsemi.c +16 -17
index 6bb48ba..df978f5 100644

Lines of this file are not shown. View the raw message.

drivers/net/netxen/netxen_nic.h +1 -0
index d4c92cc..aaa3493 100644

Lines of this file are not shown. View the raw message.

drivers/net/netxen/netxen_nic_main.c +16 -20
index 08a62ac..61e3d32 100644

Lines of this file are not shown. View the raw message.

drivers/net/pasemi_mac.c +15 -19
index 0b3066a..c9d148d 100644

Lines of this file are not shown. View the raw message.

drivers/net/pasemi_mac.h +1 -0
index c29ee15..85d3b78 100644

Lines of this file are not shown. View the raw message.

drivers/net/pcnet32.c +37 -35

72 lines not on this page · raw message

drivers/net/ps3_gelic_net.c +18 -26

44 lines not on this page · raw message

drivers/net/ps3_gelic_net.h +1 -0
index a9c4c4f..9685602 100644

Lines of this file are not shown. View the raw message.

drivers/net/qla3xxx.c +12 -17
index 69da95b..3287b69 100755

Lines of this file are not shown. View the raw message.

drivers/net/qla3xxx.h +2 -0
index 4a832c4..aa2216f 100755

Lines of this file are not shown. View the raw message.

drivers/net/r8169.c +23 -25

48 lines not on this page · raw message

drivers/net/s2io.c +12 -20
index 24feb00..6686e88 100644

Lines of this file are not shown. View the raw message.

drivers/net/s2io.h +2 -1
index 92983ee..420fefb 100644

Lines of this file are not shown. View the raw message.

drivers/net/sb1250-mac.c +16 -29

45 lines not on this page · raw message

drivers/net/skge.c +20 -24

44 lines not on this page · raw message

drivers/net/skge.h +1 -0
index edd7146..dd0fd45 100644

Lines of this file are not shown. View the raw message.

drivers/net/sky2.c +34 -46

80 lines not on this page · raw message

drivers/net/sky2.h +1 -0
index dce4d27..8d6a260 100644

Lines of this file are not shown. View the raw message.

drivers/net/spider_net.c +27 -33

60 lines not on this page · raw message

drivers/net/spider_net.h +2 -0
index dbbdb8c..a2fcdeb 100644

Lines of this file are not shown. View the 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/sungem.h +1 -0
index 58cf87c..76d760a 100644

Lines of this file are not shown. View the raw message.

drivers/net/tc35815.c +21 -22

43 lines not on this page · raw message

drivers/net/tg3.c +30 -43

73 lines not on this page · raw message

drivers/net/tg3.h +1 -0
index 5c21f49..a6a23bb 100644

Lines of this file are not shown. View the raw message.

drivers/net/tsi108_eth.c +17 -21
index 1aabc91..781e40b 100644

Lines of this file are not shown. View the raw message.

drivers/net/tulip/interrupt.c +23 -31

54 lines not on this page · raw message

drivers/net/tulip/tulip.h +2 -1
index 16f26a8..5a4d727 100644

Lines of this file are not shown. View the raw message.

drivers/net/tulip/tulip_core.c +2 -2
index eca984f..da05a3a 100644

Lines of this file are not shown. View the 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

drivers/net/ucc_geth.h +1 -0
index bb4dac8..0579ba0 100644

Lines of this file are not shown. View the raw message.

drivers/net/via-rhine.c +15 -16
index c3fe230..6af7925 100644

Lines of this file are not shown. View the raw message.

drivers/net/xen-netfront.c +15 -16
index 489f69c..ec710eb 100644

Lines of this file are not shown. View the raw message.

include/linux/netdevice.h +113 -72

185 lines not on this page · raw message

include/linux/netpoll.h +40 -13

53 lines not on this page · raw message

net/core/dev.c +85 -82

167 lines not on this page · raw message

net/core/net-sysfs.c +0 -15
index 5c19b06..79159db 100644

Lines of this file are not shown. View the raw message.

net/core/netpoll.c +25 -14
index de1b26a..abe6e3a 100644

Lines of this file are not shown. View the raw message.

net/core/rtnetlink.c +0 -6
index 4756d58..2b0b6fa 100644

Lines of this file are not shown. View the 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.

#1 lore raw
Quoted 1 line · David Miller

4) NETPOLL put hopefully into a working state.

It's no longer necessary to change the tx locking scheme in bnx2.c and tg3.c, right? May be you forgot to revert the tx locking changes you did in V4?

author maintainer
#2 lore raw

From: "Michael Chan" <[email protected]>
Date: Mon, 6 Aug 2007 11:00:45 -0700

Quoted 7 lines
Quoted 1 line · David Miller

4) NETPOLL put hopefully into a working state.

It's no longer necessary to change the tx locking scheme in bnx2.c and tg3.c, right? May be you forgot to revert the tx locking changes you did in V4?

Right, I'll fix that up, thanks for catching it.

#3 lore raw
In reply to David Miller
Quoted 3 lines · David Miller

3) Attempt to bring NAPI howto as uptodate as is possible for such a rotting document. :)

That doc is out of date on the split of work - it focusses mostly describing the original tulip which did not mix rx and tx in the napi_poll(). AFAIK, no driver does that today (although i really liked that scheme, there is a lot of fscked hardware out there that wont work well with that scheme). Where are the firemen when you need them?

Scanning your changes on the drivers for hardware i possess, I dont see any issues.

cheers,
jamal

author maintainer
#4 lore raw

From: jamal <[email protected]>
Date: Tue, 07 Aug 2007 08:52:35 -0400

Quoted 5 lines

That doc is out of date on the split of work - it focusses mostly describing the original tulip which did not mix rx and tx in the napi_poll(). AFAIK, no driver does that today (although i really liked that scheme, there is a lot of fscked hardware out there that wont work well with that scheme). Where are the firemen when you need them?

I am tempted to suggest we toss the document completely, for two reasons:

1) It's geared towards conversions, whereas %99.9999 of the conversions that will ever happen, have happened. Every single potential reader of this document is therefore writing new drivers with NAPI from the beginning.

2) Inaccurate documentation is often worse than no documentation.

It's not a bad thing to delete the document, and also we have a lot of time until 2.6.24 finalizes with these changes and in that time someone with the right incentive could write a fresh new NAPI manual that represents reality. Such a document could be added after the merge window closes.

This also reminds me that we confuse people by having two driver models for interrupt handling. I've been reluctant to remove the "optional" component of NAPI especially when it didn't handle multi-queue properly (which basically made drivers for virtualized devices impossible without using dummy devices for each queue). But that is no longer true and there isn't any reason for a new driver not to be NAPI from the beginning.

#5 lore raw
Quoted 2 lines · David Miller

I am tempted to suggest we toss the document completely, for two reasons:

Its overdue - just hasnt been anybody who has raised their hands to do it. Stephen did at one point.
Theres a lot of nice insights in that doc that will be nice to inherit. Theres also a nice state machine diagram in
http://www.kernel.org/pub/linux/kernel/people/hadi/docs/UKUUG2005.pdf
that will be very useful to capture in whatever new doc.

cheers,
jamal

author maintainer
#6 lore raw

From: jamal <[email protected]>
Date: Wed, 08 Aug 2007 08:10:59 -0400

Quoted 6 lines

Its overdue - just hasnt been anybody who has raised their hands to do it. Stephen did at one point.
Theres a lot of nice insights in that doc that will be nice to inherit. Theres also a nice state machine diagram in
http://www.kernel.org/pub/linux/kernel/people/hadi/docs/UKUUG2005.pdf
that will be very useful to capture in whatever new doc.

Stephen said he would find time to work on this, so what I'll do is yank the documentation file in my napi_struct changeset and he can crib content from the old file and your UKUUG2005 slides.

#7 lore raw
In reply to David Miller

Thanks for looking at ipoib... overall looks fine, just a few comments.

Quoted 4 lines
drivers/infiniband/ulp/ipoib/ipoib_ib.c +0 -0
@@ -281,63 +281,58 @@ static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
 			   wc->status, wr_id, wc->vendor_err);

drivers/infiniband/ulp/ipoib/ipoib_ib.c static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) · line 290

Quoted 10 lines
drivers/infiniband/ulp/ipoib/ipoib_ib.c +5 -1
 }
 
-int ipoib_poll(struct net_device *dev, int *budget)
+int ipoib_poll(struct napi_struct *napi, int budget)
 
+poll_more:
+	while (done < budget) {
+		int max = (budget - done);
+
 		t = min(IPOIB_NUM_WC, max);

I think this is the only place where max is used now. Might as well kill it and put budget-done in directly. That would get rid of the strange-looking parens in the "max =" line too.

drivers/infiniband/ulp/ipoib/ipoib_ib.c static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) · line 301

Quoted 4 lines
drivers/infiniband/ulp/ipoib/ipoib_ib.c +1 -1
 		n = ib_poll_cq(priv->cq, t, priv->ibwc);
 
-		for (i = 0; i < n; ++i) {
+		for (i = 0; i < n; i++) {

it might be nicer to avoid noise like this in the patch.

drivers/infiniband/ulp/ipoib/ipoib_ib.c static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) · line 324

Quoted 11 lines
drivers/infiniband/ulp/ipoib/ipoib_ib.c +4 -4
+	if (done < budget) {
+		netif_rx_complete(dev, napi);
 		if (unlikely(ib_req_notify_cq(priv->cq,
 					      IB_CQ_NEXT_COMP |
 					      IB_CQ_REPORT_MISSED_EVENTS)) &&
-		    netif_rx_reschedule(dev, 0))
-			return 1;
-
-		return 0;
+		    netif_rx_reschedule(napi))
+			goto poll_more;

this goto back to the polling loop is a change in behavior. When we were tuning NAPI, we found that returning in the missed event case and letting the NAPI core call the poll routine later actually performed better, because it allowed more work to pile up.

So could the code just look like:

		netif_rx_complete(dev, napi);
 		if (unlikely(ib_req_notify_cq(priv->cq,
 					      IB_CQ_NEXT_COMP |
 					      IB_CQ_REPORT_MISSED_EVENTS)))
			netif_rx_reschedule(napi);

and then just return done in all cases?

It doesn't seem like the return value of netif_rx_reschedule() matters in what we would want to do. The only thing it's used for in the old code is to decide what the poll routine should return.

- R.

author maintainer
#8 lore raw

From: Roland Dreier <[email protected]>
Date: Tue, 07 Aug 2007 15:37:30 -0700

Quoted 6 lines

drivers/infiniband/ulp/ipoib/ipoib_ib.c static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) · line 301

Quoted 4 lines
drivers/infiniband/ulp/ipoib/ipoib_ib.c +1 -1
 		n = ib_poll_cq(priv->cq, t, priv->ibwc);
 
-		for (i = 0; i < n; ++i) {
+		for (i = 0; i < n; i++) {

it might be nicer to avoid noise like this in the patch.

That one was just too much of an eye sore to ignore and it effect my ability to audit the change I was making.

I mean, this is one of the first precise examples of kinds of programming that lead to subtle bugs mentioned in The Practice of Programming.

So this is staying in the patch, sorry.

Quoted 4 lines

this goto back to the polling loop is a change in behavior. When we were tuning NAPI, we found that returning in the missed event case and letting the NAPI core call the poll routine later actually performed better, because it allowed more work to pile up.

You weren't using your quantum, which is what you're supposed to do.

Sometimes using your quantum correctly won't perform optimally, but in the interest of fairness and what NAPI wants, that is what you're supposed to do, process work until you hit budget or there is no more work.

Look, I'm not going to back down to every single tweak in every driver. All the drivers should handle this case consistently, and if I have to edit every single driver to make this patch that is exactly what I am going to do and enforce.

If you patch the ipoib driver behavior back afterwards, I will NAK that patch every single time unless you make EVERY SINGLE OTHER DRIVER do the same and thus retain the consistency.

#9 lore raw
Quoted 7 lines
Quoted 6 lines

drivers/infiniband/ulp/ipoib/ipoib_ib.c static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc) · line 301

Quoted 4 lines
drivers/infiniband/ulp/ipoib/ipoib_ib.c +1 -1
 		n = ib_poll_cq(priv->cq, t, priv->ibwc);
 
-		for (i = 0; i < n; ++i) {
+		for (i = 0; i < n; i++) {

it might be nicer to avoid noise like this in the patch.

Quoted 8 lines

That one was just too much of an eye sore to ignore and it effect my ability to audit the change I was making.

I mean, this is one of the first precise examples of kinds of programming that lead to subtle bugs mentioned in The Practice of Programming.

So this is staying in the patch, sorry.

This is a pretty minor point but this attitude is a little too much for me to take. First, there's pretty much universal agreement that patches should only contain one idea ("separate your changes"), that cleanups should not be mixed in with other changes, etc, etc.

Second, you know as well as I do *why* patches aren't supposed to do this. Adding more lines of changes into your patch is exactly what makes it *harder* for everyone to audit. Every single person who reviews the ipoib part of the patch has to look at that change and waste a few seconds realizing, "oh, I see, the only difference here is a cleanup unrelated to the NAPI conversion." As for "subtle bugs" -- we both know that even the most obviously safe changes always have a chance at introducing a bug, and it's always safer to leave something alone.

So if you want to tinker with the code here, fine, it's just a harmless annoyance -- I can spend the tiny amount of time to check that the change is OK. But don't try to tell me it's good programming practice. I know that you know better: in commit a2fb23af, you had the sense to leave the line

	for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {

alone when you copied it from arch/powerpc, rather than tinkering with known-working code.

Sorry. That's probably way too much time wasted on something so trivial.

Quoted 12 lines
Quoted 4 lines

this goto back to the polling loop is a change in behavior. When we were tuning NAPI, we found that returning in the missed event case and letting the NAPI core call the poll routine later actually performed better, because it allowed more work to pile up.

You weren't using your quantum, which is what you're supposed to do.

Sometimes using your quantum correctly won't perform optimally, but in the interest of fairness and what NAPI wants, that is what you're supposed to do, process work until you hit budget or there is no more work.

Quoted 4 lines

Look, I'm not going to back down to every single tweak in every driver. All the drivers should handle this case consistently, and if I have to edit every single driver to make this patch that is exactly what I am going to do and enforce.

OK, although I think it would be better to put changes in driver behavior into independent patches from the main NAPI change, if only for the sake of bisectability (otherwise everything is just going to bisect back to your mega-patch and that kind of sucks for debugging; cf Linus's reaction to the x86-64 timer conversion patches).

I don't have a lot invested into the details of the NAPI polling here, but I'll ask the IBM people who saw a big difference in performance between jumping back directly or waiting for the poll to be rescheduled to retest and report their results.

Although frankly, I have to say that your position here doesn't make much sense. In your earlier patches that got rid of netif_rx_reschedule(), your suggestion on how to handle the missed event race was to ask the hardware to trigger another event from the poll routine so it got rescheduled. And if the poll routine knows there's more work pending, I don't see much difference in requesting a synthetic event from the hardware and then exiting the poll routine versus raising the poll softirq directly and then exiting the poll routine.

Quoted 3 lines

If you patch the ipoib driver behavior back afterwards, I will NAK that patch every single time unless you make EVERY SINGLE OTHER DRIVER do the same and thus retain the consistency.

At a meta level, I think it would be better for everyone's blood pressure if you tried to keep the temperature down during technical discussions like this. Look back at what I wrote: "this goto ... is a change in behavior," and then I explained the current behavior. I didn't threaten to NAK this NAPI patch, or even ask you to change the patch. I just gave you the information so that you could explain your reasoning in case the change was intended, or so you could keep the current behavior if the change was inadvertent. Being treated with the same level of collegiality that (I think) I treat you with would be appreciated.

- R.

author maintainer
#10 lore raw

From: Roland Dreier <[email protected]>
Date: Tue, 07 Aug 2007 20:56:40 -0700

Quoted 3 lines

First, there's pretty much universal agreement that patches should only contain one idea ("separate your changes"), that cleanups should not be mixed in with other changes, etc, etc.

Fine I'll revert.

Quoted 2 lines

Although frankly, I have to say that your position here doesn't make much sense.

I think it does, the inconsistencies shown in each driver were either 1) unnecessarily being different or 2) causing outright races and bugs (see the discussions between Rusty and myself during the first few revisions).

Quoted 4 lines

In your earlier patches that got rid of netif_rx_reschedule(), your suggestion on how to handle the missed event race was to ask the hardware to trigger another event from the poll routine so it got rescheduled.

And I have rescinded this idea, and the removal of the resched interface, for hardware not capable in response to your feedback.

Quoted 2 lines

Being treated with the same level of collegiality that (I think) I treat you with would be appreciated.

My apologies.

I tend to lose it when people get hyper-critical on a change of which I am doing all of the work editing a large number of drivers and for which everyone benfits.

A message that is not in the archive (sent off-list or not yet received): OFA2F18805.38AA0BD0-ON87257331.005367FB-88257331.0027BEED@us.ibm.com

#12 lore raw
Quoted 4 lines · Shirley Ma

Dave, could you please hold this portion of the patch for a moment. I will test this patch ASAP. According to our previous experience, this changes significant changes some IPoIB driver performance.

If you adjust your quantum while doing that testing you may find an optimal value.
Think of a box where you have other network interfaces, the way you are implementing currently implies you are going to be very unfair to the other interfaces on the box.

cheers,
jamal

author maintainer
#13 lore raw

From: jamal <[email protected]>
Date: Wed, 08 Aug 2007 11:32:34 -0400

Quoted 3 lines

Think of a box where you have other network interfaces, the way you are implementing currently implies you are going to be very unfair to the other interfaces on the box.

This was the point I was trying to make the other day.

What's good for the goose (ipoib) is not necessarily good for the gander and NAPI exists for the gander as much as for the goose.

#14 lore raw
Quoted 7 lines · David Miller

From: jamal <[email protected]>
Date: Wed, 08 Aug 2007 11:32:34 -0400

Quoted 2 lines

Think of a box where you have other network interfaces, the way you
are implementing currently implies you are going to be very unfair to the other interfaces on the box.

This was the point I was trying to make the other day.

Agreed. That's one of the big selling points of NAPI when I talk to people -- the entire system works towards a single equilibrium, when multiple interfaces are under load.

And conversely, without NAPI, the driver has no knowledge of conditions outside its limited view, and resource imbalances inevitably ensue. Particularly so for infiniband, 10gb, etc. where the natural motivation of the driver writer appears to trend towards "performance even at the expense of other system entities."

Jeff

#15 lore raw
In reply to jamal
Quoted 10 lines
Quoted 3 lines

Dave, could you please hold this portion of the patch for a moment. I will test this patch ASAP. According to our previous experience, this changes significant changes some IPoIB driver performance.

If you adjust your quantum while doing that testing you may find an optimal value.

Think of a box where you have other network interfaces, the way you are implementing currently implies you are going to be very unfair to the other interfaces on the box.

Could you explain why this is unfair? This is an honest question: I'm not trying to be difficult, I just don't see how this implementation leads to unfairness. If a driver uses *less* than its full budget in the poll routine, requests that the poll routine be rescheduled and then returns, it seems to me that the effect on other interfaces would be to give them more than their fair share of NAPI processing time.

Also, perhaps it would be a good idea to explain exactly what the ipoib driver is doing in its NAPI poll routine. The difficultly is that the IB "interrupt" semantics are not a perfect fit for NAPI -- in effect, IB just gives us an edge-triggered one-shot interrupt, and so there is an unadvoidable race between detecting that there is no more work to do and enabling the interrupt. It's not worth going into the details of why things are this way, but IB can return a hint that says "you may have missed an event" when enabling the interrupt, which can be used to close the race. So the two implementations being discussed are roughly:

	if (may_have_missed_event &&
	    netif_rx_reschedule(napi))
		goto poll_more;

versus

	if (may_have_missed_event) {
		netif_rx_reschedule(napi))
		return done;
	}

The second one seems to perform better because in the missed event case, it gives a few more packets a chance to arrive so that we can amortize the polling overhead a little more. To be honest, I've never been able to come up with a good story of why the IBM hardware where this makes a measurable difference hits the missed event case enough for it to matter.

The other thing that confuses me about why this is a fairness issue is that if this were a driver where the missed event race didn't happen, when we detected no more work to do, we would just do:

	netif_rx_complete(napi);
	enable_hw_interrupts();
	return done;

and if a packet arrived between netif_rx_complete and enabling interrupts, we would still get an interrupt and so the effect would be to reschedule polling, just via a more inefficient route (going through the HW interrupt handler).

So clarification on this point would be appreciated -- not because I want to continue an argument, but just to improve my understanding of NAPI.

- Roland

#16 lore raw
Quoted 1 line · Roland Dreier

Could you explain why this is unfair?

The simple answer is the core attempts DRR scheduling (search for the paper by Varghese et al for more details)
If you have multiple users of a resource (network interfaces in this case), then the quantum defines their weight. If you use more than your fair quota, then you are being unfair.

Quoted 6 lines

This is an honest question: I'm
not trying to be difficult, I just don't see how this implementation leads to unfairness. If a driver uses *less* than its full budget in the poll routine, requests that the poll routine be rescheduled and then returns, it seems to me that the effect on other interfaces would be to give them more than their fair share of NAPI processing time.

Yes, thats what the "deficit" part of DRR does; however, you still will be unfair by utilizing larger quanta.

Quoted 7 lines

Also, perhaps it would be a good idea to explain exactly what the ipoib driver is doing in its NAPI poll routine. The difficultly is that the IB "interrupt" semantics are not a perfect fit for NAPI -- in effect, IB just gives us an edge-triggered one-shot interrupt, and so there is an unadvoidable race between detecting that there is no more work to do and enabling the interrupt. It's not worth going into the details of why things are this way,

Talk to your vendor (your hardware guys in your case ;->) next time to fix their chip.
The best scheme is to allow a Clear-on-write only on the specific bit/event.

Quoted 3 lines

but IB can return a hint that says
"you may have missed an event" when enabling the interrupt, which can be used to close the race.

Certainly helps. Is this IB specific or hardware specific?

Quoted 9 lines

So the two implementations being discussed
are roughly:

	if (may_have_missed_event &&
	    netif_rx_reschedule(napi))
		goto poll_more;

versus

Quoted 8 lines
	if (may_have_missed_event) {
		netif_rx_reschedule(napi))
		return done;
	}

The second one seems to perform better because in the missed event case, it gives a few more packets a chance to arrive so that we can amortize the polling overhead a little more.

Theory makes sense. Have you validated?

Quoted 4 lines

To be honest, I've never
been able to come up with a good story of why the IBM hardware where this makes a measurable difference hits the missed event case enough for it to matter.

Someone needs to prove one of the schemes is better. Regardless, either scheme seems to me to be viable as long as you dont violate your quantum.

cheers,
jamal

author maintainer
#17 lore raw

From: jamal <[email protected]>
Date: Fri, 10 Aug 2007 09:55:07 -0400

Quoted 9 lines · Roland Dreier
Quoted 2 lines

Could you explain why this is unfair?

The simple answer is the core attempts DRR scheduling (search for the paper by Varghese et al for more details)
If you have multiple users of a resource (network interfaces in this case), then the quantum defines their weight. If you use more than your fair quota, then you are being unfair.

Actually, in the ipoib case they use less than their share :)

When they re-enable interrupts and then recheck for pending events, if events are pending they re-disable interrupts and return immediately instead of looping and trying to use the rest of their available "budget" in-situ.

They do this because the time it takes to return back to the ->poll() invoker and then call back into ->poll() the chip accumulates more work.

If they don't do this it's really easy for them to hit cases where they process one packet, enable interrupts, more events arrive, so re-disable interrupts and loop, over and over again which is very inefficient if that is in fact what happens.

To be honest, it's a workaround for the hardware design and they would do well with even the most minimalist HW irq mitigation assist.

#18 lore raw
In reply to jamal
Quoted 7 lines
Quoted 1 line

Could you explain why this is unfair?

The simple answer is the core attempts DRR scheduling (search for the paper by Varghese et al for more details)
If you have multiple users of a resource (network interfaces in this case), then the quantum defines their weight. If you use more than your fair quota, then you are being unfair.

OK, I think we were talking past each other. As you noted later, the current behavior *is* fair, since it uses less than the full quota. What I couldn't understand was why everyone was telling me that using *less* than a full quota was unfair -- and now I think we all agree that it is fair.

Quoted 3 lines

Talk to your vendor (your hardware guys in your case ;->) next time to fix their chip. The best scheme is to allow a Clear-on-write only on the specific bit/event.

Actually it is more of an IB spec issue than a hardware issue. IPoIB is really more of a protocol than a hardware driver in many ways; one analogy would be PPP, which runs on various serial drivers ranging from an analog modem to cellular data cards using USB serial to PPPoE.

The primitives for event handling that the IB spec defines are such that this NAPI event handling gap is unavoidable. But in fact a lot of IB adapter hardware has somewhat better event handling so that the gap never occurs. We take advantage of this by having the "request event" operation simply be hard-coded never to return the missed event hint on hardware where we know the missed event is impossible by design. However IPoIB has to run on all IB hardware so we can only assume the least-common-denominator behavior, which means we have to have the missed event handling for the hardware where it does apply.

Quoted 5 lines
Quoted 3 lines

The second one seems to perform better because in the missed event case, it gives a few more packets a chance to arrive so that we can amortize the polling overhead a little more.

Theory makes sense. Have you validated?

Yes, IBM (the people with the adapter hardware where this path triggers) did benchmarking and report that allowing the work to pile up makes a huge performance difference. In fact it is kind of suspicious that the difference is huge -- I wouldn't expect the missed event path to be common enough to make that much of a difference, but for some reason it is.

- R.

author maintainer
#19 lore raw
In reply to a message not in the archive

From: Shirley Ma <[email protected]>
Date: Wed, 8 Aug 2007 08:14:13 -0700

Quoted 3 lines

Dave, could you please hold this portion of the patch for a moment. I will test this patch ASAP. According to our previous experience, this changes significant changes some IPoIB driver performance.

I reverted everything Roland had an issue with, I got tired of arguing my position and doing all of the coding too. He won.

#20 lore raw

Dave,

Quoted 2 lines

I reverted everything Roland had an issue with, I got tired of arguing my position and doing all of the coding too. He won.

Thanks. I think the reschedule in the IPoIB poll should maintain fairness.

Shirley

#21 lore raw
In reply to David Miller
Quoted 6 lines
Quoted 3 lines

Dave, could you please hold this portion of the patch for a moment. I will test this patch ASAP. According to our previous experience, this changes significant changes some IPoIB driver performance.

I reverted everything Roland had an issue with, I got tired of arguing my position and doing all of the coding too. He won.

Why does this have to become a contest of wills where someone wins? I wish we could just have a technical discussion and get to the best solution. You posted an RFC, and I commented on the parts where I believe I have some expertise. We're all on the same side here.

Shirley, I think it would still be useful to run benchmarks of IPoIB on ehca with Dave's NAPI patches, both V5 that changed the "missed event" behavior and V6 that didn't. At least I'm curious to know how much the difference is.

- R.

#22 lore raw

Hello Roland,

Quoted 6 lines

Shirley, I think it would still be useful to run benchmarks of IPoIB on ehca with Dave's NAPI patches, both V5 that changed the "missed event" behavior and V6 that didn't. At least I'm curious to know how much the difference is.

- R.

The performance difference was huge before. Most of the time the poll more method was only polling one packet again and agin.
Yes, we will definitely run the performance measurement, but I have lowered this task priority since Dave has V6 version. Actually IPoIB is not the only one device using rescheduling instead of polling more for NAPI. I think it's not a bad idea to do so.

Thanks
Shirley