mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 20:42:56 +01:00
blinktree: Use Genode::Threads for fill and mixed workload threads.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <libc/component.h>
|
||||
|
||||
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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
#include "phase.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libc/component.h>
|
||||
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<NumericTuple> &);
|
||||
NumericWorkloadSet &_workload_set;
|
||||
|
||||
public:
|
||||
Fill_thread(Libc::Env &env, Genode::Mutex &mutex, std::string fill_workload_name, bool (*parse)(std::ifstream&, std::vector<NumericTuple>&), 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<std::size_t>(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<NumericTuple> &);
|
||||
NumericWorkloadSet &_workload_set;
|
||||
|
||||
public:
|
||||
Mixed_thread(Libc::Env &env, Genode::Mutex &mutex, std::string mixed_workload_name, bool (*parse)(std::ifstream&, std::vector<NumericTuple>&), 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<std::size_t>(phase::MIXED)]);
|
||||
} else {
|
||||
_mutex.acquire();
|
||||
std::cerr << "Could not open workload file '" << _mixed_workload_file << "'." << std::endl;
|
||||
_mutex.release();
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace benchmark
|
||||
@@ -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)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <mx/util/core_set.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <libc/component.h>
|
||||
|
||||
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,
|
||||
|
||||
@@ -27,7 +27,7 @@ std::tuple<Benchmark *, std::uint16_t, bool> 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<Benchmark *, std::uint16_t, bool> create_benchmark(int count_arguments, char **arguments)
|
||||
std::tuple<Benchmark *, std::uint16_t, bool> 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<Benchmark *, std::uint16_t, bool> create_benchmark(int count_argument
|
||||
|
||||
// Create the benchmark.
|
||||
auto *benchmark =
|
||||
new Benchmark(std::move(cores), argument_parser.get<std::uint16_t>("-i"), std::move(workload_files[0]),
|
||||
new Benchmark(env, std::move(cores), argument_parser.get<std::uint16_t>("-i"), std::move(workload_files[0]),
|
||||
std::move(workload_files[1]), argument_parser.get<bool>("-p"), isolation_level,
|
||||
preferred_synchronization_method, argument_parser.get<bool>("--print-stats"),
|
||||
argument_parser.get<bool>("--disable-check") == false, argument_parser.get<std::string>("-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); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user