From 3eb071e80ad8117fbde9be2a72c7eb14b4eb5fea Mon Sep 17 00:00:00 2001 From: Gloop Team Date: Thu, 13 Aug 2026 01:15:10 -0700 Subject: [PATCH] Internal cleanup PiperOrigin-RevId: 963922192 --- gloop/base/percpu.h | 2 +- gloop/concurrent/percpu/object.h | 6 +++++- gloop/concurrent/percpu/object_test.cc | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gloop/base/percpu.h b/gloop/base/percpu.h index 6cf6ddc5..6a766440 100644 --- a/gloop/base/percpu.h +++ b/gloop/base/percpu.h @@ -443,7 +443,7 @@ static inline int RseqFunction_PerCpuTryLock(volatile kernel_rseq* rseq_abi, PERCPU_RSEQ_PROLOGUE(RseqFunction_PerCpuTryLock, scratch) "4:\n" - PERCPU_RSEQ_LOAD_CPU_ID(cpu) + PERCPU_RSEQ_LOAD_VIRTUAL_FLAT_CPU_ID(cpu) "mov %[cpu], %[scratch]\n" "shl %[shift], %[scratch]\n" "cmpq $0, (%[scratch], %[base])\n" diff --git a/gloop/concurrent/percpu/object.h b/gloop/concurrent/percpu/object.h index ab85d320..eb359870 100644 --- a/gloop/concurrent/percpu/object.h +++ b/gloop/concurrent/percpu/object.h @@ -294,7 +294,11 @@ class iterator : public std::iterator { template template -PerCpu::PerCpu(Args... args) : lock_(), array_(NumCPUs()) { +PerCpu::PerCpu(Args... args) + : lock_(), + array_(base::subtle::percpu::UsingRseqVirtualCpus() + ? base::AvailableCPUs() + : NumCPUs()) { for (std::size_t i = 0; i != size(); ++i) { new (&array_[i]) T(args...); } diff --git a/gloop/concurrent/percpu/object_test.cc b/gloop/concurrent/percpu/object_test.cc index 94737a97..c46393c9 100644 --- a/gloop/concurrent/percpu/object_test.cc +++ b/gloop/concurrent/percpu/object_test.cc @@ -100,7 +100,7 @@ TEST_F(PerCpuTest, SetSomethingAndIterate) { // We should see zero (for default-initialization) NumCPUs - 1 times, since we // never touch the other CPUs' values, and 3 once. EXPECT_THAT(observations, - testing::UnorderedElementsAre(testing::Pair(0, NumCPUs() - 1), + testing::UnorderedElementsAre(testing::Pair(0, pc.size() - 1), testing::Pair(3, 1))); } @@ -183,7 +183,7 @@ TEST_F(PerCpuTest, Initialization) { // We should see one (for the initialization we did in the constructor) // NumCPUs - 1 times, since we never touch the other CPUs' values, and 3 once. EXPECT_THAT(observations, - testing::UnorderedElementsAre(testing::Pair(1, NumCPUs() - 1), + testing::UnorderedElementsAre(testing::Pair(1, pc.size() - 1), testing::Pair(3, 1))); } @@ -197,7 +197,7 @@ TEST_F(PerCpuTest, DestructorsMustBeCalled) { { PerCpu pc; - EXPECT_EQ(outstanding_objects, NumCPUs()); + EXPECT_EQ(outstanding_objects, pc.size()); } EXPECT_EQ(outstanding_objects, 0); }