diff --git a/repos/ports/include/vmm/vcpu_dispatcher.h b/repos/ports/include/vmm/vcpu_dispatcher.h index 92398ebd3..08b67cab0 100644 --- a/repos/ports/include/vmm/vcpu_dispatcher.h +++ b/repos/ports/include/vmm/vcpu_dispatcher.h @@ -57,13 +57,18 @@ class Vmm::Vcpu_dispatcher : public T public: - Vcpu_dispatcher(size_t stack_size, Cap_connection &cap) + Vcpu_dispatcher(size_t stack_size, Cap_connection &cap, + Cpu_session * cpu_session, + Genode::Affinity::Location location) : T("vCPU dispatcher", stack_size), _cap(cap) { using namespace Genode; + /* place the thread on CPU described by location object */ + cpu_session->affinity(T::cap(), location); + /* request creation of a 'local' EC */ T::_tid.ec_sel = Native_thread::INVALID_INDEX - 1; T::start(); @@ -72,12 +77,17 @@ class Vmm::Vcpu_dispatcher : public T template Vcpu_dispatcher(size_t stack_size, Cap_connection &cap, + Cpu_session * cpu_session, + Genode::Affinity::Location location, X attr, void *(*start_routine) (void *), void *arg) : T(attr, start_routine, arg, stack_size, "vCPU dispatcher", nullptr), _cap(cap) { using namespace Genode; + /* place the thread on CPU described by location object */ + cpu_session->affinity(T::cap(), location); + /* request creation of a 'local' EC */ T::_tid.ec_sel = Native_thread::INVALID_INDEX - 1; T::start(); diff --git a/repos/ports/include/vmm/vcpu_thread.h b/repos/ports/include/vmm/vcpu_thread.h index 8bfa222f9..0ab087206 100644 --- a/repos/ports/include/vmm/vcpu_thread.h +++ b/repos/ports/include/vmm/vcpu_thread.h @@ -43,16 +43,18 @@ class Vmm::Vcpu_other_pd : public Vmm::Vcpu_thread { private: - Genode::Pd_connection _pd_session; - Genode::Cpu_session *_cpu_session; + Genode::Pd_connection _pd_session; + Genode::Affinity::Location _location; + Genode::Cpu_session *_cpu_session; Genode::addr_t _exc_pt_sel; public: - Vcpu_other_pd(Cpu_session * cpu_session) + Vcpu_other_pd(Cpu_session * cpu_session, + Genode::Affinity::Location location) : - _pd_session("VM"), _cpu_session(cpu_session), + _pd_session("VM"), _location(location), _cpu_session(cpu_session), _exc_pt_sel(Genode::cap_map()->insert(Nova::NUM_INITIAL_VCPU_PT_LOG2)) { } @@ -83,6 +85,9 @@ class Vmm::Vcpu_other_pd : public Vmm::Vcpu_thread */ delegate_vcpu_portals(pager_cap, exc_base()); + /* place the thread on CPU described by location object */ + _cpu_session->affinity(vcpu_vm, _location); + /* start vCPU in separate PD */ _cpu_session->start(vcpu_vm, 0, 0); @@ -101,7 +106,8 @@ class Vmm::Vcpu_same_pd : public Vmm::Vcpu_thread, Genode::Thread_base { public: - Vcpu_same_pd(size_t stack_size, Cpu_session * cpu_session) + Vcpu_same_pd(size_t stack_size, Cpu_session * cpu_session, + Genode::Affinity::Location location) : Thread_base("vCPU", stack_size, Type::NORMAL, cpu_session) { @@ -113,6 +119,9 @@ class Vmm::Vcpu_same_pd : public Vmm::Vcpu_thread, Genode::Thread_base /* tell generic thread code that this becomes a vCPU */ this->tid().is_vcpu = true; + + /* place the thread on CPU described by location object */ + cpu_session->affinity(Thread_base::cap(), location); } ~Vcpu_same_pd() diff --git a/repos/ports/ports/seoul.hash b/repos/ports/ports/seoul.hash index 3e1f45ab9..127b8cfd3 100644 --- a/repos/ports/ports/seoul.hash +++ b/repos/ports/ports/seoul.hash @@ -1 +1 @@ -320f1607901ba6ba2fe18905997a611c7046b9b0 +f9a8e04cc3b086d8cbdff95cd5fcd1f7a3fdaad7 diff --git a/repos/ports/ports/seoul.port b/repos/ports/ports/seoul.port index bd1169f10..a08f1297c 100644 --- a/repos/ports/ports/seoul.port +++ b/repos/ports/ports/seoul.port @@ -3,7 +3,8 @@ VERSION := git DOWNLOADS := seoul.git URL(seoul) := https://github.com/alex-ab/seoul.git -REV(seoul) := genode_13_08 +# branch genode_virtualsmp +REV(seoul) := 86c743a519abb87d3a729db07137222d836420a6 DIR(seoul) := src/app/seoul # diff --git a/repos/ports/run/seoul-auto.run b/repos/ports/run/seoul-auto.run index 8a7823640..5e6d81b35 100644 --- a/repos/ports/run/seoul-auto.run +++ b/repos/ports/run/seoul-auto.run @@ -24,6 +24,8 @@ set use_fancy_stuff 0 set memory_vmm_vm "128M" +set vcpus_to_be_used 2 + set multiboot_files { diff --git a/repos/ports/run/seoul-disc.run b/repos/ports/run/seoul-disc.run index c0d719bd3..dfe31a435 100644 --- a/repos/ports/run/seoul-disc.run +++ b/repos/ports/run/seoul-disc.run @@ -22,6 +22,8 @@ set use_fancy_stuff 0 set memory_vmm_vm "128M" +set vcpus_to_be_used 1 + source ${genode_dir}/repos/ports/run/seoul.inc if {[is_qemu_available]} { diff --git a/repos/ports/run/seoul-fancy.run b/repos/ports/run/seoul-fancy.run index 24ba9ce1f..ba9efb60c 100644 --- a/repos/ports/run/seoul-fancy.run +++ b/repos/ports/run/seoul-fancy.run @@ -26,6 +26,8 @@ set use_fancy_stuff 1 set memory_init "288M" set memory_vmm_vm "128M" +set vcpus_to_be_used 1 + set multiboot_files { diff --git a/repos/ports/run/seoul-kernelbuild.run b/repos/ports/run/seoul-kernelbuild.run index 1ff29bd0d..9a20f0535 100644 --- a/repos/ports/run/seoul-kernelbuild.run +++ b/repos/ports/run/seoul-kernelbuild.run @@ -29,9 +29,12 @@ set use_fancy_stuff 0 set memory_vmm_vm "950M" +# adjust also '-j option' accordingly - see benchmark_cmd +set vcpus_to_be_used 1 + set multiboot_files { - + } diff --git a/repos/ports/run/seoul-net.run b/repos/ports/run/seoul-net.run index 677aa4864..f23a910db 100644 --- a/repos/ports/run/seoul-net.run +++ b/repos/ports/run/seoul-net.run @@ -22,6 +22,8 @@ set use_fancy_stuff 0 set memory_vmm_vm "128M" +set vcpus_to_be_used 1 + set multiboot_files { diff --git a/repos/ports/run/seoul.inc b/repos/ports/run/seoul.inc index ad0c274c7..7233ca2a0 100644 --- a/repos/ports/run/seoul.inc +++ b/repos/ports/run/seoul.inc @@ -83,9 +83,12 @@ puts $vm_cfg_fd { - + } +for {set i 0} {$i < $vcpus_to_be_used} {incr i 1} { + puts $vm_cfg_fd { } +} if {!$use_multiboot} { puts $vm_cfg_fd { @@ -120,7 +123,7 @@ create_boot_directory # append config { - + @@ -143,33 +146,33 @@ append config { - + } append_if [expr !$use_usb] config { - + } append_if $use_block_sata config { - + } append_if $use_block_ide config { - + } append_if [have_spec acpi] config { - + @@ -183,7 +186,7 @@ append_if [have_spec acpi] config { } append_if [expr ![have_spec acpi] && [have_spec pci]] config { - + @@ -191,7 +194,7 @@ append_if [expr ![have_spec acpi] && [have_spec pci]] config { } append_if $use_nic_session config { - + @@ -199,7 +202,7 @@ append_if $use_nic_session config { } append_if [expr $use_nic_session && $use_nic_bridge] config { - + @@ -210,7 +213,7 @@ append_if [expr $use_nic_session && $use_nic_bridge] config { } append_if $use_framebuffer config { - + @@ -223,7 +226,7 @@ append_if $use_framebuffer config { if {!$use_fancy_stuff} { append config { - + } append config " " @@ -245,7 +248,7 @@ append config { } append_if $use_usb config { - + @@ -254,7 +257,7 @@ append_if $use_usb config { } append_if $use_fancy_stuff config { - + @@ -263,7 +266,7 @@ append_if $use_fancy_stuff config { - + @@ -305,7 +308,7 @@ if {$use_fancy_stuff} { - + @@ -318,7 +321,7 @@ if {$use_fancy_stuff} { - + diff --git a/repos/ports/src/app/seoul/main.cc b/repos/ports/src/app/seoul/main.cc index 19257da2d..506ef4d0a 100644 --- a/repos/ports/src/app/seoul/main.cc +++ b/repos/ports/src/app/seoul/main.cc @@ -683,9 +683,11 @@ class Vcpu_dispatcher : public Vcpu_handler, Synced_motherboard &motherboard, bool has_svm, bool has_vmx, - Vmm::Vcpu_thread *vcpu_thread) + Vmm::Vcpu_thread *vcpu_thread, + Genode::Cpu_session *cpu_session, + Genode::Affinity::Location &location) : - Vcpu_handler(STACK_SIZE, cap_connection), + Vcpu_handler(STACK_SIZE, cap_connection, cpu_session, location), _vcpu(vcpu_lock, unsynchronized_vcpu), _vcpu_thread(vcpu_thread), _guest_memory(guest_memory), @@ -837,6 +839,7 @@ class Machine : public StaticReceiver bool _alloc_fb_mem; /* For detecting FB alloc message */ bool _colocate_vm_vmm; + unsigned short _vcpus_up; Nic::Session *_nic; Rtc::Session *_rtc; @@ -911,13 +914,17 @@ class Machine : public StaticReceiver if (verbose_debug) Logging::printf("OP_VCPU_CREATE_BACKEND\n"); + _vcpus_up ++; + Vmm::Vcpu_thread * vcpu_thread; - Genode::Cpu_session * cpu = Genode::env()->cpu_session(); + Genode::Cpu_session * cpu_session = Genode::env()->cpu_session(); + Genode::Affinity::Space cpu_space = cpu_session->affinity_space(); + Genode::Affinity::Location location = cpu_space.location_of_index(_vcpus_up); if (_colocate_vm_vmm) - vcpu_thread = new Vmm::Vcpu_same_pd(Vcpu_dispatcher::STACK_SIZE, cpu); + vcpu_thread = new Vmm::Vcpu_same_pd(Vcpu_dispatcher::STACK_SIZE, cpu_session, location); else - vcpu_thread = new Vmm::Vcpu_other_pd(cpu); + vcpu_thread = new Vmm::Vcpu_other_pd(cpu_session, location); Vcpu_dispatcher *vcpu_dispatcher = new Vcpu_dispatcher(_motherboard_lock, @@ -927,7 +934,9 @@ class Machine : public StaticReceiver _motherboard, _hip->has_feature_svm(), _hip->has_feature_vmx(), - vcpu_thread); + vcpu_thread, + cpu_session, + location); msg.value = vcpu_dispatcher->sel_sm_ec(); return true; @@ -1216,7 +1225,8 @@ class Machine : public StaticReceiver _timeouts(_timeouts_lock, &_unsynchronized_timeouts), _guest_memory(guest_memory), _boot_modules(boot_modules), - _colocate_vm_vmm(colocate) + _colocate_vm_vmm(colocate), + _vcpus_up(0) { _timeouts()->init(); @@ -1304,6 +1314,10 @@ class Machine : public StaticReceiver */ void boot() { + PINF("VM and VMM are %s. VM is starting with %u %s.", + _colocate_vm_vmm ? "co-located" : "not co-located", + _vcpus_up, _vcpus_up > 1 ? "vCPUs" : "vCPU"); + /* init VCPUs */ for (VCpu *vcpu = _unsynchronized_motherboard.last_vcpu; vcpu; vcpu = vcpu->get_last()) { @@ -1462,8 +1476,6 @@ int main(int argc, char **argv) machine.setup_devices(Genode::config()->xml_node().sub_node("machine")); - PINF("VM and VMM %s.", colocate ? "co-located" : "not co-located"); - Genode::printf("\n--- Booting VM ---\n"); machine.boot(); diff --git a/repos/ports/src/test/vmm_utils/main.cc b/repos/ports/src/test/vmm_utils/main.cc index f116ab526..9ec3d53e9 100644 --- a/repos/ports/src/test/vmm_utils/main.cc +++ b/repos/ports/src/test/vmm_utils/main.cc @@ -60,8 +60,8 @@ class Vcpu_dispatcher : public Vmm::Vcpu_dispatcher Vcpu_dispatcher(Cap_connection &cap, Type type) : - Vmm::Vcpu_dispatcher(STACK_SIZE, cap), - _vcpu_thread(STACK_SIZE, Genode::env()->cpu_session()) + Vmm::Vcpu_dispatcher(STACK_SIZE, cap, Genode::env()->cpu_session(), Genode::Affinity::Location()), + _vcpu_thread(STACK_SIZE, Genode::env()->cpu_session(), Genode::Affinity::Location()) { using namespace Nova; diff --git a/repos/ports/src/virtualbox/accloff/sup.cc b/repos/ports/src/virtualbox/accloff/sup.cc index 9f7730539..70bd06d50 100644 --- a/repos/ports/src/virtualbox/accloff/sup.cc +++ b/repos/ports/src/virtualbox/accloff/sup.cc @@ -80,10 +80,11 @@ int SUPR3CallVMMR0Ex(PVMR0 pVMR0, VMCPUID idCpu, unsigned } -extern "C" bool create_emt_vcpu(pthread_t * thread, size_t stack_size, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg) + void *(*start_routine)(void *), void *arg, + Genode::Cpu_session * cpu_session, + Genode::Affinity::Location location) { /* no hardware acceleration support */ return false; diff --git a/repos/ports/src/virtualbox/nova/sup.cc b/repos/ports/src/virtualbox/nova/sup.cc index 7ea7f3d3d..842f7e2bb 100644 --- a/repos/ports/src/virtualbox/nova/sup.cc +++ b/repos/ports/src/virtualbox/nova/sup.cc @@ -178,11 +178,11 @@ bool Vmm_memory::unmap_from_vm(RTGCPHYS GCPhys) extern "C" void pthread_yield(void) { Nova::ec_ctrl(Nova::EC_YIELD); } -extern "C" bool create_emt_vcpu(pthread_t * pthread, size_t stack, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg, - Genode::Cpu_session * cpu_session) + Genode::Cpu_session * cpu_session, + Genode::Affinity::Location location) { Nova::Hip * hip = hip_rom.local_addr(); @@ -191,11 +191,11 @@ bool create_emt_vcpu(pthread_t * pthread, size_t stack, if (hip->has_feature_vmx()) vcpu_handler = new Vcpu_handler_vmx(stack, attr, start_routine, arg, - cpu_session); + cpu_session, location); if (hip->has_feature_svm()) vcpu_handler = new Vcpu_handler_svm(stack, attr, start_routine, arg, - cpu_session); + cpu_session, location); *pthread = vcpu_handler; return true; diff --git a/repos/ports/src/virtualbox/nova/vcpu.h b/repos/ports/src/virtualbox/nova/vcpu.h index 25400b295..e200a972f 100644 --- a/repos/ports/src/virtualbox/nova/vcpu.h +++ b/repos/ports/src/virtualbox/nova/vcpu.h @@ -526,11 +526,13 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher Vcpu_handler(size_t stack_size, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, - Genode::Cpu_session * cpu_session) + Genode::Cpu_session * cpu_session, + Genode::Affinity::Location location) : Vmm::Vcpu_dispatcher(stack_size, _cap_connection, + cpu_session, location, attr ? *attr : 0, start_routine, arg), - _vcpu(cpu_session), + _vcpu(cpu_session, location), _ec_sel(Genode::cap_map()->insert()), _irq_win(false) { } diff --git a/repos/ports/src/virtualbox/nova/vcpu_svm.h b/repos/ports/src/virtualbox/nova/vcpu_svm.h index ecb63f22e..195d01f69 100644 --- a/repos/ports/src/virtualbox/nova/vcpu_svm.h +++ b/repos/ports/src/virtualbox/nova/vcpu_svm.h @@ -83,8 +83,11 @@ class Vcpu_handler_svm : public Vcpu_handler Vcpu_handler_svm(size_t stack_size, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, - Genode::Cpu_session * cpu_session) - : Vcpu_handler(stack_size, attr, start_routine, arg, cpu_session) + Genode::Cpu_session * cpu_session, + Genode::Affinity::Location location) + : + Vcpu_handler(stack_size, attr, start_routine, arg, cpu_session, + location) { using namespace Nova; diff --git a/repos/ports/src/virtualbox/nova/vcpu_vmx.h b/repos/ports/src/virtualbox/nova/vcpu_vmx.h index e7454d87d..c8ca1800e 100644 --- a/repos/ports/src/virtualbox/nova/vcpu_vmx.h +++ b/repos/ports/src/virtualbox/nova/vcpu_vmx.h @@ -117,8 +117,11 @@ class Vcpu_handler_vmx : public Vcpu_handler Vcpu_handler_vmx(size_t stack_size, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, - Genode::Cpu_session * cpu_session) - : Vcpu_handler(stack_size, attr, start_routine, arg, cpu_session) + Genode::Cpu_session * cpu_session, + Genode::Affinity::Location location) + : + Vcpu_handler(stack_size, attr, start_routine, arg, cpu_session, + location) { using namespace Nova; diff --git a/repos/ports/src/virtualbox/sup.h b/repos/ports/src/virtualbox/sup.h index ce32a11c7..e7c1c61a4 100644 --- a/repos/ports/src/virtualbox/sup.h +++ b/repos/ports/src/virtualbox/sup.h @@ -27,8 +27,20 @@ /* libc memory allocator */ #include +/** + * Returns true if a vCPU could be started. If false we run without + * hardware acceleration support. + */ +bool create_emt_vcpu(pthread_t * pthread, size_t stack, + const pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg, + Genode::Cpu_session * cpu_session, + Genode::Affinity::Location location); + + uint64_t genode_cpu_hz(); + void inline genode_VMMR0_DO_GVMM_CREATE_VM(PSUPVMMR0REQHDR pReqHdr) { GVMMCREATEVMREQ &req = reinterpret_cast(*pReqHdr); diff --git a/repos/ports/src/virtualbox/thread.cc b/repos/ports/src/virtualbox/thread.cc index 4dbd25813..d1719ca8f 100644 --- a/repos/ports/src/virtualbox/thread.cc +++ b/repos/ports/src/virtualbox/thread.cc @@ -20,6 +20,8 @@ /* Genode libc pthread binding */ #include "thread.h" +#include "sup.h" + /* libc */ #include #include @@ -55,15 +57,6 @@ static Genode::Cpu_session * get_cpu_session(RTTHREADTYPE type) { extern "C" { - /** - * Returns true if a vCPU could be started. If false we run without - * hardware acceleration support. - */ - bool create_emt_vcpu(pthread_t * pthread, size_t stack, - const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg, - Genode::Cpu_session *); - int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { @@ -86,9 +79,12 @@ extern "C" { Assert(rtthread->enmType == RTTHREADTYPE_EMULATION); if (rtthread->enmType == RTTHREADTYPE_EMULATION) { - + Genode::Cpu_session * cpu_session = get_cpu_session(RTTHREADTYPE_EMULATION); + Genode::Affinity::Space cpu_space = cpu_session->affinity_space(); +/* Genode::Affinity::Location location = cpu_space.location_of_index(i); */ + Genode::Affinity::Location location; if (create_emt_vcpu(thread, stack_size, attr, start_routine, arg, - get_cpu_session(RTTHREADTYPE_EMULATION))) + cpu_session, location)) return 0; /* no haredware support, create normal pthread thread */ }