Skip to content

Commit

Permalink
clean up thread_pool_3 thing
Browse files Browse the repository at this point in the history
  • Loading branch information
petiaccja committed Feb 29, 2024
1 parent 4dcf76b commit 6f7d76b
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 354 deletions.
21 changes: 13 additions & 8 deletions benchmark/benchmark_atomic.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <asyncpp/threading/cache.hpp>

#include <array>
#include <atomic>
#include <thread>
Expand All @@ -10,11 +12,14 @@
// achievable and reasonable on the hardware.


using namespace asyncpp;


static constexpr size_t base_reps = 4'000'000;


BASELINE(atomic_rmw, x1_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps;

static const auto func = [&counter] {
Expand All @@ -29,7 +34,7 @@ BASELINE(atomic_rmw, x1_thread, 30, 1) {


BENCHMARK(atomic_rmw, x2_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps / 2;

static const auto func = [&counter] {
Expand All @@ -44,7 +49,7 @@ BENCHMARK(atomic_rmw, x2_thread, 30, 1) {


BENCHMARK(atomic_rmw, x4_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps / 4;

static const auto func = [&counter] {
Expand All @@ -59,7 +64,7 @@ BENCHMARK(atomic_rmw, x4_thread, 30, 1) {


BENCHMARK(atomic_rmw, x8_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps / 8;

static const auto func = [&counter] {
Expand All @@ -74,7 +79,7 @@ BENCHMARK(atomic_rmw, x8_thread, 30, 1) {


BASELINE(atomic_read, x1_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps;

static const auto func = [&counter] {
Expand All @@ -89,7 +94,7 @@ BASELINE(atomic_read, x1_thread, 30, 1) {


BENCHMARK(atomic_read, x2_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps / 2;

static const auto func = [&counter] {
Expand All @@ -104,7 +109,7 @@ BENCHMARK(atomic_read, x2_thread, 30, 1) {


BENCHMARK(atomic_read, x4_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps / 4;

static const auto func = [&counter] {
Expand All @@ -119,7 +124,7 @@ BENCHMARK(atomic_read, x4_thread, 30, 1) {


BENCHMARK(atomic_read, x8_thread, 30, 1) {
alignas(64) std::atomic_size_t counter = 0;
alignas(avoid_false_sharing) std::atomic_size_t counter = 0;
static constexpr size_t reps = base_reps / 8;

static const auto func = [&counter] {
Expand Down
3 changes: 2 additions & 1 deletion benchmark/benchmark_task_spawn.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <asyncpp/join.hpp>
#include <asyncpp/task.hpp>
#include <asyncpp/threading/cache.hpp>

#include <array>
#include <memory_resource>
Expand Down Expand Up @@ -56,7 +57,7 @@ struct FixtureStack : celero::TestFixture {
private:
static constexpr inline size_t size = 10485760;
struct block {
alignas(64) std::byte content[64];
alignas(avoid_false_sharing) std::byte content[avoid_false_sharing];
};
std::unique_ptr<block[]> buffer = std::make_unique_for_overwrite<block[]>(size / sizeof(block));
std::pmr::monotonic_buffer_resource resource;
Expand Down
14 changes: 7 additions & 7 deletions benchmark/benchmark_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct FixturePool : celero::TestFixture {
sync();
}

thread_pool_3 pool;
thread_pool pool;
std::atomic_size_t num_running;
std::vector<noop_promise> promises;
};
Expand Down Expand Up @@ -68,7 +68,7 @@ BENCHMARK_F(tp_schedule_outside, x4_thread, FixturePool<4>, 30, 1) {


BASELINE_F(tp_schedule_inside, x1_thread, FixturePool<1>, 30, 1) {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool_3& pool) -> task<void> {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool& pool) -> task<void> {
for (auto& promise : promises) {
pool.schedule(promise);
}
Expand All @@ -80,7 +80,7 @@ BASELINE_F(tp_schedule_inside, x1_thread, FixturePool<1>, 30, 1) {


BENCHMARK_F(tp_schedule_inside, x2_thread, FixturePool<2>, 30, 1) {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool_3& pool) -> task<void> {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool& pool) -> task<void> {
for (auto& promise : promises) {
pool.schedule(promise);
}
Expand All @@ -95,7 +95,7 @@ BENCHMARK_F(tp_schedule_inside, x2_thread, FixturePool<2>, 30, 1) {


BENCHMARK_F(tp_schedule_inside, x4_thread, FixturePool<4>, 30, 1) {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool_3& pool) -> task<void> {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool& pool) -> task<void> {
for (auto& promise : promises) {
pool.schedule(promise);
}
Expand All @@ -114,7 +114,7 @@ BENCHMARK_F(tp_schedule_inside, x4_thread, FixturePool<4>, 30, 1) {


BASELINE_F(tp_stealing, x1_thread, FixturePool<1 + 1>, 30, 1) {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool_3& pool) -> task<void> {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool& pool) -> task<void> {
for (auto& promise : promises) {
pool.schedule(promise);
}
Expand All @@ -125,7 +125,7 @@ BASELINE_F(tp_stealing, x1_thread, FixturePool<1 + 1>, 30, 1) {


BENCHMARK_F(tp_stealing, x2_thread, FixturePool<2 + 1>, 30, 1) {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool_3& pool) -> task<void> {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool& pool) -> task<void> {
for (auto& promise : promises) {
pool.schedule(promise);
}
Expand All @@ -136,7 +136,7 @@ BENCHMARK_F(tp_stealing, x2_thread, FixturePool<2 + 1>, 30, 1) {


BENCHMARK_F(tp_stealing, x4_thread, FixturePool<4 + 1>, 30, 1) {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool_3& pool) -> task<void> {
static constexpr auto coro = [](std::span<noop_promise> promises, thread_pool& pool) -> task<void> {
for (auto& promise : promises) {
pool.schedule(promise);
}
Expand Down
Loading

0 comments on commit 6f7d76b

Please sign in to comment.