104 lines
3.5 KiB
YAML
104 lines
3.5 KiB
YAML
---
|
|
- hosts: localhost
|
|
become: true
|
|
vars:
|
|
# list of source tuned profiles available on Fedora (TODO: should dynamically discover)
|
|
# further modified with AMD GPU power/clock parameters, creating new profiles. eg: 'balanced-amdgpu-VR'
|
|
base_profiles:
|
|
- balanced
|
|
- desktop
|
|
- latency-performance
|
|
- network-latency
|
|
- network-throughput
|
|
- powersave
|
|
- virtual-host
|
|
handlers:
|
|
- name: restart tuned
|
|
ansible.builtin.service:
|
|
name: tuned
|
|
state: restarted
|
|
tasks:
|
|
- name: Gather package facts
|
|
ansible.builtin.package_facts:
|
|
manager: auto
|
|
- name: replace 'power-profiles-daemon' with 'tuned' on Fedora 35+
|
|
dnf: # use with_items since 'dnf' module in Ansible doesn't support 'swap'
|
|
name: "{{ item.name }}"
|
|
state: "{{ item.state }}"
|
|
with_items:
|
|
- {name: 'power-profiles-daemon', state: 'absent'}
|
|
- {name: 'tuned', state: 'present'}
|
|
when:
|
|
- ('power-profiles-daemon' in ansible_facts.packages) or ('tuned' not in ansible_facts.packages)
|
|
- ansible_distribution == 'Fedora'
|
|
- ansible_distribution_major_version|int > 35
|
|
register: fed_ppdtuned_swap
|
|
# 'power-profiles-daemon' was added/conflicts with 'tuned' since F35
|
|
# otherwise, ensure the 'tuned' package is installed
|
|
- name: install tuned
|
|
package:
|
|
name: tuned
|
|
state: present
|
|
when: (fed_ppdtuned_swap is not defined) or ('tuned' not in ansible_facts.packages)
|
|
- name: determine GPU device in drm subsystem
|
|
shell:
|
|
cmd: grep -ls ^connected /sys/class/drm/*/status | grep -o card[0-9] | sort | uniq | sort -h | tail -1
|
|
executable: /bin/bash
|
|
changed_when: false
|
|
register: card
|
|
- name: find hwmon/max power capability file for {{ card.stdout }}
|
|
find:
|
|
paths: /sys/class/drm/{{ card.stdout }}/device/hwmon
|
|
file_type: file
|
|
recurse: true
|
|
use_regex: true
|
|
patterns:
|
|
- '^power1_cap_max$'
|
|
register: hwmon
|
|
- name: find hwmon/current power limit file for {{ card.stdout }}
|
|
find:
|
|
paths: /sys/class/drm/{{ card.stdout }}/device/hwmon
|
|
file_type: file
|
|
recurse: true
|
|
use_regex: true
|
|
patterns:
|
|
- '^power1_cap$'
|
|
register: powercap_set
|
|
- name: get max power capability for {{ card.stdout }}
|
|
slurp:
|
|
src: "{{ hwmon.files.0.path }}"
|
|
register: power_max_b64
|
|
- name: create custom profile directories
|
|
file:
|
|
state: directory
|
|
path: /etc/tuned/{{ item.1 }}-amdgpu-{{ item.0.key }}
|
|
mode: "0755"
|
|
with_nested:
|
|
- "{{ lookup('dict', amdgpu_profiles) }}"
|
|
- "{{ base_profiles }}"
|
|
- name: template AMDGPU control/reset scripts
|
|
template:
|
|
src: templates/amdgpu-clock.sh.j2
|
|
dest: /etc/tuned/{{ item.1 }}-amdgpu-{{ item.0.key }}/amdgpu-clock.sh
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
with_nested:
|
|
- "{{ lookup('dict', amdgpu_profiles) }}"
|
|
- "{{ base_profiles }}"
|
|
notify: restart tuned
|
|
- name: template custom tuned profiles
|
|
template:
|
|
src: templates/tuned.conf.j2
|
|
dest: /etc/tuned/{{ item.1 }}-amdgpu-{{ item.0.key }}/tuned.conf
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
with_nested:
|
|
- "{{ lookup('dict', amdgpu_profiles) }}"
|
|
- "{{ base_profiles }}"
|
|
notify: restart tuned
|
|
- name: ensure tuned is enabled
|
|
service:
|
|
name: tuned
|
|
enabled: true
|