KiStartThreadCycleAccumulation

VOID __stdcall KiStartThreadCycleAccumulation(_KPRCB *Prcb, _ETHREAD *CurrentThread, UINT8 DispatchInterruptActive){
  unsigned __int64 v6; 
  unsigned __int64 v7; 
  UINT64 v8; 
  _PROC_PERF_DOMAIN *Domain; 
  _PROC_PERF_CONSTRAINT *Constraint; 
  unsigned int LatestFrequencyPercent; 
  unsigned int v12; 
  char v13; 
  bool v14; 
  _BYTE *SchedulerAssist; 

  v6 = __rdtsc();
  v7 = v6 - Prcb->StartCycles;
  Prcb->CycleTime += v7;
  v8 = (unsigned __int8)CurrentThread->Tcb.gap0[2];
  if( (v8 & 0x20) != 0 )
  {
    Domain = Prcb->PowerState.CheckContext.Domain;
    Constraint = Prcb->PowerState.CheckContext.Constraint;
    if( !Domain || !Constraint )
      goto LABEL_8;
    if( Constraint->Selection.Autonomous )
    {
      LatestFrequencyPercent = Constraint->LatestFrequencyPercent;
    }
    else
    {
      LatestFrequencyPercent = Constraint->Selection.SelectedPercent;
      if( LatestFrequencyPercent >= Domain->GuaranteedPercent )
        LatestFrequencyPercent = Domain->GuaranteedPercent;
    }
    if( LatestFrequencyPercent < 0x4B )
      v12 = LatestFrequencyPercent / 0x19;
    else
LABEL_8:
      v12 = 3;
    Prcb->Cycles[v12][Prcb->PowerState.ArchitecturalEfficiencyClass] += v7;
    v8 = (unsigned __int8)CurrentThread->Tcb.gap0[2];
  }
  if( (v8 & 0x40) != 0 )
  {
    SchedulerAssist = CurrentThread->Tcb.SchedulerAssist;
    if( SchedulerAssist )
      SchedulerAssist[64] = 1;
  }
  Prcb->StartCycles = v6;
  v13 = CurrentThread->Tcb.gap0[2];
  if( (v13 & 0x10) != 0 )
  {
    Prcb->TaggedCyclesStart = v6;
    v13 = CurrentThread->Tcb.gap0[2];
  }
  if( (v13 & 2) != 0 )
    KiBeginCounterAccumulation(&CurrentThread->Tcb, 0);
  v14 = Prcb->InterruptRequest == 0;
  Prcb->NestingLevel = 0;
  if( !v14 )
  {
    Prcb->InterruptRequest = 0;
    if( !DispatchInterruptActive )
    {
      LOBYTE(v8) = 2;
      HalRequestSoftwareInterrupt(v8);
    }
  }
}

Referenced by:

KeQueryTotalCycleTimeThread
KeUpdateThreadTag
KiGroupSchedulingGenerationEnd
KiSwapThread
KiUpdateTotalCyclesCurrentThread