Post · 5 min read· pp. 79–84

The Amd64 Profile Interface

If the HAL’s initialisation of Hardware Performance Counters establishes that the boot processor is from AMD, has 64-bit architecture, and that its support for performance monitoring counters is not masked from Windows by a Microsoft-compatible hypervisor, the HAL chooses the Amd64 profile interface.

Profile Sources

For the purpose of interaction with the kernel, and indeed all the way to user mode through such functions as NtCreateProfile and NtCreateProfileEx, these performance events are abstracted as profile sources, represented numerically by a KPROFILE_SOURCE enumeration. Microsoft’s public definition of this enumeration goes only to 0x18 as ProfileMaximum, presumably having covered sources that are anticipated for arbitrary processor architectures. The Amd64 profile interface in the HAL from the original release of Windows 10 continues with many more:

ValueSymbolSelect
0x00ProfileTime0x00030076
0x02ProfileTotalIssues0x000300C0
0x06ProfileBranchInstructions0x000300C2
0x08ProfileDcacheMisses0x00030041
0x09ProfileIcacheMisses0x00030081
0x0BProfileBranchMispredictions0x000300C3
0x0DProfileFpInstructions0x00030FCB
0x14ProfileIcacheIssues0x00030080
0x15ProfileDcacheAccesses0x00030040
0x19ProfileFPDispatchedFPUOps0x00033F00
0x1AProfileFPDispatchedFPUOpsAddExcludeJunk0x00030100
0x1BProfileFPDispatchedFPUOpsMulExcludeJunk0x00030200
0x1CProfileFPDispatchedFPUOpsStoreExcludeJunk0x00030400
0x1DProfileFPDispatchedFPUOpsAddJunk0x00030800
0x1EProfileFPDispatchedFPUOpsMulJunk0x00031000
0x1FProfileFPDispatchedFPUOpsStoreJunk0x00032000
0x20ProfileFPCyclesNoFPUOpsRetired0x00030001
0x21ProfileFPDispatchedFPUOpsWithFastFlag0x00030002
0x22ProfileLSSegmentRegisterLoad0x00037F20
0x23ProfileLSSegmentRegisterLoadES0x00030120
0x24ProfileLSSegmentRegisterLoadCS0x00030220
0x25ProfileLSSegmentRegisterLoadSS0x00030420
0x26ProfileLSSegmentRegisterLoadDS0x00030820
0x27ProfileLSSegmentRegisterLoadFS0x00031020
0x28ProfileLSSegmentRegisterLoadGS0x00032020
0x29ProfileLSSegmentRegisterLoadHS0x00034020
0x2AProfileLSResyncBySelfModifyingCode0x00030021
0x2BProfileLSResyncBySnoop0x00030022
0x2CProfileLSBuffer2Full0x00030023
0x2DProfileLSLockedOperation0x00030024
0x2EProfileLSLateCancelOperation0x00030025
0x2FProfileLSRetiredCFLUSH0x00030026
0x30ProfileLSRetiredCPUID0x00030027
0x31ProfileDCAccess0x00030040
0x32ProfileDCMiss0x00030041
0x33ProfileDCRefillFromL20x00031F42
0x34ProfileDCRefillFromL2Invalid0x00030142
0x35ProfileDCRefillFromL2Shared0x00030242
0x36ProfileDCRefillFromL2Exclusive0x00030442
0x37ProfileDCRefillFromL2Owner0x00030842
0x38ProfileDCRefillFromL2Modified0x00031042
0x39ProfileDCRefillFromSystem0x00031F43
0x3AProfileDCRefillFromSystemInvalid0x00030143
0x3BProfileDCRefillFromSystemShared0x00030243
0x3CProfileDCRefillFromSystemExclusive0x00030443
0x3DProfileDCRefillFromSystemOwner0x00030843
0x3EProfileDCRefillFromSystemModified0x00031043
0x3FProfileDCRefillCopyBack0x00031F44
0x40ProfileDCRefillCopyBackInvalid0x00030144
0x41ProfileDCRefillCopyBackShared0x00030244
0x42ProfileDCRefillCopyBackExclusive0x00030444
0x43ProfileDCRefillCopyBackOwner0x00030844
0x44ProfileDCRefillCopyBackModified0x00031044
0x45ProfileDCL1DTLBMissL2DTLBHit0x00030745
0x46ProfileDCL1DTLBMissL2DTLBMiss0x00030746
0x47ProfileDCMisaligndDataReference0x00030047
0x48ProfileDCLateCancelOfAccess0x00030048
0x49ProfileDCEarlyCancelOfAccess0x00030049
0x4AProfileDCOneBitECCError0x0003034A
0x4BProfileDCOneBitECCErrorScrubberError0x0003014A
0x4CProfileDCOneBitECCErrorPiggybackScrubberError0x0003024A
0x4DProfileDCDispatchedPrefetchInstructions0x0003074B
0x4EProfileDCDispatchedPrefetchInstructionsLoad0x0003014B
0x4FProfileDCDispatchedPrefetchInstructionsStore0x0003024B
0x50ProfileDCDispatchedPrefetchInstructionsNTA0x0003044B
0x51ProfileBUInternalL2Request0x00031F7D
0x52ProfileBUInternalL2RequestICFill0x0003017D
0x53ProfileBUInternalL2RequestDCFill0x0003027D
0x54ProfileBUInternalL2RequestTLBReload0x0003047D
0x55ProfileBUInternalL2RequestTagSnoopRequest0x0003087D
0x56ProfileBUInternalL2RequestCancelledRequest0x0003107D
0x57ProfileBUFillRequestMissedInL20x0003077E
0x58ProfileBUFillRequestMissedInL2ICFill0x0003017E
0x59ProfileBUFillRequestMissedInL2DCFill0x0003027E
0x5AProfileBUFillRequestMissedInL2TLBLoad0x0003047E
0x5BProfileBUFillIntoL20x0003037F
0x5CProfileBUFillIntoL2DirtyL2Victim0x0003017F
0x5DProfileBUFillIntoL2VictimFromL10x0003027F
0x5EProfileICFetch0x00030080
0x5FProfileICMiss0x00030081
0x60ProfileICRefillFromL20x00030082
0x61ProfileICRefillFromSystem0x00030083
0x62ProfileICL1TLBMissL2TLBHit0x00030084
0x63ProfileICL1TLBMissL2TLBMiss0x00030385
0x64ProfileICResyncBySnoop0x00030086
0x65ProfileICInstructionFetchStall0x00030087
0x66ProfileICReturnStackHit0x00030088
0x67ProfileICReturnStackOverflow0x00030089
0x68ProfileFRRetiredx86Instructions0x000300C0
0x69ProfileFRRetireduops0x000300C1
0x6AProfileFRRetiredBranches0x000300C2
0x6BProfileFRRetiredBranchesMispredicted0x000300C3
0x6CProfileFRRetiredTakenBranches0x000300C4
0x6DProfileFRRetiredTakenBranchesMispredicted0x000300C5
0x6EProfileFRRetiredFarControlTransfers0x000300C6
0x6FProfileFRRetiredResyncsNonControlTransferBranches0x000300C7
0x70ProfileFRRetiredNearReturns0x000300C8
0x71ProfileFRRetiredNearReturnsMispredicted0x000300C9
0x72ProfileFRRetiredTakenBranchMispredictedByAddressMiscompare0x000300CA
0x73ProfileFRRetiredFPUInstructions0x00030FCB
0x74ProfileFRRetiredFPUInstructionsx870x000301CB
0x75ProfileFRRetiredFPUInstructionsMMXAnd3DNow0x000302CB
0x76ProfileFRRetiredFPUInstructionsPackedSSEAndSSE20x000304CB
0x77ProfileFRRetiredFPUInstructionsScalarSSEAndSSE20x000308CB
0x78ProfileFRRetiredFastpathDoubleOpInstructions0x000307CC
0x79ProfileFRRetiredFastpathDoubleOpInstructionsLowOpInPosition00x000301CC
0x7AProfileFRRetiredFastpathDoubleOpInstructionsLowOpInPosition10x000302CC
0x7BProfileFRRetiredFastpathDoubleOpInstructionsLowOpInPosition20x000304CC
0x7CProfileFRInterruptsMaskedCycles0x000300CD
0x7DProfileFRInterruptsMaskedWhilePendingCycles0x000300CE
0x7EProfileFRTakenHardwareInterrupts0x000300CF
0x7FProfileFRNothingToDispatch0x000300D0
0x80ProfileFRDispatchStalls0x000300D1
0x81ProfileFRDispatchStallsFromBranchAbortToRetire0x000300D2
0x82ProfileFRDispatchStallsForSerialization0x000300D3
0x83ProfileFRDispachStallsForSegmentLoad0x000300D4
0x84ProfileFRDispatchStallsWhenReorderBufferFull0x000300D5
0x85ProfileFRDispatchStallsWhenReservationStationsFull0x000300D6
0x86ProfileFRDispatchStallsWhenFPUFull0x000300D7
0x87ProfileFRDispatchStallsWhenLSFull0x000300D8
0x88ProfileFRDispatchStallsWhenWaitingForAllQuiet0x000300D9
0x89ProfileFRDispatchStallsWhenFarControlOrResyncBranchPending0x000300DA
0x8AProfileFRFPUExceptions0x00030FDB
0x8BProfileFRFPUExcpetionsx87ReclassMicroFaults0x000301DB
0x8CProfileFRFPUExceptionsSSERetypeMicroFaults0x000302DB
0x8DProfileFRFPUExceptionsSSEReclassMicroFaults0x000304DB
0x8EProfileFRFPUExceptionsSSEAndx87MicroTraps0x000308DB
0x8FProfileFRNumberOfBreakPointsForDR00x000300DC
0x90ProfileFRNumberOfBreakPointsForDR10x000300DD
0x91ProfileFRNumberOfBreakPointsForDR20x000300DE
0x92ProfileFRNumberOfBreakPointsForDR30x000300DF
0x93ProfileNBMemoryControllerPageAccessEvent0x000307E0
0x94ProfileNBMemoryControllerPageAccessEventPageHit0x000301E0
0x95ProfileNBMemoryControllerPageAccessEventPageMiss0x000302E0
0x96ProfileNBMemoryControllerPageAccessEventPageConflict0x000304E0
0x97ProfileNBMemoryControllerPageTableOverflow0x000300E1
0x98ProfileNBMemoryControllerDRAMCommandSlotsMissed0x000300E2
0x99ProfileNBMemoryControllerTurnAround0x000307E3
0x9AProfileNBMemoryControllerTurnAroundDIMM0x000301E3
0x9BProfileNBMemoryControllerTurnAroundReadToWrite0x000302E3
0x9CProfileNBMemoryControllerTurnAroundWriteToRead0x000304E3
0x9DProfileNBMemoryControllerBypassCounter0x00030FE4
0x9EProfileNBMemoryControllerBypassCounterHighPriority0x000301E4
0x9FProfileNBMemoryControllerBypassCounterLowPriority0x000302E4
0xA0ProfileNBMemoryControllerBypassCounterDRAMControllerInterface0x000304E4
0xA1ProfileNBMemoryControllerBypassCounterDRAMControllerQueue0x000308E4
0xA2ProfileNBSizedCommands0x00037FEB
0xA3ProfileNBSizedCommandsNonPostWrSzByte0x000301EB
0xA4ProfileNBSizedCommandsNonPostWrSzDword0x000302EB
0xA5ProfileNBSizedCommandsWrSzByte0x000304EB
0xA6ProfileNBSizedCommandsWrSzDword0x000308EB
0xA7ProfileNBSizedCommandsRdSzByte0x000310EB
0xA8ProfileNBSizedCommandsRdSzDword0x000320EB
0xA9ProfileNBSizedCommandsRdModWr0x000340EB
0xAAProfileNBProbeResult0x00030FEC
0xABProfileNBProbeResultMiss0x000301EC
0xACProfileNBProbeResultHit0x000302EC
0xADProfileNBProbeResultHitDirtyWithoutMemoryCanceL0x000304EC
0xAEProfileNBProbeResultHitDirtyWithMemoryCancel0x000308EC
0xAFProfileNBHyperTransportBus0Bandwidth0x00030FF6
0xB0ProfileNBHyperTransportBus0BandwidthCommandSent0x000301F6
0xB1ProfileNBHyperTransportBus0BandwidthDataSent0x000302F6
0xB2ProfileNBHyperTransportBus0BandwidthBufferReleaseSent0x000304F6
0xB3ProfileNBHyperTransportBug0BandwidthNopSent0x000308F6
0xB4ProfileNBHyperTransportBus1Bandwidth0x00030FF7
0xB5ProfileNBHyperTransportBus1BandwidthCommandSent0x000301F7
0xB6ProfileNBHyperTransportBus1BandwidthDataSent0x000302F7
0xB7ProfileNBHyperTransportBus1BandwidthBufferReleaseSent0x000304F7
0xB8ProfileNBHyperTransportBus1BandwidthNopSent0x000308F7
0xB9ProfileNBHyperTransportBus2Bandwidth0x00030FF8
0xBAProfileNBHyperTransportBus2BandwidthCommandSent0x000301F8
0xBBProfileNBHyperTransportBus2BandwidthDataSent0x000302F8
0xBCProfileNBHyperTransportBus2BandwidthBufferReleaseSent0x000304F8
0xBDProfileNBHyperTransportBus2BandwidthNopSen0x000308F8
0xBEProfileBUCleanToDirty0x00031063
0xBFProfileBUSharedToDirty0x00032063

Microsoft’s names for values below 0x19 are known from the enumeration’s C-language definition in WDM.H from the Windows Driver Kit (WDK). Presumably, the values from 0x19 and higher are omitted from that definition because they are processor-specific and the definition is meant to be general. Names for the Amd64-specific profile sources are inferred from descriptive strings in the HAL, which can be obtained even from user mode through ZwQuerySystemInformation when given the information class SystemPerformanceTraceInformation (0x1F) and the secondary information class EventTraceProfileSourceListInformation (0x0D) as the first dword in the information buffer. For the values that Microsoft names in KPROFILE_SOURCE, each name is this descriptive string but with Profile as a prefix. Extrapolation of this relationship to the extra values seems at least a reasonable guess.

To each profile source there corresponds a value that must be loaded into a Performance Event Select Register to, well, select the corresponding performance event. The four Performance Event Select Registers are the model-specific registers 0xC0010000 to 0xC0040000. The counters themselves are the model-specific registers 0xC0010004 to 0xC0010007. Initially, the Amd64 profile interface loads zero into each of the declared Performance Event Select Registers.

Except for ProfileTime, which is handled separately, the Amd64-specific profile sources are the complete set. The generally defined profile sources, numbered below 0x19, that the Amd64 profile interface can support are just those that map to the Amd64-specific profile sources. The mapping is not one-to-one: very many more profile sources are available than are generally defined.

For the sake of completeness, note that the Amd64 profile interface requires 8 bytes per counter per processor. The number of counters per processor is fixed at four, as noted above. The number of processors is not known at the time and anyway can change. The HAL allows for the maximum possible number of registered processors, the meaning of which is a small topic in itself. Failure to get the memory, which is almost unthinkable, causes the HAL_MEMORY_ALLOCATION (0xAC) bug check.