Power: Correct hz on update and improve resched.

It only reschedules when the PLL changes, which changes in steps.  This
also reads back much more accurate Mhz for each of PLL, CPU, and bus.
This commit is contained in:
Unknown W. Brackets committed 2019-04-14 14:51:35 -07:00
1 parent 54e102cfad
commit bc4a203fcf
4 files changed
+147 -91

No files matched your search

+15 -18
View File
@@ -92,43 +92,40 @@ static std::mutex externalEventLock;
std::vector<MHzChangeCallback> mhzChangeCallbacks;
void FireMhzChange() {
for (auto it = mhzChangeCallbacks.begin(), end = mhzChangeCallbacks.end(); it != end; ++it) {
MHzChangeCallback cb = *it;
for (MHzChangeCallback cb : mhzChangeCallbacks) {
cb();
}
}
void SetClockFrequencyMHz(int cpuMhz)
{
void SetClockFrequencyHz(int cpuHz) {
// When the mhz changes, we keep track of what "time" it was before hand.
// This way, time always moves forward, even if mhz is changed.
lastGlobalTimeUs = GetGlobalTimeUs();
lastGlobalTimeTicks = GetTicks();
CPU_HZ = cpuMhz * 1000000;
CPU_HZ = cpuHz;
// TODO: Rescale times of scheduled events?
FireMhzChange();
}
int GetClockFrequencyMHz()
{
return CPU_HZ / 1000000;
int GetClockFrequencyHz() {
return CPU_HZ;
}
u64 GetGlobalTimeUsScaled()
{
s64 ticksSinceLast = GetTicks() - lastGlobalTimeTicks;
int freq = GetClockFrequencyMHz();
s64 usSinceLast = ticksSinceLast / freq;
return lastGlobalTimeUs + usSinceLast;
u64 GetGlobalTimeUsScaled() {
return GetGlobalTimeUs();
}
u64 GetGlobalTimeUs()
{
u64 GetGlobalTimeUs() {
s64 ticksSinceLast = GetTicks() - lastGlobalTimeTicks;
int freq = GetClockFrequencyMHz();
s64 usSinceLast = ticksSinceLast / freq;
int freq = GetClockFrequencyHz();
s64 usSinceLast = ticksSinceLast * 1000000 / freq;
if (ticksSinceLast > UINT_MAX) {
// Adjust the calculated value to avoid overflow errors.
lastGlobalTimeUs += usSinceLast;
lastGlobalTimeTicks = GetTicks();
}
return lastGlobalTimeUs + usSinceLast;
}