Skip to content

Commit

Permalink
add cpu governor settings to pve role (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhoesel authored Jul 14, 2022
1 parent db1a8b5 commit 1b9a26d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions roles/pve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ the underlying system. Right now, it manages the root users password and configu
- Choices: `enterprise`, `no-subscription`, `test`
- Please note that this role does not configure your subscription key, you will have to do so yourself
- Default: `no-subscription`

##### `pve_set_cpu`
- Whether to modify the CPU configuration, such as the chosen governor.
- Default: `false`

##### `pve_cpu_governor`
- Which CPU governor to use for all CPU cores on each node
- You can check which CPU governors are available for your CPU and driver by running
`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors` on one of your nodes.
- The `intel_pstate` driver hands much of the CPU scaling off to the hardware and only supports two governors - `powersave` and `performance`.
See the [kernel docs](https://www.kernel.org/doc/html/v4.19/admin-guide/pm/intel_pstate.html) for more information.
- Older Intel CPUs under (`intel_cpufreq`) and AMD CPUs can use any [generic governor](https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt).
- Proxmox defaults to `performance` due to potential [BSODs in Windows guests when running with variable frequency](https://forum.proxmox.com/threads/windows-7-x64-vms-crashing-randomly-during-process-termination.18238/#post-93273)
- `ondemand` and `schedutil` both scale CPU frequency dynamically and may improve power consumption.
- Default: `performance`. Set to `schedutil` if you want to save power and aware of the limitations mentioned above.
3 changes: 3 additions & 0 deletions roles/pve/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pve_repo_type: no-subscription

pve_set_cpu: no
pve_cpu_governor: performance
15 changes: 15 additions & 0 deletions roles/pve/tasks/cpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: intel-cpupower is installed
ansible.builtin.apt:
name: linux-cpupower

- name: Get current governor
ansible.builtin.shell: "cat /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor"
changed_when: no
check_mode: no
register: _pve_current_governor

- name: Set CPU governor to {{ pve_cpu_governor }}
ansible.builtin.command: "cpupower frequency-set -g {{ pve_cpu_governor }}"
when: >
(_pve_current_governor.stdout_lines | unique | select | list).0 != pve_cpu_governor or
(_pve_current_governor.stdout_lines | unique | select | list | length) > 1
2 changes: 2 additions & 0 deletions roles/pve/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
password: "{{ pve_root_password | password_hash('sha512', 65534 | random(seed=inventory_hostname) | string) }}"

- include_tasks: repo.yml
- include_tasks: cpu.yml
when: pve_set_cpu

0 comments on commit 1b9a26d

Please sign in to comment.