ia64/xen-unstable

changeset 14290:42b29f084c31

linux: Use fake carrier flag for netfront/netback rather than the real
netif_carrier_XXX() functions. This makes network bringup much faster.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Mar 07 16:00:47 2007 +0000 (2007-03-07)
parents fbbf1f07fefe
children 7c8dcc5efd12
files linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Wed Mar 07 13:07:12 2007 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Wed Mar 07 16:00:47 2007 +0000
     1.3 @@ -99,9 +99,21 @@ typedef struct netif_st {
     1.4  	struct net_device *dev;
     1.5  	struct net_device_stats stats;
     1.6  
     1.7 +	unsigned int carrier;
     1.8 +
     1.9  	wait_queue_head_t waiting_to_free;
    1.10  } netif_t;
    1.11  
    1.12 +/*
    1.13 + * Implement our own carrier flag: the network stack's version causes delays
    1.14 + * when the carrier is re-enabled (in particular, dev_activate() may not
    1.15 + * immediately be called, which can cause packet loss; also the etherbridge
    1.16 + * can be rather lazy in activating its port).
    1.17 + */
    1.18 +#define netback_carrier_on(netif)	((netif)->carrier = 1)
    1.19 +#define netback_carrier_off(netif)	((netif)->carrier = 0)
    1.20 +#define netback_carrier_ok(netif)	((netif)->carrier)
    1.21 +
    1.22  #define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
    1.23  #define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
    1.24  
    1.25 @@ -120,7 +132,8 @@ int netif_map(netif_t *netif, unsigned l
    1.26  
    1.27  void netif_xenbus_init(void);
    1.28  
    1.29 -#define netif_schedulable(dev) (netif_running(dev) && netif_carrier_ok(dev))
    1.30 +#define netif_schedulable(netif)				\
    1.31 +	(netif_running((netif)->dev) && netback_carrier_ok(netif))
    1.32  
    1.33  void netif_schedule_work(netif_t *netif);
    1.34  void netif_deschedule_work(netif_t *netif);
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Wed Mar 07 13:07:12 2007 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Wed Mar 07 16:00:47 2007 +0000
     2.3 @@ -66,16 +66,19 @@ static void __netif_down(netif_t *netif)
     2.4  static int net_open(struct net_device *dev)
     2.5  {
     2.6  	netif_t *netif = netdev_priv(dev);
     2.7 -	if (netif_carrier_ok(dev))
     2.8 +	if (netback_carrier_ok(netif)) {
     2.9  		__netif_up(netif);
    2.10 +		netif_start_queue(dev);
    2.11 +	}
    2.12  	return 0;
    2.13  }
    2.14  
    2.15  static int net_close(struct net_device *dev)
    2.16  {
    2.17  	netif_t *netif = netdev_priv(dev);
    2.18 -	if (netif_carrier_ok(dev))
    2.19 +	if (netback_carrier_ok(netif))
    2.20  		__netif_down(netif);
    2.21 +	netif_stop_queue(dev);
    2.22  	return 0;
    2.23  }
    2.24  
    2.25 @@ -138,8 +141,6 @@ netif_t *netif_alloc(domid_t domid, unsi
    2.26  		return ERR_PTR(-ENOMEM);
    2.27  	}
    2.28  
    2.29 -	netif_carrier_off(dev);
    2.30 -
    2.31  	netif = netdev_priv(dev);
    2.32  	memset(netif, 0, sizeof(*netif));
    2.33  	netif->domid  = domid;
    2.34 @@ -148,6 +149,8 @@ netif_t *netif_alloc(domid_t domid, unsi
    2.35  	init_waitqueue_head(&netif->waiting_to_free);
    2.36  	netif->dev = dev;
    2.37  
    2.38 +	netback_carrier_off(netif);
    2.39 +
    2.40  	netif->credit_bytes = netif->remaining_credit = ~0UL;
    2.41  	netif->credit_usec  = 0UL;
    2.42  	init_timer(&netif->credit_timeout);
    2.43 @@ -285,7 +288,7 @@ int netif_map(netif_t *netif, unsigned l
    2.44  	netif_get(netif);
    2.45  
    2.46  	rtnl_lock();
    2.47 -	netif_carrier_on(netif->dev);
    2.48 +	netback_carrier_on(netif);
    2.49  	if (netif_running(netif->dev))
    2.50  		__netif_up(netif);
    2.51  	rtnl_unlock();
    2.52 @@ -302,9 +305,10 @@ err_rx:
    2.53  
    2.54  void netif_disconnect(netif_t *netif)
    2.55  {
    2.56 -	if (netif_carrier_ok(netif->dev)) {
    2.57 +	if (netback_carrier_ok(netif)) {
    2.58  		rtnl_lock();
    2.59 -		netif_carrier_off(netif->dev);
    2.60 +		netback_carrier_off(netif);
    2.61 +		netif_carrier_off(netif->dev); /* discard queued packets */
    2.62  		if (netif_running(netif->dev))
    2.63  			__netif_down(netif);
    2.64  		rtnl_unlock();
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Wed Mar 07 13:07:12 2007 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Wed Mar 07 16:00:47 2007 +0000
     3.3 @@ -38,7 +38,7 @@
     3.4  #include <xen/balloon.h>
     3.5  #include <xen/interface/memory.h>
     3.6  
     3.7 -/*#define NETBE_DEBUG_INTERRUPT*/
     3.8 +#define NETBE_DEBUG_INTERRUPT
     3.9  
    3.10  /* extra field used in struct page */
    3.11  #define netif_page_index(pg) (*(long *)&(pg)->mapping)
    3.12 @@ -234,7 +234,7 @@ static inline int netbk_queue_full(netif
    3.13  static void tx_queue_callback(unsigned long data)
    3.14  {
    3.15  	netif_t *netif = (netif_t *)data;
    3.16 -	if (netif_schedulable(netif->dev))
    3.17 +	if (netif_schedulable(netif))
    3.18  		netif_wake_queue(netif->dev);
    3.19  }
    3.20  
    3.21 @@ -245,7 +245,7 @@ int netif_be_start_xmit(struct sk_buff *
    3.22  	BUG_ON(skb->dev != dev);
    3.23  
    3.24  	/* Drop the packet if the target domain has no receive buffers. */
    3.25 -	if (unlikely(!netif_schedulable(dev) || netbk_queue_full(netif)))
    3.26 +	if (unlikely(!netif_schedulable(netif) || netbk_queue_full(netif)))
    3.27  		goto drop;
    3.28  
    3.29  	/*
    3.30 @@ -684,7 +684,7 @@ static void net_rx_action(unsigned long 
    3.31  		}
    3.32  
    3.33  		if (netif_queue_stopped(netif->dev) &&
    3.34 -		    netif_schedulable(netif->dev) &&
    3.35 +		    netif_schedulable(netif) &&
    3.36  		    !netbk_queue_full(netif))
    3.37  			netif_wake_queue(netif->dev);
    3.38  
    3.39 @@ -742,7 +742,7 @@ static void add_to_net_schedule_list_tai
    3.40  
    3.41  	spin_lock_irq(&net_schedule_list_lock);
    3.42  	if (!__on_net_schedule_list(netif) &&
    3.43 -	    likely(netif_schedulable(netif->dev))) {
    3.44 +	    likely(netif_schedulable(netif))) {
    3.45  		list_add_tail(&netif->list, &net_schedule_list);
    3.46  		netif_get(netif);
    3.47  	}
    3.48 @@ -1340,7 +1340,7 @@ irqreturn_t netif_be_int(int irq, void *
    3.49  	add_to_net_schedule_list_tail(netif);
    3.50  	maybe_schedule_tx_action();
    3.51  
    3.52 -	if (netif_schedulable(netif->dev) && !netbk_queue_full(netif))
    3.53 +	if (netif_schedulable(netif) && !netbk_queue_full(netif))
    3.54  		netif_wake_queue(netif->dev);
    3.55  
    3.56  	return IRQ_HANDLED;
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Wed Mar 07 13:07:12 2007 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Wed Mar 07 16:00:47 2007 +0000
     4.3 @@ -338,9 +338,7 @@ static void connect(struct backend_info 
     4.4  
     4.5  	xenbus_switch_state(dev, XenbusStateConnected);
     4.6  
     4.7 -	/* May not get a kick from the frontend, so start the tx_queue now. */
     4.8 -	if (!netbk_can_queue(be->netif->dev))
     4.9 -		netif_wake_queue(be->netif->dev);
    4.10 +	netif_wake_queue(be->netif->dev);
    4.11  }
    4.12  
    4.13  
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Wed Mar 07 13:07:12 2007 +0000
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Wed Mar 07 16:00:47 2007 +0000
     5.3 @@ -154,6 +154,7 @@ struct netfront_info {
     5.4  
     5.5  	unsigned int irq;
     5.6  	unsigned int copying_receiver;
     5.7 +	unsigned int carrier;
     5.8  
     5.9  	/* Receive-ring batched refills. */
    5.10  #define RX_MIN_TARGET 8
    5.11 @@ -193,6 +194,15 @@ struct netfront_rx_info {
    5.12  };
    5.13  
    5.14  /*
    5.15 + * Implement our own carrier flag: the network stack's version causes delays
    5.16 + * when the carrier is re-enabled (in particular, dev_activate() may not
    5.17 + * immediately be called, which can cause packet loss).
    5.18 + */
    5.19 +#define netfront_carrier_on(netif)	((netif)->carrier = 1)
    5.20 +#define netfront_carrier_off(netif)	((netif)->carrier = 0)
    5.21 +#define netfront_carrier_ok(netif)	((netif)->carrier)
    5.22 +
    5.23 +/*
    5.24   * Access macros for acquiring freeing slots in tx_skbs[].
    5.25   */
    5.26  
    5.27 @@ -590,26 +600,6 @@ static int send_fake_arp(struct net_devi
    5.28  	return dev_queue_xmit(skb);
    5.29  }
    5.30  
    5.31 -static int network_open(struct net_device *dev)
    5.32 -{
    5.33 -	struct netfront_info *np = netdev_priv(dev);
    5.34 -
    5.35 -	memset(&np->stats, 0, sizeof(np->stats));
    5.36 -
    5.37 -	spin_lock(&np->rx_lock);
    5.38 -	if (netif_carrier_ok(dev)) {
    5.39 -		network_alloc_rx_buffers(dev);
    5.40 -		np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
    5.41 -		if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
    5.42 -			netif_rx_schedule(dev);
    5.43 -	}
    5.44 -	spin_unlock(&np->rx_lock);
    5.45 -
    5.46 -	netif_start_queue(dev);
    5.47 -
    5.48 -	return 0;
    5.49 -}
    5.50 -
    5.51  static inline int netfront_tx_slot_available(struct netfront_info *np)
    5.52  {
    5.53  	return ((np->tx.req_prod_pvt - np->tx.rsp_cons) <
    5.54 @@ -626,6 +616,26 @@ static inline void network_maybe_wake_tx
    5.55  		netif_wake_queue(dev);
    5.56  }
    5.57  
    5.58 +static int network_open(struct net_device *dev)
    5.59 +{
    5.60 +	struct netfront_info *np = netdev_priv(dev);
    5.61 +
    5.62 +	memset(&np->stats, 0, sizeof(np->stats));
    5.63 +
    5.64 +	spin_lock(&np->rx_lock);
    5.65 +	if (netfront_carrier_ok(np)) {
    5.66 +		network_alloc_rx_buffers(dev);
    5.67 +		np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
    5.68 +		if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
    5.69 +			netif_rx_schedule(dev);
    5.70 +	}
    5.71 +	spin_unlock(&np->rx_lock);
    5.72 +
    5.73 +	network_maybe_wake_tx(dev);
    5.74 +
    5.75 +	return 0;
    5.76 +}
    5.77 +
    5.78  static void network_tx_buf_gc(struct net_device *dev)
    5.79  {
    5.80  	RING_IDX cons, prod;
    5.81 @@ -633,7 +643,7 @@ static void network_tx_buf_gc(struct net
    5.82  	struct netfront_info *np = netdev_priv(dev);
    5.83  	struct sk_buff *skb;
    5.84  
    5.85 -	BUG_ON(!netif_carrier_ok(dev));
    5.86 +	BUG_ON(!netfront_carrier_ok(np));
    5.87  
    5.88  	do {
    5.89  		prod = np->tx.sring->rsp_prod;
    5.90 @@ -703,7 +713,7 @@ static void network_alloc_rx_buffers(str
    5.91  	int nr_flips;
    5.92  	netif_rx_request_t *req;
    5.93  
    5.94 -	if (unlikely(!netif_carrier_ok(dev)))
    5.95 +	if (unlikely(!netfront_carrier_ok(np)))
    5.96  		return;
    5.97  
    5.98  	/*
    5.99 @@ -934,7 +944,7 @@ static int network_start_xmit(struct sk_
   5.100  
   5.101  	spin_lock_irq(&np->tx_lock);
   5.102  
   5.103 -	if (unlikely(!netif_carrier_ok(dev) ||
   5.104 +	if (unlikely(!netfront_carrier_ok(np) ||
   5.105  		     (frags > 1 && !xennet_can_sg(dev)) ||
   5.106  		     netif_needs_gso(dev, skb))) {
   5.107  		spin_unlock_irq(&np->tx_lock);
   5.108 @@ -1024,7 +1034,7 @@ static irqreturn_t netif_int(int irq, vo
   5.109  
   5.110  	spin_lock_irqsave(&np->tx_lock, flags);
   5.111  
   5.112 -	if (likely(netif_carrier_ok(dev))) {
   5.113 +	if (likely(netfront_carrier_ok(np))) {
   5.114  		network_tx_buf_gc(dev);
   5.115  		/* Under tx_lock: protects access to rx shared-ring indexes. */
   5.116  		if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
   5.117 @@ -1299,7 +1309,7 @@ static int netif_poll(struct net_device 
   5.118  
   5.119  	spin_lock(&np->rx_lock);
   5.120  
   5.121 -	if (unlikely(!netif_carrier_ok(dev))) {
   5.122 +	if (unlikely(!netfront_carrier_ok(np))) {
   5.123  		spin_unlock(&np->rx_lock);
   5.124  		return 0;
   5.125  	}
   5.126 @@ -1317,7 +1327,7 @@ static int netif_poll(struct net_device 
   5.127  	work_done = 0;
   5.128  	while ((i != rp) && (work_done < budget)) {
   5.129  		memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx));
   5.130 -		memset(extras, 0, sizeof(extras));
   5.131 +		memset(extras, 0, sizeof(rinfo.extras));
   5.132  
   5.133  		err = xennet_get_responses(np, &rinfo, rp, &tmpq,
   5.134  					   &pages_flipped);
   5.135 @@ -1744,7 +1754,7 @@ static int network_connect(struct net_de
   5.136  	 * domain a kick because we've probably just requeued some
   5.137  	 * packets.
   5.138  	 */
   5.139 -	netif_carrier_on(dev);
   5.140 +	netfront_carrier_on(np);
   5.141  	notify_remote_via_irq(np->irq);
   5.142  	network_tx_buf_gc(dev);
   5.143  	network_alloc_rx_buffers(dev);
   5.144 @@ -1989,7 +1999,7 @@ static struct net_device * __devinit cre
   5.145  
   5.146  	np->netdev = netdev;
   5.147  
   5.148 -	netif_carrier_off(netdev);
   5.149 +	netfront_carrier_off(np);
   5.150  
   5.151  	return netdev;
   5.152  
   5.153 @@ -2023,7 +2033,7 @@ static void netif_disconnect_backend(str
   5.154  	/* Stop old i/f to prevent errors whilst we rebuild the state. */
   5.155  	spin_lock_irq(&info->tx_lock);
   5.156  	spin_lock(&info->rx_lock);
   5.157 -	netif_carrier_off(info->netdev);
   5.158 +	netfront_carrier_off(info);
   5.159  	spin_unlock(&info->rx_lock);
   5.160  	spin_unlock_irq(&info->tx_lock);
   5.161