From 1b9a26d814dd3e12a9b355bca7d63806167c72e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=B6sel?= Date: Thu, 14 Jul 2022 20:41:11 +0200 Subject: [PATCH] add cpu governor settings to pve role (#37) --- roles/pve/README.md | 15 +++++++++++++++ roles/pve/defaults/main.yml | 3 +++ roles/pve/tasks/cpu.yml | 15 +++++++++++++++ roles/pve/tasks/main.yml | 2 ++ 4 files changed, 35 insertions(+) create mode 100644 roles/pve/tasks/cpu.yml diff --git a/roles/pve/README.md b/roles/pve/README.md index be57edb..f98e7ea 100644 --- a/roles/pve/README.md +++ b/roles/pve/README.md @@ -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. diff --git a/roles/pve/defaults/main.yml b/roles/pve/defaults/main.yml index ce0cbbc..996a4e8 100644 --- a/roles/pve/defaults/main.yml +++ b/roles/pve/defaults/main.yml @@ -1 +1,4 @@ pve_repo_type: no-subscription + +pve_set_cpu: no +pve_cpu_governor: performance diff --git a/roles/pve/tasks/cpu.yml b/roles/pve/tasks/cpu.yml new file mode 100644 index 0000000..3911a97 --- /dev/null +++ b/roles/pve/tasks/cpu.yml @@ -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 diff --git a/roles/pve/tasks/main.yml b/roles/pve/tasks/main.yml index d2f0f04..72c43c4 100644 --- a/roles/pve/tasks/main.yml +++ b/roles/pve/tasks/main.yml @@ -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