xref: /OK3568_Linux_fs/kernel/tools/perf/arch/arm64/util/tsc.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun #include <linux/types.h>
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include "../../../util/tsc.h"
6*4882a593Smuzhiyun 
rdtsc(void)7*4882a593Smuzhiyun u64 rdtsc(void)
8*4882a593Smuzhiyun {
9*4882a593Smuzhiyun 	u64 val;
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun 	/*
12*4882a593Smuzhiyun 	 * According to ARM DDI 0487F.c, from Armv8.0 to Armv8.5 inclusive, the
13*4882a593Smuzhiyun 	 * system counter is at least 56 bits wide; from Armv8.6, the counter
14*4882a593Smuzhiyun 	 * must be 64 bits wide.  So the system counter could be less than 64
15*4882a593Smuzhiyun 	 * bits wide and it is attributed with the flag 'cap_user_time_short'
16*4882a593Smuzhiyun 	 * is true.
17*4882a593Smuzhiyun 	 */
18*4882a593Smuzhiyun 	asm volatile("mrs %0, cntvct_el0" : "=r" (val));
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun 	return val;
21*4882a593Smuzhiyun }
22