win-pvdrivers

changeset 183:f2774dbb6257

xennet: reuse buffers, but allocate not on init, but when we run out.
author Andy Grover <andy.grover@oracle.com>
date Tue Feb 12 18:13:29 2008 -0800 (2008-02-12)
parents 1034a8ecd391
children e13475347e4a
files xennet/xennet.c
line diff
     1.1 --- a/xennet/xennet.c	Mon Feb 11 16:18:30 2008 -0800
     1.2 +++ b/xennet/xennet.c	Tue Feb 12 18:13:29 2008 -0800
     1.3 @@ -311,6 +311,8 @@ XenNet_RxBufferAlloc(struct xennet_info 
     1.4    grant_ref_t ref;
     1.5    netif_rx_request_t *req;
     1.6    PLIST_ENTRY entry;
     1.7 +  buffer_entry_t *buffer_entry;
     1.8 +  NDIS_STATUS status;
     1.9  
    1.10  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    1.11  
    1.12 @@ -318,11 +320,27 @@ XenNet_RxBufferAlloc(struct xennet_info 
    1.13  
    1.14    for (i = 0; i < batch_target; i++)
    1.15    {
    1.16 +    /* reuse entries off the free buffer list, unless it's exhausted */
    1.17      entry = RemoveHeadList(&xi->rx_free_buf_list);
    1.18 -    if (entry == &xi->rx_free_buf_list)
    1.19 -      break;
    1.20 -    buffer = CONTAINING_RECORD(entry, buffer_entry_t, entry)->buffer;
    1.21 -    
    1.22 +    if (entry != &xi->rx_free_buf_list)
    1.23 +    {
    1.24 +      buffer = CONTAINING_RECORD(entry, buffer_entry_t, entry)->buffer;
    1.25 +    }
    1.26 +    else
    1.27 +    {
    1.28 +      status = NdisAllocateMemoryWithTag(&buffer_entry,
    1.29 +        sizeof(buffer_entry_t), XENNET_POOL_TAG);
    1.30 +      if (status != NDIS_STATUS_SUCCESS)
    1.31 +      {
    1.32 +        KdPrint(("NdisAllocateMemoryWithTag Failed! status = 0x%x\n", status));
    1.33 +        break;
    1.34 +      }
    1.35 +      NdisAllocateBuffer(&status, &buffer_entry->buffer, xi->buffer_pool,
    1.36 +        buffer_entry, sizeof(buffer_entry->data));
    1.37 +      ASSERT(status == NDIS_STATUS_SUCCESS); // should never fail
    1.38 +      buffer = buffer_entry->buffer;
    1.39 +    }
    1.40 +
    1.41      /* Give to netback */
    1.42      id = (unsigned short)(req_prod + i) & (NET_RX_RING_SIZE - 1);
    1.43      ASSERT(!xi->rx_buffers[id]);
    1.44 @@ -649,7 +667,6 @@ XenNet_Init(
    1.45    char *err;
    1.46    xenbus_transaction_t xbt = 0;
    1.47    KIRQL OldIrql;
    1.48 -  buffer_entry_t *buffer_entry;
    1.49  
    1.50    UNREFERENCED_PARAMETER(OpenErrorStatus);
    1.51    UNREFERENCED_PARAMETER(WrapperConfigurationContext);
    1.52 @@ -867,22 +884,7 @@ XenNet_Init(
    1.53    KdPrint((__DRIVER_NAME "     Connected\n"));
    1.54  
    1.55    KeAcquireSpinLock(&xi->rx_lock, &OldIrql);
    1.56 -
    1.57 -  for (i = 0; i < XN_RX_QUEUE_LEN; i++)
    1.58 -  {
    1.59 -    status = NdisAllocateMemoryWithTag(&buffer_entry, sizeof(buffer_entry_t), XENNET_POOL_TAG);
    1.60 -    if (status != NDIS_STATUS_SUCCESS)
    1.61 -    {
    1.62 -      KdPrint(("NdisAllocateMemoryWithTag Failed! status = 0x%x\n", status));
    1.63 -      break;
    1.64 -    }
    1.65 -    NdisAllocateBuffer(&status, &buffer_entry->buffer, xi->buffer_pool, buffer_entry, sizeof(buffer_entry->data));
    1.66 -    ASSERT(status == NDIS_STATUS_SUCCESS); // should never fail
    1.67 -    InsertTailList(&xi->rx_free_buf_list, &buffer_entry->entry);
    1.68 -  }
    1.69 -
    1.70    XenNet_RxBufferAlloc(xi);
    1.71 -
    1.72    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
    1.73  
    1.74    /* get mac address */