Skip to content

Commit b487ac2

Browse files
committed
cpu: Only check governor type on online cores
Kernels don't accept to access the governor strategy on an offline core, so we need to only validate strategies for online cores. Change-Id: I14c9b268d0b97221216bd1a9ab9e48b48d6dcc2c Closes-Bug: #2073528 (cherry picked from commit 757c333) (cherry picked from commit cf72133) (cherry picked from commit 52f6968)
1 parent 47428f6 commit b487ac2

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,21 @@ def test_validate_all_dedicated_cpus_no_cpu(self):
244244
self.api.validate_all_dedicated_cpus()
245245
# no assert we want to make sure the validation won't raise if
246246
# no dedicated cpus are configured
247+
248+
@mock.patch.object(core, 'get_governor')
249+
@mock.patch.object(core, 'get_online')
250+
def test_validate_all_dedicated_cpus_for_cpu_state_with_off_cores(
251+
self, mock_get_online, mock_get_governor):
252+
self.flags(cpu_power_management=True, group='libvirt')
253+
self.flags(cpu_dedicated_set='1-3', group='compute')
254+
self.flags(cpu_power_management_strategy='cpu_state', group='libvirt')
255+
# CPU1 and CPU3 are online while CPU2 is offline
256+
mock_get_online.side_effect = (True, False, True)
257+
mock_get_governor.return_value = 'performance'
258+
self.api.validate_all_dedicated_cpus()
259+
260+
mock_get_online.assert_has_calls([mock.call(1), mock.call(2),
261+
mock.call(3)])
262+
# we only have two calls as CPU2 was skipped
263+
mock_get_governor.assert_has_calls([mock.call(1),
264+
mock.call(3)])

nova/virt/libvirt/cpu/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,29 @@ def validate_all_dedicated_cpus(self) -> None:
172172
if not CONF.libvirt.cpu_power_management:
173173
return
174174
cpu_dedicated_set = hardware.get_cpu_dedicated_set() or set()
175-
governors = set()
176-
cpu_states = set()
175+
pcpus = []
177176
for pcpu in cpu_dedicated_set:
178177
if (pcpu == 0 and
179178
CONF.libvirt.cpu_power_management_strategy == 'cpu_state'):
180179
LOG.warning('CPU0 is in cpu_dedicated_set, '
181180
'but it is not eligible for state management '
182181
'and will be ignored')
183182
continue
184-
pcpu = self.core(pcpu)
185183
# we need to collect the governors strategy and the CPU states
186-
governors.add(pcpu.governor)
187-
cpu_states.add(pcpu.online)
184+
pcpus.append(self.core(pcpu))
188185
if CONF.libvirt.cpu_power_management_strategy == 'cpu_state':
186+
# NOTE(sbauza): offline cores can't have a governor, it returns a
187+
# DeviceBusy exception.
188+
governors = set([pcpu.governor for pcpu in pcpus
189+
if pcpu.online])
189190
# all the cores need to have the same governor strategy
190191
if len(governors) > 1:
191192
msg = _("All the cores need to have the same governor strategy"
192193
"before modifying the CPU states. You can reboot the "
193194
"compute node if you prefer.")
194195
raise exception.InvalidConfiguration(msg)
195196
elif CONF.libvirt.cpu_power_management_strategy == 'governor':
197+
cpu_states = set([pcpu.online for pcpu in pcpus])
196198
# all the cores need to be online
197199
if False in cpu_states:
198200
msg = _("All the cores need to be online before modifying the "

0 commit comments

Comments
 (0)