Skip to content

Commit b9a1eaf

Browse files
committed
Fixes potential cause of freezes after sleep
1 parent 35e83b7 commit b9a1eaf

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
@@ -376,15 +376,15 @@ IOReturn AMDRyzenCPUPowerManagement::setPowerState(unsigned long powerStateOrdin
376376
IOLog("AMDCPUSupport::setPowerState preparing for sleep\n");
377377
sleepState.sleep = true;
378378
sleepState.cpb = getCPBState();
379-
dumpPstate(sleepState.pstate);
379+
//dumpPstate(sleepState.pstate);
380380

381381
stopWorkLoop();
382382
} else if (1 == powerStateOrdinal && sleepState.sleep) {
383383
// Waking up
384384
IOLog("AMDCPUSupport::setPowerState preparing for wakeup\n");
385385
sleepState.sleep = false;
386386
setCPBState(sleepState.cpb);
387-
writePstate(sleepState.pstate);
387+
//writePstate(sleepState.pstate);
388388
startWorkLoop();
389389
}
390390

@@ -498,18 +498,22 @@ void AMDRyzenCPUPowerManagement::calculateEffectiveFrequency(uint8_t physical){
498498
//read of last APERF, the effective frequency calculated in is invalid.
499499
//Yeah, so we will do nothing.
500500
if(APERF <= lastAPERF || MPERF <= lastMPERF) {
501-
IOLog("AMDCPUSupport::calculateEffectiveFrequency: frequency is invalid!!!");
501+
IOLog("AMDCPUSupport::calculateEffectiveFrequency: frequency is invalid for %u", physical);
502+
lastAPERF_PerCore[physical] = APERF;
503+
lastMPERF_PerCore[physical] = MPERF;
502504
return;
503505
}
504506

505507
float freqP0 = PStateDefClock_perCore[0];
506508

507509
uint64_t deltaAPERF = APERF - lastAPERF;
510+
uint64_t deltaMPERF = MPERF - lastMPERF;
508511
deltaAPERF_PerCore[physical] = deltaAPERF;
509-
deltaMPERF_PerCore[physical] = MPERF - lastMPERF;
510-
float effFreq = ((float)deltaAPERF / (float)(MPERF - lastMPERF)) * freqP0;
511-
512-
effFreq_perCore[physical] = effFreq;
512+
deltaMPERF_PerCore[physical] = deltaMPERF;
513+
if (deltaMPERF != 0) {
514+
float effFreq = ((float)deltaAPERF / (float)(deltaMPERF)) * freqP0;
515+
effFreq_perCore[physical] = effFreq;
516+
}
513517

514518
lastAPERF_PerCore[physical] = APERF;
515519
lastMPERF_PerCore[physical] = MPERF;

0 commit comments

Comments
 (0)