base-hw: add trace execution time support

This enables the 'top' program on base-hw for debugging issue #3247 on
rpi.

Fixes #3572
This commit is contained in:
Sebastian Sumpf 2019-04-09 11:34:32 +02:00 committed by Christian Helmuth
parent 1ddf1dbc25
commit 04969b6be0
7 changed files with 71 additions and 8 deletions

View File

@ -140,7 +140,8 @@ Cpu_job & Cpu::schedule()
_scheduler.update(_timer.time());
time_t t = _scheduler.head_quota();
_timer.set_timeout(this, t);
_timer.schedule_timeout();
time_t duration = _timer.schedule_timeout();
old_job.update_execution_time(duration);
}
/* return new job */

View File

@ -178,6 +178,11 @@ class Kernel::Cpu : public Genode::Cpu, private Irq::Pool, private Timeout
Inter_processor_work_list & work_list() {
return _local_work_list; }
/**
* Return CPU's idle thread object
*/
Kernel::Thread &idle_thread() { return _idle; }
};

View File

@ -35,6 +35,8 @@ class Kernel::Cpu_job : private Cpu_share
friend class Cpu; /* static_cast from 'Cpu_share' to 'Cpu_job' */
time_t _execution_time { 0 };
/*
* Noncopyable
*/
@ -112,6 +114,16 @@ class Kernel::Cpu_job : private Cpu_share
*/
bool own_share_active() { return Cpu_share::ready(); }
/**
* Update total execution time
*/
void update_execution_time(time_t duration) { _execution_time += duration; }
/**
* Return total execution time
*/
time_t execution_time() const { return _execution_time; }
/***************
** Accessors **

View File

@ -60,16 +60,19 @@ void Timer::set_timeout(Timeout * const timeout, time_t const duration)
}
void Timer::schedule_timeout()
time_t Timer::schedule_timeout()
{
/* get the timeout with the nearest end time */
Timeout * timeout = _timeout_list.first();
assert(timeout);
/* install timeout at timer hardware */
_time += _duration();
time_t duration = _duration();
_time += duration;
_last_timeout_duration = (timeout->_end > _time) ? timeout->_end - _time : 1;
_start_one_shot(_last_timeout_duration);
return duration;
}

View File

@ -91,7 +91,10 @@ class Kernel::Timer
Timer(Cpu & cpu);
void schedule_timeout();
/**
* Return duration from last call of this function
*/
time_t schedule_timeout();
void process_timeouts();

View File

@ -12,8 +12,6 @@
* under the terms of the GNU Affero General Public License version 3.
*/
/* Genode includes */
#include <base/log.h>
/* core includes */
#include <boot_modules.h>
@ -32,6 +30,10 @@
#include <base/internal/crt0.h>
#include <base/internal/stack_area.h>
/* Genode includes */
#include <base/log.h>
#include <trace/source_registry.h>
using namespace Genode;
@ -205,6 +207,40 @@ Platform::Platform()
init_core_log(Core_log_range { core_local_addr, log_size } );
}
struct Trace_source : public Trace::Source::Info_accessor,
private Trace::Control,
private Trace::Source
{
Kernel::Thread &thread;
Affinity::Location const affinity;
/**
* Trace::Source::Info_accessor interface
*/
Info trace_source_info() const override
{
Trace::Execution_time execution_time { thread.execution_time(), 0 };
return { Session_label("kernel"), thread.label(), execution_time,
affinity };
}
Trace_source(Trace::Source_registry &registry,
Kernel::Thread &thread, Affinity::Location affinity)
:
Trace::Control(),
Trace::Source(*this, *this),
thread(thread), affinity(affinity)
{
registry.insert(this);
}
};
/* create trace sources for idle threads */
Kernel::cpu_pool().for_each_cpu([&] (Kernel::Cpu & cpu) {
new (core_mem_alloc()) Trace_source(Trace::sources(), cpu.idle_thread(),
Affinity::Location(cpu.id(), 0));
});
log(_rom_fs);
}

View File

@ -208,8 +208,11 @@ namespace Genode {
/**
* Return execution time consumed by the thread
*/
Trace::Execution_time execution_time() const {
return { 0, 0, _quota, _priority }; }
Trace::Execution_time execution_time() const
{
Genode::uint64_t execution_time =
const_cast<Platform_thread *>(this)->_kobj->execution_time();
return { execution_time, 0, _quota, _priority }; }
/***************