diff --git a/gloop/base/percpu.h b/gloop/base/percpu.h index 6cf6ddc5a..6a7664400 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 ab85d320c..eb3598706 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 94737a97a..c46393c97 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); }