Merge pull request #5025 from jroweboy/tomoscrewme

Add CPU Clock Frequency slider
This commit is contained in:
Hamish Milne 2020-03-28 12:31:41 +00:00 committed by GitHub
commit 1ff8d002a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 204 additions and 84 deletions

View file

@ -258,7 +258,7 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, u32 system_mo
memory = std::make_unique<Memory::MemorySystem>();
timing = std::make_unique<Timing>(num_cores);
timing = std::make_unique<Timing>(num_cores, Settings::values.cpu_clock_percentage);
kernel = std::make_unique<Kernel::KernelSystem>(
*memory, *timing, [this] { PrepareReschedule(); }, system_mode, num_cores, n3ds_mode);

View file

@ -20,14 +20,20 @@ bool Timing::Event::operator<(const Timing::Event& right) const {
return std::tie(time, fifo_order) < std::tie(right.time, right.fifo_order);
}
Timing::Timing(std::size_t num_cores) {
Timing::Timing(std::size_t num_cores, u32 cpu_clock_percentage) {
timers.resize(num_cores);
for (std::size_t i = 0; i < num_cores; ++i) {
timers[i] = std::make_shared<Timer>();
timers[i] = std::make_shared<Timer>(100.0 / cpu_clock_percentage);
}
current_timer = timers[0];
}
void Timing::UpdateClockSpeed(u32 cpu_clock_percentage) {
for (auto& timer : timers) {
timer->cpu_clock_scale = 100.0 / cpu_clock_percentage;
}
}
TimingEventType* Timing::RegisterEvent(const std::string& name, TimedCallback callback) {
// check for existing type with same name.
// we want event type names to remain unique so that we can use them for serialization.
@ -117,6 +123,8 @@ std::shared_ptr<Timing::Timer> Timing::GetTimer(std::size_t cpu_id) {
return timers[cpu_id];
}
Timing::Timer::Timer(double cpu_clock_scale_) : cpu_clock_scale(cpu_clock_scale_) {}
Timing::Timer::~Timer() {
MoveEvents();
}
@ -130,7 +138,7 @@ u64 Timing::Timer::GetTicks() const {
}
void Timing::Timer::AddTicks(u64 ticks) {
downcount -= ticks;
downcount -= static_cast<u64>(ticks * cpu_clock_scale);
}
u64 Timing::Timer::GetIdleTicks() const {

View file

@ -148,6 +148,7 @@ public:
class Timer {
public:
Timer(double cpu_clock_scale);
~Timer();
s64 GetMaxSliceLength() const;
@ -190,10 +191,13 @@ public:
s64 slice_length = MAX_SLICE_LENGTH;
s64 downcount = MAX_SLICE_LENGTH;
s64 executed_ticks = 0;
u64 idled_cycles;
u64 idled_cycles = 0;
// Stores a scaling for the internal clockspeed. Changing this number results in
// under/overclocking the guest cpu
double cpu_clock_scale = 1.0;
};
explicit Timing(std::size_t num_cores);
explicit Timing(std::size_t num_cores, u32 cpu_clock_percentage);
~Timing(){};
@ -220,6 +224,11 @@ public:
global_timer += ticks;
}
/**
* Updates the value of the cpu clock scaling to the new percentage.
*/
void UpdateClockSpeed(u32 cpu_clock_percentage);
std::chrono::microseconds GetGlobalTimeUs() const;
std::shared_ptr<Timer> GetTimer(std::size_t cpu_id);
@ -229,10 +238,14 @@ private:
// unordered_map stores each element separately as a linked list node so pointers to
// elements remain stable regardless of rehashes/resizing.
std::unordered_map<std::string, TimingEventType> event_types;
std::unordered_map<std::string, TimingEventType> event_types = {};
std::vector<std::shared_ptr<Timer>> timers;
std::shared_ptr<Timer> current_timer;
// Stores a scaling for the internal clockspeed. Changing this number results in
// under/overclocking the guest cpu
double cpu_clock_scale = 1.0;
};
} // namespace Core

View file

@ -44,6 +44,7 @@ void Apply() {
auto& system = Core::System::GetInstance();
if (system.IsPoweredOn()) {
system.CoreTiming().UpdateClockSpeed(values.cpu_clock_percentage);
Core::DSP().SetSink(values.sink_id, values.audio_device_id);
Core::DSP().EnableStretching(values.enable_audio_stretching);

View file

@ -128,6 +128,7 @@ struct Values {
// Core
bool use_cpu_jit;
int cpu_clock_percentage;
// Data Storage
bool use_virtual_sd;