Ensure that wait sufficiently on faster CPUs. Signed-off-by: Alice Guo <[email protected]> --- hypervisor/arch/arm-common/Kbuild | 2 +- .../arch/arm-common/include/asm/timing.h | 17 ++++++++ hypervisor/arch/arm-common/timing.c | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 hypervisor/arch/arm-common/include/asm/timing.h create mode 100644 hypervisor/arch/arm-common/timing.c
diff --git a/hypervisor/arch/arm-common/Kbuild b/hypervisor/arch/arm-common/Kbuild index ab86eca6..86ef9b86 100644 --- a/hypervisor/arch/arm-common/Kbuild +++ b/hypervisor/arch/arm-common/Kbuild @@ -17,6 +17,6 @@ ccflags-$(CONFIG_JAILHOUSE_GCOV) += -fprofile-arcs -ftest-coverage objs-y += dbg-write.o lib.o psci.o control.o paging.o mmu_cell.o setup.o objs-y += irqchip.o pci.o ivshmem.o uart-pl011.o uart-xuartps.o uart-mvebu.o objs-y += uart-hscif.o uart-scifa.o uart-imx.o uart-imx-lpuart.o -objs-y += gic-v2.o gic-v3.o smccc.o +objs-y += gic-v2.o gic-v3.o smccc.o timing.o common-objs-y = $(addprefix ../arm-common/,$(objs-y)) diff --git a/hypervisor/arch/arm-common/include/asm/timing.h b/hypervisor/arch/arm-common/include/asm/timing.h new file mode 100644 index 00000000..145beb6c --- /dev/null +++ b/hypervisor/arch/arm-common/include/asm/timing.h @@ -0,0 +1,17 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright 2020 NXP + * + * Authors: + * Alice Guo <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include <jailhouse/types.h> + +unsigned long timer_get_frequency(void); +u64 timer_get_ticks(void); +void delay_us(unsigned long microsecs); diff --git a/hypervisor/arch/arm-common/timing.c b/hypervisor/arch/arm-common/timing.c new file mode 100644 index 00000000..ad4a5a86 --- /dev/null +++ b/hypervisor/arch/arm-common/timing.c @@ -0,0 +1,39 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright 2020 NXP + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Partly derived from inmates/lib/arm-common/timing.c + */ + +#include <asm/processor.h> +#include <asm/sysregs.h> +#include <asm/timing.h> + +unsigned long timer_get_frequency(void) +{ + unsigned long freq; + + arm_read_sysreg(CNTFRQ_EL0, freq); + return freq; +} + +u64 timer_get_ticks(void) +{ + u64 pct64; + + arm_read_sysreg(CNTPCT_EL0, pct64); + return pct64; +} + +void delay_us(unsigned long microsecs) +{ + unsigned long long timeout = timer_get_ticks() + + microsecs * (timer_get_frequency() / 1000 / 1000); + + while ((long long)(timeout - timer_get_ticks()) > 0) + cpu_relax(); +} -- 2.17.1 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/20200828084425.21282-1-alice.guo%40nxp.com.
