[libc-commits] [libc] [libc][sched] add vdso fast path to getcpu (PR #195070)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Thu Apr 30 05:46:21 PDT 2026


https://github.com/SchrodingerZhu created https://github.com/llvm/llvm-project/pull/195070

None

>From 56ae5497ecc7d462823c27c1c186a7293a16872a Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Thu, 30 Apr 2026 08:45:49 -0400
Subject: [PATCH] [libc][sched] add vdso fast path to getcpu

---
 libc/src/sched/linux/CMakeLists.txt | 1 +
 libc/src/sched/linux/getcpu.cpp     | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

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;



More information about the libc-commits mailing list