From c0a00019c0b4464968e9e9a3cbc6c5864995dc51 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 3 May 2019 10:37:13 +0200 Subject: [PATCH] foc/sel4: place vcpu thread on same cpu as ep Issue #3111 --- repos/base-foc/src/lib/base/x86/vm_session.cc | 11 +++++++---- repos/base-sel4/src/lib/base/x86/vm_session.cc | 12 +++++++++--- repos/base/include/base/thread.h | 5 +++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/repos/base-foc/src/lib/base/x86/vm_session.cc b/repos/base-foc/src/lib/base/x86/vm_session.cc index 966965844..1ec2f839e 100644 --- a/repos/base-foc/src/lib/base/x86/vm_session.cc +++ b/repos/base-foc/src/lib/base/x86/vm_session.cc @@ -1174,10 +1174,10 @@ struct Vcpu : Genode::Thread Vcpu(Env &env, Signal_context_capability &cap, Semaphore &handler_ready, Vm_session_client::Vcpu_id &id, enum Virt type, - Allocator &alloc) + Allocator &alloc, Affinity::Location location) : - Thread(env, "vcpu_thread", STACK_SIZE), _signal(cap), - _handler_ready(handler_ready), _alloc(alloc), + Thread(env, "vcpu_thread", STACK_SIZE, location, Weight(), env.cpu()), + _signal(cap), _handler_ready(handler_ready), _alloc(alloc), _id(id), _vm_type(type) { } @@ -1256,10 +1256,13 @@ Vm_session_client::create_vcpu(Allocator &alloc, Env &env, return id; } + Thread * ep = reinterpret_cast(&handler._rpc_ep); + Affinity::Location location = ep->affinity(); + /* create thread that switches modes between thread/cpu */ Vcpu * vcpu = new (alloc) Registered(vcpus, env, handler._cap, handler._done, id, vm_type, - alloc); + alloc, location); try { /* now it gets actually valid - vcpu->cap() becomes valid */ diff --git a/repos/base-sel4/src/lib/base/x86/vm_session.cc b/repos/base-sel4/src/lib/base/x86/vm_session.cc index 333f2a5e0..993a12c1e 100644 --- a/repos/base-sel4/src/lib/base/x86/vm_session.cc +++ b/repos/base-sel4/src/lib/base/x86/vm_session.cc @@ -742,9 +742,11 @@ struct Vcpu : Genode::Thread public: Vcpu(Genode::Env &env, Genode::Signal_context_capability &cap, - Semaphore &handler_ready, unsigned id, Allocator &alloc) + Semaphore &handler_ready, unsigned id, Allocator &alloc, + Affinity::Location &location) : - Thread(env, "vcpu_thread", STACK_SIZE), _signal(cap), + Thread(env, "vcpu_thread", STACK_SIZE, location, Weight(), env.cpu()), + _signal(cap), _handler_ready(handler_ready), _alloc(alloc), _id({id}) { } @@ -795,11 +797,15 @@ Genode::Vm_session_client::Vcpu_id Genode::Vm_session_client::create_vcpu(Allocator &alloc, Env &env, Vm_handler_base &handler) { + Thread * ep = reinterpret_cast(&handler._rpc_ep); + Affinity::Location location = ep->affinity(); + /* create thread that switches modes between thread/cpu */ Vcpu * vcpu = new (alloc) Genode::Registered (vcpus, env, handler._cap, handler._done, - vcpu_id, alloc); + vcpu_id, alloc, + location); try { /* now it gets actually valid - vcpu->cap() becomes valid */ diff --git a/repos/base/include/base/thread.h b/repos/base/include/base/thread.h index f59d6be93..a4b408d9a 100644 --- a/repos/base/include/base/thread.h +++ b/repos/base/include/base/thread.h @@ -430,6 +430,11 @@ class Genode::Thread */ template static void trace(EVENT const *event) { _logger()->log(event); } + + /** + * Thread affinity + */ + Affinity::Location affinity() const { return _affinity; } };