Re: [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: Re: [chrony-dev] [PATCH] Use pthread_setschedparam instead of sched_setscheduler
- From: "Stefan R. Filipek" <srfilipek@xxxxxxxxx>
- Date: Mon, 8 Apr 2019 10:24:52 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=z1uqKikd5ce3aDBxXQZktn2YEBgcew0dld3Fxn1Xxaw=; b=SDL+P5SWCtc/fVIxqHRm05lPby/Cy5J0pQuGKm3hntGVpu8mcLwQVb5Ihpi2w1GTi7 JIrw3Wlbw5gmCAttzeW/N9Y28EoEg5gUc3aYyV9JZkD6A4+5gghSkm+A7GuaMsCOcmBN cIeNMrONXFeVV3vZe/mIQBCYiGjTL91ZO1EZtfqQPe0f/+OfpZUhGJ9rIkQxmNnIZGHV O7pMSeehCbsnuYdOMLD7a4baDKu7F0k4m2aoFRaegvVB3x6CoyeV30zREr7EWasItybw ba+6xE4lN2iM05L6sak2ZdQulUe4WJgMtoMFxkJ1JHxhqbwbmRkNv/FY6GhGBEOUpr8o 2dUA==
The extra line wrapping caused the issue.
Updated patch attached with an expanded commit message.
Regards,
Stefan
From d49ca2c7984bc43c2a71bccb382e445844b4acf3 Mon Sep 17 00:00:00 2001
From: "Stefan R. Filipek" <srfilipek@xxxxxxxxx>
Date: Thu, 4 Apr 2019 19:12:39 -0400
Subject: [PATCH] sys_linux: use pthread_setschedparam instead of
sched_setscheduler
Fix an issue with Linux and musl libc where sched_setscheduler is not
implemented. It seems that pthread_setschedparam is more widely
supported across different C libraries and OSs. For our use case, it
should make no difference which call is used.
---
configure | 16 +++++++++++-----
sys.c | 2 +-
sys_linux.c | 11 ++++++-----
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/configure b/configure
index 486b0bc..c434127 100755
--- a/configure
+++ b/configure
@@ -227,6 +227,7 @@ feat_timestamping=1
try_timestamping=0
feat_ntp_signd=0
ntp_era_split=""
+use_pthread=0
default_user="root"
default_hwclockfile=""
default_pidfile="/var/run/chrony/chronyd.pid"
@@ -652,7 +653,7 @@ then
add_def FEAT_ASYNCDNS
add_def USE_PTHREAD_ASYNCDNS
EXTRA_OBJECTS="$EXTRA_OBJECTS nameserv_async.o"
- MYCFLAGS="$MYCFLAGS -pthread"
+ use_pthread=1
fi
if test_code 'arc4random_buf()' 'stdlib.h' '' '' 'arc4random_buf(NULL, 0);'; then
@@ -786,13 +787,14 @@ fi
if [ $try_setsched = "1" ] && \
test_code \
- 'sched_setscheduler()' \
- 'sched.h' '' '' '
+ 'pthread_setschedparam()' \
+ 'pthread.h sched.h' '-pthread' '' '
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
+ use_pthread=1
fi
if [ $try_lockmem = "1" ] && \
@@ -896,6 +898,10 @@ if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_tomcrypt = "1" ]
fi
fi
+if [ $use_pthread = "1" ]; then
+ MYCFLAGS="$MYCFLAGS -pthread"
+fi
+
SYSCONFDIR=/etc
if [ "x$SETSYSCONFDIR" != "x" ]; then
SYSCONFDIR=$SETSYSCONFDIR
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..9e4ab3f 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -33,7 +33,8 @@
#include <sys/utsname.h>
-#if defined(HAVE_SCHED_SETSCHEDULER)
+#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
+# include <pthread.h>
# include <sched.h>
#endif
@@ -632,7 +633,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 +652,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 +661,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 */
--
2.21.0