12 #include <spdlog/spdlog.h>
25 constexpr
int kPid = 0;
26 cpu_set_t cpuset = {};
28 CPU_SET(cpu, &cpuset);
29 if (::sched_setaffinity(kPid,
sizeof(cpu_set_t), &cpuset) < 0) {
30 throw std::runtime_error(
"Error setting CPU affinity");
33 spdlog::warn(
"[configure_cpu] This function does nothing on macOS");
47 constexpr
int kPid = 0;
48 struct sched_param params = {};
49 params.sched_priority = priority;
50 if (::sched_setscheduler(kPid, SCHED_RR, ¶ms) < 0) {
51 throw std::runtime_error(
52 "Error setting realtime scheduler, try running as root (use sudo)");
55 spdlog::warn(
"[configure_scheduler] This function does nothing on macOS");
64 return (::mlockall(MCL_CURRENT | MCL_FUTURE) >= 0);
void configure_scheduler(int priority)
Configure the scheduler policy to round-robin for this thread.
void configure_cpu(int cpu)
Set the current thread to run on a given CPU core.
bool lock_memory()
Lock all memory to RAM so that the kernel doesn't page it to swap.