Bug#175740: dpkg: Add realtime scheduler support to the start-stop-daemon
Package: dpkg
Version: 1.10.9
Severity: wishlist
Tags: patch
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This patch allows the start-stop-daemon to start processes from the realtime
scheduler. It uses the "--realtime" and "-l" options. This is usefull
for processes that never should be unable to run (eg high resolution monitoring,
high quality audio jobs, system essentials)
Example:
start-stop-daemon --start --quiet --realtime 1 --pidfile /var/run/sshd.pid
- --exec /usr/sbin/sshd
This way ssh will always be able to start a responsive shell, even if the
machine is under extreme high load (crashed for all practical purposes).
Problems:
- -It is not (yet) possible to select a scheduling policy, it defaults to
SCHED_RR (Round Robin).
- -Use with care, processes that ask for all of the processor will get it,
thus preventing other processes from running.
- -- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux vodka.huis 2.4.20vodka.3 #1 ma dec 9 21:08:19 CET 2002 i686
Locale: LANG=C, LC_CTYPE=C (ignored: LC_ALL set)
Versions of packages dpkg depends on:
ii dselect 1.10.9 a user tool to manage Debian packa
ii libc6 2.3.1-9 GNU C Library: Shared libraries an
- -- no debconf information
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+GyguIhQIPPgOSvcRApyfAJ9H28Ue/R6tAAcWoMsJfW9PSiOuIACfRi83
OssizL1hPibONvuc1M6uiuk=
=cMF1
-----END PGP SIGNATURE-----
diff -ru dpkg-1.10.9/utils/start-stop-daemon.c dpkg-1.10.9-cas/utils/start-stop-daemon.c
--- dpkg-1.10.9/utils/start-stop-daemon.c 2002-07-12 05:32:00.000000000 +0200
+++ dpkg-1.10.9-cas/utils/start-stop-daemon.c 2003-01-07 19:33:31.000000000 +0100
@@ -83,6 +83,7 @@
#include <limits.h>
#include <assert.h>
#include <ctype.h>
+#include <sched.h>
#ifdef HAVE_ERROR_H
# include <error.h>
@@ -115,6 +116,7 @@
static const char *schedule_str = NULL;
static const char *progname = "";
static int nicelevel = 0;
+static int rtlevel = 0;
static struct stat exec_stat;
#if defined(OSHURD)
@@ -276,6 +278,7 @@
" -s|--signal <signal> signal to send (default TERM)\n"
" -a|--startas <pathname> program to start (default is <executable>)\n"
" -N|--nicelevel <incr> add incr to the process's nice level\n"
+" -l|--realtime <incr> add incr to the process's realtime priority level\n"
" -b|--background force the process to detach\n"
" -m|--make-pidfile create the pidfile before starting\n"
" -R|--retry <schedule> check whether processes die, and retry\n"
@@ -459,6 +462,7 @@
{ "exec", 1, NULL, 'x'},
{ "chuid", 1, NULL, 'c'},
{ "nicelevel", 1, NULL, 'N'},
+ { "realtime", 1, NULL, 'l'},
{ "background", 0, NULL, 'b'},
{ "make-pidfile", 0, NULL, 'm'},
{ "retry", 1, NULL, 'R'},
@@ -467,7 +471,7 @@
int c;
for (;;) {
- c = getopt_long(argc, argv, "HKSVa:n:op:qr:s:tu:vx:c:N:bmR:",
+ c = getopt_long(argc, argv, "HKSVa:n:op:qr:s:tu:vx:c:N:l:bmR:",
longopts, (int *) 0);
if (c == -1)
break;
@@ -523,6 +527,9 @@
break;
case 'r': /* --chroot /new/root */
changeroot = optarg;
+ break;
+ case 'l': /* --realtime */
+ rtlevel = atoi(optarg);
break;
case 'N': /* --nice */
nicelevel = atoi(optarg);
@@ -1178,6 +1185,8 @@
printf(" in directory %s", changeroot);
if (nicelevel)
printf(", and add %i to the priority", nicelevel);
+ if (rtlevel)
+ printf(", and add %i to the realtime priority", rtlevel);
printf(".\n");
exit(0);
}
@@ -1247,6 +1256,16 @@
fatal("Unable to alter nice level by %i: %s", nicelevel,
strerror(errno));
}
+ if (rtlevel) {
+ struct sched_param tmp;
+ errno=0;
+ tmp.sched_priority=rtlevel;
+
+ if ((sched_setscheduler(getpid(), SCHED_RR, &tmp)==-1) && (errno!=0))
+ fatal("Unable to set realtime scheduler priority to %i: %s", rtlevel,
+ strerror(errno));
+ }
+
if (mpidfile && pidfile != NULL) { /* user wants _us_ to make the pidfile :) */
FILE *pidf = fopen(pidfile, "w");
pid_t pidt = getpid();
Reply to: