Skip to content

Commit

Permalink
Improve has_realtime_kernel method (backport #260) (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored and christophfroehlich committed Jan 30, 2025
1 parent b27d382 commit 777187e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/realtime_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,40 @@
#include <sched.h>
#include <sys/capability.h>
#include <sys/mman.h>
#include <sys/utsname.h>

#include <unistd.h>
#endif

#include <cstring>
#include <fstream>
#include <iostream>

namespace realtime_tools
{
bool has_realtime_kernel()
{
#ifdef _WIN32
std::cerr << "Realtime kernel detection is not supported on Windows." << std::endl;
return false;
#else
std::ifstream realtime_file("/sys/kernel/realtime", std::ios::in);
bool has_realtime = false;
if (realtime_file.is_open()) {
realtime_file >> has_realtime;
}
if (!has_realtime) {
struct utsname kernel_info;
if (uname(&kernel_info) == -1) {
std::cerr << "Error: Could not get kernel information : " << std::strerror(errno)
<< std::endl;
return false;
}
const std::string kernel_version(kernel_info.version);
return kernel_version.find("PREEMPT_RT") != std::string::npos;
}
return has_realtime;
#endif
}

bool configure_sched_fifo(int priority)
Expand Down

0 comments on commit 777187e

Please sign in to comment.