52b84b
From 82156850f6642a363aa2ff06677ad089a460104e Mon Sep 17 00:00:00 2001
be3800
From: Lennart Poettering <lennart@poettering.net>
be3800
Date: Tue, 26 Nov 2019 09:46:00 +0100
be3800
Subject: [PATCH] pid1: add new kernel cmdline arg systemd.cpu_affinity=
be3800
be3800
Let's allow configuration of the CPU affinity via the kernel cmdline,
be3800
overriding CPUAffinity= in /etc/systemd/system.conf
be3800
be3800
Prompted by:
be3800
be3800
https://lists.freedesktop.org/archives/systemd-devel/2019-November/043754.html
be3800
be3800
(cherry picked from commit 68d58f38693e586b5ce5785274f8e42a79625196)
be3800
52b84b
Resolves: #1812894
be3800
---
be3800
 man/kernel-command-line.xml | 11 +++++++++++
be3800
 src/core/main.c             |  9 +++++++++
be3800
 2 files changed, 20 insertions(+)
be3800
be3800
diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml
be3800
index 0545f9d84b..4d8cb4e50e 100644
be3800
--- a/man/kernel-command-line.xml
be3800
+++ b/man/kernel-command-line.xml
be3800
@@ -366,6 +366,17 @@
be3800
         </listitem>
be3800
       </varlistentry>
be3800
 
be3800
+      <varlistentry>
be3800
+        <term><varname>systemd.cpu_affinity=</varname></term>
be3800
+
be3800
+        <listitem>
be3800
+          <para>Overrides the CPU affinity mask for the service manager and the default for all child
be3800
+          processes it forks. This takes precedence over <varname>CPUAffinity=</varname>, see
be3800
+          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
be3800
+          for details.</para>
be3800
+        </listitem>
be3800
+      </varlistentry>
be3800
+
be3800
       <varlistentry>
be3800
         <term><varname>modules_load=</varname></term>
be3800
         <term><varname>rd.modules_load=</varname></term>
be3800
diff --git a/src/core/main.c b/src/core/main.c
be3800
index 45d09b1e11..9f238a8430 100644
be3800
--- a/src/core/main.c
be3800
+++ b/src/core/main.c
be3800
@@ -472,6 +472,15 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
be3800
                 if (arg_default_timeout_start_usec <= 0)
be3800
                         arg_default_timeout_start_usec = USEC_INFINITY;
be3800
 
be3800
+        } else if (proc_cmdline_key_streq(key, "systemd.cpu_affinity")) {
be3800
+
be3800
+                if (proc_cmdline_value_missing(key, value))
be3800
+                        return 0;
be3800
+
be3800
+                r = parse_cpu_set(value, &arg_cpu_affinity);
be3800
+                if (r < 0)
be3800
+                        log_warning_errno(r, "Failed to parse CPU affinity mask '%s', ignoring: %m", value);
be3800
+
be3800
         } else if (proc_cmdline_key_streq(key, "systemd.watchdog_device")) {
be3800
 
be3800
                 if (proc_cmdline_value_missing(key, value))