PpmPerfApplyProcessorState

CHAR __fastcall PpmPerfApplyProcessorState(__int64 a1, char a2){
  __int64 v2; 
  __int64 v3; 
  __int64 v4; 
  char v6; 
  char v7; 
  __int64 v8; 
  UINT8 v9; 
  __int64 QuadPart; 
  INT64 v11; 
  UINT64 *v12; 
  bool v13; 
  CHAR updated; 
  __int64 v15; 
  __int64 v16; 
  void(__fastcall *v17)(_QWORD, __int64, __int64, __int64); 
  __int64 IdleGenerationCounter; 
  UINT64 *v20; 
  __int16 v21; 
  __int64 v22; 
  v2 = *(_QWORD *)(a1 + 33136);
  v3 = a1 + 33128;
  v4 = *(_QWORD *)(a1 + 33128);
  v22 = v2;
  v6 = a2;
  v7 = 1;
  v8 = *(_QWORD *)(v4 + 16);
  if( v3 == v8 || (v9 = 0, *(_BYTE *)(v4 + 358)) )
    v9 = 1;
  if( *(_BYTE *)(v4 + 353) != 0xFD && a2 )
    v9 = 1;
  if( (struct _KPRCB *)a1 != KeGetCurrentPrcb() && (v3 == v8 || v9 && *(_BYTE *)(v4 + 355)) )
    return 0;
  QuadPart = KeQueryPerformanceCounter(0i64).QuadPart;
  if( KeGetCurrentPrcb() != (struct _KPRCB *)a1 )
  {
    IdleGenerationCounter = PpmGetIdleGenerationCounter(a1);
    if( IdleGenerationCounter )
    {
      updated = PpmUpdatePerformanceFeedback(a1, 0, 1, 0, 0i64);
      if( !updated )
      {
LABEL_30:
        if( !updated )
          return updated;
        v6 = a2;
        v2 = v22;
        goto LABEL_9;
      }
      if( IdleGenerationCounter == PpmGetIdleGenerationCounter(a1) )
      {
        updated = 1;
        goto LABEL_30;
      }
    }
    return 0;
  }
  PpmContinueActiveTimeAccumulation(a1, QuadPart);
LABEL_9:
  v12 = (UINT64 *)(v2 + 128);
  if( *(_BYTE *)(v2 + 125) )
  {
    _disable();
    v20 = (UINT64 *)(v2 + 128);
    v13 = (v21 & 0x200) != 0;
    KxAcquireSpinLock(v20);
  }
  else
  {
    v7 = 0;
    v13 = 0;
  }
  updated = PpmPerfArbitratorApplyProcessorState(a1, v9, v6, v11);
  if( v7 )
  {
    KxReleaseSpinLock(v12);
    if( v13 )
      _enable();
  }
  if( updated )
  {
    if( v3 == *(_QWORD *)(v4 + 16) )
    {
      v17 = *(void(__fastcall **)(_QWORD, __int64, __int64, __int64))(v4 + 304);
      if( v17 )
      {
        LOBYTE(v16) = a2;
        LOBYTE(v15) = v9;
        v17(*(_QWORD *)(v4 + 192), v4 + 552, v15, v16);
      }
    }
    if( !a2 )
    {
      PpmEventLegacyProcessorPerfStateChange(a1);
      PpmScaleIdleStateValues(a1 + 0x8000);
      PpmEventTraceExpectedUtility(v3);
    }
  }
  return updated;
}

Referenced by:

PpmPerfAction
PpmPerfApplyProcessorStates