riscv-isa-manual icon indicating copy to clipboard operation
riscv-isa-manual copied to clipboard

Userspace unique CPU identifier

Open wangpc-pp opened this issue 1 year ago • 4 comments

When optimizing __vdso_getcpu, we need an userspace unique identifier as the CPU id. Currently we just invoke the syscall.

#include <linux/linkage.h>
#include <asm/unistd.h>

	.text
/* int __vdso_getcpu(unsigned *cpu, unsigned *node, void *unused); */
SYM_FUNC_START(__vdso_getcpu)
	.cfi_startproc
	/* For now, just do the syscall. */
	li a7, __NR_getcpu
	ecall
	ret
	.cfi_endproc
SYM_FUNC_END(__vdso_getcpu)

But we can't read mhartid, is there a way/extension to expose mhartid to userspace? Or is there an unique identifier that can be used as CPU id?

wangpc-pp avatar Mar 27 '24 04:03 wangpc-pp

Ping for comments.

wangpc-pp avatar Apr 09 '24 08:04 wangpc-pp

No, there is no plan to add such a feature.

aswaterman avatar Apr 09 '24 08:04 aswaterman

No, there is no plan to add such a feature.

If so, then there is no meaning for getcpu in vDSO, which may cause some performance issues compared to other archs. What if we add an extension to expose mhartid to unprivileged code?

wangpc-pp avatar Apr 09 '24 08:04 wangpc-pp

There is a reason to have getcpu in the vDSO, which is that a user-space facility could eventually be added if deemed necessary. Perhaps its day will come.

Directly exposing mhartid is a virtualization hole.

aswaterman avatar Apr 09 '24 09:04 aswaterman