1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

Kernel: Use a separate timer for profiling the system

This updates the profiling subsystem to use a separate timer to
trigger CPU sampling. This timer has a higher resolution (1000Hz)
and is independent from the scheduler. At a later time the
resolution could even be made configurable with an argument for
sys$profiling_enable() - but not today.
This commit is contained in:
Gunnar Beutner 2021-05-13 22:15:13 +02:00 committed by Andreas Kling
parent d6b3513aab
commit 8614d18956
5 changed files with 46 additions and 8 deletions

View file

@ -58,11 +58,7 @@ public:
if (g_profiling_all_threads) {
VERIFY(g_global_perf_events);
// FIXME: We currently don't collect samples while idle.
// That will be an interesting mode to add in the future. :^)
if (&current_thread != Processor::current().idle_thread()) {
perf_events = g_global_perf_events;
}
perf_events = g_global_perf_events;
} else if (current_thread.process().is_profiling()) {
VERIFY(current_thread.process().perf_events());
perf_events = current_thread.process().perf_events();
@ -88,6 +84,17 @@ public:
[[maybe_unused]] auto res = event_buffer->append(PERF_EVENT_MUNMAP, region.base().get(), region.size(), nullptr);
}
}
inline static void timer_tick(RegisterState const& regs)
{
auto current_thread = Thread::current();
// FIXME: We currently don't collect samples while idle.
// That will be an interesting mode to add in the future. :^)
if (!current_thread || current_thread == Processor::current().idle_thread())
return;
PerformanceManager::add_cpu_sample_event(*current_thread, regs);
}
};
}