diff options
author | Clark Williams <williams@redhat.com> | 2020-08-21 15:17:19 -0500 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2020-08-21 15:17:19 -0500 |
commit | 7eb37f27ffd32514d1df7dae60f936e4e7a3c095 (patch) | |
tree | 7ed4f7da2427a3d75411233a4cdd87544524786d | |
parent | dc4981e4e48cc613ec1b7068925ad1da873a47e7 (diff) | |
download | stalld-7eb37f27ffd32514d1df7dae60f936e4e7a3c095.tar.gz |
Add logic for writing a pidfile on startup
The systemd service really wants a pidfile for a 'forking' daemon, so
add the '--pidfile/-P' option to specify a path and add logic to
write the pid after we've finished configuring. Added the option
to the systemd service file as well.
Signed-off-by: Clark Williams <williams@redhat.com>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | redhat/starvation_monitor.conf | 4 | ||||
-rw-r--r-- | redhat/starvation_monitor.service | 2 | ||||
-rw-r--r-- | redhat/starvation_monitor.spec | 9 | ||||
-rw-r--r-- | src/starvation_monitor.c | 35 |
5 files changed, 44 insertions, 8 deletions
@@ -1,5 +1,5 @@ NAME := starvation_monitor -VERSION := 0.1 +VERSION := 0.2 INSTALL=install diff --git a/redhat/starvation_monitor.conf b/redhat/starvation_monitor.conf index 9e256bf..8d9753d 100644 --- a/redhat/starvation_monitor.conf +++ b/redhat/starvation_monitor.conf @@ -42,3 +42,7 @@ LOGGING= # ex: FG=--foreground # note: when using this should change the service Type to be simple FG= + +# Write a pidfile +# ex: PF=--pidfile /run/starvation_monitor.pid +PF="--pidfile /run/starvation_monitor.pid" diff --git a/redhat/starvation_monitor.service b/redhat/starvation_monitor.service index d20f871..fced98e 100644 --- a/redhat/starvation_monitor.service +++ b/redhat/starvation_monitor.service @@ -5,7 +5,7 @@ Description=Starvation Monitor # Type=simple Type=forking EnvironmentFile=/etc/systemd/starvation_monitor.conf -ExecStart=/usr/bin/starvation_monitor $CLIST $AGGR $BP $BR $BD $THRESH $LOGGING $FG +ExecStart=/usr/bin/starvation_monitor $CLIST $AGGR $BP $BR $BD $THRESH $LOGGING $FG $PF [Install] WantedBy=multi-user.target diff --git a/redhat/starvation_monitor.spec b/redhat/starvation_monitor.spec index 33aab67..fc05903 100644 --- a/redhat/starvation_monitor.spec +++ b/redhat/starvation_monitor.spec @@ -1,5 +1,5 @@ Name: starvation_monitor -Version: 0.1 +Version: 0.2 Release: 1%{?dist} Summary: daemon that finds starving tasks and gives them a temporary boost @@ -38,11 +38,14 @@ make DESTDIR=$RPM_BUILD_ROOT -C redhat install %changelog -* Thu Aug 20 2020 williams@redhat.com +* Fri Aug 21 2020 williams@redhat.com - 0.2-1 +- add pidfile logic + +* Thu Aug 20 2020 williams@redhat.com - 0.1-1 - Added systemd service to redhat subdirectory - added make and rpm logic for systemd files -* Wed Aug 19 2020 williams@redhat.com +* Wed Aug 19 2020 williams@redhat.com - 0.0-1 - initial version of specfile - Makefile mods for RPM builds - added systemd service and config files diff --git a/src/starvation_monitor.c b/src/starvation_monitor.c index c312478..445484c 100644 --- a/src/starvation_monitor.c +++ b/src/starvation_monitor.c @@ -4,7 +4,7 @@ * This program was born after Daniel and Juri started debugging once again * problems caused kernel threads starving due to busy-loop sched FIFO threads. * - * The idea is simple: after detecting a thread starving on a given CPU for a + * The idea is simple: after detecting a thread starving on a given CPU for a * given period, this thread will receive a "bounded" chance to run, using * SCHED_DEADLINE. In this way, the starving thread is able to make progress * causing a bounded Operating System noise (OS Noise). @@ -121,6 +121,11 @@ int config_monitor_all_cpus = 1; char *config_monitored_cpus; +/* + * path to file for storing daemon pid + */ +char pidfile[MAXPATHLEN]; + void log_msg(const char *fmt, ...) { const char *log_prefix = "starvation_monitor: "; @@ -185,6 +190,19 @@ void die(const char *fmt, ...) exit(ret); } +void write_pidfile(void) +{ + FILE *f = fopen(pidfile, "w"); + if (f != NULL) { + fprintf(f, "%d", getpid()); + fclose(f); + } + else + die("unable to open pidfile %s: %s\n", pidfile, strerror(errno)); +} + + + /* * Based on: * https://github.com/pasce/daemon-skeleton-linux-c @@ -496,7 +514,7 @@ long get_variable_long_value(char *buffer, const char *variable) return get_long_after_colon(start); } -/* +/* * Example: * ' S task PID tree-key switches prio wait-time sum-exec sum-sleep' * '-----------------------------------------------------------------------------------------------------------' @@ -662,7 +680,7 @@ int boost_starving_task(int pid) struct sched_attr new_attr; struct sched_attr old_attr; - memset(&new_attr, 0, sizeof(new_attr)); + memset(&new_attr, 0, sizeof(new_attr)); new_attr.size = sizeof(new_attr); new_attr.sched_policy = SCHED_DEADLINE; new_attr.sched_runtime = config_dl_runtime; @@ -794,6 +812,7 @@ void print_usage(void) " -A/--aggressive_mode: dispatch one thread per run queue, even when there is no starving", " threads on all CPU (uses more CPU/power).", " misc:", + " --pidfile: write daemon pid to specified file", " -h/--help: print this menu", NULL, }; @@ -883,6 +902,9 @@ int parse_args(int argc, char **argv) { int c; + /* ensure the pidfile is an empty string */ + pidfile[0] = '\0'; + while (1) { static struct option long_options[] = { {"cpu", required_argument, 0, 'c'}, @@ -897,6 +919,7 @@ int parse_args(int argc, char **argv) {"boost_runtime", required_argument, 0, 'r'}, {"boost_duration", required_argument, 0, 'd'}, {"starving_threshold", required_argument, 0, 't'}, + {"pidfile", required_argument, 0, 'P'}, {0, 0, 0, 0} }; @@ -970,6 +993,9 @@ int parse_args(int argc, char **argv) print_usage(); exit(EXIT_SUCCESS); break; + case 'P': + strncpy(pidfile, optarg, sizeof(pidfile)-1); + break; case '?': usage("Invalid option"); break; @@ -1134,6 +1160,9 @@ int main(int argc, char **argv) if (!config_foreground) deamonize(); + if (strlen(pidfile) > 0) + write_pidfile(); + if (config_aggressive) aggressive_main(cpus, nr_cpus); else |