[chrony-dev] [PATCH] Use pthread_setschedparam instead of sched_setscheduler |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH] Use pthread_setschedparam instead of sched_setscheduler
- From: "Stefan R. Filipek" <srfilipek@xxxxxxxxx>
- Date: Thu, 4 Apr 2019 17:59:28 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=/HzjqwP6/GUy52QNlvsjpNilP+3gkFAjr/efUPp2XZ0=; b=b0E4tH3IMMXzX6DwuLUTBYBO0dWXXFyetycx3LXhLAvHA7WHaczOI8NvapZmuFk5RI Qh0wODPofoFPztHrxT8s8bgHcx5FggcD633NAkkHbukrSblxM6EakOloYMOOx+XHSjCd QlYLppSo0PMdGOyqpw5aJp/aZpqL1PHUScRYddzKguvKdqQjKW/iKTE1lz4e90QtdmF9 QOdSggozcJ8JGybREjLtojU8BG0DL1sbulzdmgtQtBUlaPvHEGbXBS+n8uKz+MUbsgin U1uKy3k0+NdzxvvgkIxdFGZlgoxF3nTX/7yCWI5d9znAZgtQMIWd/FEJKX3DGcAPkOv4 AnVA==
Hi,
I ran into an issue with musl libc on Linux where sched_setscheduler
isn't implemented. Overall, it seems that pthread_setschedparam is
more widely supported across different C libraries and OSs. For
chrony's purposes on Linux, it should make no difference which call is
used.
Below is the simplest diff I could make, but cleaning up the
dependency check for pthreads is probably in order. I could also work
on a more general patch that brings real-time scheduling to any posix
platform.
I tested on Arch x86_64 Linux with glibc and buildroot ARM Linux with musl libc.
Regards,
Stefan
diff --git a/configure b/configure
index 486b0bc..565b888 100755
--- a/configure
+++ b/configure
@@ -786,13 +786,14 @@ fi
if [ $try_setsched = "1" ] && \
test_code \
- 'sched_setscheduler()' \
+ 'pthread_setschedparam()' \
'sched.h' '' '' '
struct sched_param sched;
sched_get_priority_max(SCHED_FIFO);
- sched_setscheduler(0, SCHED_FIFO, &sched);'
+ pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched);'
then
- add_def HAVE_SCHED_SETSCHEDULER
+ add_def HAVE_PTHREAD_SETSCHEDPARAM
+ MYCFLAGS="$MYCFLAGS -pthread"
fi
if [ $try_lockmem = "1" ] && \
diff --git a/sys.c b/sys.c
index 4d68b37..2c42db1 100644
--- a/sys.c
+++ b/sys.c
@@ -124,7 +124,7 @@ void SYS_EnableSystemCallFilter(int level)
void SYS_SetScheduler(int SchedPriority)
{
-#if defined(LINUX) && defined(HAVE_SCHED_SETSCHEDULER)
+#if defined(LINUX) && defined(HAVE_PTHREAD_SETSCHEDPARAM)
SYS_Linux_SetScheduler(SchedPriority);
#elif defined(MACOSX)
SYS_MacOSX_SetScheduler(SchedPriority);
diff --git a/sys_linux.c b/sys_linux.c
index 6ae7c0d..c339f09 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -33,8 +33,8 @@
#include <sys/utsname.h>
-#if defined(HAVE_SCHED_SETSCHEDULER)
-# include <sched.h>
+#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
+# include <pthread.h>
#endif
#if defined(HAVE_MLOCKALL)
@@ -632,7 +632,7 @@ add_failed:
/* ================================================== */
-#if defined(HAVE_SCHED_SETSCHEDULER)
+#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
/* Install SCHED_FIFO real-time scheduler with specified priority */
void SYS_Linux_SetScheduler(int SchedPriority)
{
@@ -651,8 +651,8 @@ void SYS_Linux_SetScheduler(int SchedPriority)
else if ( SchedPriority < pmin ) {
sched.sched_priority = pmin;
}
- if ( sched_setscheduler(0, SCHED_FIFO, &sched) == -1 ) {
- LOG(LOGS_ERR, "sched_setscheduler() failed");
+ if ( pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched) == -1 ) {
+ LOG(LOGS_ERR, "pthread_setschedparam() failed");
}
else {
DEBUG_LOG("Enabled SCHED_FIFO with priority %d",
@@ -660,7 +660,7 @@ void SYS_Linux_SetScheduler(int SchedPriority)
}
}
}
-#endif /* HAVE_SCHED_SETSCHEDULER */
+#endif /* HAVE_PTHREAD_SETSCHEDPARAM */
#if defined(HAVE_MLOCKALL)
/* Lock the process into RAM so that it will never be swapped out */
--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.