From 647cfcb64121dc5f595c7d169172138d495b88de Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 17 Jan 2021 10:53:18 +0100 Subject: [PATCH] Kernel: Prune uninteresting kernel frames from profiling samples Start capturing the sample stacks at the EIP/EBP of the pre-empted thread instead of capturing EBP in the sampling function itself. --- Kernel/PerformanceEventBuffer.cpp | 14 ++++++++++---- Kernel/PerformanceEventBuffer.h | 1 + Kernel/Scheduler.cpp | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 851d3098da..ec61c1ee27 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -39,6 +39,16 @@ PerformanceEventBuffer::PerformanceEventBuffer() } KResult PerformanceEventBuffer::append(int type, FlatPtr arg1, FlatPtr arg2) +{ + FlatPtr ebp; + asm volatile("movl %%ebp, %%eax" + : "=a"(ebp)); + auto current_thread = Thread::current(); + auto eip = current_thread->get_register_dump_from_stack().eip; + return append_with_eip_and_ebp(eip, ebp, type, arg1, arg2); +} + +KResult PerformanceEventBuffer::append_with_eip_and_ebp(u32 eip, u32 ebp, int type, FlatPtr arg1, FlatPtr arg2) { if (count() >= capacity()) return KResult(-ENOBUFS); @@ -60,11 +70,7 @@ KResult PerformanceEventBuffer::append(int type, FlatPtr arg1, FlatPtr arg2) return KResult(-EINVAL); } - FlatPtr ebp; - asm volatile("movl %%ebp, %%eax" - : "=a"(ebp)); auto current_thread = Thread::current(); - auto eip = current_thread->get_register_dump_from_stack().eip; Vector backtrace; { SmapDisabler disabler; diff --git a/Kernel/PerformanceEventBuffer.h b/Kernel/PerformanceEventBuffer.h index 19844b7103..c1cb429266 100644 --- a/Kernel/PerformanceEventBuffer.h +++ b/Kernel/PerformanceEventBuffer.h @@ -61,6 +61,7 @@ public: PerformanceEventBuffer(); KResult append(int type, FlatPtr arg1, FlatPtr arg2); + KResult append_with_eip_and_ebp(u32 eip, u32 ebp, int type, FlatPtr arg1, FlatPtr arg2); void clear() { diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 44f65f06de..a55e6af3f9 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -495,7 +495,7 @@ void Scheduler::timer_tick(const RegisterState& regs) if (current_thread->process().is_profiling()) { ASSERT(current_thread->process().perf_events()); auto& perf_events = *current_thread->process().perf_events(); - [[maybe_unused]] auto rc = perf_events.append(PERF_EVENT_SAMPLE, 0, 0); + [[maybe_unused]] auto rc = perf_events.append_with_eip_and_ebp(regs.eip, regs.ebp, PERF_EVENT_SAMPLE, 0, 0); } if (current_thread->tick((regs.cs & 3) == 0))