summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/system/cpu_id.cpp
diff options
context:
space:
mode:
authorbabenko <[email protected]>2026-06-15 11:13:32 +0300
committerbabenko <[email protected]>2026-06-15 11:32:51 +0300
commit12be02b42fc24cf7bd990d56da8cf8908a35db2d (patch)
tree801270254f6351c6fe2b30e81f19df5cd4a1578e /library/cpp/yt/system/cpu_id.cpp
parent03c4def7658a9ce2bcf05bd4e9feee83d89d3fe6 (diff)
Make library/cpp/yt/rseq a Linux-only dependency of library/cpp/yt/system
Make library/cpp/yt/rseq a Linux-only dependency of library/cpp/yt/system commit_hash:7d6f5e738658447529440425b55b2891f6664d81
Diffstat (limited to 'library/cpp/yt/system/cpu_id.cpp')
-rw-r--r--library/cpp/yt/system/cpu_id.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/library/cpp/yt/system/cpu_id.cpp b/library/cpp/yt/system/cpu_id.cpp
index d4cccc21ee1..9f6e46c9fc9 100644
--- a/library/cpp/yt/system/cpu_id.cpp
+++ b/library/cpp/yt/system/cpu_id.cpp
@@ -1,10 +1,10 @@
#include "cpu_id.h"
-#include <library/cpp/yt/rseq/rseq.h>
-
#include <library/cpp/yt/misc/tls.h>
-#if defined(__linux__)
+#ifdef __linux__
+#include <library/cpp/yt/rseq/rseq.h>
+
#include <sched.h>
#endif
@@ -12,33 +12,26 @@ namespace NYT::NDetail {
////////////////////////////////////////////////////////////////////////////////
-#ifdef YT_RSEQ_AVAILABLE
+#ifdef __linux__
YT_PREVENT_TLS_CACHING int GetCurrentCpuIdSlow()
{
+#ifdef YT_RSEQ_AVAILABLE
if (NRseq::EnsureCurrentThreadRegistered()) {
auto cpuId = NRseq::ReadField<int>(NRseq::CpuIdFieldOffset);
if (cpuId >= 0) {
return cpuId;
}
}
-
- auto cpuId = ::sched_getcpu();
- return cpuId >= 0 ? cpuId : 0;
-}
-
-#elif defined(__linux__)
-
-// Linux without a known fast path (e.g. an unsupported arch): use sched_getcpu.
-int GetCurrentCpuIdSlow()
-{
+#endif
+ // No rseq fast path (unsupported arch, or thread not registered): sched_getcpu.
auto cpuId = ::sched_getcpu();
return cpuId >= 0 ? cpuId : 0;
}
#else
-// No rseq and no sched_getcpu (darwin / windows): sharding degenerates to one shard.
+// No sched_getcpu (darwin / windows): sharding degenerates to one shard.
int GetCurrentCpuIdSlow()
{
return 0;