Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.0 KiB

  1. // Copyright (c) 1999-2000 Microsoft Corporation
  2. ///======================================================================
  3. //
  4. // Perf.h
  5. //
  6. // Fill in this header file with definitions for the performance
  7. // counters you want to use.
  8. //
  9. ///======================================================================
  10. #ifndef _PERF_H_
  11. #define _PERF_H_
  12. //**********************************************************************
  13. //
  14. // Modify this section for your counters
  15. //
  16. #define DRV_NAME "WCEUSBSH"
  17. //
  18. // Define PERFORMANCE to "1" turn on the cycle performance counters.
  19. // I currently set it in the debug build (or explicitely in SOURCES for free build) since
  20. // the free build only sees a slight gain IFF *all* debug tracing (except DBG_ERR)
  21. // is turned off.
  22. //
  23. #if DBG
  24. #if !defined(MSFT_NT_BUILD)
  25. #define PERFORMANCE 1
  26. #endif
  27. #endif
  28. //
  29. // This is the array of counter index definitions.
  30. // Note that when a new entry is added here that the name array
  31. // in perf.c must be updated as well. The convention is that
  32. // the index name should match the function name identically, with
  33. // the PERF_ prefix.
  34. //
  35. enum {
  36. //
  37. // Write path
  38. //
  39. PERF_Write,
  40. PERF_WriteComplete,
  41. PERF_WriteTimeout,
  42. //
  43. // Read path
  44. //
  45. PERF_StartUsbReadWorkItem,
  46. PERF_UsbRead,
  47. PERF_UsbReadCompletion,
  48. PERF_CheckForQueuedUserReads,
  49. PERF_GetUserData,
  50. PERF_PutUserData,
  51. PERF_CancelUsbReadIrp,
  52. PERF_Read,
  53. PERF_StartOrQueueIrp,
  54. PERF_StartUserRead,
  55. PERF_GetNextUserIrp,
  56. PERF_CancelCurrentRead,
  57. PERF_CancelQueuedIrp,
  58. PERF_ReadTimeout,
  59. PERF_IntervalReadTimeout,
  60. PERF_CancelUsbReadWorkItem,
  61. //
  62. // USB Path
  63. //
  64. PERF_UsbReadWritePacket,
  65. //
  66. // Serial path
  67. //
  68. PERF_ProcessSerialWaits,
  69. //
  70. // Utils
  71. //
  72. PERF_TryToCompleteCurrentIrp,
  73. PERF_RundownIrpRefs,
  74. PERF_RecycleIrp,
  75. PERF_ReuseIrp,
  76. PERF_CalculateTimeout,
  77. //
  78. // leave this entry alone
  79. //
  80. NUM_PERF_COUNTERS
  81. } PERF_INDICED;
  82. //
  83. // End of user-modified portion
  84. //
  85. //**********************************************************************
  86. typedef struct {
  87. KSPIN_LOCK Lock;
  88. LONG Count;
  89. LARGE_INTEGER TotalCycles;
  90. } PERF_COUNTER, *PPERF_COUNTER;
  91. #if PERFORMANCE
  92. extern PERF_COUNTER PerfCounter[];
  93. //
  94. // Definition for raw bytes that generate RDTSC instruction
  95. //
  96. #define RDTSC(_VAR) \
  97. _asm { \
  98. _asm push eax \
  99. _asm push edx \
  100. _asm _emit 0Fh \
  101. _asm _emit 31h \
  102. _asm mov _VAR.LowPart, eax \
  103. _asm mov _VAR.HighPart, edx \
  104. _asm pop edx \
  105. _asm pop eax \
  106. }
  107. //
  108. // Definitions for performance counters that execute
  109. // at DISPATCH_LEVEL (e.g. in DPCs) and lower IRQLs.
  110. //
  111. // NOTE: we read the cycle counter at the outside of the
  112. // macros since we compensate for the overhead of the macros themselves.
  113. //
  114. #define PERF_ENTRY(_INDEX) \
  115. LARGE_INTEGER _INDEX##perfStart; \
  116. LARGE_INTEGER _INDEX##perfEnd; \
  117. RDTSC(_INDEX##perfStart); \
  118. InterlockedIncrement( &PerfCounter[_INDEX].Count )
  119. #define PERF_EXIT(_INDEX) \
  120. RDTSC(_INDEX##perfEnd); \
  121. _INDEX##perfEnd.QuadPart -= _INDEX##perfStart.QuadPart; \
  122. ExInterlockedAddLargeInteger( &PerfCounter[_INDEX].TotalCycles, \
  123. _INDEX##perfEnd, \
  124. &PerfCounter[_INDEX].Lock )
  125. //
  126. // Definitions for performance counters that execute
  127. // in ISRs, and hence need no locking
  128. //
  129. #define PERF_ISR_ENTRY(_INDEX) PERF_ENTRY(_INDEX)
  130. #define PERF_ISR_EXIT(_INDEX) \
  131. _INDEX##perfEnd.QuadPart -= _INDEX##perfStart.QuadPart; \
  132. PerfCounter[_INDEX].TotalCycles.QuadPart += _INDEX##perfEnd.QuadPart; \
  133. RDTSC(_INDEX##perfEnd)
  134. #else // PERFORMANCE
  135. #define PERF_ENTRY(_INDEX)
  136. #define PERF_EXIT(_INDEX)
  137. #endif PERFORMANCE
  138. //
  139. // Externs for perf.c
  140. //
  141. VOID InitPerfCounters();
  142. VOID DumpPerfCounters();
  143. #endif _PERF_H_