KeQueryPerformanceCounter

UINT64 __fastcall KeQueryPerformanceCounter(_LARGE_INTEGER *PerformanceFrequency){
  void *v1; 
  void *v2; 
  unsigned __int64 v3; 
  INT64 v5; 
  __int64 v6; 
  UINT64 result; 
  __int64 v8; 
  __int64 v9; 
  __int64 v10; 
  __int64 v11; 
  signed __int64 v12; 
  int v13; 
  unsigned __int64 v14; 
  __int64 v15; 
  UINT64 v16; 
  __int64 v17; 
  __int64 v18; 
  unsigned __int64 v19; 
  signed __int64 v20; 
  __int64 v21; 
  __int64 v22; 
  __int64 v23; 
  signed __int64 v24; 
  __int64 v25; 
  __int64 v26; 
  unsigned __int64 v27; 
  signed __int64 v28; 
  int v29; 
  unsigned __int64 v30; 
  __int64 v31; 
  __int64 v32; 
  unsigned __int64 v33; 
  __int64 v34; 
  signed __int32 v35[10]; 
  UINT64 FromFrequency; 

  v5 = HalpPerformanceCounter;
  if( *(_DWORD *)(HalpPerformanceCounter + 228) == 5 )
  {
    FromFrequency = 10000000i64;
    if( HalpTimerReferencePage )
    {
      if( (*(_DWORD *)(HalpPerformanceCounter + 224) & 0x10000) != 0 )
        v6 = *(_QWORD *)(HalpPerformanceCounter + 72)
           + *(_DWORD *)(HalpPerformanceCounter + 80) * KeGetPcr()->Prcb.Number;
      else
        v6 = *(_QWORD *)(HalpPerformanceCounter + 72);
      result = KUSER_SHARED_DATA.QpcBias
             + (((unsigned __int64)(*(__int64(__fastcall **)(__int64))(HalpPerformanceCounter + 112))(v6)
               * (unsigned __int128)*((unsigned __int64 *)HalpTimerReferencePage + 1)) >> 64);
    }
    else
    {
      if( *(_DWORD *)(HalpPerformanceCounter + 220) == 64 )
      {
        HalpTimerGetInternalData((_KDPC *)HalpPerformanceCounter, v1, v2, (PVOID)v3);
        v22 = (*(__int64(__fastcall **)(__int64))(v5 + 112))(v21);
        v23 = *(_QWORD *)(v5 + 208);
        v24 = v22;
      }
      else
      {
        do
        {
          v23 = *(_QWORD *)(v5 + 208);
          do
          {
            v25 = *(_QWORD *)(v5 + 200);
            HalpTimerGetInternalData((_KDPC *)v5, v1, v2, (PVOID)v3);
            v27 = (*(__int64(__fastcall **)(__int64))(v5 + 112))(v26);
            _InterlockedOr(v35, 0);
            v28 = *(_QWORD *)(v5 + 200);
          }
          while( v25 != v28 );
        }
        while( v23 != *(_QWORD *)(v5 + 208) );
        v29 = *(_DWORD *)(v5 + 220);
        v30 = v25 ^ v27;
        if( _bittest64((const __int64 *)&v30, (unsigned __int8)(v29 - 1)) )
        {
          v31 = 1i64;
          if( v29 == 64 )
            v32 = -1i64;
          else
            v32 = (1i64 << v29) - 1;
          if( v29 != 64 )
            v31 = 1i64 << v29;
          v33 = v25 & v32;
          v24 = v27 | v25 ^ v33;
          if( v27 < v33 )
            v24 += v31;
          _InterlockedCompareExchange64((volatile signed __int64 *)(v5 + 200), v24, v28);
        }
        else
        {
          if( v29 == 64 )
            v34 = -1i64;
          else
            v34 = (1i64 << v29) - 1;
          v24 = v27 | v25 & ~v34;
        }
      }
      result = HalpTimerScaleCounter(v23 + v24, *(_QWORD *)(v5 + 192), 0x989680ui64);
    }
  }
  else
  {
    FromFrequency = *(_QWORD *)(HalpPerformanceCounter + 192);
    if( *(_DWORD *)(HalpPerformanceCounter + 220) == 64 )
    {
      HalpTimerGetInternalData((_KDPC *)HalpPerformanceCounter, v1, v2, (PVOID)v3);
      result = *(_QWORD *)(v5 + 208) + (*(__int64(__fastcall **)(__int64))(v5 + 112))(v8);
    }
    else
    {
      do
      {
        v9 = *(_QWORD *)(v5 + 208);
        do
        {
          v10 = *(_QWORD *)(v5 + 200);
          HalpTimerGetInternalData((_KDPC *)v5, v1, v2, (PVOID)v3);
          v3 = (*(__int64(__fastcall **)(__int64))(v5 + 112))(v11);
          _InterlockedOr(v35, 0);
          v12 = *(_QWORD *)(v5 + 200);
        }
        while( v10 != v12 );
      }
      while( v9 != *(_QWORD *)(v5 + 208) );
      v13 = *(_DWORD *)(v5 + 220);
      v14 = v10 ^ v3;
      if( _bittest64((const __int64 *)&v14, (unsigned __int8)(v13 - 1)) )
      {
        if( v13 == 64 )
        {
          v18 = -1i64;
          v17 = 1i64;
        }
        else
        {
          v17 = 1i64 << v13;
          v18 = v17 - 1;
        }
        v19 = v10 & v18;
        v20 = v3 | v10 ^ v19;
        if( v3 < v19 )
          v20 += v17;
        _InterlockedCompareExchange64((volatile signed __int64 *)(v5 + 200), v20, v12);
        result = v9 + v20;
      }
      else
      {
        if( v13 == 64 )
          v15 = -1i64;
        else
          v15 = (1i64 << v13) - 1;
        result = v9 + (v3 | v10 & ~v15);
      }
    }
  }
  if( v5 == HalpOriginalPerformanceCounter || !HalpOriginalPerformanceCounter )
  {
    if( PerformanceFrequency )
      PerformanceFrequency->QuadPart = FromFrequency;
  }
  else
  {
    v16 = *(_QWORD *)(HalpOriginalPerformanceCounter + 192);
    if( *(_DWORD *)(HalpOriginalPerformanceCounter + 228) == 5 )
      v16 = 10000000i64;
    result = HalpTimerScaleCounter(result, FromFrequency, v16);
    if( PerformanceFrequency )
      PerformanceFrequency->QuadPart = v16;
  }
  return result;
}

Referenced by:

Amd64OverflowHandler
BgpFwDisplayBugCheckProgressUpdate
BgpFwDisplayBugCheckScreen
BgpFwQueryPerformanceCounter
CmpRecordShutdownStopTime
EmonOverflowHandler
EtwGetKernelTraceTimestamp
EtwGetKernelTraceTimestampSilo
EtwInitializeSiloState
EtwpAddLogHeader
EtwpCompressPendingBuffers
EtwpGetDurationSince
EtwpGetLoggerTimeStamp
EtwpInitialize
EtwpReserveTraceBuffer
ExpAllocateUuids
HalWheaUpdateCmciPolicy
HalpCmciHandler
HalpCmciInit
HalpCmciLoadThresholdConfiguration
HalpDpReplaceControl
HalpQueryVirtualRtc
HalpSetVirtualRtc
HalpTimerCaptureCloestAuxiliaryQpcPair
HalpTimerCaptureCurrentAuxiliaryQpcPair
HalpTimerDetermineValidTimerPairReadLatency
HalpTimerDpcRoutine
HalpTimerMeasureProcessorsWorker
HalpTimerReadTimerPairWithLatencyLimit
HalpTimerRestorePerformanceCounter
HalpTimerSchedulePeriodicQueries
HalpTscFallback
InitBootProcessor
IoCaptureLiveDump
IopLiveDumpGetMillisecondCounter
IopLiveDumpMirrorPhysicalMemoryCallback
KdInitSystem
KdpSendWaitContinue
KeFreezeExecution
KeInitializeClock
KeInsertSchedulingGroup
KeQuerySchedulingGroupHistory
KeQueryUnbiasedInterruptTimePrecise
KeRebaselineInterruptTime
KeRebaselineSystemTime
KeSwitchFrozenProcessor
KeThawExecution
KiCalibrateTimeAdjustment
KiCheckStall
KiExecuteAllDpcs
KiFreezeTargetExecution
KiIpiGenericCallTarget
KiSetClockTickRate
KiSetupTimeIncrement
KiTimerExpiration
KiUpdateCpuTargetByRate
KiUpdateCpuTargetByWeight
KiUpdateSystemTime
KiUpdateTimeAssist
MiAllocateContiguousMemory
MiAllocatePagesForMdl
MiInitNucleus
MiInitSystem
MiReassessZeroThreads
MiScheduleZeroPageThreads
MiZeroBootLargePages
NtPowerInformation
NtQueryInformationProcess
NtQueryPerformanceCounter
PdcPoCurrentPdcPhase
Phase1Initialization
PnprGetMillisecondCounter
PoBroadcastSystemState
PoInitSystem
PoInitiateProcessorWake
PopDecompressHiberBlocks
PopDeepSleepResiliencyPhaseAccountingBegin
PopDeepSleepResiliencyPhaseAccountingEnd
PopDeepSleepResiliencyPhaseAccountingUpdate
PopExecutePowerAction
PopFxUpdateDeviceIRPhaseAccounting
PopGetIdleTimesCallback
PopHiberCheckForDebugBreak
PopInvokeSystemStateHandler
PopIssueActionRequest
PopResumeApps
PopResumeServices
PopTransitionSystemPowerStateEx
PopUmpoSendFlushSleepStudyLoggerNotification
PopWriteBsdPoInfo
PopWriteImageHeader
PpmIdleInstallConcurrency
PpmIdlePrepare
PpmIdleRemoveConcurrency
PpmIdleSelectStates
PpmIdleSnapConcurrency
PpmIdleSnapConcurrencyIdleTime
PpmIdleTransitionStall
PpmInstallFeedbackCounters
PpmPerfApplyDomainState
PpmPerfApplyProcessorState
PpmRegisterPerfStates
PpmResetIdlePolicy
PpmResetPerformanceAccumulation
PpmTraceExitLatency
PspUserThreadStartup
RtlCapabilityCheck
RtlGetInterruptTimePrecise
RtlGetMultiTimePrecise
RtlGetSystemTimePrecise
RtlpCapChkTelemetryRunOnce
SMKM_STORE_MGR::SmAsyncReadQueueWorker
SMKM_STORE_MGR::SmReadPickStore
ST_STORE::StDeviceIoIssue
ST_STORE::StDmDeviceIoCompletion
ST_STORE::StDmInitialize
ST_STORE::StNpLeafPageIn
StEtaIoStart
StEtaStart
StLcBucketsCopy
StLcInitialize
VfFillAllocatedMemory
ViInitSystemPhase0
WmiGetClock
XmRdtscOp