Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gloop/base/percpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion gloop/concurrent/percpu/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ class iterator : public std::iterator<std::random_access_iterator_tag, T> {

template <typename T>
template <typename... Args>
PerCpu<T>::PerCpu(Args... args) : lock_(), array_(NumCPUs()) {
PerCpu<T>::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...);
}
Expand Down
6 changes: 3 additions & 3 deletions gloop/concurrent/percpu/object_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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)));
}

Expand All @@ -197,7 +197,7 @@ TEST_F(PerCpuTest, DestructorsMustBeCalled) {

{
PerCpu<TrackableObject> pc;
EXPECT_EQ(outstanding_objects, NumCPUs());
EXPECT_EQ(outstanding_objects, pc.size());
}
EXPECT_EQ(outstanding_objects, 0);
}
Expand Down
Loading