2021-10-13 02:02:22 +00:00
|
|
|
---
|
|
|
|
- hosts: localhost
|
2022-11-27 04:59:35 +00:00
|
|
|
name: "Configure 'tuned' with AMD GPU control"
|
2022-11-04 01:04:59 +00:00
|
|
|
become: true
|
2021-10-13 02:02:22 +00:00
|
|
|
vars:
|
2022-08-03 05:47:43 +00:00
|
|
|
# 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
|
2021-10-13 02:02:22 +00:00
|
|
|
- desktop
|
2022-01-30 05:02:26 +00:00
|
|
|
- latency-performance
|
2021-10-13 02:02:22 +00:00
|
|
|
- network-latency
|
2022-01-30 05:02:26 +00:00
|
|
|
- network-throughput
|
2021-10-13 02:02:22 +00:00
|
|
|
- powersave
|
2022-01-30 05:02:26 +00:00
|
|
|
- virtual-host
|
|
|
|
handlers:
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Restart tuned
|
2022-01-30 05:02:26 +00:00
|
|
|
ansible.builtin.service:
|
|
|
|
name: tuned
|
|
|
|
state: restarted
|
2021-10-13 02:02:22 +00:00
|
|
|
tasks:
|
2022-06-08 02:15:31 +00:00
|
|
|
- name: Gather package facts
|
|
|
|
ansible.builtin.package_facts:
|
|
|
|
manager: auto
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Replace 'power-profiles-daemon' with 'tuned' on Fedora 35+
|
|
|
|
ansible.builtin.package: # use with_items/pkg since 'dnf' module in Ansible doesn't support 'swap'
|
2022-06-08 02:15:31 +00:00
|
|
|
name: "{{ item.name }}"
|
|
|
|
state: "{{ item.state }}"
|
|
|
|
with_items:
|
|
|
|
- {name: 'power-profiles-daemon', state: 'absent'}
|
|
|
|
- {name: 'tuned', state: 'present'}
|
2022-11-04 01:04:59 +00:00
|
|
|
when:
|
|
|
|
- ('power-profiles-daemon' in ansible_facts.packages) or ('tuned' not in ansible_facts.packages)
|
|
|
|
- ansible_distribution == 'Fedora'
|
|
|
|
- ansible_distribution_major_version|int > 35
|
2022-06-08 02:15:31 +00:00
|
|
|
register: fed_ppdtuned_swap
|
|
|
|
# 'power-profiles-daemon' was added/conflicts with 'tuned' since F35
|
|
|
|
# otherwise, ensure the 'tuned' package is installed
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Install tuned
|
|
|
|
ansible.builtin.package:
|
2022-06-08 02:15:31 +00:00
|
|
|
name: tuned
|
|
|
|
state: present
|
|
|
|
when: (fed_ppdtuned_swap is not defined) or ('tuned' not in ansible_facts.packages)
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Determine GPU device in drm subsystem
|
|
|
|
ansible.builtin.shell:
|
2022-11-04 01:09:52 +00:00
|
|
|
cmd: grep -ls ^connected /sys/class/drm/*/status | grep -o card[0-9] | sort | uniq | sort -h | tail -1
|
2022-11-04 01:04:59 +00:00
|
|
|
executable: /bin/bash
|
|
|
|
changed_when: false
|
|
|
|
register: card
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Find hwmon/max power capability file for {{ card.stdout }}
|
|
|
|
ansible.builtin.find:
|
2022-11-04 01:04:59 +00:00
|
|
|
paths: /sys/class/drm/{{ card.stdout }}/device/hwmon
|
2022-02-01 01:18:10 +00:00
|
|
|
file_type: file
|
2022-11-04 01:04:59 +00:00
|
|
|
recurse: true
|
|
|
|
use_regex: true
|
2022-02-01 01:18:10 +00:00
|
|
|
patterns:
|
|
|
|
- '^power1_cap_max$'
|
|
|
|
register: hwmon
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Find hwmon/current power limit file for {{ card.stdout }}
|
|
|
|
ansible.builtin.find:
|
2022-11-04 01:04:59 +00:00
|
|
|
paths: /sys/class/drm/{{ card.stdout }}/device/hwmon
|
2022-06-13 02:20:10 +00:00
|
|
|
file_type: file
|
2022-11-04 01:04:59 +00:00
|
|
|
recurse: true
|
|
|
|
use_regex: true
|
2022-06-13 02:20:10 +00:00
|
|
|
patterns:
|
|
|
|
- '^power1_cap$'
|
|
|
|
register: powercap_set
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Get max power capability for {{ card.stdout }}
|
|
|
|
ansible.builtin.slurp:
|
2022-02-01 01:18:10 +00:00
|
|
|
src: "{{ hwmon.files.0.path }}"
|
2022-05-06 02:48:35 +00:00
|
|
|
register: power_max_b64
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Create custom profile directories
|
|
|
|
ansible.builtin.file:
|
2021-10-13 02:02:22 +00:00
|
|
|
state: directory
|
2022-08-03 05:47:43 +00:00
|
|
|
path: /etc/tuned/{{ item.1 }}-amdgpu-{{ item.0.key }}
|
2021-10-13 02:02:22 +00:00
|
|
|
mode: "0755"
|
|
|
|
with_nested:
|
2022-08-03 05:47:43 +00:00
|
|
|
- "{{ lookup('dict', amdgpu_profiles) }}"
|
2021-10-13 02:02:22 +00:00
|
|
|
- "{{ base_profiles }}"
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Template AMDGPU control/reset scripts
|
|
|
|
ansible.builtin.template:
|
2022-06-04 16:38:40 +00:00
|
|
|
src: templates/amdgpu-clock.sh.j2
|
2022-08-03 05:47:43 +00:00
|
|
|
dest: /etc/tuned/{{ item.1 }}-amdgpu-{{ item.0.key }}/amdgpu-clock.sh
|
2022-06-04 16:38:40 +00:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: "0755"
|
|
|
|
with_nested:
|
2022-08-03 05:47:43 +00:00
|
|
|
- "{{ lookup('dict', amdgpu_profiles) }}"
|
2022-06-04 16:38:40 +00:00
|
|
|
- "{{ base_profiles }}"
|
|
|
|
notify: restart tuned
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Template custom tuned profiles
|
|
|
|
ansible.builtin.template:
|
2021-10-13 02:02:22 +00:00
|
|
|
src: templates/tuned.conf.j2
|
2022-08-03 05:47:43 +00:00
|
|
|
dest: /etc/tuned/{{ item.1 }}-amdgpu-{{ item.0.key }}/tuned.conf
|
2021-10-13 02:02:22 +00:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: "0644"
|
|
|
|
with_nested:
|
2022-08-03 05:47:43 +00:00
|
|
|
- "{{ lookup('dict', amdgpu_profiles) }}"
|
2022-01-30 05:02:26 +00:00
|
|
|
- "{{ base_profiles }}"
|
|
|
|
notify: restart tuned
|
2022-11-27 04:59:35 +00:00
|
|
|
- name: Ensure tuned is enabled
|
|
|
|
ansible.builtin.service:
|
2022-08-03 05:47:43 +00:00
|
|
|
name: tuned
|
2022-11-04 01:04:59 +00:00
|
|
|
enabled: true
|