From e4d6723c8c56349eb7dcf2528acdfc0f25f3f965 Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Sat, 9 Nov 2024 04:04:25 -0600 Subject: [PATCH 1/3] ensure 'tuned-ppd' is absent (Fedora 41), +gamescope RT --- roles/tuned_amdgpu/files/rt_gamescope.sh | 33 ++++++++++++++++++++++++ roles/tuned_amdgpu/tasks/main.yml | 15 +++++++++++ 2 files changed, 48 insertions(+) create mode 100755 roles/tuned_amdgpu/files/rt_gamescope.sh diff --git a/roles/tuned_amdgpu/files/rt_gamescope.sh b/roles/tuned_amdgpu/files/rt_gamescope.sh new file mode 100755 index 0000000..82ad68b --- /dev/null +++ b/roles/tuned_amdgpu/files/rt_gamescope.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# script run by 'tuned' to ensure gamescope has the proper capability + +# Check for arguments +if [ $# -eq 0 ]; then + echo "Usage: $0 {verify|start}" + exit 1 +fi + +function verify_cap() { + /usr/sbin/getcap "$(which gamescope)" |& grep 'sys_nice=eip' + return $? +} + +function set_cap() { + /usr/sbin/setcap 'CAP_SYS_NICE=eip' "$(which gamescope)" +} + +# Handle arguments +case "$1" in + verify) + verify_cap + ;; + start) + set_cap + ;; + *) + echo "Invalid argument. Use 'verify' or 'start'." + exit 1 + ;; +esac + diff --git a/roles/tuned_amdgpu/tasks/main.yml b/roles/tuned_amdgpu/tasks/main.yml index d22e160..9518ae3 100644 --- a/roles/tuned_amdgpu/tasks/main.yml +++ b/roles/tuned_amdgpu/tasks/main.yml @@ -22,6 +22,12 @@ state: present become: true +- name: Ensure 'tuned-ppd' is absent + ansible.builtin.package: + name: tuned-ppd + state: absent + become: true + - name: Find bundled 'tuned' profiles ansible.builtin.find: paths: @@ -85,6 +91,15 @@ notify: Restart tuned become: true +- name: Copy gamescope RT capability script + ansible.builtin.copy: + src: rt_gamescope.sh + dest: /etc/tuned/rt_gamescope.sh + owner: root + group: root + mode: '0755' + become: true + - name: Template tuned.conf for custom profiles ansible.builtin.template: src: templates/tuned.conf.j2 From d4970f2b3b7d5f12f5e6ae396b8cc5fde09c155f Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Sat, 9 Nov 2024 04:05:12 -0600 Subject: [PATCH 2/3] profile template: set (manual) perf level before properties --- .../tuned_amdgpu/templates/amdgpu-profile.sh.j2 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/roles/tuned_amdgpu/templates/amdgpu-profile.sh.j2 b/roles/tuned_amdgpu/templates/amdgpu-profile.sh.j2 index e15e5f7..b7fca2d 100644 --- a/roles/tuned_amdgpu/templates/amdgpu-profile.sh.j2 +++ b/roles/tuned_amdgpu/templates/amdgpu-profile.sh.j2 @@ -9,6 +9,8 @@ # Variables shown below named '$TUNED_...' are given values by '/etc/tuned/amdgpu-profile-vars.conf' # # determine the connected GPU using the DRM subsystem. FIXME: assumes one card, make configurable +# TODO: break this out into a role var; assume renderD128 +# allow/use many configs CARD=$(/usr/bin/grep -ls ^connected /sys/class/drm/*/status | /usr/bin/grep -o 'card[0-9]' | /usr/bin/sort | /usr/bin/uniq | /usr/bin/sort -h | /usr/bin/tail -1) function get_hwmon_dir() { @@ -21,7 +23,6 @@ function get_hwmon_dir() { done } - # determine the hwmon directory HWMON_DIR=$(get_hwmon_dir "${CARD}") @@ -51,11 +52,16 @@ function amdgpu_profile_reset() { echo "${PROF_DEFAULT_NUM}" | tee /sys/class/drm/"${CARD}"/device/pp_power_profile_mode # delay before returning - have mercy, may be followed with other profile function calls - sleep 0.5 + sleep 0.25 } function amdgpu_profile_overclock() { + # set manual control mode + # allows control via 'pp_dpm_mclk', 'pp_dpm_sclk', 'pp_dpm_pcie', 'pp_dpm_fclk', and 'pp_power_profile_mode' files + echo 'manual' | tee /sys/class/drm/"${CARD}"/device/power_dpm_force_performance_level + + # force GPU core and memory into highest clocks (fix flickering and poor power management) echo "s 0 ${TUNED_tuned_amdgpu_clock_min}" | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage echo "s 1 ${TUNED_tuned_amdgpu_clock_max}" | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage echo "m 1 ${TUNED_tuned_amdgpu_memclock_static}" | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage @@ -68,11 +74,6 @@ function amdgpu_profile_overclock() { # commit the changes echo 'c' | tee /sys/class/drm/"${CARD}"/device/pp_od_clk_voltage - # force GPU core and memory into highest clocks (fix flickering and poor power management) - # set manual control mode - # allows control via 'pp_dpm_mclk', 'pp_dpm_sclk', 'pp_dpm_pcie', 'pp_dpm_fclk', and 'pp_power_profile_mode' files - echo 'manual' | tee /sys/class/drm/"${CARD}"/device/power_dpm_force_performance_level - # adjust power limit using multiplier against board capability POWER_LIM_OC=$(/usr/bin/awk -v m="$POWER_CAP" -v n="${TUNED_tuned_amdgpu_power_multi_oc}" 'BEGIN {printf "%.0f", (m*n)}') echo "$POWER_LIM_OC" | tee "${HWMON_DIR}/power1_cap" @@ -88,7 +89,7 @@ function amdgpu_profile_overclock() { echo "${PROF_VR_NUM}" | tee /sys/class/drm/"${CARD}"/device/pp_power_profile_mode # delay before returning - have mercy, may be followed with other profile function calls - sleep 0.5 + sleep 0.25 } From 516d29e0a2458f26995dd12156d0d614f0d0f849 Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Sat, 9 Nov 2024 04:05:43 -0600 Subject: [PATCH 3/3] localhost: adjust profile --- host_vars/localhost.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/host_vars/localhost.yml b/host_vars/localhost.yml index 9451555..9fd8f26 100644 --- a/host_vars/localhost.yml +++ b/host_vars/localhost.yml @@ -2,7 +2,7 @@ # the profile tries to find the card with displays attached to apply these settings. # configuration of many GPUs not yet supported, one is assumed tuned_amdgpu_clock_min: "500" -tuned_amdgpu_clock_max: "2715" +tuned_amdgpu_clock_max: "2725" tuned_amdgpu_memclock_static: "1075" tuned_amdgpu_power_multi_def: 0.869969040247678 # 281W - real default tuned_amdgpu_power_multi_oc: 1.0 # full board power capability @@ -11,16 +11,25 @@ tuned_amdgpu_power_multi_oc: 1.0 # full board power capability # 310: 0.959752321981424 # sample worksheet in 'power_max multi tab calculator.ods' -tuned_amdgpu_mv_offset: "+45" # add 45mV / 0.045V +tuned_amdgpu_mv_offset: "+70" # add 70mV / 0.07V # '-50' undervolts GPU core voltage 50mV / 0.05V; warning: here be dragons/instability # 'tuned' plugins - used to set the kernel cmdline via bootloader... and sysctl tunables tuned_amdgpu_plugins: # ref: https://github.com/redhat-performance/tuned/tree/master/tuned/plugins + rt_gamescope: + type: script + script: '/etc/tuned/rt_gamescope.sh' # ensures gamescope has proper capability when profile is loaded + cpu: + boost: 1 + governor: performance + energy_perf_bias: performance bootloader: # 'cmdline' allows entries w/ a suffix, names should be unique across *all* profiles. values accept +/- operators - cmdline_amdgpu_general: "delayacct nowatchdog kvm.ignore_msrs=1 kvm_amd.npt=1 amdgpu.ppfeaturemask=0xfff7ffff" + cmdline_amdgpu_general: "delayacct nowatchdog amdgpu.ppfeaturemask=0xfff7ffff" + # cmdline_kvm: 'kvm.ignore_msrs=1 kvm_amd.npt=1' + cmdline_amdgpu_kvm: 'kvm_amd.npt=1' cmdline_amdgpu_hugepages: "default_hugepagesz=1G hugepagesz=1G hugepages=16" cmdline_amdgpu_iommu: "amd_iommu=on iommu=pt" - cmdline_amdgpu_devs: "nvme_core.default_ps_max_latency_us=0 pci=realloc=off" + cmdline_amdgpu_nvme: "nvme_core.default_ps_max_latency_us=0" sysctl: # quote ints/cast to string to avoid surprises kernel.dmesg_restrict: '0' # allow regular users to see the kernel ring buffer # net.core.default_qdisc: fq # congestion control