Skip to content

Commit

Permalink
Fixes potential cause of freezes after sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
aluveitie committed May 26, 2020
1 parent 222ca5f commit b74a624
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions AMDRyzenCPUPowerManagement/AMDRyzenCPUPowerManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,15 @@ IOReturn AMDRyzenCPUPowerManagement::setPowerState(unsigned long powerStateOrdin
IOLog("AMDCPUSupport::setPowerState preparing for sleep\n");
sleepState.sleep = true;
sleepState.cpb = getCPBState();
dumpPstate(sleepState.pstate);
//dumpPstate(sleepState.pstate);

stopWorkLoop();
} else if (1 == powerStateOrdinal && sleepState.sleep) {
// Waking up
IOLog("AMDCPUSupport::setPowerState preparing for wakeup\n");
sleepState.sleep = false;
setCPBState(sleepState.cpb);
writePstate(sleepState.pstate);
//writePstate(sleepState.pstate);
startWorkLoop();
}

Expand Down Expand Up @@ -505,18 +505,22 @@ void AMDRyzenCPUPowerManagement::calculateEffectiveFrequency(uint8_t physical){
//read of last APERF, the effective frequency calculated in is invalid.
//Yeah, so we will do nothing.
if(APERF <= lastAPERF || MPERF <= lastMPERF) {
IOLog("AMDCPUSupport::calculateEffectiveFrequency: frequency is invalid!!!");
IOLog("AMDCPUSupport::calculateEffectiveFrequency: frequency is invalid for %u", physical);
lastAPERF_PerCore[physical] = APERF;
lastMPERF_PerCore[physical] = MPERF;
return;
}

float freqP0 = PStateDefClock_perCore[0];

uint64_t deltaAPERF = APERF - lastAPERF;
uint64_t deltaMPERF = MPERF - lastMPERF;
deltaAPERF_PerCore[physical] = deltaAPERF;
deltaMPERF_PerCore[physical] = MPERF - lastMPERF;
float effFreq = ((float)deltaAPERF / (float)(MPERF - lastMPERF)) * freqP0;

effFreq_perCore[physical] = effFreq;
deltaMPERF_PerCore[physical] = deltaMPERF;
if (deltaMPERF != 0) {
float effFreq = ((float)deltaAPERF / (float)(deltaMPERF)) * freqP0;
effFreq_perCore[physical] = effFreq;
}

lastAPERF_PerCore[physical] = APERF;
lastMPERF_PerCore[physical] = MPERF;
Expand Down

0 comments on commit b74a624

Please sign in to comment.