OsPerfState saves for all CPUs

This commit is contained in:
Carl Pearson
2019-09-26 10:58:01 -05:00
parent d576ac099d
commit 1b3cf604a8
4 changed files with 62 additions and 32 deletions

View File

@@ -3,6 +3,7 @@
#include <vector>
#include <string>
#include <cassert>
#include <map>
#ifdef __linux__
#include "detail/os/linux.hpp"
@@ -17,19 +18,23 @@ namespace perfect {
struct OsPerfState {
#ifdef __linux__
std::string governor;
std::map<int, std::string> governors;
#else
#error "unsupported platform"
#endif
};
Result get_os_perf_state(OsPerfState *state, const int cpu) {
assert(state);
Result get_os_perf_state(OsPerfState &state) {
#ifdef __linux__
return get_governor(state->governor, cpu);
for (auto cpu : cpus()) {
std::string gov;
PERFECT_SUCCESS_OR_RETURN(get_governor(gov, cpu));
state.governors[cpu] = gov;
}
#else
#error "unsupported platform"
#endif
return Result::SUCCESS;
}
Result os_perf_state_maximum(const int cpu) {
@@ -48,13 +53,15 @@ Result os_perf_state_minimum(const int cpu) {
#endif
}
Result set_os_perf_state(const int cpu, OsPerfState state) {
#ifdef __linux__
return set_governor(cpu, state.governor);
Result set_os_perf_state(OsPerfState state) {
#ifdef __linux__
for (auto kv : state.governors) {
PERFECT_SUCCESS_OR_RETURN(set_governor(kv.first, kv.second));
}
#else
#error "unsupported platform"
#endif
return Result::SUCCESS;
}
};