win-pvdrivers

changeset 253:58ce01887603

fixed a number of particularly stupid bugs. rx performance still sucks greatly. a backup of my test machine still fails.
author James Harper <james.harper@bendigoit.com.au>
date Sat Apr 19 00:36:34 2008 +1000 (2008-04-19)
parents 7e3bcd88515c
children 2d25f964e1d1
files common.inc xennet/xennet.c xennet/xennet.h xennet/xennet_common.c xennet/xennet_rx.c xennet/xennet_tx.c xenscsi/xenscsi.c
line diff
     1.1 --- a/common.inc	Tue Apr 15 23:36:10 2008 +1000
     1.2 +++ b/common.inc	Sat Apr 19 00:36:34 2008 +1000
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.8.8.54
     1.5 +VERSION=0.8.8.65
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  KMDF_VERSION=1
     1.8  !IF $(_NT_TOOLS_VERSION) > 0x700
     2.1 --- a/xennet/xennet.c	Tue Apr 15 23:36:10 2008 +1000
     2.2 +++ b/xennet/xennet.c	Sat Apr 19 00:36:34 2008 +1000
     2.3 @@ -324,7 +324,6 @@ XenNet_Init(
     2.4    xi->state = XenbusStateUnknown;
     2.5    xi->backend_state = XenbusStateUnknown;
     2.6  
     2.7 -  KeInitializeSpinLock(&xi->tx_lock);
     2.8    KeInitializeSpinLock(&xi->rx_lock);
     2.9  
    2.10    InitializeListHead(&xi->tx_waiting_pkt_list);
     3.1 --- a/xennet/xennet.h	Tue Apr 15 23:36:10 2008 +1000
     3.2 +++ b/xennet/xennet.h	Sat Apr 19 00:36:34 2008 +1000
     3.3 @@ -112,7 +112,6 @@ Foundation, Inc., 51 Franklin Street, Fi
     3.4  
     3.5  #define MAX_BUFFERS_PER_PACKET 128
     3.6  
     3.7 -
     3.8  typedef struct {
     3.9    PNDIS_BUFFER mdls[MAX_BUFFERS_PER_PACKET];
    3.10    ULONG mdl_count;
    3.11 @@ -175,7 +174,7 @@ struct xennet_info
    3.12    struct netif_tx_sring *tx_pgs;
    3.13    PMDL tx_mdl;
    3.14    ULONG tx_id_free;
    3.15 -  ULONG tx_no_id_free;
    3.16 +  ULONG tx_no_id_used;
    3.17    USHORT tx_id_list[NET_TX_RING_SIZE];
    3.18    grant_ref_t tx_gref_list[NET_TX_RING_SIZE];
    3.19    PNDIS_PACKET tx_pkts[NET_TX_RING_SIZE];
     4.1 --- a/xennet/xennet_common.c	Tue Apr 15 23:36:10 2008 +1000
     4.2 +++ b/xennet/xennet_common.c	Sat Apr 19 00:36:34 2008 +1000
     4.3 @@ -75,6 +75,13 @@ XenNet_ParsePacketHeader(
     4.4    }
     4.5    pi->ip4_length = GET_NET_USHORT(pi->header[XN_HDR_SIZE + 2]);
     4.6    pi->tcp_header_length = (pi->header[XN_HDR_SIZE + pi->ip4_header_length + 12] & 0xf0) >> 2;
     4.7 +
     4.8 +  if (header_length < (ULONG)(pi->ip4_header_length + pi->tcp_header_length))
     4.9 +  {
    4.10 +    KdPrint((__DRIVER_NAME "     first buffer is only %d bytes long, must be >= %d\n", XN_HDR_SIZE + header_length, (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + pi->tcp_header_length)));
    4.11 +    return PARSE_TOO_SMALL;
    4.12 +  }
    4.13 +
    4.14    pi->tcp_length = pi->ip4_length - pi->ip4_header_length - pi->tcp_header_length;
    4.15    pi->tcp_remaining = pi->tcp_length;
    4.16    pi->tcp_seq = GET_NET_ULONG(pi->header[XN_HDR_SIZE + pi->ip4_header_length + 4]);
     5.1 --- a/xennet/xennet_rx.c	Tue Apr 15 23:36:10 2008 +1000
     5.2 +++ b/xennet/xennet_rx.c	Sat Apr 19 00:36:34 2008 +1000
     5.3 @@ -111,11 +111,14 @@ XenNet_RxBufferAlloc(struct xennet_info 
     5.4    {
     5.5      ASSERT(cycles++ < 256);
     5.6      if (xi->rx_id_free == 0)
     5.7 +    {
     5.8 +      KdPrint((__DRIVER_NAME "     Added %d out of %d buffers to rx ring (ran out of id's)\n", i, batch_target));
     5.9        break;
    5.10 +    }
    5.11      mdl = get_page_from_freelist(xi);
    5.12      if (mdl == NULL)
    5.13      {
    5.14 -      KdPrint((__DRIVER_NAME "     Added %d out of %d buffers to rx ring\n", i, batch_target));
    5.15 +      KdPrint((__DRIVER_NAME "     Added %d out of %d buffers to rx ring (no free pages)\n", i, batch_target));
    5.16        break;
    5.17      }
    5.18      xi->rx_id_free--;
    5.19 @@ -403,7 +406,7 @@ XenNet_RxBufferCheck(struct xennet_info 
    5.20  
    5.21    do {
    5.22      ASSERT(cycles++ < 256);
    5.23 -    prod = min(xi->rx.sring->rsp_prod, xi->rx.rsp_cons + MAXIMUM_PACKETS_PER_INDICATE);
    5.24 +    prod = xi->rx.sring->rsp_prod;
    5.25      KeMemoryBarrier(); /* Ensure we see responses up to 'rp'. */
    5.26  
    5.27      for (cons = xi->rx.rsp_cons; cons != prod; cons++)
    5.28 @@ -468,6 +471,8 @@ XenNet_RxBufferCheck(struct xennet_info 
    5.29        {
    5.30          XenNet_MakePackets(xi, packets, &packet_count);
    5.31          RtlZeroMemory(&xi->rxpi, sizeof(xi->rxpi));
    5.32 +//        if (packet_count >= MAXIMUM_PACKETS_PER_INDICATE)
    5.33 +//          break;
    5.34        }
    5.35      }
    5.36      ASSERT(packet_count < NET_RX_RING_SIZE);
    5.37 @@ -491,6 +496,9 @@ XenNet_RxBufferCheck(struct xennet_info 
    5.38    /* Give netback more buffers */
    5.39    XenNet_RxBufferAlloc(xi);
    5.40  
    5.41 +if (xi->rxpi.more_frags || xi->rxpi.extra_info)
    5.42 +  KdPrint(("Partial receive (more_frags = %d, extra_info = %d, total_length = %d, mdl_count = %d)\n", xi->rxpi.more_frags, xi->rxpi.extra_info, xi->rxpi.total_length, xi->rxpi.mdl_count));
    5.43 +
    5.44    KeReleaseSpinLockFromDpcLevel(&xi->rx_lock);
    5.45  
    5.46  #if defined(XEN_PROFILE)
     6.1 --- a/xennet/xennet_tx.c	Tue Apr 15 23:36:10 2008 +1000
     6.2 +++ b/xennet/xennet_tx.c	Sat Apr 19 00:36:34 2008 +1000
     6.3 @@ -31,13 +31,13 @@ Foundation, Inc., 51 Franklin Street, Fi
     6.4  static ULONG
     6.5  free_requests(struct xennet_info *xi)
     6.6  {
     6.7 -  return xi->tx_id_free;
     6.8 +  return xi->tx_id_free - xi->tx_no_id_used;
     6.9  }
    6.10  
    6.11  static USHORT
    6.12  get_id_from_freelist(struct xennet_info *xi)
    6.13  {
    6.14 -  if (xi->tx_id_free - xi->tx_no_id_free == 0)
    6.15 +  if (xi->tx_id_free - xi->tx_no_id_used == 0)
    6.16      return FREELIST_ID_ERROR;
    6.17    xi->tx_id_free--;
    6.18    return xi->tx_id_list[xi->tx_id_free];
    6.19 @@ -46,9 +46,9 @@ get_id_from_freelist(struct xennet_info 
    6.20  static USHORT
    6.21  get_no_id_from_freelist(struct xennet_info *xi)
    6.22  {
    6.23 -  if (xi->tx_id_free - xi->tx_no_id_free == 0)
    6.24 +  if (xi->tx_id_free - xi->tx_no_id_used == 0)
    6.25      return FREELIST_ID_ERROR;
    6.26 -  xi->tx_no_id_free--;
    6.27 +  xi->tx_no_id_used++;
    6.28    return 0;
    6.29  }
    6.30  
    6.31 @@ -62,7 +62,7 @@ put_id_on_freelist(struct xennet_info *x
    6.32  static VOID
    6.33  put_no_id_on_freelist(struct xennet_info *xi)
    6.34  {
    6.35 -  xi->tx_no_id_free++;
    6.36 +  xi->tx_no_id_used--;
    6.37  }
    6.38  
    6.39  static grant_ref_t
    6.40 @@ -212,6 +212,8 @@ XenNet_PutOnTxRing(
    6.41    return tx;
    6.42  }
    6.43  
    6.44 +static ULONG full_count = 0;
    6.45 +
    6.46  /* Called at DISPATCH_LEVEL with tx_lock held */
    6.47  /*
    6.48   * Send one NDIS_PACKET. This may involve multiple entries on TX ring.
    6.49 @@ -272,8 +274,10 @@ KdPrint((__DRIVER_NAME "     Split heade
    6.50  KdPrint((__DRIVER_NAME "     length = %d\n", length));
    6.51      }
    6.52    }
    6.53 -  if (mss > 0 && mss < pi.tcp_length)
    6.54 +  if (mss > 0 && pi.tcp_length < mss)
    6.55 +  {
    6.56      mss = 0;
    6.57 +  }
    6.58    ASSERT(buffer != NULL);
    6.59    NdisGetNextBuffer(buffer, &buffer);
    6.60    while (buffer != NULL)
    6.61 @@ -286,9 +290,15 @@ KdPrint((__DRIVER_NAME "     length = %d
    6.62    num_elements = NET_TX_RING_SIZE;
    6.63    XenNet_BuildPageList(&pi, elements, &num_elements);
    6.64  
    6.65 +  if (num_elements < pi.mdl_count)
    6.66 +  {
    6.67 +    KdPrint((__DRIVER_NAME "     Less buffers (%d) than mdls (%d)\n", num_elements, pi.mdl_count));
    6.68 +  }
    6.69 +
    6.70    if (num_elements + !!mss > (int)free_requests(xi))
    6.71    {
    6.72 -    KdPrint((__DRIVER_NAME "     Full on send - required = %d, available = %d\n", num_elements + !!mss, (int)free_requests(xi)));
    6.73 +//    KdPrint((__DRIVER_NAME "     Full on send - required = %d, available = %d\n", num_elements + !!mss, (int)free_requests(xi)));
    6.74 +    full_count++;
    6.75      if (merged_buffer)
    6.76        FreePages(merged_buffer);
    6.77      return FALSE;
    6.78 @@ -303,8 +313,8 @@ KdPrint((__DRIVER_NAME "     length = %d
    6.79  
    6.80    if (mss > 0)
    6.81    {
    6.82 -    if (!csum_info->Transmit.NdisPacketTcpChecksum)
    6.83 -      KdPrint((__DRIVER_NAME "     strange... mss set but checksum offload not set\n"));
    6.84 +//    if (!csum_info->Transmit.NdisPacketTcpChecksum)
    6.85 +//      KdPrint((__DRIVER_NAME "     strange... mss set but checksum offload not set\n"));
    6.86      flags |= NETTXF_extra_info | NETTXF_csum_blank | NETTXF_data_validated;
    6.87      XenNet_SumIpHeader(MmGetSystemAddressForMdlSafe(pi.mdls[0], NormalPagePriority), pi.ip4_header_length);
    6.88      PC_INC(ProfCount_TxPacketsLargeOffload);
    6.89 @@ -352,7 +362,6 @@ if (length != total_packet_length) {
    6.90    KdPrint((__DRIVER_NAME "     length (%d) != total_packet_length (%d)\n", length, total_packet_length));
    6.91  }
    6.92  
    6.93 -
    6.94    /* only set the packet on the last buffer, clear more_data */
    6.95    ASSERT(tx);
    6.96    xi->tx_pkts[tx->id] = packet;
    6.97 @@ -417,6 +426,8 @@ XenNet_SendQueuedPackets(struct xennet_i
    6.98  #endif
    6.99  }
   6.100  
   6.101 +static ULONG ndis_outstanding = 0;
   6.102 +
   6.103  // Called at DISPATCH_LEVEL
   6.104  NDIS_STATUS
   6.105  XenNet_TxBufferGC(struct xennet_info *xi)
   6.106 @@ -462,13 +473,14 @@ XenNet_TxBufferGC(struct xennet_info *xi
   6.107          continue; // This would be the response to an extra_info packet
   6.108        }
   6.109  
   6.110 -      id  = txrsp->id;
   6.111 +      id = txrsp->id;
   6.112        packets[packet_count] = xi->tx_pkts[id];
   6.113        if (packets[packet_count])
   6.114        {
   6.115          xi->tx_pkts[id] = NULL;
   6.116          packet_count++;
   6.117          xi->stat_tx_ok++;
   6.118 +        xi->tx_outstanding--;
   6.119        }
   6.120        if (xi->tx_mdls[id])
   6.121        {
   6.122 @@ -495,7 +507,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
   6.123      /* A miniport driver must release any spin lock that it is holding before
   6.124         calling NdisMSendComplete. */
   6.125      NdisMSendComplete(xi->adapter_handle, packets[i], NDIS_STATUS_SUCCESS);
   6.126 -    xi->tx_outstanding--;
   6.127 +ndis_outstanding--;
   6.128    }
   6.129  
   6.130  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   6.131 @@ -543,6 +555,7 @@ XenNet_SendPackets(
   6.132  #if defined(XEN_PROFILE)
   6.133      ProfCount_PacketsPerSendPackets++;
   6.134  #endif
   6.135 +ndis_outstanding++;
   6.136    }
   6.137  
   6.138    XenNet_SendQueuedPackets(xi);
   6.139 @@ -592,11 +605,14 @@ XenNet_TxTimer(
   6.140    UNREFERENCED_PARAMETER(SystemSpecific2);
   6.141    UNREFERENCED_PARAMETER(SystemSpecific3);
   6.142  
   6.143 +  ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
   6.144    KeAcquireSpinLockAtDpcLevel(&xi->tx_lock);
   6.145  
   6.146  //  KdPrint((__DRIVER_NAME " --- tx_timer - lowest = %d\n", xi->tx_page_free_lowest));
   6.147  
   6.148 -  KdPrint((__DRIVER_NAME " --- tx_outstanding = %d\n", xi->tx_outstanding));
   6.149 +  KdPrint((__DRIVER_NAME " --- tx_outstanding = %d, ndis_outstanding = %d, full_count = %d\n", xi->tx_outstanding, ndis_outstanding, full_count));
   6.150 +  KdPrint((__DRIVER_NAME " --- tx_id_free = %d, xi->tx_no_id_used = %d\n", xi->tx_id_free, xi->tx_no_id_used));
   6.151 +
   6.152  
   6.153  #if 0
   6.154    if (xi->tx_page_free_lowest > max(RX_DFL_MIN_TARGET / 4, 16)) // lots of potential for tuning here
   6.155 @@ -655,6 +671,8 @@ XenNet_TxInit(xennet_info_t *xi)
   6.156  {
   6.157    USHORT i;
   6.158  
   6.159 +  KeInitializeSpinLock(&xi->tx_lock);
   6.160 +
   6.161    xi->tx_mdl = AllocatePage();
   6.162    xi->tx_pgs = MmGetMdlVirtualAddress(xi->tx_mdl);
   6.163    SHARED_RING_INIT(xi->tx_pgs);
   6.164 @@ -663,7 +681,7 @@ XenNet_TxInit(xennet_info_t *xi)
   6.165      xi->XenInterface.InterfaceHeader.Context, 0,
   6.166      *MmGetMdlPfnArray(xi->tx_mdl), FALSE, 0);
   6.167    xi->tx_id_free = 0;
   6.168 -  xi->tx_no_id_free = 0;
   6.169 +  xi->tx_no_id_used = 0;
   6.170    for (i = 0; i < NET_TX_RING_SIZE; i++)
   6.171    {
   6.172      xi->tx_pkts[i] = NULL;
     7.1 --- a/xenscsi/xenscsi.c	Tue Apr 15 23:36:10 2008 +1000
     7.2 +++ b/xenscsi/xenscsi.c	Sat Apr 19 00:36:34 2008 +1000
     7.3 @@ -570,8 +570,8 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
     7.4    DeviceData->EnumeratedDevices = 0;
     7.5    DeviceData->TotalInitialDevices = 0;
     7.6  
     7.7 -  if (DeviceData->XenDeviceData->AutoEnumerate)
     7.8 -  {
     7.9 +//  if (DeviceData->XenDeviceData->AutoEnumerate)
    7.10 +//  {
    7.11      msg = DeviceData->XenDeviceData->XenInterface.XenBus_List(
    7.12        DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
    7.13        XBT_NIL, "device/vscsi", &ScsiDevices);
    7.14 @@ -585,7 +585,7 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
    7.15          DeviceData->TotalInitialDevices++;
    7.16        }  
    7.17      }
    7.18 -  }
    7.19 +//  }
    7.20  
    7.21    *Again = FALSE;
    7.22