riscv / riscv-isa-manual

RISC-V Instruction Set Manual
https://riscv.org/
Creative Commons Attribution 4.0 International
3.46k stars 597 forks source link

Userspace unique CPU identifier #1297

Open wangpc-pp opened 4 months ago

wangpc-pp commented 4 months ago

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 commented 3 months ago

Ping for comments.

aswaterman commented 3 months ago

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

wangpc-pp commented 3 months ago

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?

aswaterman commented 3 months ago

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.