From 57662d5c8cf3fae2106dc3c3433004fbd93609e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Thu, 21 Jul 2022 11:37:13 +0200 Subject: [PATCH] blinktree: Use Genode::Threads for fill and mixed workload threads. --- .../src/app/blinktree/benchmark/workload.h | 3 +- .../app/blinktree/benchmark/workload_set.cpp | 18 +++-- .../app/blinktree/benchmark/workload_set.h | 67 ++++++++++++++++++- .../blinktree_benchmark/benchmark.cpp | 4 +- .../blinktree/blinktree_benchmark/benchmark.h | 3 +- .../blinktree/blinktree_benchmark/main.cpp | 8 +-- 6 files changed, 87 insertions(+), 16 deletions(-) diff --git a/repos/mml/src/app/blinktree/benchmark/workload.h b/repos/mml/src/app/blinktree/benchmark/workload.h index d790a18c1c..588db4bb6d 100644 --- a/repos/mml/src/app/blinktree/benchmark/workload.h +++ b/repos/mml/src/app/blinktree/benchmark/workload.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace benchmark { class Workload @@ -13,7 +14,7 @@ class Workload friend std::ostream &operator<<(std::ostream &stream, const Workload &workload); public: - Workload() noexcept = default; + Workload(Libc::Env &env) : _workload_set(env) {} ~Workload() noexcept = default; [[maybe_unused]] void build(const std::string &fill_workload_file, const std::string &mixed_workload_file) diff --git a/repos/mml/src/app/blinktree/benchmark/workload_set.cpp b/repos/mml/src/app/blinktree/benchmark/workload_set.cpp index fbb5413011..b2ac5e208f 100644 --- a/repos/mml/src/app/blinktree/benchmark/workload_set.cpp +++ b/repos/mml/src/app/blinktree/benchmark/workload_set.cpp @@ -39,8 +39,7 @@ void NumericWorkloadSet::build(const std::string &fill_workload_file, const std: return contains_update; }; - std::mutex out_mutex; - std::thread fill_thread{[this, &out_mutex, &parse, &fill_workload_file]() { + /*std::thread fill_thread{[this, &out_mutex, &parse, &fill_workload_file]() { std::ifstream fill_file(fill_workload_file); if (fill_file.good()) { @@ -51,9 +50,15 @@ void NumericWorkloadSet::build(const std::string &fill_workload_file, const std: std::lock_guard lock{out_mutex}; std::cerr << "Could not open workload file '" << fill_workload_file << "'." << std::endl; } - }}; + }};*/ + Genode::Mutex out_mutex; - std::thread mixed_thread{[this, &out_mutex, &parse, &mixed_workload_file]() { + Fill_thread fill_thread(_env, out_mutex, fill_workload_file, parse, *this); + + fill_thread.start(); + + + /*std::thread mixed_thread{[this, &out_mutex, &parse, &mixed_workload_file]() { std::ifstream mixed_file(mixed_workload_file); if (mixed_file.good()) { @@ -65,7 +70,10 @@ void NumericWorkloadSet::build(const std::string &fill_workload_file, const std: std::lock_guard lock{out_mutex}; std::cerr << "Could not open workload file '" << mixed_workload_file << "'." << std::endl; } - }}; + }};*/ + + Mixed_thread mixed_thread(_env, out_mutex, mixed_workload_file, parse, *this); + mixed_thread.start(); fill_thread.join(); mixed_thread.join(); diff --git a/repos/mml/src/app/blinktree/benchmark/workload_set.h b/repos/mml/src/app/blinktree/benchmark/workload_set.h index c64dbd0d8b..c2cd68274e 100644 --- a/repos/mml/src/app/blinktree/benchmark/workload_set.h +++ b/repos/mml/src/app/blinktree/benchmark/workload_set.h @@ -3,10 +3,11 @@ #include "phase.h" #include #include -#include +#include +#include #include #include - +#include namespace benchmark { class NumericTuple { @@ -46,10 +47,13 @@ private: class NumericWorkloadSet { friend std::ostream &operator<<(std::ostream &stream, const NumericWorkloadSet &workload_set); + friend class Fill_thread; + friend class Mixed_thread; public: - NumericWorkloadSet() = default; + NumericWorkloadSet(Libc::Env &env) : _env(env) {} ~NumericWorkloadSet() = default; + Libc::Env &_env; void build(const std::string &fill_workload_file, const std::string &mixed_workload_file); void build(std::uint64_t fill_inserts, std::uint64_t mixed_inserts, std::uint64_t mixed_lookups, @@ -71,4 +75,61 @@ private: static std::ostream &nice_print(std::ostream &stream, std::size_t number) noexcept; }; + +class Fill_thread : public Genode::Thread +{ + private: + Genode::Mutex &_mutex; + const std::string &_fill_workload_file; + bool (*parse)(std::ifstream &, std::vector &); + NumericWorkloadSet &_workload_set; + + public: + Fill_thread(Libc::Env &env, Genode::Mutex &mutex, std::string fill_workload_name, bool (*parse)(std::ifstream&, std::vector&), NumericWorkloadSet &workload_set) + : Genode::Thread(env, Name("btree::fill_thread"), 4*4096), + _mutex(mutex), _fill_workload_file(fill_workload_name), _workload_set(workload_set) + { + this->parse = parse; + } + + void entry() { + std::ifstream fill_file(_fill_workload_file); + if (fill_file.good()) { + parse(fill_file, _workload_set._data_sets[static_cast(phase::FILL)]); + } else { + _mutex.acquire(); + std::cerr << "Could not open workload file '" << _fill_workload_file << "'." << std::endl; + _mutex.release(); + } + } +}; + +class Mixed_thread : public Genode::Thread +{ + private: + Genode::Mutex &_mutex; + const std::string &_mixed_workload_file; + bool (*parse)(std::ifstream &, std::vector &); + NumericWorkloadSet &_workload_set; + + public: + Mixed_thread(Libc::Env &env, Genode::Mutex &mutex, std::string mixed_workload_name, bool (*parse)(std::ifstream&, std::vector&), NumericWorkloadSet &workload_set) + : Genode::Thread(env, Name("btree::mixed_thread"), 4*4096), + _mutex(mutex), _mixed_workload_file(mixed_workload_name), _workload_set(workload_set) + { + this->parse = parse; + } + + void entry() + { + std::ifstream mixed_file(_mixed_workload_file); + if (mixed_file.good()) { + _workload_set._mixed_phase_contains_update = parse(mixed_file, _workload_set._data_sets[static_cast(phase::MIXED)]); + } else { + _mutex.acquire(); + std::cerr << "Could not open workload file '" << _mixed_workload_file << "'." << std::endl; + _mutex.release(); + } + } +}; } // namespace benchmark \ No newline at end of file diff --git a/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.cpp b/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.cpp index fc567deea2..67dbd888a2 100644 --- a/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.cpp +++ b/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.cpp @@ -7,7 +7,7 @@ using namespace application::blinktree_benchmark; -Benchmark::Benchmark(benchmark::Cores &&cores, const std::uint16_t iterations, std::string &&fill_workload_file, +Benchmark::Benchmark(Libc::Env &env, benchmark::Cores &&cores, const std::uint16_t iterations, std::string &&fill_workload_file, std::string &&mixed_workload_file, const bool use_performance_counter, const mx::synchronization::isolation_level node_isolation_level, const mx::synchronization::protocol preferred_synchronization_method, @@ -17,7 +17,7 @@ Benchmark::Benchmark(benchmark::Cores &&cores, const std::uint16_t iterations, s _preferred_synchronization_method(preferred_synchronization_method), _print_tree_statistics(print_tree_statistics), _check_tree(check_tree), _result_file_name(std::move(result_file_name)), _statistic_file_name(std::move(statistic_file_name)), - _tree_file_name(std::move(tree_file_name)), _profile(profile) + _tree_file_name(std::move(tree_file_name)), _profile(profile), _workload(env) { #ifdef PERF_SUPPORT if (use_performance_counter) diff --git a/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.h b/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.h index b8261992a5..72cb9598d0 100644 --- a/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.h +++ b/repos/mml/src/app/blinktree/blinktree_benchmark/benchmark.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace application::blinktree_benchmark { /** @@ -21,7 +22,7 @@ namespace application::blinktree_benchmark { class Benchmark final : public Listener { public: - Benchmark(benchmark::Cores &&, std::uint16_t iterations, std::string &&fill_workload_file, + Benchmark(Libc::Env &env, benchmark::Cores &&, std::uint16_t iterations, std::string &&fill_workload_file, std::string &&mixed_workload_file, bool use_performance_counter, mx::synchronization::isolation_level node_isolation_level, mx::synchronization::protocol preferred_synchronization_method, bool print_tree_statistics, diff --git a/repos/mml/src/app/blinktree/blinktree_benchmark/main.cpp b/repos/mml/src/app/blinktree/blinktree_benchmark/main.cpp index 177afc1015..74fa16f6fd 100644 --- a/repos/mml/src/app/blinktree/blinktree_benchmark/main.cpp +++ b/repos/mml/src/app/blinktree/blinktree_benchmark/main.cpp @@ -27,7 +27,7 @@ std::tuple create_benchmark(int count_argument * * @return Return code of the application. */ -int main(int count_arguments, char **arguments) +int bt_main(Libc::Env &env, int count_arguments, char **arguments) { if (mx::system::Environment::is_numa_balancing_enabled()) { @@ -53,7 +53,7 @@ int main(int count_arguments, char **arguments) return 0; } -std::tuple create_benchmark(int count_arguments, char **arguments) +std::tuple create_benchmark(Libc::Env &env, int count_arguments, char **arguments) { // Set up arguments. argparse::ArgumentParser argument_parser("blinktree_benchmark"); @@ -169,7 +169,7 @@ std::tuple create_benchmark(int count_argument // Create the benchmark. auto *benchmark = - new Benchmark(std::move(cores), argument_parser.get("-i"), std::move(workload_files[0]), + new Benchmark(env, std::move(cores), argument_parser.get("-i"), std::move(workload_files[0]), std::move(workload_files[1]), argument_parser.get("-p"), isolation_level, preferred_synchronization_method, argument_parser.get("--print-stats"), argument_parser.get("--disable-check") == false, argument_parser.get("-o"), @@ -187,5 +187,5 @@ void Libc::Component::construct(Libc::Env &env) { char *args[] = {"blinktree", "1:4", "-o /dev/log"}; Libc::with_libc([&]() - { main(3, args); }); + { bt_main(env, 3, args); }); }