KiUpdateCpuTargetByRate

VOID __stdcall KiUpdateCpuTargetByRate(_KSCHEDULING_GROUP *SchedulingGroup, UINT8 ResetHistory, _KPRCB *a3){
  UINT8 v3; 
  unsigned __int64 v5; 
  unsigned __int64 v6; 
  __int64 v7; 
  char v8; 
  __int64 v9; 
  _KSCB *v10; 
  char v11; 
  _KPRCB *v12; 
  _LIST_ENTRY *p_ChildList; 
  __int64 v14; 
  _KPRCB *v15; 
  _KSCB *Parent; 
  unsigned int v17; 
  bool v18; 
  UINT64 v20; 
  UINT64 SpinCount; 

  v3 = ResetHistory;
  if( SchedulingGroup->Parent )
  {
    LODWORD(v20) = 0;
    v15 = KiProcessorBlock;
    while( _interlockedbittestandset64((volatile signed __int32 *)&v15->PrcbLock, 0i64) )
    {
      do
        KeYieldProcessorEx(&v20);
      while( v15->PrcbLock );
    }
    Parent = SchedulingGroup->PerProcessor[0].Parent;
    v5 = SchedulingGroup->Policy.Weight * Parent->MinQuotaCycleTarget / 0x2710;
    v6 = Parent->MaxQuotaCycleTarget * SchedulingGroup->Policy.MaxRate / 0x2710;
    _InterlockedAnd64((volatile signed __int64 *)&v15->PrcbLock, 0i64);
    v3 = ResetHistory;
  }
  else
  {
    v5 = KiCyclesPerGeneration * (unsigned __int64)SchedulingGroup->Policy.Weight / 0x2710;
    v6 = KiCyclesPerGeneration * (unsigned __int64)SchedulingGroup->Policy.MaxRate / 0x2710;
  }
  v17 = KeNumberProcessors_0;
  v7 = 0i64;
  v18 = v6 == KiCyclesPerGeneration;
  if( (_DWORD)KeMaximumProcessors )
  {
    v8 = 16 * (v6 == KiCyclesPerGeneration);
    do
    {
      v9 = (__int64)*(&KiProcessorBlock + v7);
      v10 = &SchedulingGroup->PerProcessor[(unsigned int)v7];
      if( v9 )
      {
        LODWORD(SpinCount) = 0;
        while( _interlockedbittestandset64((volatile signed __int32 *)(v9 + 48), 0i64) )
        {
          do
            KeYieldProcessorEx(&SpinCount);
          while( *(_QWORD *)(v9 + 48) );
        }
        if( !v18 && *(_BYTE *)(v9 + 33) )
        {
          v14 = v6 * v17;
          SchedulingGroup->MaxQuotaLimitCycles = v14;
          SchedulingGroup->MaxQuotaCyclesRemaining = v14;
        }
      }
      v3 = ResetHistory;
      v11 = v8 | *((_BYTE *)v10 + 112) & 0xEF;
      v10->MinQuotaCycleTarget = v5;
      v10->MaxQuotaCycleTarget = v6;
      *((_BYTE *)v10 + 112) = v11;
      if( v9 )
      {
        if( ResetHistory )
        {
          v10->LongTermCycles = 0i64;
          v10->OverQuotaHistory = 0i64;
          if( (SchedulingGroup->Policy.AllFlags & 2) != 0 )
          {
            KiResetScb(v10);
            KiCheckForEffectivePriorityChange((_KPRCB *)v9, v10, v12);
          }
        }
        _InterlockedAnd64((volatile signed __int64 *)(v9 + 48), 0i64);
      }
      v7 = (unsigned int)(v7 + 1);
    }
    while( (unsigned int)v7 < (unsigned int)KeMaximumProcessors );
  }
  if( v3 )
    SchedulingGroup->QueryHistoryTimeStamp = KeQueryPerformanceCounter(0i64);
  p_ChildList = &SchedulingGroup->ChildList;
  if( p_ChildList->Flink != p_ChildList )
    KiUpdateChildrenCpuTarget(p_ChildList, v3);
}

Referenced by:

KeInsertSchedulingGroup
KeSetSchedulingGroupCpuRates
KiUpdateChildrenCpuTarget