Re: [chrony-dev] [PATCH v2] sys_posix: support SCHED_FIFO and mlockall on more OSs

2019-04-24 Thread Miroslav Lichvar
On Fri, Apr 19, 2019 at 02:41:14PM -0400, Stefan R. Filipek wrote:
> Real-time scheduling and memory locking is available on posix compliant
> OSs. This patch centralizes this functionality and brings support to
> FreeBSD, NetBSD, and Solaris.

Applied. Thanks!

-- 
Miroslav Lichvar

-- 
To unsubscribe email chrony-dev-requ...@chrony.tuxfamily.org with "unsubscribe" 
in the subject.
For help email chrony-dev-requ...@chrony.tuxfamily.org with "help" in the 
subject.
Trouble?  Email listmas...@chrony.tuxfamily.org.



[chrony-dev] [PATCH v2] sys_posix: support SCHED_FIFO and mlockall on more OSs

2019-04-19 Thread Stefan R. Filipek
Real-time scheduling and memory locking is available on posix compliant
OSs. This patch centralizes this functionality and brings support to
FreeBSD, NetBSD, and Solaris.
---
 configure|  27 ---
 doc/chrony.conf.adoc |  46 +-
 sys.c|  13 +++--
 sys_linux.c  |  67 --
 sys_linux.h  |   4 --
 sys_posix.c  | 111 +++
 sys_posix.h  |  36 ++
 7 files changed, 198 insertions(+), 106 deletions(-)
 create mode 100644 sys_posix.c
 create mode 100644 sys_posix.h

diff --git a/configure b/configure
index c434127..9e21a8b 100755
--- a/configure
+++ b/configure
@@ -396,7 +396,7 @@ SYSTEM=${OPERATINGSYSTEM}-${MACHINE}
 
 case $OPERATINGSYSTEM in
 Linux)
-EXTRA_OBJECTS="sys_generic.o sys_linux.o sys_timex.o"
+EXTRA_OBJECTS="sys_generic.o sys_linux.o sys_timex.o sys_posix.o"
 [ $try_libcap != "0" ] && try_libcap=1
 try_rtc=1
 [ $try_seccomp != "0" ] && try_seccomp=1
@@ -411,7 +411,9 @@ case $OPERATINGSYSTEM in
 # recvmmsg() seems to be broken on FreeBSD 11.0 and it's just
 # a wrapper around recvmsg()
 try_recvmmsg=0
-EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o"
+EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
+try_setsched=1
+try_lockmem=1
 add_def FREEBSD
 if [ $feat_droproot = "1" ]; then
   add_def FEAT_PRIVDROP
@@ -420,8 +422,10 @@ case $OPERATINGSYSTEM in
 echo "Configuring for $SYSTEM"
 ;;
 NetBSD)
-EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o"
+EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
 try_clockctl=1
+try_setsched=1
+try_lockmem=1
 add_def NETBSD
 echo "Configuring for $SYSTEM"
 ;;
@@ -446,9 +450,11 @@ case $OPERATINGSYSTEM in
 echo "Configuring for macOS (" $SYSTEM "macOS version" $VERSION ")"
 ;;
 SunOS)
-EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o"
+EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o sys_posix.o"
 EXTRA_LIBS="-lsocket -lnsl -lresolv"
 EXTRA_CLI_LIBS="-lsocket -lnsl -lresolv"
+try_setsched=1
+try_lockmem=1
 add_def SOLARIS
 # These are needed to have msg_control in struct msghdr
 add_def __EXTENSIONS__
@@ -800,13 +806,20 @@ fi
 if [ $try_lockmem = "1" ] && \
   test_code \
 'mlockall()' \
-'sys/mman.h sys/resource.h' '' '' '
- struct rlimit rlim;
- setrlimit(RLIMIT_MEMLOCK, &rlim);
+'sys/mman.h' '' '' '
  mlockall(MCL_CURRENT|MCL_FUTURE);'
 then
   add_def HAVE_MLOCKALL
 fi
+if [ $try_lockmem = "1" ] && \
+  test_code \
+'setrlimit(RLIMIT_MEMLOCK, ...)' \
+'sys/resource.h' '' '' '
+ struct rlimit rlim;
+ setrlimit(RLIMIT_MEMLOCK, &rlim);'
+then
+  add_def HAVE_SETRLIMIT_MEMLOCK
+fi
 
 if [ $feat_forcednsretry = "1" ]
 then
diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc
index 7aa2116..aa5cafe 100644
--- a/doc/chrony.conf.adoc
+++ b/doc/chrony.conf.adoc
@@ -2063,11 +2063,11 @@ file when the <> command is 
issued by *chronyc*).
 
 [[lock_all]]*lock_all*::
 The *lock_all* directive will lock chronyd into RAM so that it will never be
-paged out. This mode is only supported on Linux. This directive uses the Linux
-*mlockall()* system call to prevent *chronyd* from ever being swapped out. This
-should result in lower and more consistent latency. It should not have
-significant impact on performance as *chronyd's* memory usage is modest. The
-*mlockall(2)* man page has more details.
+paged out. This mode is supported on Linux, FreeBSD, NetBSD, and Solaris.  This
+directive uses the POSIX *mlockall()* system call to prevent *chronyd* from
+ever being swapped out. This should result in lower and more consistent
+latency. It should not have significant impact on performance as *chronyd's*
+memory usage is modest. The *mlockall(2)* man page has more details.
 
 [[pidfile]]*pidfile* _file_::
 Unless *chronyd* is started with the *-Q* option, it writes its process ID
@@ -2081,26 +2081,26 @@ pidfile /run/chronyd.pid
 
 
 [[sched_priority]]*sched_priority* _priority_::
-On Linux, the *sched_priority* directive will select the SCHED_FIFO real-time
-scheduler at the specified priority (which must be between 0 and 100). On
-macOS, this option must have either a value of 0 (the default) to disable the
-thread time constraint policy or 1 for the policy to be enabled. Other systems
-do not support this option.
-+
-On Linux, this directive uses the *sched_setscheduler()* system call to
-instruct the kernel to use the SCHED_FIFO first-in, first-out real-time
-scheduling policy for *chronyd* with the specified priority. This means that
-whenever *chronyd* is ready to run it will run, interrupting whatever else is
-running unless it is a higher priority