Skip to content

Commit

Permalink
Kernel: Prune uninteresting kernel frames from profiling samples
Browse files Browse the repository at this point in the history
Start capturing the sample stacks at the EIP/EBP of the pre-empted
thread instead of capturing EBP in the sampling function itself.
  • Loading branch information
awesomekling committed Jan 17, 2021
1 parent bf07190 commit 647cfcb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions Kernel/PerformanceEventBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<FlatPtr> backtrace;
{
SmapDisabler disabler;
Expand Down
1 change: 1 addition & 0 deletions Kernel/PerformanceEventBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PerformanceEventBuffer {
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()
{
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 647cfcb

Please sign in to comment.