From a2d0b8d1b0954c6fdc622dda8fe8777e41566d92 Mon Sep 17 00:00:00 2001 From: Eli Qiao Date: Tue, 6 Sep 2016 11:51:29 +0800 Subject: [PATCH] Libvirt: Correct PERF_EVENTS_CPU_FLAG_MAPPING History: libvirt 1.3.3 had added perf event support for cmt, mbmt, mbml support when we landing the spec https://blueprints.launchpad.net/nova/+spec/support-perf-event . For the event cmt, mbmt, mbml, we requires that libvirt to expose some some specify cpu features, but libvirt 2.0.0 only has that expose merged `cpu_map.xml: add cmt/mbm feature to x86 (Qiaowei Ren)`, the capabilities changed to: Need to adopt this to let nova driver discover these features when enable cmt, mbmt, mbml event. That is to say: even libvirt 1.3.3 has support perf event, but nova cannot get noticed since libvirt don't expose cpu features until 2.0.0. This patch bump MIN_LIBVIRT_PERF_VERSION to 2.0.0, see: https://libvirt.org/formatdomain.html#elementsPerf Closes-Bug: #1620445 Change-Id: Ie896cfd478f4528903ca5dd56c61680837b646b7 --- nova/conf/libvirt.py | 3 ++- nova/tests/unit/virt/libvirt/test_driver.py | 23 +++++++++++++------ nova/virt/libvirt/driver.py | 8 +++---- .../add-perf-event-e1385b6b6346fbda.yaml | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/nova/conf/libvirt.py b/nova/conf/libvirt.py index fb9ca041b36b..b0b0df56f1da 100644 --- a/nova/conf/libvirt.py +++ b/nova/conf/libvirt.py @@ -448,7 +448,8 @@ Related options: This is a performance event list which could be used as monitor. These events will be passed to libvirt domain xml while creating a new instances. Then event statistics data can be collected from libvirt. The minimum -libvirt version is 1.3.3. +libvirt version is 2.0.0. For more information about `Performance monitoring +events`, refer https://libvirt.org/formatdomain.html#elementsPerf . * Possible values: A string list. diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index f93f125593fa..23b761472987 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -5623,7 +5623,6 @@ class LibvirtConnTestCase(test.NoDBTestCase): @mock.patch.object(host.Host, "get_capabilities") def _test_get_guest_with_perf(self, caps, events, mock_get_caps): - self.flags(enabled_perf_events=['cmt'], group='libvirt') mock_get_caps.return_value = caps drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) @@ -5641,21 +5640,31 @@ class LibvirtConnTestCase(test.NoDBTestCase): @mock.patch.object(fakelibvirt, 'VIR_PERF_PARAM_CMT', True, create=True) + @mock.patch.object(fakelibvirt, 'VIR_PERF_PARAM_MBMT', True, + create=True) + @mock.patch.object(fakelibvirt, 'VIR_PERF_PARAM_MBML', True, + create=True) @mock.patch.object(host.Host, 'has_min_version', return_value=True) def test_get_guest_with_perf_supported(self, mock_min_version): - self.flags(enabled_perf_events=['cmt'], group='libvirt') + self.flags(enabled_perf_events=['cmt', 'mbml', 'mbmt'], + group='libvirt') caps = vconfig.LibvirtConfigCaps() caps.host = vconfig.LibvirtConfigCapsHost() caps.host.cpu = vconfig.LibvirtConfigCPU() caps.host.cpu.arch = "x86_64" caps.host.topology = self._fake_caps_numa_topology() - feature = vconfig.LibvirtConfigGuestCPUFeature() - feature.name = 'cqm' - feature.policy = cpumodel.POLICY_REQUIRE - caps.host.cpu.features = set([feature]) - self._test_get_guest_with_perf(caps, ['cmt']) + features = [] + for f in ('cmt', 'mbm_local', 'mbm_total'): + feature = vconfig.LibvirtConfigGuestCPUFeature() + feature.name = f + feature.policy = cpumodel.POLICY_REQUIRE + features.append(feature) + + caps.host.cpu.features = set(features) + + self._test_get_guest_with_perf(caps, ['cmt', 'mbml', 'mbmt']) @mock.patch.object(host.Host, 'has_min_version') def test_get_guest_with_perf_libvirt_unsupported(self, mock_min_version): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index c6632cf2cd65..feb137f211f2 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -310,12 +310,12 @@ MIN_QEMU_OTHER_ARCH = {arch.S390: MIN_QEMU_S390_VERSION, } # perf events support -MIN_LIBVIRT_PERF_VERSION = (1, 3, 3) +MIN_LIBVIRT_PERF_VERSION = (2, 0, 0) LIBVIRT_PERF_EVENT_PREFIX = 'VIR_PERF_PARAM_' -PERF_EVENTS_CPU_FLAG_MAPPING = {'cmt': 'cqm', - 'mbml': 'cqm_mbm_local', - 'mbmt': 'cqm_mbm_total', +PERF_EVENTS_CPU_FLAG_MAPPING = {'cmt': 'cmt', + 'mbml': 'mbm_local', + 'mbmt': 'mbm_total', } diff --git a/releasenotes/notes/add-perf-event-e1385b6b6346fbda.yaml b/releasenotes/notes/add-perf-event-e1385b6b6346fbda.yaml index d1bbd0766969..b76f94d16b76 100644 --- a/releasenotes/notes/add-perf-event-e1385b6b6346fbda.yaml +++ b/releasenotes/notes/add-perf-event-e1385b6b6346fbda.yaml @@ -3,4 +3,4 @@ features: - Add perf event support for libvirt driver. This can be done by adding new configure option 'enabled_perf_events' in libvirt section of - nova.conf. This feature requires libvirt>=1.3.3. + nova.conf. This feature requires libvirt>=2.0.0.