diff options
author | Raghavendra Rao Ananta <rananta@google.com> | 2021-10-08 01:34:31 +0200 |
---|---|---|
committer | Marc Zyngier <maz@kernel.org> | 2021-10-17 12:17:20 +0200 |
commit | 80166904655976bb9babc48fd283c2bba5799920 (patch) | |
tree | 3481ef6b6a002cf4f1e0184765ab99620516c0ba /tools | |
parent | KVM: arm64: selftests: Add basic support for arch_timers (diff) | |
download | linux-80166904655976bb9babc48fd283c2bba5799920.tar.xz linux-80166904655976bb9babc48fd283c2bba5799920.zip |
KVM: arm64: selftests: Add basic support to generate delays
Add udelay() support to generate a delay in the guest.
The routines are derived and simplified from kernel's
arch/arm64/lib/delay.c.
Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Oliver Upton <oupton@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20211007233439.1826892-8-rananta@google.com
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/kvm/include/aarch64/delay.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/include/aarch64/delay.h b/tools/testing/selftests/kvm/include/aarch64/delay.h new file mode 100644 index 000000000000..329e4f5079ea --- /dev/null +++ b/tools/testing/selftests/kvm/include/aarch64/delay.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * ARM simple delay routines + */ + +#ifndef SELFTEST_KVM_ARM_DELAY_H +#define SELFTEST_KVM_ARM_DELAY_H + +#include "arch_timer.h" + +static inline void __delay(uint64_t cycles) +{ + enum arch_timer timer = VIRTUAL; + uint64_t start = timer_get_cntct(timer); + + while ((timer_get_cntct(timer) - start) < cycles) + cpu_relax(); +} + +static inline void udelay(unsigned long usec) +{ + __delay(usec_to_cycles(usec)); +} + +#endif /* SELFTEST_KVM_ARM_DELAY_H */ |