xref: /linux/arch/loongarch/vdso/vgetcpu.c (revision 9551a26f17d9445eed497bd7c639d48dfc3c0af4)
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 
read_cpu_id(void)9 static __always_inline int read_cpu_id(void)
10 {
11 	int cpu_id;
12 
13 #ifdef CONFIG_64BIT
14 	__asm__ __volatile__(
15 	"	rdtime.d $zero, %0\n"
16 	: "=r" (cpu_id)
17 	:
18 	: "memory");
19 #else
20 	__asm__ __volatile__(
21 	"	rdtimel.w $zero, %0\n"
22 	: "=r" (cpu_id)
23 	:
24 	: "memory");
25 #endif
26 
27 	return cpu_id;
28 }
29 
30 extern
31 int __vdso_getcpu(unsigned int *cpu, unsigned int *node, struct getcpu_cache *unused);
__vdso_getcpu(unsigned int * cpu,unsigned int * node,struct getcpu_cache * unused)32 int __vdso_getcpu(unsigned int *cpu, unsigned int *node, struct getcpu_cache *unused)
33 {
34 	int cpu_id;
35 
36 	cpu_id = read_cpu_id();
37 
38 	if (cpu)
39 		*cpu = cpu_id;
40 
41 	if (node)
42 		*node = vdso_u_arch_data.pdata[cpu_id].node;
43 
44 	return 0;
45 }
46