From d7f0cb5463eec22f49349dbb050add81bd67957b Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 7 Apr 2017 11:30:43 +0200 Subject: [PATCH] vbox5: use gip thread also for timer watchdog causes the rem timer callback pending check to run more often (every 1 ms instead 10 ms). This is essential to met the timeout requirements of the audio backend, which must be checked&run every 5ms. --- repos/ports/lib/mk/virtualbox-runtime.mk | 4 +- repos/ports/lib/mk/virtualbox5-runtime.mk | 4 +- repos/ports/src/virtualbox/sup.cc | 76 ++++++++++++++++++----- repos/ports/src/virtualbox/unimpl.cc | 3 - repos/ports/src/virtualbox5/sup.cc | 38 +++++++++++- 5 files changed, 102 insertions(+), 23 deletions(-) diff --git a/repos/ports/lib/mk/virtualbox-runtime.mk b/repos/ports/lib/mk/virtualbox-runtime.mk index e675d33ae..6c6330a82 100644 --- a/repos/ports/lib/mk/virtualbox-runtime.mk +++ b/repos/ports/lib/mk/virtualbox-runtime.mk @@ -25,7 +25,9 @@ FILTERED_OUT_SRC_CC = RTLogDefaultInit-generic.cpp \ RTSemMutexRequest-generic.cpp \ RTSemMutexRequestDebug-generic.cpp \ RTDirExists-generic.cpp \ - RTMpOnPair-generic.cpp + RTMpOnPair-generic.cpp \ + RTTimerCreate-generic.cpp \ + timer-generic.cpp CC_WARN += -Wno-unused-variable diff --git a/repos/ports/lib/mk/virtualbox5-runtime.mk b/repos/ports/lib/mk/virtualbox5-runtime.mk index 74c01a201..dfd7dc8be 100644 --- a/repos/ports/lib/mk/virtualbox5-runtime.mk +++ b/repos/ports/lib/mk/virtualbox5-runtime.mk @@ -27,7 +27,9 @@ FILTERED_OUT_SRC_CC = fs-stubs-generic.cpp \ RTSemEventMultiWait-2-ex-generic.cpp \ RTSemMutexRequest-generic.cpp \ RTSemMutexRequestDebug-generic.cpp \ - RTTimeLocalExplode-generic.cpp + RTTimeLocalExplode-generic.cpp \ + RTTimerCreate-generic.cpp \ + timer-generic.cpp CC_WARN += -Wno-unused-variable diff --git a/repos/ports/src/virtualbox/sup.cc b/repos/ports/src/virtualbox/sup.cc index 7065107d1..1747b9739 100644 --- a/repos/ports/src/virtualbox/sup.cc +++ b/repos/ports/src/virtualbox/sup.cc @@ -20,24 +20,19 @@ #include "vmm.h" /* VirtualBox includes */ -#include #include +#include +#include #include #include - -struct Attached_gip : Genode::Attached_ram_dataspace -{ - Attached_gip() - : Attached_ram_dataspace(genode_env().ram(), genode_env().rm(), PAGE_SIZE) - { } -}; - +static PFNRTTIMER rttimer_func = nullptr; +static void * rttimer_obj = nullptr; enum { UPDATE_HZ = 1000, - UPDATE_MS = 1000 / UPDATE_HZ, - UPDATE_NS = UPDATE_MS * 1000 * 1000, + UPDATE_US = 1000 * 1000 / UPDATE_HZ, + UPDATE_NS = UPDATE_US * 1000, }; @@ -95,12 +90,51 @@ struct Periodic_gip : public Genode::Thread * read struct SUPGIPCPU description for more details. */ ASMAtomicIncU32(&cpu->u32TransactionId); + + /* call the timer function of the RTTimerCreate call */ + if (rttimer_func) + rttimer_func(nullptr, rttimer_obj, 0); } - void entry() override { genode_update_tsc(update, UPDATE_MS * 1000); } + void entry() override { genode_update_tsc(update, UPDATE_US); } }; +struct Attached_gip : Genode::Attached_ram_dataspace +{ + Attached_gip() + : Attached_ram_dataspace(genode_env().ram(), genode_env().rm(), PAGE_SIZE) + { } +}; + + +int RTTimerCreate(PRTTIMER *pptimer, unsigned ms, PFNRTTIMER func, void *obj) +{ + if (pptimer) + *pptimer = NULL; + + /* used solely at one place in TM.cpp */ + Assert(!rttimer_func); + + /* + * Ignore (10) ms which is too high for audio. Instead the callback + * handler will run at UPDATE_HZ rate. + */ + rttimer_func = func; + rttimer_obj = obj; + + return VINF_SUCCESS; +} + + +int RTTimerDestroy(PRTTIMER) +{ + rttimer_obj = nullptr; + rttimer_func = nullptr; + return VINF_SUCCESS; +} + + int SUPR3Init(PSUPDRVSESSION *ppSession) { static bool initialized = false; @@ -212,8 +246,7 @@ int SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, } -SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION, - PSUPSEMEVENTMULTI phEventMulti) +int SUPSemEventMultiCreate(PSUPDRVSESSION, PSUPSEMEVENTMULTI phEventMulti) { RTSEMEVENTMULTI sem; @@ -233,11 +266,22 @@ SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION, } -SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION, SUPSEMEVENTMULTI hEvMulti) +int SUPSemEventMultiWaitNoResume(PSUPDRVSESSION, SUPSEMEVENTMULTI event, + uint32_t ms) { - return RTSemEventMultiDestroy(reinterpret_cast(hEvMulti)); + RTSEMEVENTMULTI const rtevent = reinterpret_cast(event); + return RTSemEventMultiWait(rtevent, ms); } +int SUPSemEventMultiSignal(PSUPDRVSESSION, SUPSEMEVENTMULTI event) { + return RTSemEventMultiSignal(reinterpret_cast(event)); } + +int SUPSemEventMultiReset(PSUPDRVSESSION, SUPSEMEVENTMULTI event) { + return RTSemEventMultiReset(reinterpret_cast(event)); } + +int SUPSemEventMultiClose(PSUPDRVSESSION, SUPSEMEVENTMULTI event) { + return RTSemEventMultiDestroy(reinterpret_cast(event)); } + int SUPR3CallVMMR0(PVMR0 pVMR0, VMCPUID idCpu, unsigned uOperation, void *pvArg) diff --git a/repos/ports/src/virtualbox/unimpl.cc b/repos/ports/src/virtualbox/unimpl.cc index 96e5b366d..9c1ff3df4 100644 --- a/repos/ports/src/virtualbox/unimpl.cc +++ b/repos/ports/src/virtualbox/unimpl.cc @@ -128,9 +128,6 @@ DUMMY(SELMR3GetShadowSelectorInfo) DUMMY(SUPR3HardenedLdrLoadPlugIn) -DUMMY(SUPSemEventMultiWaitNoResume) -DUMMY(SUPSemEventMultiReset) - DUMMY(VMMR3GetHostToGuestSwitcher) DUMMY(RTHeapSimpleRelocate) diff --git a/repos/ports/src/virtualbox5/sup.cc b/repos/ports/src/virtualbox5/sup.cc index e5eedbefa..6e6fc53ce 100644 --- a/repos/ports/src/virtualbox5/sup.cc +++ b/repos/ports/src/virtualbox5/sup.cc @@ -17,14 +17,17 @@ /* Genode/Virtualbox includes */ #include "sup.h" +#include "vmm.h" /* VirtualBox includes */ -#include #include +#include +#include #include #include -#include "vmm.h" +static PFNRTTIMER rttimer_func = nullptr; +static void * rttimer_obj = nullptr; enum { UPDATE_HZ = 1000, @@ -87,6 +90,10 @@ struct Periodic_gip : public Genode::Thread * read struct SUPGIPCPU description for more details. */ ASMAtomicIncU32(&cpu->u32TransactionId); + + /* call the timer function of the RTTimerCreate call */ + if (rttimer_func) + rttimer_func(nullptr, rttimer_obj, 0); } void entry() override { genode_update_tsc(update, UPDATE_US); } @@ -137,6 +144,33 @@ struct Attached_gip : Genode::Attached_ram_dataspace }; +int RTTimerCreate(PRTTIMER *pptimer, unsigned ms, PFNRTTIMER func, void *obj) +{ + if (pptimer) + *pptimer = NULL; + + /* used solely at one place in TM.cpp */ + Assert(!rttimer_func); + + /* + * Ignore (10) ms which is too high for audio. Instead the callback + * handler will run at UPDATE_HZ rate. + */ + rttimer_func = func; + rttimer_obj = obj; + + return VINF_SUCCESS; +} + + +int RTTimerDestroy(PRTTIMER) +{ + rttimer_obj = nullptr; + rttimer_func = nullptr; + return VINF_SUCCESS; +} + + int SUPR3Init(PSUPDRVSESSION *ppSession) { static Attached_gip gip;