From a8a9d38687284ad8bcf93af72519635e72123fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 3 Mar 2026 20:01:03 +0100 Subject: [PATCH] systemd: used drop-ins for configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: RHEL-97580 Signed-off-by: Jaroslav Škarvada --- 00-tuned.conf.systemd | 1 + 00_tuned => 00_tuned.grub | 0 Makefile | 16 ++++++++++++---- profiles/cpu-partitioning/script.sh | 4 ++-- profiles/cpu-partitioning/tuned.conf | 2 +- tuned.spec | 3 +++ tuned/consts.py | 8 ++++++-- tuned/plugins/plugin_systemd.py | 20 ++++++++++++-------- 8 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 00-tuned.conf.systemd rename 00_tuned => 00_tuned.grub (100%) diff --git a/00-tuned.conf.systemd b/00-tuned.conf.systemd new file mode 100644 index 0000000..26bca3d --- /dev/null +++ b/00-tuned.conf.systemd @@ -0,0 +1 @@ +[Manager] diff --git a/00_tuned b/00_tuned.grub similarity index 100% rename from 00_tuned rename to 00_tuned.grub diff --git a/Makefile b/Makefile index 907fced..b2fd40c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ NAME = tuned # set to devel for nightly GIT snapshot BUILD = release +SYSTEMD_SUPPORT = 1 # which config to use in mock-build target MOCK_CONFIG = rhel-7-x86_64 # scratch-build for triggering Jenkins @@ -72,9 +73,9 @@ release-cp: release-dir cp -a AUTHORS COPYING INSTALL README.md $(VERSIONED_NAME) cp -a tuned.py tuned.spec tuned.service tuned.tmpfiles Makefile tuned-adm.py \ - tuned-adm.bash dbus.conf recommend.conf tuned-main.conf 00_tuned \ - 92-tuned.install bootcmdline modules.conf com.redhat.tuned.policy \ - tuned-gui.py tuned-gui.glade tuned-ppd.py \ + tuned-adm.bash dbus.conf recommend.conf tuned-main.conf 00_tuned.grub \ + 00-tuned.conf.systemd 92-tuned.install bootcmdline modules.conf \ + com.redhat.tuned.policy tuned-gui.py tuned-gui.glade tuned-ppd.py \ tuned-gui.desktop functions $(VERSIONED_NAME) cp -a doc experiments libexec man profiles systemtap tuned contrib icons \ tests $(VERSIONED_NAME) @@ -210,14 +211,21 @@ install: install-dirs # runtime directory install -Dpm 0644 tuned.tmpfiles $(DESTDIR)$(TMPFILESDIR)/tuned.conf +ifeq ($(SYSTEMD_SUPPORT), 1) # systemd units install -Dpm 0644 tuned.service $(DESTDIR)$(UNITDIR)/tuned.service +endif # dbus configuration install -Dpm 0644 dbus.conf $(DESTDIR)$(DATADIR)/dbus-1/system.d/com.redhat.tuned.conf # grub template - install -Dpm 0755 00_tuned $(DESTDIR)$(SYSCONFDIR)/grub.d/00_tuned + install -Dpm 0755 00_tuned.grub $(DESTDIR)$(SYSCONFDIR)/grub.d/00_tuned + +ifeq ($(SYSTEMD_SUPPORT), 1) + # systemd template + install -Dpm 0644 00-tuned.conf.systemd $(DESTDIR)$(SYSCONFDIR)/systemd/system.conf.d/00-tuned.conf +endif # kernel install hook install -Dpm 0755 92-tuned.install $(DESTDIR)$(KERNELINSTALLHOOKDIR)/92-tuned.install diff --git a/profiles/cpu-partitioning/script.sh b/profiles/cpu-partitioning/script.sh index 5fe8d7d..0e7aee7 100755 --- a/profiles/cpu-partitioning/script.sh +++ b/profiles/cpu-partitioning/script.sh @@ -12,9 +12,9 @@ start() { else DRACUT_HOOK_DIR="/usr/lib/dracut/hooks/pre-udev" fi - mkdir -p "${TUNED_tmpdir}/etc/systemd" + mkdir -p "${TUNED_tmpdir}/etc/systemd/system.conf.d" mkdir -p "${TUNED_tmpdir}${DRACUT_HOOK_DIR}" - cp /etc/systemd/system.conf "${TUNED_tmpdir}/etc/systemd/" + cp /etc/systemd/system.conf.d/00-tuned.conf "${TUNED_tmpdir}/etc/systemd/system.conf.d/00-tuned.conf" cp 00-tuned-pre-udev.sh "${TUNED_tmpdir}${DRACUT_HOOK_DIR}" setup_kvm_mod_low_latency disable_ksm diff --git a/profiles/cpu-partitioning/tuned.conf b/profiles/cpu-partitioning/tuned.conf index e795dcb..3e698c8 100644 --- a/profiles/cpu-partitioning/tuned.conf +++ b/profiles/cpu-partitioning/tuned.conf @@ -63,4 +63,4 @@ priority=10 initrd_remove_dir=True initrd_dst_img=tuned-initrd.img initrd_add_dir=${tmpdir} -cmdline_cpu_part=+nohz=on${cmd_isolcpus} nohz_full=${isolated_cores} rcu_nocbs=${isolated_cores} tuned.non_isolcpus=${not_isolated_cpumask} systemd.cpu_affinity=${not_isolated_cores} intel_pstate=disable nosoftlockup +cmdline_cpu_part=+nohz=on${cmd_isolcpus} nohz_full=${isolated_cores} rcu_nocbs=${isolated_cores} tuned.non_isolcpus=${not_isolated_cpumask} intel_pstate=disable nosoftlockup diff --git a/tuned.spec b/tuned.spec index cd5671c..ea1d339 100644 --- a/tuned.spec +++ b/tuned.spec @@ -519,6 +519,9 @@ fi %config(noreplace) %{_sysconfdir}/tuned/tuned-main.conf %config(noreplace) %verify(not size mtime md5) %{_sysconfdir}/tuned/bootcmdline %verify(not size mtime md5) %{_sysconfdir}/modprobe.d/tuned.conf +# https://bugzilla.redhat.com/show_bug.cgi?id=2444143 +%dir %{_sysconfdir}/systemd/system.conf.d +%verify(not size mtime md5) %{_sysconfdir}/systemd/system.conf.d/00-tuned.conf %{_tmpfilesdir}/tuned.conf %{_unitdir}/tuned.service %dir %{_localstatedir}/log/tuned diff --git a/tuned/consts.py b/tuned/consts.py index 931a55b..ba16f59 100644 --- a/tuned/consts.py +++ b/tuned/consts.py @@ -57,15 +57,19 @@ PROCFS_MOUNT_POINT = "/proc" DEF_CGROUP_MOUNT_POINT = "/sys/fs/cgroup/cpuset" DEF_CGROUP_MODE = 0o770 +# systemd paths used by multiple plugins +SYSTEMD_CFG_PATH = "/etc/systemd" + # service plugin configuration -SERVICE_SYSTEMD_CFG_PATH = "/etc/systemd/system/%s.service.d" +SERVICE_SYSTEMD_CFG_PATH = SYSTEMD_CFG_PATH + "/system/%s.service.d" DEF_SERVICE_CFG_DIR_MODE = 0o755 # modules plugin configuration MODULES_FILE = "/etc/modprobe.d/tuned.conf" # systemd plugin configuration -SYSTEMD_SYSTEM_CONF_FILE = "/etc/systemd/system.conf" +SYSTEMD_SYSTEM_CONF_FILE = SYSTEMD_CFG_PATH + "/system.conf.d/00-tuned.conf" +SYSTEMD_SYSTEM_CONF_HEADER = "[Manager]" SYSTEMD_CPUAFFINITY_VAR = "CPUAffinity" # irqbalance plugin configuration diff --git a/tuned/plugins/plugin_systemd.py b/tuned/plugins/plugin_systemd.py index 5583588..478b3b0 100644 --- a/tuned/plugins/plugin_systemd.py +++ b/tuned/plugins/plugin_systemd.py @@ -15,10 +15,10 @@ class SystemdPlugin(base.Plugin): Plug-in for tuning systemd options. The [option]`cpu_affinity` option allows setting CPUAffinity in - `/etc/systemd/system.conf`. This configures the CPU affinity for the - service manager as well as the default CPU affinity for all forked - off processes. The option takes a comma-separated list of CPUs with - optional CPU ranges specified by the minus sign (`-`). + `/etc/systemd/system.conf.d/00-tuned.conf`. This configures the CPU + affinity for the service manager as well as the default CPU affinity + for all forked off processes. The option takes a comma-separated + list of CPUs with optional CPU ranges specified by the minus sign (`-`). .Set the CPUAffinity for `systemd` to `0 1 2 3` ==== @@ -32,10 +32,15 @@ class SystemdPlugin(base.Plugin): """ def __init__(self, *args, **kwargs): - if not os.path.isfile(consts.SYSTEMD_SYSTEM_CONF_FILE): - raise exceptions.NotSupportedPluginException("Required systemd '%s' configuration file not found, disabling plugin." % consts.SYSTEMD_SYSTEM_CONF_FILE) - super(SystemdPlugin, self).__init__(*args, **kwargs) self._cmd = commands() + if not os.path.isfile(consts.SYSTEMD_SYSTEM_CONF_FILE): + if os.path.isdir(consts.SYSTEMD_CFG_PATH): + log.info("Systemd configuration file '%s' not found, attempting to create it." % consts.SYSTEMD_SYSTEM_CONF_FILE) + if not self._cmd.write_to_file(consts.SYSTEMD_SYSTEM_CONF_FILE, consts.SYSTEMD_SYSTEM_CONF_HEADER + "\n", makedir=True): + raise exceptions.NotSupportedPluginException("Error creating systemd configuration file '%s', disabling plugin." % consts.SYSTEMD_SYSTEM_CONF_FILE) + else: + raise exceptions.NotSupportedPluginException("Systemd directory '%s' not found, systemd is not probably used, disabling plugin." % consts.SYSTEMD_CFG_PATH) + super(SystemdPlugin, self).__init__(*args, **kwargs) def _instance_init(self, instance): instance._has_dynamic_tuning = False @@ -143,4 +148,3 @@ class SystemdPlugin(base.Plugin): self._write_systemd_system_conf(self._add_keyval(conf, consts.SYSTEMD_CPUAFFINITY_VAR, v_unpacked)) return True return None -