Skip to content

Commit f70d806

Browse files
author
Maxim Egorushkin
committed
Add B variant stress tests for MPMC and SPSC modes
1 parent 43ca2e8 commit f70d806

3 files changed

Lines changed: 46 additions & 14 deletions

File tree

include/atomic_queue/atomic_queue.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,15 @@ struct RetryDecorator : Queue {
649649

650650
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
651651

652+
template<class Queue, size_t Capacity>
653+
struct CapacityArgDecorator : Queue {
654+
CapacityArgDecorator()
655+
: Queue(Capacity)
656+
{}
657+
};
658+
659+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
660+
652661
} // namespace atomic_queue
653662

654663
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/benchmarks.cc

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ struct TbbAdapter : RetryDecorator<Queue> {
129129

130130
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
131131

132-
template<class Queue, size_t Capacity>
133-
struct CapacityToConstructor : Queue {
134-
CapacityToConstructor()
135-
: Queue(Capacity) {}
136-
};
137-
138-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139-
140132
using Allocator = HugePageAllocator<unsigned>;
141133
using BoostAllocator = boost::lockfree::allocator<Allocator>;
142134

@@ -160,14 +152,14 @@ struct QueueTypes {
160152
// For atomic elements only.
161153
using AtomicQueue = Type<RetryDecorator<atomic_queue::AtomicQueue<T, SIZE, T{}, MINIMIZE_CONTENTION, MAXIMIZE_THROUGHPUT, false, SPSC>>>;
162154
using OptimistAtomicQueue = Type<atomic_queue::AtomicQueue<T, SIZE, T{}, MINIMIZE_CONTENTION, MAXIMIZE_THROUGHPUT, false, SPSC>>;
163-
using AtomicQueueB = Type<RetryDecorator<CapacityToConstructor<atomic_queue::AtomicQueueB<T, Allocator, T{}, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>>;
164-
using OptimistAtomicQueueB = Type<CapacityToConstructor<atomic_queue::AtomicQueueB<T, Allocator, T{}, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>;
155+
using AtomicQueueB = Type<RetryDecorator<CapacityArgDecorator<atomic_queue::AtomicQueueB<T, Allocator, T{}, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>>;
156+
using OptimistAtomicQueueB = Type<CapacityArgDecorator<atomic_queue::AtomicQueueB<T, Allocator, T{}, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>;
165157

166158
// For non-atomic elements.
167159
using AtomicQueue2 = Type<RetryDecorator<atomic_queue::AtomicQueue2<T, SIZE, MINIMIZE_CONTENTION, MAXIMIZE_THROUGHPUT, false, SPSC>>>;
168160
using OptimistAtomicQueue2 = Type<atomic_queue::AtomicQueue2<T, SIZE, MINIMIZE_CONTENTION, MAXIMIZE_THROUGHPUT, false, SPSC>>;
169-
using AtomicQueueB2 = Type<RetryDecorator<CapacityToConstructor<atomic_queue::AtomicQueueB2<T, Allocator, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>>;
170-
using OptimistAtomicQueueB2 = Type<CapacityToConstructor<atomic_queue::AtomicQueueB2<T, Allocator, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>;
161+
using AtomicQueueB2 = Type<RetryDecorator<CapacityArgDecorator<atomic_queue::AtomicQueueB2<T, Allocator, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>>;
162+
using OptimistAtomicQueueB2 = Type<CapacityArgDecorator<atomic_queue::AtomicQueueB2<T, Allocator, MAXIMIZE_THROUGHPUT, false, SPSC>, SIZE>>;
171163
};
172164

173165
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -354,7 +346,7 @@ void run_throughput_benchmarks(HugePages& hp, std::vector<CpuTopologyInfo> const
354346
run_throughput_mpmc_benchmark("xenium::ramalhete_queue", hp, hw_thread_ids,
355347
Type<XeniumQueueAdapter<xenium::ramalhete_queue<unsigned, xenium::policy::reclaimer<Reclaimer>>>>{});
356348
run_throughput_mpmc_benchmark("xenium::vyukov_bounded_queue", hp, hw_thread_ids,
357-
Type<RetryDecorator<CapacityToConstructor<xenium::vyukov_bounded_queue<unsigned>, SIZE>>>{});
349+
Type<RetryDecorator<CapacityArgDecorator<xenium::vyukov_bounded_queue<unsigned>, SIZE>>>{});
358350

359351
using SPSC = QueueTypes<SIZE, true, false, false>;
360352
using MPMC = QueueTypes<SIZE, false, true, true>; // Enable MAXIMIZE_THROUGHPUT for 2 or more producers/consumers.
@@ -501,7 +493,7 @@ void run_ping_pong_benchmarks(HugePages& hp, std::vector<CpuTopologyInfo> const&
501493

502494
run_ping_pong_benchmark<XeniumQueueAdapter<xenium::michael_scott_queue<unsigned, xenium::policy::reclaimer<Reclaimer>>>>("xenium::michael_scott_queue", hp, hw_thread_ids);
503495
run_ping_pong_benchmark<XeniumQueueAdapter<xenium::ramalhete_queue<unsigned, xenium::policy::reclaimer<Reclaimer>>>>("xenium::ramalhete_queue", hp, hw_thread_ids);
504-
run_ping_pong_benchmark<RetryDecorator<CapacityToConstructor<xenium::vyukov_bounded_queue<unsigned>, SIZE>>>("xenium::vyukov_bounded_queue", hp, hw_thread_ids);
496+
run_ping_pong_benchmark<RetryDecorator<CapacityArgDecorator<xenium::vyukov_bounded_queue<unsigned>, SIZE>>>("xenium::vyukov_bounded_queue", hp, hw_thread_ids);
505497

506498
// Use MAXIMIZE_THROUGHPUT=false for better latency.
507499
using SPSC = QueueTypes<SIZE, true, false, false>;

src/tests.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,37 @@ BOOST_AUTO_TEST_CASE(spsc_stress_OptimistAtomicQueue2) {
188188
stress<AtomicQueue2<unsigned, CAPACITY, true, true, false, true>, 1, 1>();
189189
}
190190

191+
BOOST_AUTO_TEST_CASE(stress_AtomicQueueB) {
192+
stress<RetryDecorator<CapacityArgDecorator<AtomicQueueB<unsigned>, CAPACITY>>>();
193+
}
194+
195+
BOOST_AUTO_TEST_CASE(stress_OptimistAtomicQueueB) {
196+
stress<CapacityArgDecorator<AtomicQueueB<unsigned>, CAPACITY>>();
197+
}
198+
199+
BOOST_AUTO_TEST_CASE(stress_AtomicQueueB2) {
200+
stress<RetryDecorator<CapacityArgDecorator<AtomicQueueB2<unsigned>, CAPACITY>>>();
201+
}
202+
203+
BOOST_AUTO_TEST_CASE(stress_OptimistAtomicQueueB2) {
204+
stress<CapacityArgDecorator<AtomicQueueB2<unsigned>, CAPACITY>>();
205+
}
206+
207+
BOOST_AUTO_TEST_CASE(spsc_stress_AtomicQueueB) {
208+
stress<RetryDecorator<CapacityArgDecorator<AtomicQueueB<unsigned, std::allocator<unsigned>, 0u, true, false, true>, CAPACITY>>, 1, 1>();
209+
}
210+
211+
BOOST_AUTO_TEST_CASE(spsc_stress_OptimistAtomicQueueB) {
212+
stress<CapacityArgDecorator<AtomicQueueB<unsigned, std::allocator<unsigned>, 0u, true, false, true>, CAPACITY>, 1, 1>();
213+
}
214+
215+
BOOST_AUTO_TEST_CASE(spsc_stress_AtomicQueueB2) {
216+
stress<RetryDecorator<CapacityArgDecorator<AtomicQueueB2<unsigned, std::allocator<unsigned>, true, false, true>, CAPACITY>>, 1, 1>();
217+
}
218+
219+
BOOST_AUTO_TEST_CASE(spsc_stress_OptimistAtomicQueueB2) {
220+
stress<CapacityArgDecorator<AtomicQueueB2<unsigned, std::allocator<unsigned>, true, false, true>, CAPACITY>, 1, 1>();
221+
}
191222

192223
BOOST_AUTO_TEST_CASE(move_only_2) {
193224
AtomicQueue2<std::unique_ptr<int>, 2> q;

0 commit comments

Comments
 (0)