1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Fast user context implementation of getcpu()
4  */
5 
6 #include <asm/vdso.h>
7 #include <linux/getcpu.h>
8 
9 static __always_inline int read_cpu_id(void)
10 {
11 	int cpu_id;
12 
13 	__asm__ __volatile__(
14 	"	rdtime.d $zero, %0\n"
15 	: "=r" (cpu_id)
16 	:
17 	: "memory");
18 
19 	return cpu_id;
20 }
21 
22 extern
23 int __vdso_getcpu(unsigned int *cpu, unsigned int *node, struct getcpu_cache *unused);
24 int __vdso_getcpu(unsigned int *cpu, unsigned int *node, struct getcpu_cache *unused)
25 {
26 	int cpu_id;
27 
28 	cpu_id = read_cpu_id();
29 
30 	if (cpu)
31 		*cpu = cpu_id;
32 
33 	if (node)
34 		*node = vdso_u_arch_data.pdata[cpu_id].node;
35 
36 	return 0;
37 }
38