summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/include/aarch64/delay.h
blob: 329e4f5079ea55a698e4acef652fdfad09bf4c51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 */