Re: Detecting PREEMPT_RT
From: Carsten Emde <hidden>
Date: 2013-01-20 01:45:06
John,
I'm part of a project that recently added PREEMPT_RT support (as well as Xenomai) to LinuxCNC/EMC2. The next sub-project is a 'universal binary'. The LCNC real-time module will run some checks to determine what RT systems, if any, are available on the running kernel, and then load the appropriate RT support module. We wish to distinguish between PREEMPT_RT and non-RT kernels because LCNC must confirm that the kernel really does have realtime capabilities, if that's what the user expects, and print big warning messages if not. LCNC drives machines that weigh many tons and spins spindles at 24k RPM, so this is important! The RT PREEMPT HOWTO discusses checking the kernel here: https://rt.wiki.kernel.org/index.php/RT_PREEMPT_HOWTO#Checking_the_Kernel One method is to use string matching against the kernel version, which I'm a bit suspicious of.
Unfortunately, this wiki article is old and unmaintained. You're
probably right to be a bit suspicious when checking for the "-rt" suffix
of the kernel release (uname -r). But looking for the occurrence of
"PREEMPT RT" in the kernel version (uname -v) should work. An
application may use the system call uname() and check the version
element of the utsname structure.
In addition you may want to make sure the system has high-resolution
timers. If so, the timers in /proc/timer_list have ".resolution: 1
nsecs". An application may use the function check_timer() from
cyclictest for this purpose:
static int check_timer(void)
{
struct timespec ts;
if (clock_getres(CLOCK_MONOTONIC, &ts))
return 1;
return (ts.tv_sec != 0 || ts.tv_nsec != 1);
}
Hope this helps,
-Carsten.