win-pvdrivers

changeset 201:63780c11acbe

Added some profiling. Batched calls to NdisMIndicateReceivePacket.
author James Harper <james.harper@bendigoit.com.au>
date Thu Feb 28 23:37:17 2008 +1100 (2008-02-28)
parents b29b0e8d9126
children 71b9f608bb80
files common.inc xennet/xennet.c
line diff
     1.1 --- a/common.inc	Thu Feb 28 17:45:08 2008 +1100
     1.2 +++ b/common.inc	Thu Feb 28 23:37:17 2008 +1100
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.8.4.8
     1.5 +VERSION=0.8.4.17
     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	Thu Feb 28 17:45:08 2008 +1100
     2.2 +++ b/xennet/xennet.c	Thu Feb 28 23:37:17 2008 +1100
     2.3 @@ -50,6 +50,26 @@ struct _buffer_entry
     2.4    PNDIS_BUFFER buffer;
     2.5  } typedef buffer_entry_t;
     2.6  
     2.7 +static LARGE_INTEGER ProfTime_TxBufferGC;
     2.8 +static LARGE_INTEGER ProfTime_TxBufferFree;
     2.9 +static LARGE_INTEGER ProfTime_RxBufferAlloc;
    2.10 +static LARGE_INTEGER ProfTime_RxBufferFree;
    2.11 +static LARGE_INTEGER ProfTime_ReturnPacket;
    2.12 +static LARGE_INTEGER ProfTime_RxBufferCheck;
    2.13 +static LARGE_INTEGER ProfTime_Linearize;
    2.14 +static LARGE_INTEGER ProfTime_SendPackets;
    2.15 +static LARGE_INTEGER ProfTime_SendQueuedPackets;
    2.16 +
    2.17 +static int ProfCount_TxBufferGC;
    2.18 +static int ProfCount_TxBufferFree;
    2.19 +static int ProfCount_RxBufferAlloc;
    2.20 +static int ProfCount_RxBufferFree;
    2.21 +static int ProfCount_ReturnPacket;
    2.22 +static int ProfCount_RxBufferCheck;
    2.23 +static int ProfCount_Linearize;
    2.24 +static int ProfCount_SendPackets;
    2.25 +static int ProfCount_SendQueuedPackets;
    2.26 +
    2.27  struct xennet_info
    2.28  {
    2.29    /* Base device vars */
    2.30 @@ -192,11 +212,14 @@ XenNet_TxBufferGC(struct xennet_info *xi
    2.31    PMDL pmdl;
    2.32    KIRQL OldIrql;
    2.33    PVOID ptr;
    2.34 +  LARGE_INTEGER tsc, dummy;
    2.35  
    2.36    ASSERT(xi->connected);
    2.37  
    2.38  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.39  
    2.40 +  tsc = KeQueryPerformanceCounter(&dummy);
    2.41 +
    2.42    KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
    2.43  
    2.44    do {
    2.45 @@ -249,6 +272,9 @@ XenNet_TxBufferGC(struct xennet_info *xi
    2.46  
    2.47  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.48  
    2.49 +  ProfTime_TxBufferGC.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
    2.50 +  ProfCount_TxBufferGC++;
    2.51 +
    2.52    return NDIS_STATUS_SUCCESS;
    2.53  }
    2.54  
    2.55 @@ -313,8 +339,10 @@ XenNet_RxBufferAlloc(struct xennet_info 
    2.56    PLIST_ENTRY entry;
    2.57    buffer_entry_t *buffer_entry;
    2.58    NDIS_STATUS status;
    2.59 +  LARGE_INTEGER tsc, dummy;
    2.60  
    2.61  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.62 +  tsc = KeQueryPerformanceCounter(&dummy);
    2.63  
    2.64    batch_target = xi->rx_target - (req_prod - xi->rx.rsp_cons);
    2.65  
    2.66 @@ -367,6 +395,9 @@ XenNet_RxBufferAlloc(struct xennet_info 
    2.67  
    2.68  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.69  
    2.70 +  ProfTime_RxBufferAlloc.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
    2.71 +  ProfCount_RxBufferAlloc++;
    2.72 +
    2.73    return NDIS_STATUS_SUCCESS;
    2.74  }
    2.75  
    2.76 @@ -381,9 +412,12 @@ XenNet_RxBufferFree(struct xennet_info *
    2.77    PVOID buff_va;
    2.78    PLIST_ENTRY entry;
    2.79    int ungranted;
    2.80 +  LARGE_INTEGER tsc, dummy;
    2.81  
    2.82    ASSERT(!xi->connected);
    2.83  
    2.84 +  tsc = KeQueryPerformanceCounter(&dummy);
    2.85 +
    2.86    KeAcquireSpinLock(&xi->rx_lock, &OldIrql);
    2.87  
    2.88    for (i = 0; i < NET_RX_RING_SIZE; i++)
    2.89 @@ -416,6 +450,9 @@ XenNet_RxBufferFree(struct xennet_info *
    2.90    }
    2.91  
    2.92    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
    2.93 +
    2.94 +  ProfTime_RxBufferFree.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
    2.95 +  ProfCount_RxBufferFree++;
    2.96  }
    2.97  
    2.98  VOID
    2.99 @@ -427,9 +464,12 @@ XenNet_ReturnPacket(
   2.100    struct xennet_info *xi = MiniportAdapterContext;
   2.101    PNDIS_BUFFER buffer;
   2.102    buffer_entry_t *buffer_entry;
   2.103 +  LARGE_INTEGER tsc, dummy;
   2.104  
   2.105  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.106  
   2.107 +  tsc = KeQueryPerformanceCounter(&dummy);
   2.108 +
   2.109    NdisUnchainBufferAtBack(Packet, &buffer);
   2.110    while (buffer)
   2.111    {
   2.112 @@ -448,6 +488,9 @@ XenNet_ReturnPacket(
   2.113      KeSetEvent(&xi->shutdown_event, 1, FALSE);  
   2.114  
   2.115  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.116 +
   2.117 +  ProfTime_ReturnPacket.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
   2.118 +  ProfCount_ReturnPacket++;
   2.119  }
   2.120  
   2.121  // Called at DISPATCH_LEVEL
   2.122 @@ -455,20 +498,25 @@ static NDIS_STATUS
   2.123  XenNet_RxBufferCheck(struct xennet_info *xi)
   2.124  {
   2.125    RING_IDX cons, prod;
   2.126 -  PNDIS_PACKET packet = NULL;
   2.127 +  PNDIS_PACKET packets[NET_RX_RING_SIZE];
   2.128 +  ULONG packet_count;
   2.129    PNDIS_BUFFER buffer;
   2.130    int moretodo;
   2.131    KIRQL OldIrql;
   2.132    struct netif_rx_response *rxrsp = NULL;
   2.133    int more_frags = 0;
   2.134    NDIS_STATUS status;
   2.135 +  LARGE_INTEGER tsc, dummy;
   2.136    
   2.137  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.138  
   2.139 +  tsc = KeQueryPerformanceCounter(&dummy);
   2.140 +
   2.141    ASSERT(xi->connected);
   2.142  
   2.143    KeAcquireSpinLock(&xi->rx_lock, &OldIrql);
   2.144  
   2.145 +  packet_count = 0;
   2.146    do {
   2.147      prod = xi->rx.sring->rsp_prod;
   2.148      KeMemoryBarrier(); /* Ensure we see responses up to 'rp'. */
   2.149 @@ -486,15 +534,15 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.150  
   2.151        if (!more_frags) // handling the packet's 1st buffer
   2.152        {
   2.153 -        NdisAllocatePacket(&status, &packet, xi->packet_pool);
   2.154 +        NdisAllocatePacket(&status, &packets[packet_count], xi->packet_pool);
   2.155          ASSERT(status == NDIS_STATUS_SUCCESS);
   2.156 -        NDIS_SET_PACKET_HEADER_SIZE(packet, XN_HDR_SIZE);
   2.157 +        NDIS_SET_PACKET_HEADER_SIZE(packets[packet_count], XN_HDR_SIZE);
   2.158        }
   2.159  
   2.160        buffer = xi->rx_buffers[rxrsp->id];
   2.161        xi->rx_buffers[rxrsp->id] = NULL;
   2.162        NdisAdjustBufferLength(buffer, rxrsp->status);
   2.163 -      NdisChainBufferAtBack(packet, buffer);
   2.164 +      NdisChainBufferAtBack(packets[packet_count], buffer);
   2.165        xi->XenInterface.GntTbl_EndAccess(xi->XenInterface.InterfaceHeader.Context,
   2.166          xi->grant_rx_ref[rxrsp->id]);
   2.167        xi->grant_rx_ref[rxrsp->id] = GRANT_INVALID_REF;
   2.168 @@ -508,8 +556,13 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.169        {
   2.170          xi->stat_rx_ok++;
   2.171          InterlockedIncrement(&xi->rx_outstanding);
   2.172 -        NDIS_SET_PACKET_STATUS(packet, NDIS_STATUS_SUCCESS);
   2.173 -        NdisMIndicateReceivePacket(xi->adapter_handle, &packet, 1);
   2.174 +        NDIS_SET_PACKET_STATUS(packets[packet_count], NDIS_STATUS_SUCCESS);
   2.175 +        packet_count++;
   2.176 +        if (packet_count == NET_RX_RING_SIZE)
   2.177 +        {
   2.178 +          NdisMIndicateReceivePacket(xi->adapter_handle, packets, packet_count);
   2.179 +          packet_count = 0;
   2.180 +        }
   2.181        }
   2.182      }
   2.183      xi->rx.rsp_cons = prod;
   2.184 @@ -520,7 +573,12 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.185    if (more_frags)
   2.186    {
   2.187      KdPrint((__DRIVER_NAME "     Missing fragments\n"));
   2.188 -    XenNet_ReturnPacket(xi, packet);
   2.189 +    XenNet_ReturnPacket(xi, packets[packet_count]);
   2.190 +  }
   2.191 +
   2.192 +  if (packet_count != 0)
   2.193 +  {
   2.194 +    NdisMIndicateReceivePacket(xi->adapter_handle, packets, packet_count);
   2.195    }
   2.196  
   2.197    /* Give netback more buffers */
   2.198 @@ -530,6 +588,9 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.199  
   2.200  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.201  
   2.202 +  ProfTime_RxBufferCheck.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
   2.203 +  ProfCount_RxBufferCheck++;
   2.204 +
   2.205    return NDIS_STATUS_SUCCESS;
   2.206  }
   2.207  
   2.208 @@ -1437,9 +1498,14 @@ XenNet_Linearize(PNDIS_PACKET Packet)
   2.209    PVOID buff_va;
   2.210    UINT buff_len;
   2.211    UINT tot_buff_len;
   2.212 +  LARGE_INTEGER tsc, dummy;
   2.213 +  KIRQL OldIrql;
   2.214  
   2.215  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.216  
   2.217 +  KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);  
   2.218 +  tsc = KeQueryPerformanceCounter(&dummy);
   2.219 +
   2.220    NdisGetFirstBufferFromPacketSafe(Packet, &buffer, &buff_va, &buff_len,
   2.221      &tot_buff_len, NormalPagePriority);
   2.222    ASSERT(tot_buff_len <= XN_MAX_PKT_SIZE);
   2.223 @@ -1469,6 +1535,11 @@ XenNet_Linearize(PNDIS_PACKET Packet)
   2.224    }
   2.225  
   2.226  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.227 +  ProfTime_Linearize.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
   2.228 +  ProfCount_Linearize++;
   2.229 +
   2.230 +  KeLowerIrql(OldIrql);
   2.231 +
   2.232    return pmdl;
   2.233  }
   2.234  
   2.235 @@ -1483,7 +1554,12 @@ XenNet_SendQueuedPackets(struct xennet_i
   2.236    int notify;
   2.237    PMDL pmdl;
   2.238    UINT pkt_size;
   2.239 +  LARGE_INTEGER tsc, dummy;
   2.240 +  KIRQL OldIrql2;
   2.241  
   2.242 +  KeRaiseIrql(DISPATCH_LEVEL, &OldIrql2);
   2.243 +
   2.244 +  tsc = KeQueryPerformanceCounter(&dummy);
   2.245    KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
   2.246  
   2.247    entry = RemoveHeadList(&xi->tx_waiting_pkt_list);
   2.248 @@ -1530,6 +1606,10 @@ XenNet_SendQueuedPackets(struct xennet_i
   2.249    }
   2.250  
   2.251    KeReleaseSpinLock(&xi->tx_lock, OldIrql);
   2.252 +  ProfTime_SendQueuedPackets.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
   2.253 +  ProfCount_SendQueuedPackets++;
   2.254 +
   2.255 +  KeLowerIrql(OldIrql2);
   2.256  }
   2.257  
   2.258  VOID
   2.259 @@ -1545,7 +1625,12 @@ XenNet_SendPackets(
   2.260    PMDL pmdl;
   2.261    PLIST_ENTRY entry;
   2.262    KIRQL OldIrql;
   2.263 +  LARGE_INTEGER tsc, dummy;
   2.264 +  KIRQL OldIrql2;
   2.265  
   2.266 +  KeRaiseIrql(DISPATCH_LEVEL, &OldIrql2);
   2.267 +
   2.268 +  tsc = KeQueryPerformanceCounter(&dummy);
   2.269    //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.270    for (i = 0; i < NumberOfPackets; i++)
   2.271    {
   2.272 @@ -1575,7 +1660,23 @@ XenNet_SendPackets(
   2.273      KeReleaseSpinLock(&xi->tx_lock, OldIrql);
   2.274      InterlockedIncrement(&xi->tx_outstanding);
   2.275    }
   2.276 +  ProfTime_SendPackets.QuadPart += KeQueryPerformanceCounter(&dummy).QuadPart - tsc.QuadPart;
   2.277 +  ProfCount_SendPackets++;
   2.278 +  KeLowerIrql(OldIrql2);
   2.279    XenNet_SendQueuedPackets(xi);
   2.280 +
   2.281 +  if ((ProfCount_SendPackets & 1023) == 0)
   2.282 +  {
   2.283 +    KdPrint((__DRIVER_NAME "     TxBufferGC        Count = %10d, Avg Time = %10ld\n", ProfCount_TxBufferGC, (ProfCount_TxBufferGC == 0)?0:(ProfTime_TxBufferGC.QuadPart / ProfCount_TxBufferGC)));
   2.284 +    KdPrint((__DRIVER_NAME "     TxBufferFree      Count = %10d, Avg Time = %10ld\n", ProfCount_TxBufferFree, (ProfCount_TxBufferFree == 0)?0:(ProfTime_TxBufferFree.QuadPart / ProfCount_TxBufferFree)));
   2.285 +    KdPrint((__DRIVER_NAME "     RxBufferAlloc     Count = %10d, Avg Time = %10ld\n", ProfCount_RxBufferAlloc, (ProfCount_RxBufferAlloc == 0)?0:(ProfTime_RxBufferAlloc.QuadPart / ProfCount_RxBufferAlloc)));
   2.286 +    KdPrint((__DRIVER_NAME "     RxBufferFree      Count = %10d, Avg Time = %10ld\n", ProfCount_RxBufferFree, (ProfCount_RxBufferFree == 0)?0:(ProfTime_RxBufferFree.QuadPart / ProfCount_RxBufferFree)));
   2.287 +    KdPrint((__DRIVER_NAME "     ReturnPacket      Count = %10d, Avg Time = %10ld\n", ProfCount_ReturnPacket, (ProfCount_ReturnPacket == 0)?0:(ProfTime_ReturnPacket.QuadPart / ProfCount_ReturnPacket)));
   2.288 +    KdPrint((__DRIVER_NAME "     RxBufferCheck     Count = %10d, Avg Time = %10ld\n", ProfCount_RxBufferCheck, (ProfCount_RxBufferCheck == 0)?0:(ProfTime_RxBufferCheck.QuadPart / ProfCount_RxBufferCheck)));
   2.289 +    KdPrint((__DRIVER_NAME "     Linearize         Count = %10d, Avg Time = %10ld\n", ProfCount_Linearize, (ProfCount_Linearize == 0)?0:(ProfTime_Linearize.QuadPart / ProfCount_Linearize)));
   2.290 +    KdPrint((__DRIVER_NAME "     SendPackets       Count = %10d, Avg Time = %10ld\n", ProfCount_SendPackets, (ProfCount_SendPackets == 0)?0:(ProfTime_SendPackets.QuadPart / ProfCount_SendPackets)));
   2.291 +    KdPrint((__DRIVER_NAME "     SendQueuedPackets Count = %10d, Avg Time = %10ld\n", ProfCount_SendQueuedPackets, (ProfCount_SendQueuedPackets == 0)?0:(ProfTime_SendQueuedPackets.QuadPart / ProfCount_SendQueuedPackets)));
   2.292 +  }
   2.293    //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.294  }
   2.295  
   2.296 @@ -1727,6 +1828,27 @@ DriverEntry(
   2.297    NDIS_HANDLE ndis_wrapper_handle;
   2.298    NDIS_MINIPORT_CHARACTERISTICS mini_chars;
   2.299  
   2.300 +
   2.301 +  ProfTime_TxBufferGC.QuadPart = 0;
   2.302 +  ProfTime_TxBufferFree.QuadPart = 0;
   2.303 +  ProfTime_RxBufferAlloc.QuadPart = 0;
   2.304 +  ProfTime_RxBufferFree.QuadPart = 0;
   2.305 +  ProfTime_ReturnPacket.QuadPart = 0;
   2.306 +  ProfTime_RxBufferCheck.QuadPart = 0;
   2.307 +  ProfTime_Linearize.QuadPart = 0;
   2.308 +  ProfTime_SendPackets.QuadPart = 0;
   2.309 +  ProfTime_SendQueuedPackets.QuadPart = 0;
   2.310 +
   2.311 +  ProfCount_TxBufferGC = 0;
   2.312 +  ProfCount_TxBufferFree = 0;
   2.313 +  ProfCount_RxBufferAlloc = 0;
   2.314 +  ProfCount_RxBufferFree = 0;
   2.315 +  ProfCount_ReturnPacket = 0;
   2.316 +  ProfCount_RxBufferCheck = 0;
   2.317 +  ProfCount_Linearize = 0;
   2.318 +  ProfCount_SendPackets = 0;
   2.319 +  ProfCount_SendQueuedPackets = 0;
   2.320 +
   2.321    RtlZeroMemory(&mini_chars, sizeof(mini_chars));
   2.322  
   2.323    WDF_DRIVER_CONFIG_INIT(&config, WDF_NO_EVENT_CALLBACK);