KeQueryHardwareCounterConfiguration function (ntddk.h)

The KeQueryHardwareCounterConfiguration routine queries the operating system for the list of hardware counters to use for thread profiling.


NTSTATUS KeQueryHardwareCounterConfiguration(
  ULONG             MaximumCount,
  PULONG            Count



[out] A pointer to a caller-allocated buffer into which the routine writes an array of elements of type HARDWARE_COUNTER. Each array element is a structure that contains information about a hardware counter. The array contains one element for each hardware counter that is assigned to thread profiling. If the routine fails, it writes nothing to this buffer.


[in] Specifies the maximum number of elements that the routine can write to the buffer that is pointed to by the CounterArray parameter. The size of the caller-allocated buffer must be at least MaximumCount * sizeof(HARDWARE_COUNTER) bytes.


[out] A pointer to a location into which the routine writes the number of array elements that it has written to the buffer that is pointed to by the CounterArray parameter. If the buffer length that is specified by MaximumCount is not large enough to contain the entire array, the routine writes the required length to *Count and returns STATUS_BUFFER_TOO_SMALL.

Return value

KeQueryHardwareCounterConfiguration returns STATUS_SUCCESS if the call is successful. Possible error return values include the following:

Return code Description
The MaximumCount parameter specifies a buffer length that is not large enough to contain the counter configuration information.
This routine is not implemented for the processor architecture that the caller is running on.


In Windows 7, this routine is implemented only for the x86-based, x64-based, and Itanium-based architectures. If the caller is running on a processor architecture that is not supported, the routine returns STATUS_NOT_IMPLEMENTED.

To set the hardware counter configuration to use for thread profiling, call the KeSetHardwareCounterConfiguration routine.


Minimum supported client Available in Windows 7 and later versions of Windows.
Target Platform Universal
Header ntddk.h (include Ntddk.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe

See also