Skip to content

Commit

Permalink
spec: used macro for profiles path and other fixes
Browse files Browse the repository at this point in the history
- improved conditionals for better readability
- fixed tuned-ppd not to run install twice
- used macro for profiles path
- consolidated names of related variables
- updated Makefile to update the current profile paths during
  installation

Signed-off-by: Jaroslav Škarvada <[email protected]>
  • Loading branch information
yarda committed Oct 14, 2024
1 parent c082797 commit 1ff5e24
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 76 deletions.
54 changes: 33 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ $(error Failed to determine python library directory)
endif
KERNELINSTALLHOOKDIR = /usr/lib/kernel/install.d
TUNED_SYSTEM_DIR = /usr/lib/tuned
TUNED_PROFILES_DIR = $(TUNED_SYSTEM_DIR)/profiles
TUNED_SYSTEM_PROFILES_DIR = $(TUNED_SYSTEM_DIR)/profiles
TUNED_CFG_DIR = $(SYSCONFDIR)/tuned
TUNED_USER_PROFILES_DIR = $(TUNED_CFG_DIR)/profiles
TUNED_RECOMMEND_DIR = $(TUNED_SYSTEM_DIR)/recommend.d
TUNED_USER_RECOMMEND_DIR = $(SYSCONFDIR)/tuned/recommend.d
TUNED_USER_RECOMMEND_DIR = $(TUNED_CFG_DIR)/recommend.d
BASH_COMPLETIONS = $(DATADIR)/bash-completion/completions

copy_executable = install -Dm 0755 $(1) $(2)
Expand Down Expand Up @@ -129,13 +131,13 @@ clean-html:

install-dirs:
mkdir -p $(DESTDIR)$(PYTHON_SITELIB)
mkdir -p $(DESTDIR)$(TUNED_PROFILES_DIR)
mkdir -p $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)
mkdir -p $(DESTDIR)/var/lib/tuned
mkdir -p $(DESTDIR)/var/log/tuned
mkdir -p $(DESTDIR)/run/tuned
mkdir -p $(DESTDIR)$(DOCDIR)
mkdir -p $(DESTDIR)$(SYSCONFDIR)
mkdir -p $(DESTDIR)$(SYSCONFDIR)/tuned/profiles
mkdir -p $(DESTDIR)$(TUNED_USER_PROFILES_DIR)
mkdir -p $(DESTDIR)$(TUNED_RECOMMEND_DIR)
mkdir -p $(DESTDIR)$(TUNED_USER_RECOMMEND_DIR)

Expand All @@ -161,26 +163,36 @@ install: install-dirs
experiments/powertop2tuned.py, $(DESTDIR)/usr/bin/powertop2tuned)

# configuration files
install -Dpm 0644 tuned-main.conf $(DESTDIR)$(SYSCONFDIR)/tuned/tuned-main.conf
# Update profiles location
sed '/^\s*#\?\s*profile_dirs\s*=\s*/ s|\(profile_dirs\s*=\s*\).*$$|\1$(TUNED_SYSTEM_PROFILES_DIR),$(TUNED_USER_PROFILES_DIR)|' \
tuned-main.conf > tuned-main.conf.tmp
touch -r tuned-main.conf tuned-main.conf.tmp
sed -i '/^\s*USER_PROFILES_DIR\s*=\s*/ s|\(USER_PROFILES_DIR\s*=\s*\).*$$|\1$(TUNED_USER_PROFILES_DIR)|' \
$(DESTDIR)$(PYTHON_SITELIB)/tuned/consts.py
sed -i '/^\s*SYSTEM_PROFILES_DIR\s*=\s*/ s|\(SYSTEM_PROFILES_DIR\s*=\s*\).*$$|\1$(TUNED_SYSTEM_PROFILES_DIR)|' \
$(DESTDIR)$(PYTHON_SITELIB)/tuned/consts.py
install -Dpm 0644 tuned-main.conf.tmp $(DESTDIR)$(TUNED_CFG_DIR)/tuned-main.conf
rm -f tuned-main.conf.tmp

# None profile in the moment, autodetection will be used
echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/active_profile
echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/profile_mode
echo -n > $(DESTDIR)$(SYSCONFDIR)/tuned/post_loaded_profile
install -Dpm 0644 bootcmdline $(DESTDIR)$(SYSCONFDIR)/tuned/bootcmdline
echo -n > $(DESTDIR)$(TUNED_CFG_DIR)/active_profile
echo -n > $(DESTDIR)$(TUNED_CFG_DIR)/profile_mode
echo -n > $(DESTDIR)$(TUNED_CFG_DIR)/post_loaded_profile
install -Dpm 0644 bootcmdline $(DESTDIR)$(TUNED_CFG_DIR)/bootcmdline
install -Dpm 0644 modules.conf $(DESTDIR)$(SYSCONFDIR)/modprobe.d/tuned.conf

# profiles & system config
cp -a profiles/* $(DESTDIR)$(TUNED_PROFILES_DIR)/
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/realtime/realtime-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/realtime-virtual-guest/realtime-virtual-guest-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-virtual-guest-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/realtime-virtual-host/realtime-virtual-host-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/realtime-virtual-host-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/cpu-partitioning/cpu-partitioning-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/cpu-partitioning-variables.conf
mv $(DESTDIR)$(TUNED_PROFILES_DIR)/cpu-partitioning-powersave/cpu-partitioning-powersave-variables.conf \
$(DESTDIR)$(SYSCONFDIR)/tuned/cpu-partitioning-powersave-variables.conf
cp -a profiles/* $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/realtime/realtime-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/realtime-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/realtime-virtual-guest/realtime-virtual-guest-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/realtime-virtual-guest-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/realtime-virtual-host/realtime-virtual-host-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/realtime-virtual-host-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/cpu-partitioning/cpu-partitioning-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/cpu-partitioning-variables.conf
mv $(DESTDIR)$(TUNED_SYSTEM_PROFILES_DIR)/cpu-partitioning-powersave/cpu-partitioning-powersave-variables.conf \
$(DESTDIR)$(TUNED_CFG_DIR)/cpu-partitioning-powersave-variables.conf
install -pm 0644 recommend.conf $(DESTDIR)$(TUNED_RECOMMEND_DIR)/50-tuned.conf

# bash functions used by profile scripts
Expand Down Expand Up @@ -228,7 +240,7 @@ install: install-dirs
install -dD $(DESTDIR)$(DATADIR)/applications
desktop-file-install --dir=$(DESTDIR)$(DATADIR)/applications tuned-gui.desktop

install-ppd: install
install-ppd:
$(call install_python_script,tuned-ppd.py,$(DESTDIR)/usr/sbin/tuned-ppd)
install -Dpm 0644 tuned/ppd/tuned-ppd.service $(DESTDIR)$(UNITDIR)/tuned-ppd.service
install -Dpm 0644 tuned/ppd/tuned-ppd.dbus.service $(DESTDIR)$(DATADIR)/dbus-1/system-services/net.hadess.PowerProfiles.service
Expand Down
117 changes: 67 additions & 50 deletions tuned.spec
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
%bcond_with snapshot

%if 0%{?rhel} && 0%{?rhel} < 10
%global user_profiles_dir %{_sysconfdir}/tuned
%global system_profiles_dir %{_prefix}/lib/tuned
%else
%global user_profiles_dir %{_sysconfdir}/tuned/profiles
%global system_profiles_dir %{_prefix}/lib/tuned/profiles
%endif

%if 0%{?fedora}
%if 0%{?fedora} > 27
%bcond_without python3
%else
%bcond_with python3
%endif
%else
%if 0%{?rhel} && 0%{?rhel} < 8

# ! 0%{?fedora}
%if 0%{?rhel}
%if 0%{?rhel} < 8
%bcond_with python3
%else
%bcond_without python3
%endif
%else
# ! 0%{?rhel}
%bcond_without python3
%endif
%endif

%if %{with python3}
Expand Down Expand Up @@ -286,7 +301,9 @@ make html %{make_python_arg}
%endif

%install
make install DESTDIR=%{buildroot} DOCDIR=%{docdir} %{make_python_arg}
make install DESTDIR=%{buildroot} DOCDIR=%{docdir} %{make_python_arg} \
TUNED_USER_PROFILES_DIR=%{user_profiles_dir} \
TUNED_SYSTEM_PROFILES_DIR=%{system_profiles_dir}
make install-ppd DESTDIR=%{buildroot} DOCDIR=%{docdir} %{make_python_arg}

%if ! 0%{?rhel}
Expand Down Expand Up @@ -453,30 +470,30 @@ fi
%exclude %{_sysconfdir}/tuned/realtime-virtual-host-variables.conf
%exclude %{_sysconfdir}/tuned/cpu-partitioning-variables.conf
%exclude %{_sysconfdir}/tuned/cpu-partitioning-powersave-variables.conf
%exclude %{_prefix}/lib/tuned/profiles/default
%exclude %{_prefix}/lib/tuned/profiles/desktop-powersave
%exclude %{_prefix}/lib/tuned/profiles/laptop-ac-powersave
%exclude %{_prefix}/lib/tuned/profiles/server-powersave
%exclude %{_prefix}/lib/tuned/profiles/laptop-battery-powersave
%exclude %{_prefix}/lib/tuned/profiles/enterprise-storage
%exclude %{_prefix}/lib/tuned/profiles/spindown-disk
%exclude %{_prefix}/lib/tuned/profiles/sap-netweaver
%exclude %{_prefix}/lib/tuned/profiles/sap-hana
%exclude %{_prefix}/lib/tuned/profiles/sap-hana-kvm-guest
%exclude %{_prefix}/lib/tuned/profiles/mssql
%exclude %{_prefix}/lib/tuned/profiles/oracle
%exclude %{_prefix}/lib/tuned/profiles/atomic-host
%exclude %{_prefix}/lib/tuned/profiles/atomic-guest
%exclude %{_prefix}/lib/tuned/profiles/realtime
%exclude %{_prefix}/lib/tuned/profiles/realtime-virtual-guest
%exclude %{_prefix}/lib/tuned/profiles/realtime-virtual-host
%exclude %{_prefix}/lib/tuned/profiles/cpu-partitioning
%exclude %{_prefix}/lib/tuned/profiles/cpu-partitioning-powersave
%exclude %{_prefix}/lib/tuned/profiles/spectrumscale-ece
%exclude %{_prefix}/lib/tuned/profiles/postgresql
%exclude %{_prefix}/lib/tuned/profiles/openshift
%exclude %{_prefix}/lib/tuned/profiles/openshift-control-plane
%exclude %{_prefix}/lib/tuned/profiles/openshift-node
%exclude %{system_profiles_dir}/default
%exclude %{system_profiles_dir}/desktop-powersave
%exclude %{system_profiles_dir}/laptop-ac-powersave
%exclude %{system_profiles_dir}/server-powersave
%exclude %{system_profiles_dir}/laptop-battery-powersave
%exclude %{system_profiles_dir}/enterprise-storage
%exclude %{system_profiles_dir}/spindown-disk
%exclude %{system_profiles_dir}/sap-netweaver
%exclude %{system_profiles_dir}/sap-hana
%exclude %{system_profiles_dir}/sap-hana-kvm-guest
%exclude %{system_profiles_dir}/mssql
%exclude %{system_profiles_dir}/oracle
%exclude %{system_profiles_dir}/atomic-host
%exclude %{system_profiles_dir}/atomic-guest
%exclude %{system_profiles_dir}/realtime
%exclude %{system_profiles_dir}/realtime-virtual-guest
%exclude %{system_profiles_dir}/realtime-virtual-host
%exclude %{system_profiles_dir}/cpu-partitioning
%exclude %{system_profiles_dir}/cpu-partitioning-powersave
%exclude %{system_profiles_dir}/spectrumscale-ece
%exclude %{system_profiles_dir}/postgresql
%exclude %{system_profiles_dir}/openshift
%exclude %{system_profiles_dir}/openshift-control-plane
%exclude %{system_profiles_dir}/openshift-node
%{_prefix}/lib/tuned
%dir %{_sysconfdir}/tuned
%dir %{_sysconfdir}/tuned/recommend.d
Expand Down Expand Up @@ -534,40 +551,40 @@ fi
%{_mandir}/man8/scomes.*

%files profiles-sap
%{_prefix}/lib/tuned/profiles/sap-netweaver
%{system_profiles_dir}/sap-netweaver
%{_mandir}/man7/tuned-profiles-sap.7*

%files profiles-sap-hana
%{_prefix}/lib/tuned/profiles/sap-hana
%{_prefix}/lib/tuned/profiles/sap-hana-kvm-guest
%{system_profiles_dir}/sap-hana
%{system_profiles_dir}/sap-hana-kvm-guest
%{_mandir}/man7/tuned-profiles-sap-hana.7*

%files profiles-mssql
%{_prefix}/lib/tuned/profiles/mssql
%{system_profiles_dir}/mssql
%{_mandir}/man7/tuned-profiles-mssql.7*

%files profiles-oracle
%{_prefix}/lib/tuned/profiles/oracle
%{system_profiles_dir}/oracle
%{_mandir}/man7/tuned-profiles-oracle.7*

%files profiles-atomic
%{_prefix}/lib/tuned/profiles/atomic-host
%{_prefix}/lib/tuned/profiles/atomic-guest
%{system_profiles_dir}/atomic-host
%{system_profiles_dir}/atomic-guest
%{_mandir}/man7/tuned-profiles-atomic.7*

%files profiles-realtime
%config(noreplace) %{_sysconfdir}/tuned/realtime-variables.conf
%{_prefix}/lib/tuned/profiles/realtime
%{system_profiles_dir}/realtime
%{_mandir}/man7/tuned-profiles-realtime.7*

%files profiles-nfv-guest
%config(noreplace) %{_sysconfdir}/tuned/realtime-virtual-guest-variables.conf
%{_prefix}/lib/tuned/profiles/realtime-virtual-guest
%{system_profiles_dir}/realtime-virtual-guest
%{_mandir}/man7/tuned-profiles-nfv-guest.7*

%files profiles-nfv-host
%config(noreplace) %{_sysconfdir}/tuned/realtime-virtual-host-variables.conf
%{_prefix}/lib/tuned/profiles/realtime-virtual-host
%{system_profiles_dir}/realtime-virtual-host
%{_mandir}/man7/tuned-profiles-nfv-host.7*

%files profiles-nfv
Expand All @@ -576,32 +593,32 @@ fi
%files profiles-cpu-partitioning
%config(noreplace) %{_sysconfdir}/tuned/cpu-partitioning-variables.conf
%config(noreplace) %{_sysconfdir}/tuned/cpu-partitioning-powersave-variables.conf
%{_prefix}/lib/tuned/profiles/cpu-partitioning
%{_prefix}/lib/tuned/profiles/cpu-partitioning-powersave
%{system_profiles_dir}/cpu-partitioning
%{system_profiles_dir}/cpu-partitioning-powersave
%{_mandir}/man7/tuned-profiles-cpu-partitioning.7*

%files profiles-spectrumscale
%{_prefix}/lib/tuned/profiles/spectrumscale-ece
%{system_profiles_dir}/spectrumscale-ece
%{_mandir}/man7/tuned-profiles-spectrumscale-ece.7*

%files profiles-compat
%{_prefix}/lib/tuned/profiles/default
%{_prefix}/lib/tuned/profiles/desktop-powersave
%{_prefix}/lib/tuned/profiles/laptop-ac-powersave
%{_prefix}/lib/tuned/profiles/server-powersave
%{_prefix}/lib/tuned/profiles/laptop-battery-powersave
%{_prefix}/lib/tuned/profiles/enterprise-storage
%{_prefix}/lib/tuned/profiles/spindown-disk
%{system_profiles_dir}/default
%{system_profiles_dir}/desktop-powersave
%{system_profiles_dir}/laptop-ac-powersave
%{system_profiles_dir}/server-powersave
%{system_profiles_dir}/laptop-battery-powersave
%{system_profiles_dir}/enterprise-storage
%{system_profiles_dir}/spindown-disk
%{_mandir}/man7/tuned-profiles-compat.7*

%files profiles-postgresql
%{_prefix}/lib/tuned/profiles/postgresql
%{system_profiles_dir}/postgresql
%{_mandir}/man7/tuned-profiles-postgresql.7*

%files profiles-openshift
%{_prefix}/lib/tuned/profiles/openshift
%{_prefix}/lib/tuned/profiles/openshift-control-plane
%{_prefix}/lib/tuned/profiles/openshift-node
%{system_profiles_dir}/openshift
%{system_profiles_dir}/openshift-control-plane
%{system_profiles_dir}/openshift-node
%{_mandir}/man7/tuned-profiles-openshift.7*

%files ppd
Expand Down
5 changes: 3 additions & 2 deletions tuned/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
DBUS_OBJECT = "/Tuned"
DEFAULT_PROFILE = "balanced"
DEFAULT_STORAGE_FILE = "/run/tuned/save.pickle"
SYSTEM_PROFILE_DIR = "/usr/lib/tuned/profiles"
USER_PROFILES_DIR = "/etc/tuned/profiles"
SYSTEM_PROFILES_DIR = "/usr/lib/tuned/profiles"
PERSISTENT_STORAGE_DIR = "/var/lib/tuned"
PLUGIN_MAIN_UNIT_NAME = "main"
# Magic section header because ConfigParser does not support "headerless" config
Expand Down Expand Up @@ -174,7 +175,7 @@
# default rollback strategy
CFG_DEF_ROLLBACK = "auto"
# default profile directories
CFG_DEF_PROFILE_DIRS = [SYSTEM_PROFILE_DIR, "/etc/tuned/profiles"]
CFG_DEF_PROFILE_DIRS = [SYSTEM_PROFILES_DIR, USER_PROFILES_DIR]

PATH_CPU_DMA_LATENCY = "/dev/cpu_dma_latency"

Expand Down
6 changes: 3 additions & 3 deletions tuned/gtk/gui_profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def set_raw_profile(self, profile_name, config):

profilePath = self._locate_profile_path(profile_name)

if profilePath != tuned.consts.SYSTEM_PROFILE_DIR:
if profilePath != tuned.consts.SYSTEM_PROFILES_DIR:
file_path = profilePath + '/' + profile_name + '/' + tuned.consts.PROFILE_FILE
config_parser = ConfigParser(delimiters=('='), inline_comment_prefixes=('#'), strict=False)
config_parser.optionxform = str
Expand Down Expand Up @@ -130,7 +130,7 @@ def save_profile(self, profile):
# save the new profile to a non-system directory with the highest priority
path = None
for d in reversed(self.directories):
if d != tuned.consts.SYSTEM_PROFILE_DIR:
if d != tuned.consts.SYSTEM_PROFILES_DIR:
path = os.path.join(d, profile.name)
break
if path is None:
Expand Down Expand Up @@ -219,7 +219,7 @@ def is_profile_removable(self, profile_name):

def is_profile_factory(self, profile_name):
profile_path = self._locate_profile_path(profile_name)
return profile_path == tuned.consts.SYSTEM_PROFILE_DIR
return profile_path == tuned.consts.SYSTEM_PROFILES_DIR

def _save_profile(self, config):
ec = subprocess.call(['pkexec', sys.executable, tuned.gtk.gui_profile_saver.__file__ , json.dumps(config)])
Expand Down

0 comments on commit 1ff5e24

Please sign in to comment.