Skip to content

Commit b74a624

Browse files
committed
Fixes potential cause of freezes after sleep
1 parent 222ca5f commit b74a624

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

AMDRyzenCPUPowerManagement/AMDRyzenCPUPowerManagement.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,15 @@ IOReturn AMDRyzenCPUPowerManagement::setPowerState(unsigned long powerStateOrdin
383383
IOLog("AMDCPUSupport::setPowerState preparing for sleep\n");
384384
sleepState.sleep = true;
385385
sleepState.cpb = getCPBState();
386-
dumpPstate(sleepState.pstate);
386+
//dumpPstate(sleepState.pstate);
387387

388388
stopWorkLoop();
389389
} else if (1 == powerStateOrdinal && sleepState.sleep) {
390390
// Waking up
391391
IOLog("AMDCPUSupport::setPowerState preparing for wakeup\n");
392392
sleepState.sleep = false;
393393
setCPBState(sleepState.cpb);
394-
writePstate(sleepState.pstate);
394+
//writePstate(sleepState.pstate);
395395
startWorkLoop();
396396
}
397397

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

512514
float freqP0 = PStateDefClock_perCore[0];
513515

514516
uint64_t deltaAPERF = APERF - lastAPERF;
517+
uint64_t deltaMPERF = MPERF - lastMPERF;
515518
deltaAPERF_PerCore[physical] = deltaAPERF;
516-
deltaMPERF_PerCore[physical] = MPERF - lastMPERF;
517-
float effFreq = ((float)deltaAPERF / (float)(MPERF - lastMPERF)) * freqP0;
518-
519-
effFreq_perCore[physical] = effFreq;
519+
deltaMPERF_PerCore[physical] = deltaMPERF;
520+
if (deltaMPERF != 0) {
521+
float effFreq = ((float)deltaAPERF / (float)(deltaMPERF)) * freqP0;
522+
effFreq_perCore[physical] = effFreq;
523+
}
520524

521525
lastAPERF_PerCore[physical] = APERF;
522526
lastMPERF_PerCore[physical] = MPERF;

0 commit comments

Comments
 (0)