Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin_scheduler: make perf support optional #716

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tuned.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tuned/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions tuned/plugins/plugin_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import re
from subprocess import *
import threading
import perf
# perf is optional
try:
import perf
except ModuleNotFoundError:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in recent force push 01c46d4.

# if perf is unavailable, it will be disabled later
pass
import select
import tuned.consts as consts
import procfs
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Loading