General: Fix microprofile on dynarmic/svc, fix wait tree showing which threads were running.

This commit is contained in:
Fernando Sahmkow 2020-03-12 16:48:43 -04:00
parent e6f8bde74b
commit 7020d498c5
11 changed files with 87 additions and 13 deletions

View file

@ -13,6 +13,7 @@
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/microprofile.h"
#include "common/thread.h"
#include "core/arm/arm_interface.h"
#include "core/arm/exclusive_monitor.h"
@ -41,6 +42,8 @@
#include "core/hle/result.h"
#include "core/memory.h"
MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));
namespace Kernel {
/**
@ -408,6 +411,8 @@ struct KernelCore::Impl {
bool is_multicore{};
std::thread::id single_core_thread_id{};
std::array<u64, Core::Hardware::NUM_CPU_CORES> svc_ticks{};
// System context
Core::System& system;
};
@ -666,4 +671,14 @@ void KernelCore::ExceptionalExit() {
Suspend(true);
}
void KernelCore::EnterSVCProfile() {
std::size_t core = impl->GetCurrentHostThreadID();
impl->svc_ticks[core] = MicroProfileEnter(MICROPROFILE_TOKEN(Kernel_SVC));
}
void KernelCore::ExitSVCProfile() {
std::size_t core = impl->GetCurrentHostThreadID();
MicroProfileLeave(MICROPROFILE_TOKEN(Kernel_SVC), impl->svc_ticks[core]);
}
} // namespace Kernel

View file

@ -214,6 +214,10 @@ public:
bool IsMulticore() const;
void EnterSVCProfile();
void ExitSVCProfile();
private:
friend class Object;
friend class Process;

View file

@ -354,7 +354,9 @@ void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule,
}
if (must_context_switch) {
auto& core_scheduler = kernel.CurrentScheduler();
kernel.ExitSVCProfile();
core_scheduler.TryDoContextSwitch();
kernel.EnterSVCProfile();
}
}
@ -628,6 +630,7 @@ void Scheduler::Reload() {
// Cancel any outstanding wakeup events for this thread
thread->SetIsRunning(true);
thread->SetWasRunning(false);
thread->last_running_ticks = system.CoreTiming().GetCPUTicks();
auto* const thread_owner_process = thread->GetOwnerProcess();
@ -660,6 +663,7 @@ void Scheduler::SwitchContextStep2() {
// Cancel any outstanding wakeup events for this thread
new_thread->SetIsRunning(true);
new_thread->last_running_ticks = system.CoreTiming().GetCPUTicks();
new_thread->SetWasRunning(false);
auto* const thread_owner_process = current_thread->GetOwnerProcess();
if (previous_process != thread_owner_process && thread_owner_process != nullptr) {
@ -698,6 +702,9 @@ void Scheduler::SwitchContext() {
// Save context for previous thread
if (previous_thread) {
if (new_thread != nullptr && new_thread->IsSuspendThread()) {
previous_thread->SetWasRunning(true);
}
previous_thread->SetContinuousOnSVC(false);
previous_thread->last_running_ticks = system.CoreTiming().GetCPUTicks();
if (!previous_thread->IsHLEThread()) {

View file

@ -2454,10 +2454,10 @@ static const FunctionDef* GetSVCInfo64(u32 func_num) {
return &SVC_Table_64[func_num];
}
MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70));
void Call(Core::System& system, u32 immediate) {
MICROPROFILE_SCOPE(Kernel_SVC);
system.ExitDynarmicProfile();
auto& kernel = system.Kernel();
kernel.EnterSVCProfile();
auto* thread = system.CurrentScheduler().GetCurrentThread();
thread->SetContinuousOnSVC(true);
@ -2474,10 +2474,14 @@ void Call(Core::System& system, u32 immediate) {
LOG_CRITICAL(Kernel_SVC, "Unknown SVC function 0x{:X}", immediate);
}
kernel.ExitSVCProfile();
if (!thread->IsContinuousOnSVC()) {
auto* host_context = thread->GetHostContext().get();
host_context->Rewind();
}
system.EnterDynarmicProfile();
}
} // namespace Kernel::Svc

View file

@ -350,6 +350,22 @@ public:
return (type & THREADTYPE_HLE) != 0;
}
bool IsSuspendThread() const {
return (type & THREADTYPE_SUSPEND) != 0;
}
bool IsIdleThread() const {
return (type & THREADTYPE_IDLE) != 0;
}
bool WasRunning() const {
return was_running;
}
void SetWasRunning(bool value) {
was_running = value;
}
std::shared_ptr<Common::Fiber> GetHostContext() const;
ThreadStatus GetStatus() const {
@ -684,6 +700,8 @@ private:
bool will_be_terminated = false;
bool was_running = false;
std::string name;
};