add interface for scheduling priority
This commit is contained in:
12
README.md
12
README.md
@@ -150,6 +150,18 @@ perfect::CpuTurboState state;
|
|||||||
PERFECT(perfect::get_cpu_turbo_state(&state));
|
PERFECT(perfect::get_cpu_turbo_state(&state));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### High Priority
|
||||||
|
|
||||||
|
`perfect` can set high scheduling priority for a process
|
||||||
|
|
||||||
|
See [examples/high_priority.cpp](examples/high_priority.cpp)
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#include "perfect/priority.hpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
* `Result set_high_priority()`: set the highest possible scheduling priority for the calling process
|
||||||
|
|
||||||
### Monitoring
|
### Monitoring
|
||||||
|
|
||||||
`perfect` can monitor and record GPU activity.
|
`perfect` can monitor and record GPU activity.
|
||||||
|
@@ -43,6 +43,9 @@ target_link_libraries(cpu-turbo perfect)
|
|||||||
add_executable(os-perf os_perf.cpp)
|
add_executable(os-perf os_perf.cpp)
|
||||||
target_link_libraries(os-perf perfect)
|
target_link_libraries(os-perf perfect)
|
||||||
|
|
||||||
|
add_executable(high-priority high_priority.cpp)
|
||||||
|
target_link_libraries(high-priority perfect)
|
||||||
|
|
||||||
if(CMAKE_CUDA_COMPILER)
|
if(CMAKE_CUDA_COMPILER)
|
||||||
add_executable(gpu-clocks gpu_clocks.cu)
|
add_executable(gpu-clocks gpu_clocks.cu)
|
||||||
target_link_libraries(gpu-clocks perfect)
|
target_link_libraries(gpu-clocks perfect)
|
||||||
|
12
examples/high_priority.cpp
Normal file
12
examples/high_priority.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "perfect/priority.hpp"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
perfect::init();
|
||||||
|
|
||||||
|
PERFECT(perfect::set_high_priority());
|
||||||
|
|
||||||
|
// do things with high process scheduling priority
|
||||||
|
|
||||||
|
}
|
@@ -13,6 +13,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/personality.h>
|
#include <sys/personality.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
#include "perfect/result.hpp"
|
#include "perfect/result.hpp"
|
||||||
|
|
||||||
@@ -107,6 +109,17 @@ Result set_personality(const int persona) {
|
|||||||
}
|
}
|
||||||
return Result::SUCCESS;
|
return Result::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// give the calling process the highest priority
|
||||||
|
Result set_high_priority() {
|
||||||
|
if (setpriority(PRIO_PROCESS, 0, -20)) {
|
||||||
|
return from_errno(errno);
|
||||||
|
}
|
||||||
|
return Result::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace perfect
|
} // namespace perfect
|
15
include/perfect/priority.hpp
Normal file
15
include/perfect/priority.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include "detail/os/linux.hpp"
|
||||||
|
#else
|
||||||
|
#error "unsupported platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "init.hpp"
|
||||||
|
|
||||||
|
namespace perfect {
|
||||||
|
Result set_high_priority() {
|
||||||
|
return detail::set_high_priority();
|
||||||
|
}
|
||||||
|
}
|
@@ -26,6 +26,7 @@
|
|||||||
#include "perfect/detail/os/linux.hpp"
|
#include "perfect/detail/os/linux.hpp"
|
||||||
#include "perfect/drop_caches.hpp"
|
#include "perfect/drop_caches.hpp"
|
||||||
#include "perfect/os_perf.hpp"
|
#include "perfect/os_perf.hpp"
|
||||||
|
#include "perfect/priority.hpp"
|
||||||
|
|
||||||
// argv should be null-terminated
|
// argv should be null-terminated
|
||||||
// outf and errf are file descriptors to where stdout and stderr should be
|
// outf and errf are file descriptors to where stdout and stderr should be
|
||||||
@@ -152,6 +153,7 @@ int main(int argc, char **argv) {
|
|||||||
nonstd::optional<bool> cpuTurbo = false;
|
nonstd::optional<bool> cpuTurbo = false;
|
||||||
nonstd::optional<bool> maxOsPerf = true;
|
nonstd::optional<bool> maxOsPerf = true;
|
||||||
bool dropCaches = true;
|
bool dropCaches = true;
|
||||||
|
bool highPriority = true;
|
||||||
|
|
||||||
std::vector<std::string> program;
|
std::vector<std::string> program;
|
||||||
std::string stdoutPath;
|
std::string stdoutPath;
|
||||||
@@ -173,7 +175,8 @@ int main(int argc, char **argv) {
|
|||||||
.set(aslr, true)
|
.set(aslr, true)
|
||||||
.call([&]() { cpuTurbo = nonstd::nullopt; })
|
.call([&]() { cpuTurbo = nonstd::nullopt; })
|
||||||
.call([&]() { maxOsPerf = nonstd::nullopt; })
|
.call([&]() { maxOsPerf = nonstd::nullopt; })
|
||||||
.set(dropCaches, false));
|
.set(dropCaches, false)
|
||||||
|
.set(highPriority, false));
|
||||||
|
|
||||||
auto modMode = (shieldGroup,
|
auto modMode = (shieldGroup,
|
||||||
option("--no-drop-cache")
|
option("--no-drop-cache")
|
||||||
@@ -183,6 +186,7 @@ int main(int argc, char **argv) {
|
|||||||
maxOsPerf = false;
|
maxOsPerf = false;
|
||||||
}),
|
}),
|
||||||
option("--aslr").set(aslr, true).doc("enable ASLR"),
|
option("--aslr").set(aslr, true).doc("enable ASLR"),
|
||||||
|
option("--no-priority").set(highPriority, false).doc("don't set high priority"),
|
||||||
option("--cpu-turbo").doc("enable CPU turbo").call([&]() {
|
option("--cpu-turbo").doc("enable CPU turbo").call([&]() {
|
||||||
cpuTurbo = true;
|
cpuTurbo = true;
|
||||||
}),
|
}),
|
||||||
@@ -340,6 +344,11 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (highPriority) {
|
||||||
|
std::cerr << "set high priority\n";
|
||||||
|
PERFECT(perfect::set_high_priority());
|
||||||
|
}
|
||||||
|
|
||||||
// parent should return
|
// parent should return
|
||||||
for (int runIter = 0; runIter < iters; ++runIter) {
|
for (int runIter = 0; runIter < iters; ++runIter) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user