From 12be02b42fc24cf7bd990d56da8cf8908a35db2d Mon Sep 17 00:00:00 2001 From: babenko Date: Mon, 15 Jun 2026 11:13:32 +0300 Subject: 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 --- library/cpp/yt/rseq/ya.make | 4 ++++ library/cpp/yt/system/cpu_id-inl.h | 2 ++ library/cpp/yt/system/cpu_id.cpp | 23 ++++++++--------------- library/cpp/yt/system/ya.make | 7 ++++++- 4 files changed, 20 insertions(+), 16 deletions(-) (limited to 'library/cpp') diff --git a/library/cpp/yt/rseq/ya.make b/library/cpp/yt/rseq/ya.make index cb233c52fbb..f0f55e17f49 100644 --- a/library/cpp/yt/rseq/ya.make +++ b/library/cpp/yt/rseq/ya.make @@ -2,6 +2,10 @@ LIBRARY() INCLUDE(${ARCADIA_ROOT}/library/cpp/yt/ya_cpp.make.inc) +IF (NOT OS_LINUX) + MESSAGE(FATAL_ERROR "library/cpp/yt/rseq is Linux-only") +ENDIF() + SRCS( rseq.cpp ) diff --git a/library/cpp/yt/system/cpu_id-inl.h b/library/cpp/yt/system/cpu_id-inl.h index af3ed0d7ab4..e336ba5a2ce 100644 --- a/library/cpp/yt/system/cpu_id-inl.h +++ b/library/cpp/yt/system/cpu_id-inl.h @@ -5,7 +5,9 @@ #endif #undef CPU_ID_INL_H_ +#ifdef __linux__ #include +#endif #include 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 - #include -#if defined(__linux__) +#ifdef __linux__ +#include + #include #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(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; diff --git a/library/cpp/yt/system/ya.make b/library/cpp/yt/system/ya.make index 772cbaba788..aca2f0dcdf6 100644 --- a/library/cpp/yt/system/ya.make +++ b/library/cpp/yt/system/ya.make @@ -15,9 +15,14 @@ PEERDIR( library/cpp/yt/cpu_clock library/cpp/yt/exception library/cpp/yt/misc - library/cpp/yt/rseq ) +IF (OS_LINUX) + PEERDIR( + library/cpp/yt/rseq + ) +ENDIF() + END() RECURSE( -- cgit v1.3