[libc-commits] [libc] [libc][sched] add vdso fast path to getcpu (PR #195070)
via libc-commits
libc-commits at lists.llvm.org
Thu Apr 30 05:47:17 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Schrodinger ZHU Yifan (SchrodingerZhu)
<details>
<summary>Changes</summary>
Add a fastpath for getcpu via vDSO.
---
Full diff: https://github.com/llvm/llvm-project/pull/195070.diff
2 Files Affected:
- (modified) libc/src/sched/linux/CMakeLists.txt (+1)
- (modified) libc/src/sched/linux/getcpu.cpp (+5-1)
``````````diff
diff --git a/libc/src/sched/linux/CMakeLists.txt b/libc/src/sched/linux/CMakeLists.txt
index ceb755f8e1d1a..0edccd6ee5e8c 100644
--- a/libc/src/sched/linux/CMakeLists.txt
+++ b/libc/src/sched/linux/CMakeLists.txt
@@ -6,6 +6,7 @@ add_entrypoint_object(
../getcpu.h
DEPENDS
libc.src.__support.OSUtil.osutil
+ libc.src.__support.OSUtil.linux.vdso
libc.src.errno.errno
)
diff --git a/libc/src/sched/linux/getcpu.cpp b/libc/src/sched/linux/getcpu.cpp
index a34b693fc148e..7aa085f557b33 100644
--- a/libc/src/sched/linux/getcpu.cpp
+++ b/libc/src/sched/linux/getcpu.cpp
@@ -8,6 +8,7 @@
#include "src/sched/getcpu.h"
+#include "src/__support/OSUtil/linux/vdso.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
@@ -18,7 +19,10 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, getcpu, (unsigned int *cpu, unsigned int *node)) {
- int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_getcpu, cpu, node, nullptr);
+ vdso::TypedSymbol<vdso::VDSOSym::GetCpu> vdso_getcpu;
+ int ret = vdso_getcpu ? vdso_getcpu(cpu, node, nullptr)
+ : LIBC_NAMESPACE::syscall_impl<int>(SYS_getcpu, cpu,
+ node, nullptr);
if (ret < 0) {
libc_errno = -ret;
return -1;
``````````
</details>
https://github.com/llvm/llvm-project/pull/195070
More information about the libc-commits
mailing list