core: store new affinity on successful migration

Adjust the base-* platforms to acknowledge new thread location solely if
migration is supported and succeeded. Otherwise the wrong thread
locations are observed via the trace session and utilization time calculation
get wrong.

Issue #3842
This commit is contained in:
Alexander Boettcher 2020-09-23 07:41:39 +02:00 committed by Christian Helmuth
parent 99fa203673
commit 90bea1499e
7 changed files with 29 additions and 25 deletions

View File

@ -221,19 +221,16 @@ Foc_thread_state Platform_thread::state()
}
void Platform_thread::affinity(Affinity::Location location)
void Platform_thread::affinity(Affinity::Location const location)
{
_location = location;
int const cpu = location.xpos();
l4_sched_param_t params = l4_sched_param(_prio);
params.affinity = l4_sched_cpu_set(cpu, 0, 1);
l4_msgtag_t tag = l4_scheduler_run_thread(L4_BASE_SCHEDULER_CAP,
_thread.local.data()->kcap(), &params);
if (l4_error(tag))
warning("setting affinity of ", Hex(_thread.local.data()->kcap()),
" to ", cpu, " failed!");
if (!l4_error(tag))
_location = location;
}

View File

@ -66,6 +66,7 @@ Platform_thread::Platform_thread(Label const &label, Native_utcb &utcb)
_utcb_core_addr(&utcb),
_utcb_pd_addr(&utcb),
_main_thread(false),
_location(Affinity::Location()),
_kobj(true, _label.string())
{
/* create UTCB for a core thread */
@ -92,6 +93,7 @@ Platform_thread::Platform_thread(size_t const quota,
_priority(_scale_priority(virt_prio)),
_quota(quota),
_main_thread(false),
_location(location),
_kobj(true, _priority, _quota, _label.string())
{
try {
@ -101,7 +103,6 @@ Platform_thread::Platform_thread(size_t const quota,
throw Out_of_ram();
}
_utcb_core_addr = (Native_utcb *)core_env().rm_session()->attach(_utcb);
affinity(location);
}
@ -121,9 +122,9 @@ void Platform_thread::join_pd(Platform_pd * pd, bool const main_thread,
}
void Platform_thread::affinity(Affinity::Location const & location)
void Platform_thread::affinity(Affinity::Location const &)
{
_location = location;
/* yet no migration support, don't claim wrong location, e.g. for tracing */
}

View File

@ -72,7 +72,7 @@ namespace Genode {
*/
bool _main_thread;
Affinity::Location _location { };
Affinity::Location _location;
Kernel_object<Kernel::Thread> _kobj;

View File

@ -63,7 +63,7 @@ namespace Genode {
Platform_pd *_platform_pd = nullptr;
unsigned _priority = 0;
Pager_object *_pager = nullptr;
Affinity::Location _location { };
Affinity::Location _location;
public:
@ -74,15 +74,16 @@ namespace Genode {
* Constructor
*/
Platform_thread(size_t, char const *name, unsigned priority,
Affinity::Location, addr_t)
Affinity::Location location, addr_t)
:
_name(name), _priority(priority)
_name(name), _priority(priority), _location(location)
{ }
/**
* Constructor used for core-internal threads
*/
Platform_thread(char const *name) : _name(name) { }
Platform_thread(char const *name)
: _name(name), _location(Affinity::Location()) { }
/**
* Destructor

View File

@ -42,8 +42,6 @@ static const bool verbose2 = true;
void Platform_thread::affinity(Affinity::Location location)
{
_location = location;
unsigned const cpu_no = location.xpos();
if (cpu_no >= L4_NumProcessors(get_kip())) {
@ -51,9 +49,12 @@ void Platform_thread::affinity(Affinity::Location location)
return;
}
if (_l4_thread_id != L4_nilthread)
if (_l4_thread_id != L4_nilthread) {
if (L4_Set_ProcessorNo(_l4_thread_id, cpu_no) == 0)
error("could not set processor number");
else
_location = location;
}
}

View File

@ -13,10 +13,13 @@
#include <platform_thread.h>
void Genode::Platform_thread::affinity(Affinity::Location location)
void Genode::Platform_thread::affinity(Affinity::Location const location)
{
_location = location;
Genode::error("could not set affinity");
//seL4_TCB_SetAffinity(tcb_sel().value(), location.xpos());
#if CONFIG_MAX_NUM_NODES > 1
seL4_Error const res = seL4_TCB_SetAffinity(tcb_sel().value(), location.xpos());
if (res == seL4_NoError)
_location = location;
#else
(void)location;
#endif
}

View File

@ -23,10 +23,11 @@ Phys_allocator& Genode::phys_alloc_16k(Allocator * core_mem_alloc)
return phys_alloc_16k;
}
void Genode::Platform_thread::affinity(Affinity::Location location)
void Genode::Platform_thread::affinity(Affinity::Location const location)
{
_location = location;
seL4_TCB_SetAffinity(tcb_sel().value(), location.xpos());
seL4_Error const res = seL4_TCB_SetAffinity(tcb_sel().value(), location.xpos());
if (res == seL4_NoError)
_location = location;
}
bool Genode::Thread_info::init_vcpu(Platform &platform, Cap_sel ept)