ia64/linux-2.6.18-xen.hg

changeset 879:2ab54cc40761

netback: optionally return TX responses out-of-order

Add a mode to netback in which it tries to return TX responses in a
slightly less predictable order. This can make some otherwise
hardware-specific frontend bugs reproduce much more easily, which is
obviously rather useful when trying to fix them. It'd also be quite
useful for making sure they didn't happen in the first place.

Randomisation is only done if a module parameter is set, and defaults
to off. It certainly isn't something you'd ever want to run with in
production, but it might be useful for other people developing
frontend drivers. I don't know if that's considered an adequate
reason to apply it, but, if anyone wants it, here it is.

Signed-off-by: Steven Smith <steven.smith@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed May 27 11:21:00 2009 +0100 (2009-05-27)
parents eba6fe6d8d53
children 4ffa9ad54890
files drivers/xen/netback/netback.c
line diff
     1.1 --- a/drivers/xen/netback/netback.c	Tue May 26 11:23:16 2009 +0100
     1.2 +++ b/drivers/xen/netback/netback.c	Wed May 27 11:21:00 2009 +0100
     1.3 @@ -142,6 +142,9 @@ static unsigned int alloc_index = 0;
     1.4  static int MODPARM_copy_skb = 1;
     1.5  module_param_named(copy_skb, MODPARM_copy_skb, bool, 0);
     1.6  MODULE_PARM_DESC(copy_skb, "Copy data received from netfront without netloop");
     1.7 +static int MODPARM_permute_returns = 0;
     1.8 +module_param_named(permute_returns, MODPARM_permute_returns, bool, S_IRUSR|S_IWUSR);
     1.9 +MODULE_PARM_DESC(permute_returns, "Randomly permute the order in which TX responses are sent to the frontend");
    1.10  
    1.11  int netbk_copy_skb_mode;
    1.12  
    1.13 @@ -866,6 +869,25 @@ static inline int copy_pending_req(PEND_
    1.14  				      &mmap_pages[pending_idx]);
    1.15  }
    1.16  
    1.17 +static void permute_dealloc_ring(PEND_RING_IDX dc, PEND_RING_IDX dp)
    1.18 +{
    1.19 +	static unsigned random_src = 0x12345678;
    1.20 +	unsigned dst_offset;
    1.21 +	PEND_RING_IDX dest;
    1.22 +	u16 tmp;
    1.23 +
    1.24 +	while (dc != dp) {
    1.25 +		dst_offset = (random_src / 256) % (dp - dc);
    1.26 +		dest = dc + dst_offset;
    1.27 +		tmp = dealloc_ring[MASK_PEND_IDX(dest)];
    1.28 +		dealloc_ring[MASK_PEND_IDX(dest)] =
    1.29 +			dealloc_ring[MASK_PEND_IDX(dc)];
    1.30 +		dealloc_ring[MASK_PEND_IDX(dc)] = tmp;
    1.31 +		dc++;
    1.32 +		random_src *= 68389;
    1.33 +	}
    1.34 +}
    1.35 +
    1.36  inline static void net_tx_action_dealloc(void)
    1.37  {
    1.38  	struct netbk_tx_pending_inuse *inuse, *n;
    1.39 @@ -888,6 +910,9 @@ inline static void net_tx_action_dealloc
    1.40  		/* Ensure we see all indices enqueued by netif_idx_release(). */
    1.41  		smp_rmb();
    1.42  
    1.43 +		if (MODPARM_permute_returns)
    1.44 +			permute_dealloc_ring(dc, dp);
    1.45 +
    1.46  		while (dc != dp) {
    1.47  			unsigned long pfn;
    1.48