diff --git a/include/perfect/os_perf.hpp b/include/perfect/os_perf.hpp index e35128f..75e2d21 100644 --- a/include/perfect/os_perf.hpp +++ b/include/perfect/os_perf.hpp @@ -40,6 +40,14 @@ Result os_perf_state_maximum(const int cpu) { #endif } +Result os_perf_state_minimum(const int cpu) { + #ifdef __linux__ + return set_governor(cpu, "powersave"); + #else + #error "unsupported platform" + #endif +} + Result set_os_perf_state(const int cpu, OsPerfState state) { #ifdef __linux__ return set_governor(cpu, state.governor); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b1a76ff..271d81b 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -44,4 +44,21 @@ add_executable(sync-drop-caches sync_drop_caches.cpp) target_link_libraries(sync-drop-caches perfect) add_executable(no-aslr no_aslr.cpp) -target_link_libraries(no-aslr perfect) \ No newline at end of file +target_link_libraries(no-aslr perfect) + +add_executable(max-os-perf max_os_perf.cpp) +target_link_libraries(max-os-perf perfect) + +add_executable(min-os-perf min_os_perf.cpp) +target_link_libraries(min-os-perf perfect) + +## OpenMP +find_package(OpenMP) +if (OpenMP_FOUND) + add_executable(stress stress.cpp) + target_link_libraries(stress perfect) + target_link_libraries(stress OpenMP::OpenMP_CXX) +else(OpenMP_FOUND) + message(WARNING "didn't find OpenMP, some benchmarks will be unavailable.") +endif(OpenMP_FOUND) + diff --git a/tools/max_os_perf.cpp b/tools/max_os_perf.cpp new file mode 100644 index 0000000..c5b2a48 --- /dev/null +++ b/tools/max_os_perf.cpp @@ -0,0 +1,9 @@ +#include "perfect/os_perf.hpp" + +int main(void) { + PERFECT(perfect::init()); + + for (auto cpu : perfect::cpus()) { + PERFECT(perfect::os_perf_state_maximum(cpu)); + } +} \ No newline at end of file diff --git a/tools/min_os_perf.cpp b/tools/min_os_perf.cpp new file mode 100644 index 0000000..393e58f --- /dev/null +++ b/tools/min_os_perf.cpp @@ -0,0 +1,9 @@ +#include "perfect/os_perf.hpp" + +int main(void) { + PERFECT(perfect::init()); + + for (auto cpu : perfect::cpus()) { + PERFECT(perfect::os_perf_state_minimum(cpu)); + } +} \ No newline at end of file diff --git a/tools/stress.cpp b/tools/stress.cpp new file mode 100644 index 0000000..9b6d87f --- /dev/null +++ b/tools/stress.cpp @@ -0,0 +1,49 @@ +#include + +#include + +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + +size_t numThreads = std::stoi(argv[1]); +std::vector totals(numThreads, 0); +omp_set_num_threads(numThreads); + +auto start = std::chrono::system_clock::now(); +double time = std::stod(argv[2]); + +#pragma omp parallel +{ + size_t tid = omp_get_thread_num(); + double a = rand(); + while (true) { + for (size_t i = 0; i < 500; ++i) { + double x; + asm volatile(""::"r"(a)); + x = sqrt(a); + asm volatile(""::"r"(x)); + + asm volatile(""::"r"(a)); + x = sqrt(a); + asm volatile(""::"r"(x)); + } + totals[tid] += 1000; + auto elapsed = (std::chrono::system_clock::now() - start).count() / 1e9; + if (elapsed > time) { + break; + } + } +} + +size_t sum = 0; +for (auto t : totals) { + sum += t; +} +std::cout << (double)sum / time << "\n"; + +};