Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cd9a95365f | ||
![]() |
57bf39bb97 | ||
![]() |
c358f18c22 |
@@ -5,7 +5,7 @@
|
|||||||
# 3.13+ for target_link_directories
|
# 3.13+ for target_link_directories
|
||||||
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
|
||||||
|
|
||||||
project(perfect LANGUAGES CXX VERSION 0.4.0)
|
project(perfect LANGUAGES CXX VERSION 0.5.0)
|
||||||
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||||
|
|
||||||
include(CheckLanguage)
|
include(CheckLanguage)
|
||||||
|
@@ -190,6 +190,12 @@ See [examples/cpu_cache.cpp](examples/cpu_cache.cpp).
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
* v0.5.0
|
||||||
|
* add tools/stress
|
||||||
|
* add tools/max-os-perf
|
||||||
|
* add tools/min-os-perf
|
||||||
|
* add tools/enable-cpu-turbo
|
||||||
|
* add tools/disable-cpu-turbo
|
||||||
* v0.4.0
|
* v0.4.0
|
||||||
* Add ASLR interface
|
* Add ASLR interface
|
||||||
* Disambiguate some filesystem errors
|
* Disambiguate some filesystem errors
|
||||||
|
@@ -40,6 +40,14 @@ Result os_perf_state_maximum(const int cpu) {
|
|||||||
#endif
|
#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) {
|
Result set_os_perf_state(const int cpu, OsPerfState state) {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
return set_governor(cpu, state.governor);
|
return set_governor(cpu, state.governor);
|
||||||
|
@@ -34,11 +34,31 @@ set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} \
|
|||||||
-Wfatal-errors\
|
-Wfatal-errors\
|
||||||
")
|
")
|
||||||
|
|
||||||
add_executable(enable-turbo enable_turbo.cpp)
|
add_executable(enable-cpu-turbo enable_cpu_turbo.cpp)
|
||||||
target_link_libraries(enable-turbo perfect)
|
target_link_libraries(enable-cpu-turbo perfect)
|
||||||
|
|
||||||
|
add_executable(disable-cpu-turbo disable_cpu_turbo.cpp)
|
||||||
|
target_link_libraries(disable-cpu-turbo perfect)
|
||||||
|
|
||||||
add_executable(sync-drop-caches sync_drop_caches.cpp)
|
add_executable(sync-drop-caches sync_drop_caches.cpp)
|
||||||
target_link_libraries(sync-drop-caches perfect)
|
target_link_libraries(sync-drop-caches perfect)
|
||||||
|
|
||||||
add_executable(no-aslr no_aslr.cpp)
|
add_executable(no-aslr no_aslr.cpp)
|
||||||
target_link_libraries(no-aslr perfect)
|
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)
|
||||||
|
|
||||||
|
23
tools/disable_cpu_turbo.cpp
Normal file
23
tools/disable_cpu_turbo.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "perfect/cpu_turbo.hpp"
|
||||||
|
|
||||||
|
using namespace perfect;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
|
||||||
|
CpuTurboState state;
|
||||||
|
|
||||||
|
perfect::init();
|
||||||
|
|
||||||
|
PERFECT(get_cpu_turbo_state(&state));
|
||||||
|
|
||||||
|
if (!is_turbo_enabled(state)) {
|
||||||
|
std::cerr << "cpu turbo already disabled\n";
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
} else {
|
||||||
|
PERFECT(disable_cpu_turbo());
|
||||||
|
std::cerr << "disabled cpu turbo\n";
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
9
tools/max_os_perf.cpp
Normal file
9
tools/max_os_perf.cpp
Normal file
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
9
tools/min_os_perf.cpp
Normal file
9
tools/min_os_perf.cpp
Normal file
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
49
tools/stress.cpp
Normal file
49
tools/stress.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <omp.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <chrono>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
size_t numThreads = std::stoi(argv[1]);
|
||||||
|
std::vector<size_t> 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";
|
||||||
|
|
||||||
|
};
|
Reference in New Issue
Block a user