Skip to content

Commit 2c44215

Browse files
committed
cpu: make governors to be optional
Change-Id: Ifb7d001cfdb95b1b0aa29f45c0ef71c0673e1760 Closes-Bug: #2023018
1 parent 3fab437 commit 2c44215

File tree

6 files changed

+74
-8
lines changed

6 files changed

+74
-8
lines changed

doc/source/admin/cpu-topologies.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,11 @@ while there could be other tools outside Nova to manage the governor, like
772772
tuned. That being said, we also provide a way to automatically change the
773773
governors on the fly, as explained below.
774774

775+
.. important::
776+
Some OS platforms don't support `cpufreq` resources in sysfs, so the
777+
``governor`` strategy could be not available. Please verify if your OS
778+
supports scaling govenors before modifying the configuration option.
779+
775780
If the strategy is set to ``governor``, a couple of config options are provided
776781
to define which exact CPU govenor to use for each of the up and down states :
777782

nova/tests/fixtures/filesystem.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ def _setUp(self):
3939

4040

4141
class SysFileSystemFixture(TempFileSystemFixture):
42-
"""Creates a fake /sys filesystem"""
42+
def __init__(self, cpus_supported=None, cpufreq_enabled=True):
43+
"""Instantiates a fake sysfs.
4344
44-
def __init__(self, cpus_supported=None):
45+
:param cpus_supported: number of devices/system/cpu (default: 10)
46+
:param cpufreq_enabled: cpufreq subdir created (default: True)
47+
"""
4548
self.cpus_supported = cpus_supported or 10
49+
self.cpufreq_enabled = cpufreq_enabled
4650

4751
def _setUp(self):
4852
super()._setUp()
@@ -73,9 +77,12 @@ def _setUp(self):
7377

7478
for cpu_nr in range(self.cpus_supported):
7579
cpu_dir = os.path.join(self.cpu_path_mock % {'core': cpu_nr})
76-
os.makedirs(os.path.join(cpu_dir, 'cpufreq'))
77-
filesystem.write_sys(
78-
os.path.join(cpu_dir, 'cpufreq/scaling_governor'),
79-
data='powersave')
80+
os.makedirs(cpu_dir)
81+
filesystem.write_sys(os.path.join(cpu_dir, 'online'), data='1')
82+
if self.cpufreq_enabled:
83+
os.makedirs(os.path.join(cpu_dir, 'cpufreq'))
84+
filesystem.write_sys(
85+
os.path.join(cpu_dir, 'cpufreq/scaling_governor'),
86+
data='powersave')
8087
filesystem.write_sys(core.AVAILABLE_PATH,
8188
f'0-{self.cpus_supported - 1}')

nova/tests/functional/libvirt/test_power_manage.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,39 @@ def test_changing_strategy_fails(self):
221221
self.restart_compute_service, hostname='compute1')
222222

223223

224+
class PowerManagementTestsGovernorNotSupported(PowerManagementTestsBase):
225+
"""Test suite for OS without governor support usage (same 10-core host)"""
226+
227+
def setUp(self):
228+
super(PowerManagementTestsGovernorNotSupported, self).setUp()
229+
230+
self.useFixture(nova_fixtures.SysFileSystemFixture(
231+
cpufreq_enabled=False))
232+
233+
# Definining the CPUs to be pinned.
234+
self.flags(cpu_dedicated_set='1-9', cpu_shared_set=None,
235+
group='compute')
236+
self.flags(vcpu_pin_set=None)
237+
self.flags(cpu_power_management=True, group='libvirt')
238+
self.flags(cpu_power_management_strategy='cpu_state', group='libvirt')
239+
240+
self.flags(allow_resize_to_same_host=True)
241+
self.host_info = fakelibvirt.HostInfo(cpu_nodes=1, cpu_sockets=1,
242+
cpu_cores=5, cpu_threads=2)
243+
244+
def test_enabling_governor_strategy_fails(self):
245+
self.flags(cpu_power_management_strategy='governor', group='libvirt')
246+
self.assertRaises(exception.FileNotFound, self.start_compute,
247+
host_info=self.host_info, hostname='compute1')
248+
249+
def test_enabling_cpu_state_strategy_works(self):
250+
self.flags(cpu_power_management_strategy='cpu_state', group='libvirt')
251+
self.compute1 = self.start_compute(host_info=self.host_info,
252+
hostname='compute1')
253+
cpu_dedicated_set = hardware.get_cpu_dedicated_set()
254+
self._assert_cpu_set_state(cpu_dedicated_set, expected='offline')
255+
256+
224257
class PowerManagementMixedInstances(PowerManagementTestsBase):
225258
"""Test suite for a single host with 6 dedicated cores, 3 shared and one
226259
OS-restricted.

nova/tests/unit/virt/libvirt/cpu/test_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def test_governor(self, mock_get_governor):
5757
self.assertEqual('fake_governor', self.core_1.governor)
5858
mock_get_governor.assert_called_once_with(self.core_1.ident)
5959

60+
@mock.patch.object(core, 'get_governor')
61+
def test_governor_optional(self, mock_get_governor):
62+
mock_get_governor.side_effect = exception.FileNotFound(file_path='foo')
63+
self.assertIsNone(self.core_1.governor)
64+
mock_get_governor.assert_called_once_with(self.core_1.ident)
65+
6066
@mock.patch.object(core, 'set_governor')
6167
def test_set_governor_low(self, mock_set_governor):
6268
self.flags(cpu_power_governor_low='fake_low_gov', group='libvirt')

nova/virt/libvirt/cpu/api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# under the License.
1212

1313
from dataclasses import dataclass
14+
import typing as ty
1415

1516
from oslo_log import log as logging
1617

@@ -59,8 +60,13 @@ def __str__(self):
5960
return str(self.ident)
6061

6162
@property
62-
def governor(self) -> str:
63-
return core.get_governor(self.ident)
63+
def governor(self) -> ty.Optional[str]:
64+
try:
65+
return core.get_governor(self.ident)
66+
# NOTE(sbauza): cpufreq/scaling_governor is not enabled for some OS
67+
# platforms.
68+
except exception.FileNotFound:
69+
return None
6470

6571
def set_high_governor(self) -> None:
6672
core.set_governor(self.ident, CONF.libvirt.cpu_power_governor_high)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
fixes:
3+
- |
4+
Some OS platforms don't provide by default cpufreq resources in sysfs, so
5+
they don't have CPU scaling governors. That's why we should let the governor
6+
strategy to be optional for `CPU power management`_.
7+
8+
.. _CPU power management: https://docs.openstack.org/nova/latest/admin/cpu-topologies.html#configuring-cpu-power-management-for-dedicated-cores
9+

0 commit comments

Comments
 (0)