From 261d784c7b0e8c2b33ae8701b12397f2cc6e695b Mon Sep 17 00:00:00 2001
From: Jan Friesse <jfriesse@redhat.com>
Date: Mon, 16 Mar 2020 16:57:09 +0100
Subject: [PATCH 2/2] Add ability to move process into root cgroup
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
---
spausedd.8 | 8 +++++---
spausedd.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/spausedd.8 b/spausedd.8
index 6c35666..b23e590 100644
--- a/spausedd.8
+++ b/spausedd.8
@@ -1,5 +1,5 @@
.\"
-.\" Copyright (c) 2018-2019, Red Hat, Inc.
+.\" Copyright (c) 2018-2020, Red Hat, Inc.
.\"
.\" Permission to use, copy, modify, and/or distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -15,7 +15,7 @@
.\"
.\" Author: Jan Friesse <jfriesse@redhat.com>
.\"
-.Dd Mar 21, 2018
+.Dd Nov 11, 2020
.Dt SPAUSEDD 8
.Os
.Sh NAME
@@ -66,7 +66,9 @@ Run on foreground (do not demonize - default).
Show help.
.It Fl p
Do not set RR scheduler.
-.It Fl t Ar steal_threshold
+.It Fl P
+Do not move process to root cgroup.
+.It Fl m Ar steal_threshold
Set steal threshold percent. (default is 10 if kernel information is used and
100 if VMGuestLib is used).
.It Fl t Ar timeout
diff --git a/spausedd.c b/spausedd.c
index 0a6fe65..6a194cd 100644
--- a/spausedd.c
+++ b/spausedd.c
@@ -273,6 +273,42 @@ utils_set_rr_scheduler(void)
#endif
}
+static void
+utils_move_to_root_cgroup(void)
+{
+ FILE *f;
+
+ /*
+ * /sys/fs/cgroup is hardcoded, because most of Linux distributions are now
+ * using systemd and systemd uses hardcoded path of cgroup mount point.
+ *
+ * This feature is expected to be removed as soon as systemd gets support
+ * for managing RT configuration.
+ */
+ f = fopen("/sys/fs/cgroup/cpu/cpu.rt_runtime_us", "rt");
+ if (f == NULL) {
+ log_printf(LOG_DEBUG, "cpu.rt_runtime_us doesn't exists -> "
+ "system without cgroup or with disabled CONFIG_RT_GROUP_SCHED");
+ return ;
+ }
+ (void)fclose(f);
+
+ f = fopen("/sys/fs/cgroup/cpu/tasks", "w");
+ if (f == NULL) {
+ log_printf(LOG_WARNING, "Can't open cgroups tasks file for writing");
+ return ;
+ }
+
+ if (fprintf(f, "%jd\n", (intmax_t)getpid()) <= 0) {
+ log_printf(LOG_WARNING, "Can't write spausedd pid into cgroups tasks file");
+ }
+
+ if (fclose(f) != 0) {
+ log_printf(LOG_WARNING, "Can't close cgroups tasks file");
+ return ;
+ }
+}
+
/*
* Signal handlers
*/
@@ -603,13 +639,14 @@ poll_run(uint64_t timeout)
static void
usage(void)
{
- printf("usage: %s [-dDfhp] [-m steal_th] [-t timeout]\n", PROGRAM_NAME);
+ printf("usage: %s [-dDfhpP] [-m steal_th] [-t timeout]\n", PROGRAM_NAME);
printf("\n");
printf(" -d Display debug messages\n");
printf(" -D Run on background - daemonize\n");
printf(" -f Run foreground - do not daemonize (default)\n");
printf(" -h Show help\n");
printf(" -p Do not set RR scheduler\n");
+ printf(" -P Do not move process to root cgroup\n");
printf(" -m steal_th Steal percent threshold\n");
printf(" -t timeout Set timeout value (default: %u)\n", DEFAULT_TIMEOUT);
}
@@ -622,14 +659,16 @@ main(int argc, char **argv)
long long int tmpll;
uint64_t timeout;
int set_prio;
+ int move_to_root_cgroup;
foreground = 1;
timeout = DEFAULT_TIMEOUT;
set_prio = 1;
+ move_to_root_cgroup = 1;
max_steal_threshold = DEFAULT_MAX_STEAL_THRESHOLD;
max_steal_threshold_user_set = 0;
- while ((ch = getopt(argc, argv, "dDfhpm:t:")) != -1) {
+ while ((ch = getopt(argc, argv, "dDfhpPm:t:")) != -1) {
switch (ch) {
case 'D':
foreground = 0;
@@ -659,6 +698,9 @@ main(int argc, char **argv)
usage();
exit(1);
break;
+ case 'P':
+ move_to_root_cgroup = 0;
+ break;
case 'p':
set_prio = 0;
break;
@@ -677,6 +719,10 @@ main(int argc, char **argv)
utils_mlockall();
+ if (move_to_root_cgroup) {
+ utils_move_to_root_cgroup();
+ }
+
if (set_prio) {
utils_set_rr_scheduler();
}
--
2.18.2