Merge pull request #1043 from Subv/timing

Use an approximated amortized amount of ticks when advancing timing.
This commit is contained in:
bunnei 2018-08-12 22:31:55 -04:00 committed by GitHub
commit fecffeb0dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -86,7 +86,16 @@ public:
} }
void AddTicks(u64 ticks) override { void AddTicks(u64 ticks) override {
CoreTiming::AddTicks(ticks - num_interpreted_instructions); // Divide the number of ticks by the amount of CPU cores. TODO(Subv): This yields only a
// rough approximation of the amount of executed ticks in the system, it may be thrown off
// if not all cores are doing a similar amount of work. Instead of doing this, we should
// device a way so that timing is consistent across all cores without increasing the ticks 4
// times.
u64 amortized_ticks = (ticks - num_interpreted_instructions) / Core::NUM_CPU_CORES;
// Always execute at least one tick.
amortized_ticks = std::max<u64>(amortized_ticks, 1);
CoreTiming::AddTicks(amortized_ticks);
num_interpreted_instructions = 0; num_interpreted_instructions = 0;
} }
u64 GetTicksRemaining() override { u64 GetTicksRemaining() override {

View file

@ -91,6 +91,7 @@ void Cpu::RunLoop(bool tight_loop) {
LOG_TRACE(Core, "Core-{} idling", core_index); LOG_TRACE(Core, "Core-{} idling", core_index);
if (IsMainCore()) { if (IsMainCore()) {
// TODO(Subv): Only let CoreTiming idle if all 4 cores are idling.
CoreTiming::Idle(); CoreTiming::Idle();
CoreTiming::Advance(); CoreTiming::Advance();
} }

View file

@ -532,7 +532,6 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
CASCADE_RESULT(thread->guest_handle, g_handle_table.Create(thread)); CASCADE_RESULT(thread->guest_handle, g_handle_table.Create(thread));
*out_handle = thread->guest_handle; *out_handle = thread->guest_handle;
Core::System::GetInstance().PrepareReschedule();
Core::System::GetInstance().CpuCore(thread->processor_id).PrepareReschedule(); Core::System::GetInstance().CpuCore(thread->processor_id).PrepareReschedule();
LOG_TRACE(Kernel_SVC, LOG_TRACE(Kernel_SVC,