This patch-series adds support for reporting Hostwide(L1-Lpar) counters via perf-events. With the support for running KVM Guest in a PSeries-Lpar using nested-APIv2 via [1], the underlying L0-PowerVM hypervisor holds some state information pertaining to all running L2-KVM Guests in an L1-Lpar. This state information is held in a pre-allocated memory thats owned by L0-PowerVM and is termed as Guest-Management-Area(GMA). The GMA is allocated per L1-LPAR and is only allocated if the lpar is KVM enabled. The size of this area is a fixed percentage of the memory assigned to the KVM enabled L1-lpar and is composed of two major components, Guest Management Space(Host-Heap) and Guest Page Table Management Space(Host-Pagetable). The Host-Heap holds the various data-structures allocated by L0-PowerVM for L2-KVM Guests running in the L1-Lpar. The Host-Pagetable holds the Radix pagetable[2] for the L2-KVM Guest which is used by L0-PowerVM to handle page faults. Since the size of both of these areas is limited and fixed via partition boot profile, it puts an upper bound on the number of L2-KVM Guests that can be run in an LPAR. Also due limited size of Host-Pagetable area, L0-PowerVM is at times forced to perform reclaim operation on it. This reclaim operation is usually performed when running large number of L2-KVM Guests which are memory bound and increases Host-Pagetable utilization. In light of the above its recommended to track usage of these areas to ensure consistent L2-KVM Guest performance. Hence this patch-series attempts to expose the max-size and current-usage of these areas as well as cumulative amount of bytes reclaimed from Host-Pagetable as perf-events that can be queried via perf-stat. The patch series introduces a new 'kvm-hv' PMU which exports the perf-events mentioned below. Since perf-events exported represents the state of the whole L1-Lpar and not that of a specific L2-KVM guest hence the 'kvm-hv' PMU's scope is set as PERF_PMU_SCOPE_SYS_WIDE(System-Wide). New perf-events introduced ========================== * kvm-hv/host_heap/ : The currently used bytes in the Hypervisor's Guest Management Space associated with the Host Partition. * kvm-hv/host_heap_max/ : The maximum bytes available in the Hypervisor's Guest Management Space associated with the Host Partition. * kvm-hv/host_pagetable/ : The currently used bytes in the Hypervisor's Guest Page Table Management Space associated with the Host Partition. * kvm-hv/host_pagetable_max/ : The maximum bytes available in the Hypervisor's Guest Page Table Management Space associated with the Host Partition. * kvm-hv/host_pagetable_reclaim/: The amount of space in bytes that has been reclaimed due to overcommit in the Hypervisor's Guest Page Table Management Space associated with the Host Partition. Structure of this patch series ============================== Start with documenting and updating the KVM nested-APIv2 hcall specifications for H_GUEST_GET_STATE hcall and Hostwide guest-state-buffer elements. Subsequent patches add support for adding and parsing Hostwide guest-state-buffer elements in existing kvm-hv apiv2 infrastructure. Also add a kunit test case to verify correctness of the changes introduced. Next set of patches in the patch-set introduces a new PMU for kvm-hv on pseries named as 'kvm-hv', implement plumbing between kvm-hv module and initialization of this new PMU, necessary setup code in kvm-hv pmu to create populate and parse a guest-state-buffer holding the Hostwide counters returned from L0-PowerVM. The final patch in the series creates the five new perf-events which then leverage the kernel's perf-event infrastructure to report the Hostwide counters returned from L0-PowerVM to perf tool. Output ====== Once the patch-set is integrated, perf-stat should report the Hostwide counters for a kvm-enabled pseries lpar as below: $ sudo perf stat -e 'kvm-hv/host_heap/' -e 'kvm-hv/host_heap_max/' \ -e 'kvm-hv/host_pagetable/' -e 'kvm-hv/host_pagetable_max/' \ -e 'kvm-hv/host_pagetable_reclaim/' -- sleep 0 Performance counter stats for 'system wide': 0 kvm-hv/host_heap/ 10,995,367,936 kvm-hv/host_heap_max/ 2,178,304 kvm-hv/host_pagetable/ 2,147,483,648 kvm-hv/host_pagetable_max/ 0 kvm-hv/host_pagetable_reclaim/ References ========== [1] - commit 19d31c5f1157 ("KVM: PPC: Add support for nestedv2 guests") [2] - "KVM in a PowerVM LPAR: A Power user guide Part II" https://ibm.biz/BdGHeY Vaibhav Jain (6): powerpc: Document APIv2 KVM hcall spec for Hostwide counters kvm powerpc/book3s-apiv2: Add support for Hostwide GSB elements kvm powerpc/book3s-apiv2: Add kunit tests for Hostwide GSB elements kvm powerpc/book3s-apiv2: Introduce kvm-hv specific PMU powerpc/book3s-hv-pmu: Implement GSB message-ops for hostwide counters kvm powerpc/book3s-hv-pmu: Add perf-events for Hostwide counters Documentation/arch/powerpc/kvm-nested.rst | 40 +- arch/powerpc/include/asm/guest-state-buffer.h | 35 +- arch/powerpc/include/asm/hvcall.h | 13 +- arch/powerpc/include/asm/kvm_book3s.h | 12 + arch/powerpc/kvm/Makefile | 6 + arch/powerpc/kvm/book3s_hv.c | 7 + arch/powerpc/kvm/book3s_hv_nestedv2.c | 6 + arch/powerpc/kvm/book3s_hv_pmu.c | 412 ++++++++++++++++++ arch/powerpc/kvm/guest-state-buffer.c | 39 ++ arch/powerpc/kvm/test-guest-state-buffer.c | 210 +++++++++ 10 files changed, 757 insertions(+), 23 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_hv_pmu.c -- 2.47.1