KiUpdateCpuTargetByRate

VOID __stdcall KiUpdateCpuTargetByRate(_KSCHEDULING_GROUP *SchedulingGroup, UINT8 ResetHistory){
  UINT8 v2; 
  unsigned __int64 v4; 
  unsigned __int64 v5; 
  __int64 v6; 
  char v7; 
  __int64 v8; 
  _KSCB *v9; 
  char v10; 
  _LIST_ENTRY *p_ChildList; 
  __int64 v12; 
  _KPRCB *v13; 
  _KSCB *Parent; 
  unsigned int v15; 
  bool v16; 
  UINT64 v18; 
  UINT64 SpinCount; 
  v2 = ResetHistory;
  if( SchedulingGroup->Parent )
  {
    LODWORD(v18) = 0;
    v13 = KiProcessorBlock;
    while( _interlockedbittestandset64((volatile signed __int32 *)v13 + 12, 0i64) )
    {
      do
        KeYieldProcessorEx(&v18);
      while( *((_QWORD *)v13 + 6) );
    }
    Parent = SchedulingGroup->PerProcessor[0].Parent;
    v4 = SchedulingGroup->Policy.Weight * Parent->MinQuotaCycleTarget / 0x2710;
    v5 = Parent->MaxQuotaCycleTarget * SchedulingGroup->Policy.MaxRate / 0x2710;
    _InterlockedAnd64((volatile signed __int64 *)v13 + 6, 0i64);
    v2 = ResetHistory;
  }
  else
  {
    v4 = *(_QWORD *)KiCyclesPerGeneration * (unsigned __int64)SchedulingGroup->Policy.Weight / 0x2710;
    v5 = *(_QWORD *)KiCyclesPerGeneration * (unsigned __int64)SchedulingGroup->Policy.MaxRate / 0x2710;
  }
  v15 = KeNumberProcessors_0;
  v6 = 0i64;
  v16 = v5 == *(_QWORD *)KiCyclesPerGeneration;
  if( (_DWORD)KeMaximumProcessors )
  {
    v7 = 16 * (v5 == *(_QWORD *)KiCyclesPerGeneration);
    do
    {
      v8 = (__int64)*(&KiProcessorBlock + v6);
      v9 = &SchedulingGroup->PerProcessor[(unsigned int)v6];
      if( v8 )
      {
        LODWORD(SpinCount) = 0;
        while( _interlockedbittestandset64((volatile signed __int32 *)(v8 + 48), 0i64) )
        {
          do
            KeYieldProcessorEx(&SpinCount);
          while( *(_QWORD *)(v8 + 48) );
        }
        if( !v16 && *(_BYTE *)(v8 + 33) )
        {
          v12 = v5 * v15;
          SchedulingGroup->MaxQuotaLimitCycles = v12;
          SchedulingGroup->MaxQuotaCyclesRemaining = v12;
        }
      }
      v2 = ResetHistory;
      v10 = v7 | *((_BYTE *)v9 + 112) & 0xEF;
      v9->MinQuotaCycleTarget = v4;
      v9->MaxQuotaCycleTarget = v5;
      *((_BYTE *)v9 + 112) = v10;
      if( v8 )
      {
        if( ResetHistory )
        {
          v9->LongTermCycles = 0i64;
          v9->OverQuotaHistory = 0i64;
          if( (SchedulingGroup->Policy.AllFlags & 2) != 0 )
          {
            KiResetScb((__int64)v9, v8);
            KiCheckForEffectivePriorityChange((struct KPRCB *)v8, (INT64)v9);
          }
        }
        _InterlockedAnd64((volatile signed __int64 *)(v8 + 48), 0i64);
      }
      v6 = (unsigned int)(v6 + 1);
    }
    while( (unsigned int)v6 < (unsigned int)KeMaximumProcessors );
  }
  if( v2 )
    SchedulingGroup->QueryHistoryTimeStamp = KeQueryPerformanceCounter(0i64).QuadPart;
  p_ChildList = &SchedulingGroup->ChildList;
  if( p_ChildList->Flink != p_ChildList )
    KiUpdateChildrenCpuTarget(p_ChildList, v2);
}

Referenced by:

KeInsertSchedulingGroup
KeSetSchedulingGroupCpuRates
KiUpdateChildrenCpuTarget