summaryrefslogtreecommitdiff
path: root/minix/lib/libc/arch/arm/read_tsc.c
blob: de829f8b0b59df0177cf39515fbbcdb2b36494da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <sys/types.h>
#include <minix/minlib.h>

void
read_tsc(u32_t *hi, u32_t *lo)
{
/* Read Clock Cycle Counter (CCNT). Intel calls it Time Stamp Counter (TSC) */
	u32_t ccnt;

	/* Get value from the Performance Monitors Cycle Counter Register.
	 * See ARM Architecture Reference Manual B5.1.113.
	 */
	asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n" : "=r" (ccnt) : : "%0");

	/* The ARMv7-A clock cycle counter is only 32-bits, but read_tsc is
	 * expected to return a 64-bit value. hi is therefore always 0.
	 */
	*hi = 0;
	*lo = ccnt;
}