From 9269d09e1847da2f4893a0464a49282e09e32a5a Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Tue, 12 Sep 2017 11:25:03 +0200 Subject: [PATCH] sel4: support tracing of exec. time of core thread Issue #2646 --- repos/base-sel4/src/core/platform.cc | 17 +++++------ repos/base-sel4/src/core/thread_start.cc | 39 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/repos/base-sel4/src/core/platform.cc b/repos/base-sel4/src/core/platform.cc index 9126258d0..a960511af 100644 --- a/repos/base-sel4/src/core/platform.cc +++ b/repos/base-sel4/src/core/platform.cc @@ -553,8 +553,6 @@ Platform::Platform() */ Info trace_source_info() const override { - Genode::String<8> name("idle", affinity.xpos()); - Genode::Thread * me = Genode::Thread::myself(); addr_t const ipc_buffer = reinterpret_cast(me->utcb()); seL4_IPCBuffer * ipcbuffer = reinterpret_cast(ipc_buffer); @@ -563,29 +561,28 @@ Platform::Platform() seL4_BenchmarkGetThreadUtilisation(tcb_sel.value()); uint64_t execution_time = buf[BENCHMARK_IDLE_TCBCPU_UTILISATION]; - return { Session_label("kernel"), Trace::Thread_name(name), + return { Session_label("kernel"), Trace::Thread_name("idle"), Trace::Execution_time(execution_time), affinity }; } - Idle_trace_source(Platform &platform, Range_allocator &phys_alloc, + Idle_trace_source(Trace::Source_registry ®istry, + Platform &platform, Range_allocator &phys_alloc, Affinity::Location affinity) : Trace::Control(), Trace::Source(*this, *this), affinity(affinity) { Thread_info::init_tcb(platform, phys_alloc, 0, affinity.xpos()); + registry.insert(this); } - - Trace::Source &source() { return *this; } }; - Idle_trace_source *source = new (core_mem_alloc()) - Idle_trace_source(*this, *_core_mem_alloc.phys_alloc(), + new (core_mem_alloc()) + Idle_trace_source(Trace::sources(), *this, + *_core_mem_alloc.phys_alloc(), Affinity::Location(cpu_id, 0, affinity_space().width(), affinity_space().height())); - - Trace::sources().insert(&source->source()); } /* I/O port allocator (only meaningful for x86) */ diff --git a/repos/base-sel4/src/core/thread_start.cc b/repos/base-sel4/src/core/thread_start.cc index 625096671..45893061f 100644 --- a/repos/base-sel4/src/core/thread_start.cc +++ b/repos/base-sel4/src/core/thread_start.cc @@ -23,6 +23,10 @@ #include #include #include +#include + +/* seL4 includes */ +#include using namespace Genode; @@ -101,6 +105,41 @@ void Thread::start() { start_sel4_thread(Cap_sel(native_thread().tcb_sel), (addr_t)&_thread_start, (addr_t)stack_top(), _affinity.xpos()); + + struct Core_trace_source : public Trace::Source::Info_accessor, + private Trace::Control, + private Trace::Source + { + Thread &_thread; + + /** + * Trace::Source::Info_accessor interface + */ + Info trace_source_info() const override + { + Thread * const me = Thread::myself(); + seL4_IPCBuffer * const ipcbuffer = reinterpret_cast(me->utcb()); + uint64_t const * const buf = reinterpret_cast(ipcbuffer->msg); + + seL4_BenchmarkGetThreadUtilisation(_thread.native_thread().tcb_sel); + uint64_t const thread_time = buf[BENCHMARK_TCB_UTILISATION]; + + return { Session_label("core"), _thread.name(), + Trace::Execution_time(thread_time), _thread._affinity }; + } + + + Core_trace_source(Trace::Source_registry ®istry, Thread &t) + : + Trace::Control(), + Trace::Source(*this, *this), _thread(t) + { + registry.insert(this); + } + }; + + new (*platform()->core_mem_alloc()) + Core_trace_source(Trace::sources(), *this); }