From cd420e085a93fc65397b9c27d615e8d8905a5b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Mon, 2 Dec 2024 17:44:15 +0100 Subject: [PATCH] plugin_scheduler: make perf support optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Requested in: https://src.fedoraproject.org/rpms/tuned/pull-request/8 Signed-off-by: Jaroslav Škarvada --- tuned.spec | 9 +++++---- tuned/consts.py | 3 +++ tuned/plugins/plugin_scheduler.py | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/tuned.spec b/tuned.spec index a9ccef65..eceec8e5 100644 --- a/tuned.spec +++ b/tuned.spec @@ -83,7 +83,7 @@ BuildRequires: %{_py}-mock %endif BuildRequires: %{_py}-pyudev Requires: %{_py}-pyudev -Requires: %{_py}-linux-procfs, %{_py}-perf +Requires: %{_py}-linux-procfs %if %{without python3} Requires: %{_py}-schedutils %endif @@ -92,9 +92,6 @@ Requires: %{_py}-schedutils # BuildRequires for 'make test' BuildRequires: python3-dbus, python3-gobject-base Requires: python3-dbus, python3-gobject-base -%if 0%{?fedora} > 22 || 0%{?rhel} > 7 -Recommends: dmidecode -%endif %else # BuildRequires for 'make test' BuildRequires: dbus-python, pygobject3-base @@ -104,11 +101,15 @@ Requires: virt-what, ethtool, gawk Requires: util-linux, dbus, polkit %if 0%{?fedora} > 22 || 0%{?rhel} > 7 Recommends: dmidecode +# https://src.fedoraproject.org/rpms/tuned/pull-request/8 +Recommends: %{_py}-perf # i686 excluded Recommends: kernel-tools Requires: hdparm Requires: kmod Requires: iproute +%else +Requires: %{_py}-perf %endif # syspurpose %if 0%{?rhel} > 8 diff --git a/tuned/consts.py b/tuned/consts.py index 4606aee1..9fe79ad0 100644 --- a/tuned/consts.py +++ b/tuned/consts.py @@ -77,6 +77,9 @@ # built-in functions configuration SYSFS_CPUS_PATH = "/sys/devices/system/cpu" +# present CPUs +SYSFS_CPUS_PRESENT_PATH = "%s/present" % SYSFS_CPUS_PATH + # number of backups LOG_FILE_COUNT = 2 LOG_FILE_MAXBYTES = 100*1000 diff --git a/tuned/plugins/plugin_scheduler.py b/tuned/plugins/plugin_scheduler.py index 7d9bcbe0..a628bdc2 100644 --- a/tuned/plugins/plugin_scheduler.py +++ b/tuned/plugins/plugin_scheduler.py @@ -8,7 +8,12 @@ import re from subprocess import * import threading -import perf +# perf is optional +try: + import perf +except ModuleNotFoundError: +# if perf is unavailable, it will be disabled later + pass import select import tuned.consts as consts import procfs @@ -447,7 +452,15 @@ def __init__(self, monitor_repository, storage_factory, hardware_inventory, devi self._ps_whitelist = ".*" self._ps_blacklist = "" self._cgroup_ps_blacklist_re = "" - self._cpus = perf.cpu_map() + # perf is optional, if unavailable, it will be disabled later + try: + self._cpus = perf.cpu_map() + except (NameError, AttributeError): + cpus = self._cmd.read_file(consts.SYSFS_CPUS_PRESENT_PATH) + # it's different type than perf.cpu_map(), but without perf we use it as iterable + # which should be compatible, fallback to single core CPU if sysfs is unavailable + self._cpus = self._cmd.cpulist_unpack(cpus) if cpus else [ 0 ] + self._scheduler_storage_key = self._storage_key( command_name = "scheduler") self._irq_process = True @@ -532,6 +545,7 @@ def _instance_init(self, instance): instance._evlist.mmap(pages = perf_mmap_pages) # no perf except: + log.warn("python-perf unavailable, disabling perf support, you can try to (re)install python(3)-perf package") instance._runtime_tuning = False def _instance_cleanup(self, instance):