Skip to content

Commit

Permalink
Revert "Merge "tests: perf: measure coroutines performance" from Benny"
Browse files Browse the repository at this point in the history
This reverts commit 7217fd1, reversing
changes made to 5d1975c. It does not
build in C++17 mode.
  • Loading branch information
avikivity committed Apr 17, 2022
1 parent 02f2125 commit 4436c7f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 659 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,7 @@ if (Seastar_INSTALL OR Seastar_TESTING)
add_library(seastar_perf_testing
src/testing/random.cc
include/seastar/testing/perf_tests.hh
tests/perf/perf_tests.cc
tests/perf/linux_perf_event.cc)
tests/perf/perf_tests.cc)
add_library (Seastar::seastar_perf_testing ALIAS seastar_perf_testing)
target_compile_definitions (seastar_perf_testing
PRIVATE ${Seastar_PRIVATE_COMPILE_DEFINITIONS})
Expand Down
49 changes: 0 additions & 49 deletions include/seastar/testing/linux_perf_event.hh

This file was deleted.

144 changes: 13 additions & 131 deletions include/seastar/testing/perf_tests.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

#include <seastar/core/future.hh>
#include <seastar/core/loop.hh>
#include <seastar/testing/linux_perf_event.hh>

#ifdef SEASTAR_COROUTINES_ENABLED
#include <seastar/core/coroutine.hh>
#endif

using namespace seastar;

Expand All @@ -43,86 +38,14 @@ struct config;

using clock_type = std::chrono::steady_clock;

class perf_stats {
public:
uint64_t allocations = 0;
uint64_t tasks_executed = 0;
uint64_t instructions_retired = 0;

private:
static uint64_t perf_mallocs();
static uint64_t perf_tasks_processed();

public:
perf_stats() = default;
perf_stats(uint64_t allocations_, uint64_t tasks_executed_, uint64_t instructions_retired_ = 0)
: allocations(allocations_)
, tasks_executed(tasks_executed_)
, instructions_retired(instructions_retired_)
{}
perf_stats(perf_stats&& o) noexcept
: allocations(std::exchange(o.allocations, 0))
, tasks_executed(std::exchange(o.tasks_executed, 0))
, instructions_retired(std::exchange(o.instructions_retired, 0))
{}
perf_stats(const perf_stats& o) = default;

perf_stats& operator=(perf_stats&& o) = default;
perf_stats& operator=(const perf_stats& o) = default;

perf_stats& operator+=(perf_stats b);
perf_stats& operator-=(perf_stats b);

static perf_stats snapshot(linux_perf_event* instructions_retired_counter = nullptr);
};

inline
perf_stats
operator+(perf_stats a, perf_stats b) {
a.allocations += b.allocations;
a.tasks_executed += b.tasks_executed;
a.instructions_retired += b.instructions_retired;
return a;
}

inline
perf_stats
operator-(perf_stats a, perf_stats b) {
a.allocations -= b.allocations;
a.tasks_executed -= b.tasks_executed;
a.instructions_retired -= b.instructions_retired;
return a;
}

inline perf_stats& perf_stats::operator+=(perf_stats b) {
allocations += b.allocations;
tasks_executed += b.tasks_executed;
instructions_retired += b.instructions_retired;
return *this;
}

inline perf_stats& perf_stats::operator-=(perf_stats b) {
allocations -= b.allocations;
tasks_executed -= b.tasks_executed;
instructions_retired -= b.instructions_retired;
return *this;
}

class performance_test {
std::string _test_case;
std::string _test_group;

uint64_t _single_run_iterations = 0;
std::atomic<uint64_t> _max_single_run_iterations;
protected:
linux_perf_event _instructions_retired_counter = linux_perf_event::user_instructions_retired();
private:
void do_run(const config&);
public:
struct run_result {
clock_type::duration duration;
perf_stats stats;
};
protected:
[[gnu::always_inline]] [[gnu::hot]]
bool stop_iteration() const {
Expand All @@ -136,7 +59,7 @@ protected:

virtual void set_up() = 0;
virtual void tear_down() noexcept = 0;
virtual future<run_result> do_single_run() = 0;
virtual future<clock_type::duration> do_single_run() = 0;
public:
performance_test(const std::string& test_case, const std::string& test_group)
: _test_case(test_case)
Expand All @@ -163,47 +86,33 @@ class time_measurement {
clock_type::time_point _run_start_time;
clock_type::time_point _start_time;
clock_type::duration _total_time;

perf_stats _start_stats;
perf_stats _total_stats;

public:
[[gnu::always_inline]] [[gnu::hot]]
void start_run(linux_perf_event* instructions_retired_counter = nullptr) {
void start_run() {
_total_time = { };
auto t = clock_type::now();
_run_start_time = t;
_start_time = t;
_start_stats = perf_stats::snapshot(instructions_retired_counter);
}

[[gnu::always_inline]] [[gnu::hot]]
performance_test::run_result stop_run(linux_perf_event* instructions_retired_counter = nullptr) {
clock_type::duration stop_run() {
auto t = clock_type::now();
performance_test::run_result ret;
if (_start_time == _run_start_time) {
ret.duration = t - _start_time;
auto stats = perf_stats::snapshot(instructions_retired_counter);
ret.stats = stats - _start_stats;
} else {
ret.duration = _total_time;
ret.stats = _total_stats;
return t - _start_time;
}
return ret;
return _total_time;
}

[[gnu::always_inline]] [[gnu::hot]]
void start_iteration(linux_perf_event* instructions_retired_counter = nullptr) {
void start_iteration() {
_start_time = clock_type::now();
_start_stats = perf_stats::snapshot(instructions_retired_counter);
}

[[gnu::always_inline]] [[gnu::hot]]
void stop_iteration(linux_perf_event* instructions_retired_counter = nullptr) {
void stop_iteration() {
auto t = clock_type::now();
_total_time += t - _start_time;
auto stats = perf_stats::snapshot(instructions_retired_counter);
_total_stats += stats - _start_stats;
}
};

Expand Down Expand Up @@ -253,11 +162,10 @@ protected:
}

[[gnu::hot]]
virtual future<run_result> do_single_run() override {
virtual future<clock_type::duration> do_single_run() override {
// Redundant 'this->'s courtesy of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636
_instructions_retired_counter.enable();
return if_constexpr_<is_future<decltype(_test->run())>::value>([&] (auto&&...) {
measure_time.start_run(&_instructions_retired_counter);
measure_time.start_run();
return do_until([this] { return this->stop_iteration(); }, [this] {
return if_constexpr_<std::is_same<decltype(_test->run()), future<>>::value>([&] (auto&&...) {
this->next_iteration(1);
Expand All @@ -269,13 +177,11 @@ protected:
this->next_iteration(n);
});
})();
}).then([this] {
return measure_time.stop_run(&_instructions_retired_counter);
}).finally([this] {
_instructions_retired_counter.disable();
}).then([] {
return measure_time.stop_run();
});
}, [&] (auto&&...) {
measure_time.start_run(&_instructions_retired_counter);
measure_time.start_run();
while (!stop_iteration()) {
if_constexpr_<std::is_void<decltype(_test->run())>::value>([&] (auto&&...) {
(void)_test->run();
Expand All @@ -286,9 +192,7 @@ protected:
this->next_iteration(run_test(dependency...));
})();
}
auto ret = measure_time.stop_run(&_instructions_retired_counter);
_instructions_retired_counter.disable();
return make_ready_future<run_result>(std::move(ret));
return make_ready_future<clock_type::duration>(measure_time.stop_run());
})();
}
public:
Expand Down Expand Up @@ -330,8 +234,6 @@ void do_not_optimize(const T& v)

// PERF_TEST and PERF_TEST_F support both synchronous and asynchronous functions.
// The former should return `void`, the latter `future<>`.
// PERF_TEST_C executes a coroutine function, if enabled.
// PERF_TEST_CN executes a coroutine function, if enabled, returning the number of inner-loops.
//
// Test cases may perform multiple operations in a single run, this may be desirable
// if the cost of an individual operation is very small. This allows measuring either
Expand All @@ -355,23 +257,3 @@ void do_not_optimize(const T& v)
static ::perf_tests::internal::test_registrar<test_##test_group##_##test_case> \
test_##test_group##_##test_case##_registrar(#test_group, #test_case); \
[[gnu::always_inline]] auto test_##test_group##_##test_case::run()

#ifdef SEASTAR_COROUTINES_ENABLED

#define PERF_TEST_C(test_group, test_case) \
struct test_##test_group##_##test_case : test_group { \
inline future<> run(); \
}; \
static ::perf_tests::internal::test_registrar<test_##test_group##_##test_case> \
test_##test_group##_##test_case##_registrar(#test_group, #test_case); \
future<> test_##test_group##_##test_case::run()

#define PERF_TEST_CN(test_group, test_case) \
struct test_##test_group##_##test_case : test_group { \
inline future<size_t> run(); \
}; \
static ::perf_tests::internal::test_registrar<test_##test_group##_##test_case> \
test_##test_group##_##test_case##_registrar(#test_group, #test_case); \
future<size_t> test_##test_group##_##test_case::run()

#endif // SEASTAR_COROUTINES_ENABLED
3 changes: 0 additions & 3 deletions tests/perf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,3 @@ seastar_add_test (rpc
seastar_add_test (smp_submit_to
SOURCES smp_submit_to_perf.cc
NO_SEASTAR_PERF_TESTING_LIBRARY)

seastar_add_test (coroutine
SOURCES coroutine_perf.cc)
52 changes: 0 additions & 52 deletions tests/perf/coroutine_perf.cc

This file was deleted.

Loading

0 comments on commit 4436c7f

Please sign in to comment.