Enable fixed counter 3 and topdown perf metrics for vPMU
Subsystems (4)
v2 cover Enable fixed counter 3 and topdown perf metrics for vPMU
The TopDown Microarchitecture Analysis (TMA) Method is a structured analysis methodology to identify critical performance bottlenecks in out-of-order processors. The details about topdown metrics support on Intel processors can be found in section "Performance Metrics" of Intel's SDM Volume 3[1]. Kernel enabling code has also been merged, see patchset[2] to learn more about the feature.
The TMA method is quite powerful and efficient to help developers to identify the performance bottleneck in the program. The TMA method has been integrated into multiple performance analysis tools, such as perf, Vtune. Developers can leverage TMA method to analyze their program's performance bottleneck easily with these tools and improve their program's performance. TMA method is becoming the most widely used performance analysis method on x86 platform. Currently the TMA method has been supported fairly well on Native, but it's still not supported in Guest environment. Since the environment difference between Host and Guest, even same program may show different performance bottleneck between Guest and Host. Obviously, the most straightforward and best method to profiling Guest performance bottleneck is to run the TMA method in Guest directly. So supporting topdown perf metrics in Guest becomes a real and important requirement and we hope this patchset can mitigate this gap.
Like Xu posted a patch series to support guest Topdown[3], the patchset creates a group of topdown metric events in KVM by binding to fixed counter 3 to obtain hardware values and the guest value of PERF_METRICS MSR is assembled based on the count of grouped metric events.
This patchset improves Like's proposal, it leverages mature vPMU PMC emulation framework and current perf topdown metric handling logic to support guest topdown metrics feature.
In current perf logic, an events group is required to handle the topdown metrics profiling, and the events group couples a slots event which acts events group leader and multiple metric events. To coordinate with the perf topdown metrics handing logic and reduce the code changes in KVM, we choose to follow current mature vPMU PMC emulation framework. The only difference is that we need to create a events group for fixed counter 3 and manipulate FIXED_CTR3 and PERF_METRICS MSRS together instead of a single event and only manipulating FIXED_CTR3 MSR.
When guest writes PERF_METRICS MSR at first, KVM would create an event group which couples a slots event and a virtual metrics event. In this event group, slots event claims the fixed counter 3 HW resource and acts as group leader which is required by perf system. The virtual metrics event claims the PERF_METRICS MSR. This event group is just like the perf metrics events group on host and is scheduled by host perf system.
In this proposal, the count of slots event is calculated and emulated on host and returned to guest just like other normal counters, but there is a difference for the metrics event processing. KVM doesn't calculate the real count of topdown metrics, it just stores the raw data of PERF_METRICS MSR and directly returnthe stored raw data to guest. Thus, guest can get the real HW PERF_METRICS data and guarantee the calculation accuracy of topdown metrics.
Comparing with Like's patchset, this proposal brings two benefits.
1. Reduce the created perf events number
Like's patchset needs to create 4 (Ice Lake) or 8 (Sapphire Rapids) metric events, whereas this patchset only needs to create 1 metric event.
2. Increase the accuracy of metric calculation
Like's patchset needs to do twice metric count conversion. The first conversion happens on perf system, perf topdown metrics handling logic reads the metric percentage from PERF_METRICS MSR and times with elapsed slots count and obtains the metric count. The second conversion happens on KVM, KVM needs to convert the metric count back to metric percentage by using metric count divide elapsed slots again and then assembles the 4 or 8 metric percentage values to the virtual PERF_METRICS MSR and return to Guest at last. Considering each metric percentage in PERF_METRICS MSR is represented with only 8 bits, the twice conversions (once multiplication and once division) definitely cause accuracy loss in theory. Since this patchset directly returns the raw data of PERF_METRICS MSR to guest, it won't have any accuracy loss.
The patchset is rebased on latest kvm-x86/next branch and it is tested on both Host and Guest (SPR Platform) with below perf commands. The 'foo' is a backend-bound benchmark. We can see the output of perf commands are quite close between host and guest.
1. perf stat ./foo
Host outputs:
Performance counter stats for '/home/sdp/work/foo/foo':
26,525.25 msec task-clock # 1.000 CPUs utilized
9 context-switches # 0.339 /sec
2 cpu-migrations # 0.075 /sec
51 page-faults # 1.923 /sec
125,330,033,745 cycles # 4.725 GHz
238,172,965,287 instructions # 1.90 insn per cycle
44,904,300,430 branches # 1.693 G/sec
69,299,003 branch-misses # 0.15% of all branches
751,979,445,222 TOPDOWN.SLOTS # 59.2 % tma_backend_bound
# 38.0 % tma_retiring
# 0.8 % tma_bad_speculation
# 1.9 % tma_frontend_bound
286,047,083,084 topdown-retiring
14,744,695,003 topdown-fe-bound
445,289,789,131 topdown-be-bound
5,897,878,000 topdown-bad-spec
138,674,397 INT_MISC.UOP_DROPPING # 5.228 M/sec 26.528600835 seconds time elapsed
26.527849000 seconds user
0.000000000 seconds sysGuest outputs:
Performance counter stats for '/home/pnp/foo/foo':
29,051.43 msec task-clock # 1.000 CPUs utilized
10 context-switches # 0.344 /sec
0 cpu-migrations # 0.000 /sec
51 page-faults # 1.756 /sec
125,337,801,996 cycles # 4.314 GHz
238,139,676,030 instructions # 1.90 insn per cycle
44,897,906,380 branches # 1.545 G/sec
69,402,326 branch-misses # 0.15% of all branches
752,022,710,490 TOPDOWN.SLOTS # 58.4 % tma_backend_bound
# 37.6 % tma_retiring
# 1.2 % tma_bad_speculation
# 2.7 % tma_frontend_bound
283,114,432,184 topdown-retiring
20,643,760,680 topdown-fe-bound
439,417,191,619 topdown-be-bound
8,847,326,005 topdown-bad-spec
138,873,309 INT_MISC.UOP_DROPPING # 4.780 M/sec 29.058833449 seconds time elapsed
29.048761000 seconds user
0.004003000 seconds sys2. perf stat -e slots ./foo
Host outputs:
Performance counter stats for '/home/sdp/work/foo/foo':
713,292,346,950 slots
25.472861484 seconds time elapsed
25.470978000 seconds user
0.000000000 seconds sysGuest outputs:
Performance counter stats for '/home/pnp/foo/foo':
713,286,331,824 slots
25.264007882 seconds time elapsed
25.259790000 seconds user
0.004002000 seconds sys3.
echo 0 > /proc/sys/kernel/nmi_watchdog
echo 25 > /proc/sys/kernel/perf_cpu_time_max_percent echo 100000 > /proc/sys/kernel/perf_event_max_sample_rate echo 0 > /proc/sys/kernel/perf_cpu_time_max_percent perf record -e slots ./foo && perf report
Host outputs:
# Total Lost Samples: 0
#
# Samples: 109K of event 'slots'
# Event count (approx.): 715723903347
#
# Overhead Command Shared Object Symbol
# ........ ....... ................ ..................................
#
74.83% foo libc.so.6 [.] __random
7.22% foo foo [.] qux
7.07% foo libc.so.6 [.] __random_r
5.40% foo foo [.] main
1.82% foo foo [.] bar
1.75% foo foo [.] random@plt
1.73% foo foo [.] foo
0.02% foo [kernel.vmlinux] [k] arch_asym_cpu_priorityGuest outputs:
# Total Lost Samples: 0
#
# Samples: 7K of event 'slots'
# Event count (approx.): 24532005986
#
# Overhead Command Shared Object Symbol
# ........ ....... ................ ....................
#
75.21% foo libc.so.6 [.] __random
7.19% foo libc.so.6 [.] __random_r
7.12% foo foo [.] qux
5.21% foo foo [.] main
1.90% foo foo [.] foo
1.81% foo foo [.] bar
1.56% foo foo [.] random@plt
0.00% perf-ex [kernel.vmlinux] [k] native_write_msrTo support the guest topdown metrics feature, we have to do several fundamental changes for perf system and vPMU code, we tried to avoid these changes AMAP, but it seems it's inevitable. If you have any idea, please suggest.
The fundamental changes:
1. perf/core: Add function perf_event_create_group_kernel_counters() Add a new API to create group events from kernel space
2. perf/core: Add new function perf_event_topdown_metrics() Add a new API to update topdown metrics values
3. perf/x86/intel: Handle KVM virtual metrics event in perf system Add virtual metrics event processing logic in topdown metrics
processing code
4. KVM: x86/pmu: Extend pmc_reprogram_counter() to create group events Extend pmc_reprogram_counter() to be capable to create group events
instead of just single event
References:
[1]: Intel 64 and IA-32 Architectures Software Developer Manual
Combined Volumes: 1, 2A, 2B, 2C, 2D, 3A, 3B, 3C, 3D, and 4
https://cdrdv2.intel.com/v1/dl/getContent/671200
[2]: perf/x86/intel: Support TopDown metrics on Ice Lake
https://lwn.net/ml/linux-kernel/[email protected]/
[3]: KVM: x86/pmu: Enable Fixed Counter3 and Topdown Perf Metrics
https://lwn.net/ml/linux-kernel/[email protected]/
Dapeng Mi (13):
KVM: x86/pmu: Add Intel CPUID-hinted TopDown slots event
KVM: x86/pmu: Support PMU fixed counter 3
perf/core: Add function perf_event_group_leader_check() perf/core: Add function perf_event_move_group() perf/core: Add function perf_event_create_group_kernel_counters() perf/x86: Fix typos and inconsistent indents in perf_event header perf/x86: Add constraint for guest perf metrics event perf/core: Add new function perf_event_topdown_metrics() perf/x86/intel: Handle KVM virtual metrics event in perf system
KVM: x86/pmu: Extend pmc_reprogram_counter() to create group events
KVM: x86/pmu: Support topdown perf metrics feature
KVM: x86/pmu: Handle PERF_METRICS overflow
KVM: x86/pmu: Expose Topdown in MSR_IA32_PERF_CAPABILITIES
arch/x86/events/intel/core.c | 72 +++++-- arch/x86/events/perf_event.h | 10 +- arch/x86/include/asm/kvm_host.h | 19 +- arch/x86/include/asm/perf_event.h | 21 +- arch/x86/kvm/pmu.c | 142 +++++++++++-- arch/x86/kvm/pmu.h | 50 ++++- arch/x86/kvm/svm/pmu.c | 2 + arch/x86/kvm/vmx/capabilities.h | 1 + arch/x86/kvm/vmx/pmu_intel.c | 67 ++++++ arch/x86/kvm/vmx/vmx.c | 2 + arch/x86/kvm/vmx/vmx.h | 5 + arch/x86/kvm/x86.c | 5 +- include/linux/perf_event.h | 19 ++ kernel/events/core.c | 326 ++++++++++++++++++++---------- 14 files changed, 590 insertions(+), 151 deletions(-)
base-commit: 240f736891887939571854bd6d734b6c9291f22e
Signature · 1 line
2.34.1
PATCH v2 1/13 KVM: x86/pmu: Add Intel CPUID-hinted TopDown slots event
This patch adds support for the architectural topdown slots event which is hinted by CPUID.0AH.EBX.
The topdown slots event counts the total number of available slots for an unhalted logical processor. Software can use this event as the denominator for the top-level metrics of the topDown Microarchitecture Analysis method.
Although the MSR_PERF_METRICS MSR required for topdown events is not currently available in the guest, relying only on the data provided by the slots event is sufficient for pmu users to perceive differences in cpu pipeline machine-width across micro-architectures.
The standalone slots event, like the instruction event, can be counted with gp counter or fixed counter 3 (if any). Its availability is also controlled by CPUID.AH.EBX. On Linux, perf user may encode "-e cpu/event=0xa4,umask=0x01/" or "-e cpu/slots/" to count slots events.
This patch only enables slots event on GP counters. The enabling on fixed counter 3 will be supported in subsequent patches.
--- arch/x86/kvm/vmx/pmu_intel.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/pmu_intel.c +2 -0
@@ -34,6 +34,7 @@ enum intel_pmu_architectural_events {INTEL_ARCH_LLC_MISSES ,INTEL_ARCH_BRANCHES_RETIRED ,INTEL_ARCH_BRANCHES_MISPREDICTED , +INTEL_ARCH_TOPDOWN_SLOTS , NR_REAL_INTEL_ARCH_EVENTS,
@@ -58,6 +59,7 @@ static struct { [INTEL_ARCH_LLC_MISSES] = { 0x2e, 0x41 }, [INTEL_ARCH_BRANCHES_RETIRED] = { 0xc4, 0x00 }, [INTEL_ARCH_BRANCHES_MISPREDICTED] = { 0xc5, 0x00 }, + [INTEL_ARCH_TOPDOWN_SLOTS] = { 0xa4, 0x01 }, [PSEUDO_ARCH_REFERENCE_CYCLES] = { 0x00, 0x03 }, };
Signature · 1 line
2.34.1
PATCH v2 2/13 KVM: x86/pmu: Support PMU fixed counter 3
In reply to Dapeng MiThe TopDown slots event can be enabled on gp counter or fixed counter 3 and it does not differ from other fixed counters in terms of the use of count and sampling modes (except for the hardware logic for event accumulation).
According to commit 6017608936c1 ("perf/x86/intel: Add Icelake support"), KVM or any perf in-kernel user needs to reprogram fixed counter 3 via the kernel-defined TopDown slots event for real fixed counter 3 on the host.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/vmx/pmu_intel.c | 10 ++++++++++ arch/x86/kvm/x86.c | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -509,7 +509,7 @@ struct kvm_pmc {#define KVM_INTEL_PMC_MAX_GENERIC 8#define MSR_ARCH_PERFMON_PERFCTR_MAX (MSR_ARCH_PERFMON_PERFCTR0 + KVM_INTEL_PMC_MAX_GENERIC - 1)#define MSR_ARCH_PERFMON_EVENTSEL_MAX (MSR_ARCH_PERFMON_EVENTSEL0 + KVM_INTEL_PMC_MAX_GENERIC - 1) -#define KVM_PMC_MAX_FIXED 3 +#define KVM_PMC_MAX_FIXED 4#define MSR_ARCH_PERFMON_FIXED_CTR_MAX (MSR_ARCH_PERFMON_FIXED_CTR0 + KVM_PMC_MAX_FIXED - 1)#define KVM_AMD_PMC_MAX_GENERIC 6struct kvm_pmu {
arch/x86/kvm/vmx/pmu_intel.c +10 -0
@@ -45,6 +45,14 @@ enum intel_pmu_architectural_events {* core crystal clock or the bus clock (yeah, "architectural"). */ PSEUDO_ARCH_REFERENCE_CYCLES =NR_REAL_INTEL_ARCH_EVENTS , +/* +* Pseudo-architectural event used to implement IA32_FIXED_CTR3, a.k.a. +* topDown slots. The topdown slots event counts the total number of +* available slots for an unhalted logical processor. The topdwon slots +* event with PERF_METRICS MSR together provides support for topdown +* micro-architecture analysis method. +*/ +PSEUDO_ARCH_TOPDOWN_SLOTS , NR_INTEL_ARCH_EVENTS, };
@@ -61,6 +69,7 @@ static struct { [INTEL_ARCH_BRANCHES_MISPREDICTED] = { 0xc5, 0x00 }, [INTEL_ARCH_TOPDOWN_SLOTS] = { 0xa4, 0x01 }, [PSEUDO_ARCH_REFERENCE_CYCLES] = { 0x00, 0x03 }, + [PSEUDO_ARCH_TOPDOWN_SLOTS] = { 0x00, 0x04 }, };/* mapping between fixed pmc index and intel_arch_events array */
@@ -68,6 +77,7 @@ static int fixed_pmc_events[] = { [0] = INTEL_ARCH_INSTRUCTIONS_RETIRED, [1] = INTEL_ARCH_CPU_CYCLES, [2] = PSEUDO_ARCH_REFERENCE_CYCLES, + [3] = PSEUDO_ARCH_TOPDOWN_SLOTS, };static void reprogram_fixed_counters (struct kvm_pmu *pmu,u64 data)
arch/x86/kvm/x86.c +2 -2
@@ -1459,7 +1459,7 @@ static const u32 msrs_to_save_base[] = {static const u32 msrs_to_save_pmu[] = {MSR_ARCH_PERFMON_FIXED_CTR0 ,MSR_ARCH_PERFMON_FIXED_CTR1 , -MSR_ARCH_PERFMON_FIXED_CTR0 +2 , +MSR_ARCH_PERFMON_FIXED_CTR2 ,MSR_ARCH_PERFMON_FIXED_CTR3 ,MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_CORE_PERF_GLOBAL_STATUS ,MSR_CORE_PERF_GLOBAL_CTRL ,MSR_CORE_PERF_GLOBAL_OVF_CTRL ,MSR_IA32_PEBS_ENABLE ,MSR_IA32_DS_AREA ,MSR_PEBS_DATA_CFG ,
@@ -7181,7 +7181,7 @@ static void kvm_init_msr_lists(void) {unsigned i; -BUILD_BUG_ON_MSG (KVM_PMC_MAX_FIXED !=3 , +BUILD_BUG_ON_MSG (KVM_PMC_MAX_FIXED !=4 ,"Please update the fixed PMCs in msrs_to_save_pmu[]" ); num_msrs_to_save =0 ;
Signature · 1 line
2.34.1
PATCH v2 3/13 perf/core: Add function perf_event_group_leader_check()
In reply to Dapeng MiExtract the group leader checking code in function sys_perf_event_open() to create a new function perf_event_group_leader_check().
The subsequent change would add a new function perf_event_create_group_kernel_counters() which is used to create group events in kernel space. The function also needs to do same check for group leader event just like function sys_perf_event_open() does. So extract the checking code into a separate function and avoid the code duplication.
--- kernel/events/core.c | 143 +++++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 65 deletions(-)
kernel/events/core.c +78 -65
@@ -12324,6 +12324,81 @@ perf_check_permission(struct perf_event_attr *attr, struct task_struct *task)return is_capable ||ptrace_may_access (task, ptrace_mode); } +static int perf_event_group_leader_check (struct perf_event *group_leader, +struct perf_event *event, +struct perf_event_attr *attr, +struct perf_event_context *ctx, +struct pmu **pmu, +int *move_group) +{ +if (!group_leader) +return 0 ; + +/* +* Do not allow a recursive hierarchy (this new sibling +* becoming part of another group-sibling): +*/ +if (group_leader->group_leader != group_leader) +return -EINVAL ; + +/* All events in a group should have the same clock */ +if (group_leader->clock != event->clock) +return -EINVAL ; + +/* +* Make sure we're both events for the same CPU; +* grouping events for different CPUs is broken; since +* you can never concurrently schedule them anyhow. +*/ +if (group_leader->cpu != event->cpu) +return -EINVAL ; + +/* +* Make sure we're both on the same context; either task or cpu. +*/ +if (group_leader->ctx != ctx) +return -EINVAL ; + +/* +* Only a group leader can be exclusive or pinned +*/ +if (attr->exclusive || attr->pinned) +return -EINVAL ; + +if (is_software_event (event) && + !in_software_context (group_leader)) { +/* +* If the event is a sw event, but the group_leader +* is on hw context. +* +* Allow the addition of software events to hw +* groups, this is safe because software events +* never fail to schedule. +* +* Note the comment that goes with struct +* perf_event_pmu_context. +*/ + *pmu = group_leader->pmu_ctx->pmu; + }else if (!is_software_event (event)) { +if (is_software_event (group_leader) && + (group_leader->group_caps &PERF_EV_CAP_SOFTWARE )) { +/* +* In case the group is a pure software group, and we +* try to add a hardware event, move the whole group to +* the hardware context. +*/ + *move_group =1 ; + } + +/* Don't allow group of multiple hw events from different pmus */ +if (!in_software_context (group_leader) && + group_leader->pmu_ctx->pmu != *pmu) +return -EINVAL ; + } + +return 0 ; +} +/** * sys_perf_event_open - open a performance event, associate it to a task/cpu *
@@ -12518,71 +12593,9 @@ SYSCALL_DEFINE5(perf_event_open, } } -if (group_leader) { - err = -EINVAL ; - -/* -* Do not allow a recursive hierarchy (this new sibling -* becoming part of another group-sibling): -*/ -if (group_leader->group_leader != group_leader) - goto err_locked; - -/* All events in a group should have the same clock */ -if (group_leader->clock != event->clock) - goto err_locked; - -/* -* Make sure we're both events for the same CPU; -* grouping events for different CPUs is broken; since -* you can never concurrently schedule them anyhow. -*/ -if (group_leader->cpu != event->cpu) - goto err_locked; - -/* -* Make sure we're both on the same context; either task or cpu. -*/ -if (group_leader->ctx != ctx) - goto err_locked; - -/* -* Only a group leader can be exclusive or pinned -*/ -if (attr.exclusive || attr.pinned) - goto err_locked; - -if (is_software_event (event) && - !in_software_context (group_leader)) { -/* -* If the event is a sw event, but the group_leader -* is on hw context. -* -* Allow the addition of software events to hw -* groups, this is safe because software events -* never fail to schedule. -* -* Note the comment that goes with struct -* perf_event_pmu_context. -*/ - pmu = group_leader->pmu_ctx->pmu; - }else if (!is_software_event (event)) { -if (is_software_event (group_leader) && - (group_leader->group_caps &PERF_EV_CAP_SOFTWARE )) { -/* -* In case the group is a pure software group, and we -* try to add a hardware event, move the whole group to -* the hardware context. -*/ - move_group =1 ; - } - -/* Don't allow group of multiple hw events from different pmus */ -if (!in_software_context (group_leader) && - group_leader->pmu_ctx->pmu != pmu) - goto err_locked; - } - } + err =perf_event_group_leader_check (group_leader, event, &attr, ctx, &pmu, &move_group); +if (err) + goto err_locked;/* * Now that we're certain of the pmu; find the pmu_ctx.
Signature · 1 line
2.34.1
PATCH v2 4/13 perf/core: Add function perf_event_move_group()
In reply to Dapeng MiExtract the group moving code in function sys_perf_event_open() to create a new function perf_event_move_group().
The subsequent change would add a new function perf_event_create_group_kernel_counters() which is used to create group events in kernel space. The function also needs to do same group moving for group leader event just like function sys_perf_event_open() does. So extract the moving code into a separate function to avoid the code duplication.
--- kernel/events/core.c | 82 ++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 37 deletions(-)
kernel/events/core.c +45 -37
@@ -12399,6 +12399,48 @@ static int perf_event_group_leader_check(struct perf_event *group_leader,return 0 ; } +static void perf_event_move_group (struct perf_event *group_leader, +struct perf_event_pmu_context *pmu_ctx, +struct perf_event_context *ctx) +{ +struct perf_event *sibling; + +perf_remove_from_context (group_leader,0 ); +put_pmu_ctx (group_leader->pmu_ctx); + +for_each_sibling_event (sibling, group_leader) { +perf_remove_from_context (sibling,0 ); +put_pmu_ctx (sibling->pmu_ctx); + } + +/* +* Install the group siblings before the group leader. +* +* Because a group leader will try and install the entire group +* (through the sibling list, which is still in-tact), we can +* end up with siblings installed in the wrong context. +* +* By installing siblings first we NO-OP because they're not +* reachable through the group lists. +*/ +for_each_sibling_event (sibling, group_leader) { + sibling->pmu_ctx = pmu_ctx; +get_pmu_ctx (pmu_ctx); +perf_event__state_init (sibling); +perf_install_in_context (ctx, sibling, sibling->cpu); + } + +/* +* Removing from the context ends up with disabled +* event. What we want here is event in the initial +* startup state, ready to be add into new context. +*/ + group_leader->pmu_ctx = pmu_ctx; +get_pmu_ctx (pmu_ctx); +perf_event__state_init (group_leader); +perf_install_in_context (ctx, group_leader, group_leader->cpu); +} +/** * sys_perf_event_open - open a performance event, associate it to a task/cpu *
@@ -12414,7 +12456,7 @@ SYSCALL_DEFINE5(perf_event_open, {struct perf_event *group_leader =NULL , *output_event =NULL ;struct perf_event_pmu_context *pmu_ctx; -struct perf_event *event, *sibling; +struct perf_event *event;struct perf_event_attr attr;struct perf_event_context *ctx;struct file *event_file =NULL ;
@@ -12646,42 +12688,8 @@ SYSCALL_DEFINE5(perf_event_open,* where we start modifying current state. */ -if (move_group) { -perf_remove_from_context (group_leader,0 ); -put_pmu_ctx (group_leader->pmu_ctx); - -for_each_sibling_event (sibling, group_leader) { -perf_remove_from_context (sibling,0 ); -put_pmu_ctx (sibling->pmu_ctx); - } - -/* -* Install the group siblings before the group leader. -* -* Because a group leader will try and install the entire group -* (through the sibling list, which is still in-tact), we can -* end up with siblings installed in the wrong context. -* -* By installing siblings first we NO-OP because they're not -* reachable through the group lists. -*/ -for_each_sibling_event (sibling, group_leader) { - sibling->pmu_ctx = pmu_ctx; -get_pmu_ctx (pmu_ctx); -perf_event__state_init (sibling); -perf_install_in_context (ctx, sibling, sibling->cpu); - } - -/* -* Removing from the context ends up with disabled -* event. What we want here is event in the initial -* startup state, ready to be add into new context. -*/ - group_leader->pmu_ctx = pmu_ctx; -get_pmu_ctx (pmu_ctx); -perf_event__state_init (group_leader); -perf_install_in_context (ctx, group_leader, group_leader->cpu); - } +if (move_group) +perf_event_move_group (group_leader, pmu_ctx, ctx);/* * Precalculate sample_data sizes; do while holding ctx::mutex such
Signature · 1 line
2.34.1
PATCH v2 5/13 perf/core: Add function perf_event_create_group_kernel_counters()
In reply to Dapeng MiAdd function perf_event_create_group_kernel_counters() which can be used to create group perf events from kernel space.
Comparing with modifying function perf_event_create_kernel_counter() directly to support create group events, creating a new function looks a better method since function perf_event_create_kernel_counter() is called by many places in kernel and modifying directly this function introduces lots of changes.
Kernel space may want to create group events just like user space perf tool does. One example is to support topdown metrics feature in KVM.
Current perf logic requires perf tool creates an perf events group to handle the topdown metrics profiling. The events group couples one slots event acting as group leader and multiple metric events.
To support topdown metrics feature in KVM, KVM has to follow this requirement to create the events group from kernel space. That's why we need to add this new function.
--- include/linux/perf_event.h | 6 ++++++ kernel/events/core.c | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-)
include/linux/perf_event.h +6 -0
@@ -1104,6 +1104,12 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr,struct task_struct *task, perf_overflow_handler_t callback, void *context); +extern struct perf_event * +perf_event_create_group_kernel_counters (struct perf_event_attr *attr, +int cpu,struct task_struct *task, +struct perf_event *group_leader, +perf_overflow_handler_t overflow_handler, +void *context);extern void perf_pmu_migrate_context (struct pmu *pmu,int src_cpu,int dst_cpu); int perf_event_read_local(struct perf_event *event, u64 *value,
kernel/events/core.c +37 -2
@@ -12762,11 +12762,34 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,struct task_struct *task, perf_overflow_handler_t overflow_handler, void *context) +{ + return perf_event_create_group_kernel_counters(attr, cpu, task, +NULL ,overflow_handler ,context ); +} +EXPORT_SYMBOL_GPL (perf_event_create_kernel_counter); + +/** +* perf_event_create_group_kernel_counters +* +* @attr: attributes of the counter to create +* @cpu: cpu in which the counter is bound +* @task: task to profile (NULL for percpu) +* @group_leader: the group leader event of the created event +* @overflow_handler: callback to trigger when we hit the event +* @context: context data could be used in overflow_handler callback +*/ +struct perf_event * +perf_event_create_group_kernel_counters (struct perf_event_attr *attr, +int cpu,struct task_struct *task, +struct perf_event *group_leader, +perf_overflow_handler_t overflow_handler, +void *context) {struct perf_event_pmu_context *pmu_ctx;struct perf_event_context *ctx;struct perf_event *event;struct pmu *pmu; +int move_group =0 ;int err;/*
@@ -12776,7 +12799,11 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,if (attr->aux_output)return ERR_PTR (-EINVAL ); - event =perf_event_alloc (attr, cpu, task,NULL ,NULL , +if (task && group_leader && + group_leader->attr.inherit != attr->inherit) +return ERR_PTR (-EINVAL ); + + event =perf_event_alloc (attr, cpu, task, group_leader,NULL , overflow_handler, context,-1 );if (IS_ERR (event)) { err =PTR_ERR (event);
@@ -12806,6 +12833,11 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, goto err_unlock; } + err =perf_event_group_leader_check (group_leader, event, attr, ctx, + &pmu, &move_group); +if (err) + goto err_unlock; + pmu_ctx =find_get_pmu_context (pmu, ctx, event);if (IS_ERR (pmu_ctx)) { err =PTR_ERR (pmu_ctx);
@@ -12833,6 +12865,9 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, goto err_pmu_ctx; } +if (move_group) +perf_event_move_group (group_leader, pmu_ctx, ctx); +perf_install_in_context (ctx, event, event->cpu);perf_unpin_context (ctx);mutex_unlock (&ctx->mutex);
@@ -12851,7 +12886,7 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, err:return ERR_PTR (err); } -EXPORT_SYMBOL_GPL (perf_event_create_kernel_counter); +EXPORT_SYMBOL_GPL (perf_event_create_group_kernel_counters); static void __perf_pmu_remove(struct perf_event_context *ctx, int cpu, struct pmu *pmu,
Signature · 1 line
2.34.1
Peter Zijlstra
maintainerRe: [PATCH RFV v2 05/13] perf/core: Add function perf_event_create_group_kernel_counters()
Quoted 20 lines · Dapeng Mi
kernel/events/core.c +12
-0@@ -12762,11 +12762,34 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,struct task_struct *task, perf_overflow_handler_t overflow_handler, void *context) +{ + return perf_event_create_group_kernel_counters(attr, cpu, task, +NULL ,overflow_handler ,context ); +} +EXPORT_SYMBOL_GPL (perf_event_create_kernel_counter); + +/** +* perf_event_create_group_kernel_counters +* +* @attr: attributes of the counter to create +* @cpu: cpu in which the counter is bound +* @task: task to profile (NULL for percpu)
kernel/events/core.c perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, · line 12786
Quoted 10 lines
kernel/events/core.c +10
-0+* @group_leader: the group leader event of the created event +* @overflow_handler: callback to trigger when we hit the event +* @context: context data could be used in overflow_handler callback +*/ +struct perf_event * +perf_event_create_group_kernel_counters (struct perf_event_attr *attr, +int cpu,struct task_struct *task, +struct perf_event *group_leader, +perf_overflow_handler_t overflow_handler, +void *context)
I would much prefer if you just add the argument to perf_event_create_kernel_counter(), there aren't *that* many users.
Re: [PATCH RFV v2 05/13] perf/core: Add function perf_event_create_group_kernel_counters()
Quoted 31 lines · Peter Zijlstra
Date: Tue, 8 Aug 2023 12:21:27 +0200
From: Peter Zijlstra <[email protected]>
Subject: Re: [PATCH RFV v2 05/13] perf/core: Add function
perf_event_create_group_kernel_counters()Quoted 25 lines · Dapeng Mi
kernel/events/core.c +17
-0@@ -12762,11 +12762,34 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,struct task_struct *task, perf_overflow_handler_t overflow_handler, void *context) +{ + return perf_event_create_group_kernel_counters(attr, cpu, task, +NULL ,overflow_handler ,context ); +} +EXPORT_SYMBOL_GPL (perf_event_create_kernel_counter); + +/** +* perf_event_create_group_kernel_counters +* +* @attr: attributes of the counter to create +* @cpu: cpu in which the counter is bound +* @task: task to profile (NULL for percpu) +* @group_leader: the group leader event of the created event +* @overflow_handler: callback to trigger when we hit the event +* @context: context data could be used in overflow_handler callback +*/ +struct perf_event *
Quoted 8 lines
kernel/events/core.c perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu, · line 12786
Quoted 5 lines
kernel/events/core.c +5
-0+perf_event_create_group_kernel_counters(struct perf_event_attr *attr, + int cpu, struct task_struct *task, + struct perf_event *group_leader, + perf_overflow_handler_t overflow_handler, + void *context)I would much prefer if you just add the argument to
perf_event_create_kernel_counter(), there aren't *that* many users.
Sure. Thanks.
Signature · 2 lines
Thanks, Dapeng Mi
PATCH v2 6/13 perf/x86: Fix typos and inconsistent indents in perf_event header
In reply to Dapeng MiThere is one typo and some inconsistent indents in perf_event.h header file. Fix them.
--- arch/x86/include/asm/perf_event.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/perf_event.h +3 -3
@@ -386,15 +386,15 @@ static inline bool is_topdown_idx(int idx)* * With this fake counter assigned, the guest LBR event user (such as KVM), * can program the LBR registers on its own, and we don't actually do anything -* with then in the host context. +* with them in the host context. */ -#define INTEL_PMC_IDX_FIXED_VLBR (GLOBAL_STATUS_LBRS_FROZEN_BIT) +#define INTEL_PMC_IDX_FIXED_VLBR (GLOBAL_STATUS_LBRS_FROZEN_BIT)/* * Pseudo-encoding the guest LBR event as event=0x00,umask=0x1b, * since it would claim bit 58 which is effectively Fixed26. */ -#define INTEL_FIXED_VLBR_EVENT 0x1b00 +#define INTEL_FIXED_VLBR_EVENT 0x1b00/* * Adaptive PEBS v4
Signature · 1 line
2.34.1
PATCH v2 7/13 perf/x86: Add constraint for guest perf metrics event
In reply to Dapeng MiWhen guest wants to use PERF_METRICS MSR, a virtual metrics event needs to be created in the perf subsystem so that the guest can have exclusive ownership of the PERF_METRICS MSR.
We introduce the new vmetrics constraint, so that we can couple this virtual metrics event with slots event as a events group to involves in the host perf system scheduling. Since Guest metric events are always recognized as vCPU process's events on host, they are time-sharing multiplexed with other host metric events, so that we choose bit 48 (INTEL_PMC_IDX_METRIC_BASE) as the index of this virtual metrics event.
--- arch/x86/events/intel/core.c | 28 +++++++++++++++++++++------- arch/x86/events/perf_event.h | 1 + arch/x86/include/asm/perf_event.h | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-)
arch/x86/events/intel/core.c +21 -7
@@ -3147,17 +3147,26 @@ intel_bts_constraints(struct perf_event *event)return NULL ; } +static struct event_constraint *intel_virt_event_constraints[]__read_mostly = { + &vlbr_constraint, + &vmetrics_constraint, +}; +/* -* Note: matches a fake event, like Fixed2. +* Note: matches a virtual event, like vmetrics. */ static struct event_constraint * -intel_vlbr_constraints (struct perf_event *event) +intel_virt_constraints (struct perf_event *event) { -struct event_constraint *c = &vlbr_constraint; +int i; +struct event_constraint *c; -if (unlikely (constraint_match (c, event->hw.config))) { - event->hw.flags |= c->flags; -return c; +for (i =0 ; i <ARRAY_SIZE (intel_virt_event_constraints); i++) { + c = intel_virt_event_constraints[i]; +if (unlikely (constraint_match (c, event->hw.config))) { + event->hw.flags |= c->flags; +return c; + } }return NULL ;
@@ -3357,7 +3366,7 @@ __intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx, {struct event_constraint *c; - c =intel_vlbr_constraints (event); + c =intel_virt_constraints (event);if (c)return c;
@@ -5349,6 +5358,11 @@ static struct attribute *spr_tsx_events_attrs[] = { NULL, }; +struct event_constraint vmetrics_constraint = +__EVENT_CONSTRAINT (INTEL_FIXED_VMETRICS_EVENT , + (1ULL <<INTEL_PMC_IDX_FIXED_VMETRICS ), +FIXED_EVENT_FLAGS ,1 ,0 ,0 ); +static ssize_t freeze_on_smi_show (struct device *cdev,struct device_attribute *attr,char *buf)
arch/x86/events/perf_event.h +1 -0
@@ -1482,6 +1482,7 @@ void reserve_lbr_buffers(void);extern struct event_constraint bts_constraint;extern struct event_constraint vlbr_constraint; +extern struct event_constraint vmetrics_constraint;void intel_pmu_enable_bts (u64 config);
arch/x86/include/asm/perf_event.h +15 -0
@@ -390,6 +390,21 @@ static inline bool is_topdown_idx(int idx)*/ #define INTEL_PMC_IDX_FIXED_VLBR (GLOBAL_STATUS_LBRS_FROZEN_BIT) +/* +* We model guest TopDown metrics event tracing similarly. +* +* Guest metric events are recognized as vCPU process's events on host, they +* would be time-sharing multiplexed with other host metric events, so that +* we choose bit 48 (INTEL_PMC_IDX_METRIC_BASE) as the index of virtual +* metrics event. +*/ +#define INTEL_PMC_IDX_FIXED_VMETRICS (INTEL_PMC_IDX_METRIC_BASE) + +/* +* Pseudo-encoding the guest metrics event as event=0x00,umask=0x11, +* since it would claim bit 48 which is effectively Fixed16. +*/ +#define INTEL_FIXED_VMETRICS_EVENT 0x1100/* * Pseudo-encoding the guest LBR event as event=0x00,umask=0x1b, * since it would claim bit 58 which is effectively Fixed26.
Signature · 1 line
2.34.1
PATCH v2 8/13 perf/core: Add new function perf_event_topdown_metrics()
In reply to Dapeng MiAdd a new function perf_event_topdown_metrics(). This new function is quite familiar with function perf_event_period(), but it updates slots count and metrics raw data instead of sample period into perf system.
When guest restores FIXED_CTR3 and PERF_METRICS MSRs in sched-in process, KVM needs to capture the MSR writing trap and set the MSR values of guest into corresponding perf events just like function perf_event_period() does.
Initially we tried to reuse the function perf_event_period() to set the slots/metrics value, but we found it was quite hard. The function perf_event_period() only works on sampling events but unfortunately slots event and metric events in topdown mode are all non-sampling events. There are sampling event check and lots of sampling period related check and setting in the function perf_event_period() call-chain. If we want to reuse the function perf_event_period(), we have to add lots of if-else changes on the entire function-chain and even modify the function name. This would totally mess up the function perf_event_period().
Thus, we select to create a new function perf_event_topdown_metrics() to set the slots/metrics values. This makes logic and code both be clearer.
--- include/linux/perf_event.h | 13 ++++++++ kernel/events/core.c | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
include/linux/perf_event.h +13 -0
@@ -1661,6 +1661,11 @@ perf_event_addr_filters(struct perf_event *event)return ifh; } +struct td_metrics { +u64 slots; +u64 metric; +}; +extern void perf_event_addr_filters_sync (struct perf_event *event);extern void perf_report_aux_output_id (struct perf_event *event,u64 hw_id);
@@ -1695,6 +1700,8 @@ extern void perf_event_task_tick(void);extern int perf_event_account_interrupt (struct perf_event *event);extern int perf_event_period (struct perf_event *event,u64 value);extern u64 perf_event_pause (struct perf_event *event,bool reset); +extern int perf_event_topdown_metrics (struct perf_event *event, +struct td_metrics *value);#else /* !CONFIG_PERF_EVENTS: */ static inline void * perf_aux_output_begin(struct perf_output_handle *handle,
@@ -1781,6 +1788,12 @@ static inline u64 perf_event_pause(struct perf_event *event, bool reset) {return 0 ; } + +static inline int perf_event_topdown_metrics (struct perf_event *event, +struct td_metrics *value) +{ +return 0 ; +}#endif #if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_CPU_SUP_INTEL )
kernel/events/core.c +62 -0
68 lines not on this page · raw message
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH RFV v2 08/13] perf/core: Add new function perf_event_topdown_metrics()
kernel test robot noticed the following build warnings:
Hi Dapeng,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20230808]
[cannot apply to kvm/queue acme/perf/core tip/perf/core kvm/linux-next v6.5-rc5 v6.5-rc4 v6.5-rc3 linus/master v6.5-rc5] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Dapeng-Mi/KVM-x86-pmu-Support-PMU-fixed-counter-3/20230809-030457 base: next-20230808 patch link: https://lore.kernel.org/r/20230808063111.1870070-9-dapeng1.mi%40linux.intel.com patch subject: [PATCH RFV v2 08/13] perf/core: Add new function perf_event_topdown_metrics() config: arm-randconfig-r046-20230808 (https://download.01.org/0day-ci/archive/20230809/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce: (https://download.01.org/0day-ci/archive/20230809/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from kernel/sched/build_policy.c:34:
In file included from kernel/sched/sched.h:61:
In file included from include/linux/syscalls_api.h:1:
In file included from include/linux/syscalls.h:90:
In file included from include/trace/syscall.h:7:
In file included from include/linux/trace_events.h:10:
>> include/linux/perf_event.h:1793:18: warning: declaration of 'struct td_metrics' will not be visible outside of this function [-Wvisibility]
struct td_metrics *value)
^
1 warning generated.
--
In file included from kernel/sched/fair.c:56:
In file included from kernel/sched/sched.h:61:
In file included from include/linux/syscalls_api.h:1:
In file included from include/linux/syscalls.h:90:
In file included from include/trace/syscall.h:7:
In file included from include/linux/trace_events.h:10:
>> include/linux/perf_event.h:1793:18: warning: declaration of 'struct td_metrics' will not be visible outside of this function [-Wvisibility]
struct td_metrics *value)
^
kernel/sched/fair.c:702:6: warning: no previous prototype for function 'update_entity_lag' [-Wmissing-prototypes]
void update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
^
kernel/sched/fair.c:702:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
^
static
kernel/sched/fair.c:12732:6: warning: no previous prototype for function 'free_fair_sched_group' [-Wmissing-prototypes]
void free_fair_sched_group(struct task_group *tg) { }
^
kernel/sched/fair.c:12732:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void free_fair_sched_group(struct task_group *tg) { }
^
static
kernel/sched/fair.c:12734:5: warning: no previous prototype for function 'alloc_fair_sched_group' [-Wmissing-prototypes]
int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
^
kernel/sched/fair.c:12734:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
^
static
kernel/sched/fair.c:12739:6: warning: no previous prototype for function 'online_fair_sched_group' [-Wmissing-prototypes]
void online_fair_sched_group(struct task_group *tg) { }
^
kernel/sched/fair.c:12739:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void online_fair_sched_group(struct task_group *tg) { }
^
static
kernel/sched/fair.c:12741:6: warning: no previous prototype for function 'unregister_fair_sched_group' [-Wmissing-prototypes]
void unregister_fair_sched_group(struct task_group *tg) { }
^
kernel/sched/fair.c:12741:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void unregister_fair_sched_group(struct task_group *tg) { }
^
static
kernel/sched/fair.c:503:20: warning: unused function 'list_del_leaf_cfs_rq' [-Wunused-function]
static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq)
^
kernel/sched/fair.c:524:19: warning: unused function 'tg_is_idle' [-Wunused-function]
static inline int tg_is_idle(struct task_group *tg)
^
kernel/sched/fair.c:548:19: warning: unused function 'max_vruntime' [-Wunused-function]
static inline u64 max_vruntime(u64 max_vruntime, u64 vruntime)
^
kernel/sched/fair.c:1262:20: warning: unused function 'is_core_idle' [-Wunused-function]
static inline bool is_core_idle(int cpu)
^
kernel/sched/fair.c:3452:20: warning: unused function 'account_numa_enqueue' [-Wunused-function]
static inline void account_numa_enqueue(struct rq *rq, struct task_struct *p)
^
kernel/sched/fair.c:3456:20: warning: unused function 'account_numa_dequeue' [-Wunused-function]
static inline void account_numa_dequeue(struct rq *rq, struct task_struct *p)
^
kernel/sched/fair.c:3460:20: warning: unused function 'update_scan_period' [-Wunused-function]
static inline void update_scan_period(struct task_struct *p, int new_cpu)
^
kernel/sched/fair.c:4872:20: warning: unused function 'cfs_rq_is_decayed' [-Wunused-function]
static inline bool cfs_rq_is_decayed(struct cfs_rq *cfs_rq)
^
kernel/sched/fair.c:4887:20: warning: unused function 'remove_entity_load_avg' [-Wunused-function]
static inline void remove_entity_load_avg(struct sched_entity *se) {}
^
kernel/sched/fair.c:6259:20: warning: unused function 'cfs_bandwidth_used' [-Wunused-function]
static inline bool cfs_bandwidth_used(void)
^
kernel/sched/fair.c:6267:20: warning: unused function 'sync_throttle' [-Wunused-function]
static inline void sync_throttle(struct task_group *tg, int cpu) {}
^
kernel/sched/fair.c:6280:19: warning: unused function 'throttled_lb_pair' [-Wunused-function]
static inline int throttled_lb_pair(struct task_group *tg,
^
kernel/sched/fair.c:6291:37: warning: unused function 'tg_cfs_bandwidth' [-Wunused-function]
static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
^
kernel/sched/fair.c:6295:20: warning: unused function 'destroy_cfs_bandwidth' [-Wunused-function]
static inline void destroy_cfs_bandwidth(struct cfs_bandwidth *cfs_b) {}
^
kernel/sched/fair.c:6296:20: warning: unused function 'update_runtime_enabled' [-Wunused-function]
static inline void update_runtime_enabled(struct rq *rq) {}
^
kernel/sched/fair.c:6297:20: warning: unused function 'unthrottle_offline_cfs_rqs' [-Wunused-function]
static inline void unthrottle_offline_cfs_rqs(struct rq *rq) {}
^ 22 warnings generated.
--
In file included from kernel/sched/core.c:13:
In file included from include/linux/syscalls_api.h:1:
In file included from include/linux/syscalls.h:90:
In file included from include/trace/syscall.h:7:
In file included from include/linux/trace_events.h:10:
>> include/linux/perf_event.h:1793:18: warning: declaration of 'struct td_metrics' will not be visible outside of this function [-Wvisibility]
struct td_metrics *value)
^
kernel/sched/core.c:3695:20: warning: unused function 'rq_has_pinned_tasks' [-Wunused-function]
static inline bool rq_has_pinned_tasks(struct rq *rq)
^
kernel/sched/core.c:5822:20: warning: unused function 'sched_tick_start' [-Wunused-function]
static inline void sched_tick_start(int cpu) { }
^
kernel/sched/core.c:5823:20: warning: unused function 'sched_tick_stop' [-Wunused-function]
static inline void sched_tick_stop(int cpu) { }
^
kernel/sched/core.c:6523:20: warning: unused function 'sched_core_cpu_starting' [-Wunused-function]
static inline void sched_core_cpu_starting(unsigned int cpu) {}
^
kernel/sched/core.c:6524:20: warning: unused function 'sched_core_cpu_deactivate' [-Wunused-function]
static inline void sched_core_cpu_deactivate(unsigned int cpu) {}
^
kernel/sched/core.c:6525:20: warning: unused function 'sched_core_cpu_dying' [-Wunused-function]
static inline void sched_core_cpu_dying(unsigned int cpu) {}
^7 warnings generated.
vim +1793 include/linux/perf_event.h
1791
1792 static inline int perf_event_topdown_metrics(struct perf_event *event,
> 1793 struct td_metrics *value)
1794 {
1795 return 0;
1796 }
1797 #endif
1798
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH RFV v2 08/13] perf/core: Add new function perf_event_topdown_metrics()
In reply to Dapeng Mikernel test robot noticed the following build warnings:
Hi Dapeng,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20230808]
[cannot apply to kvm/queue acme/perf/core tip/perf/core kvm/linux-next v6.5-rc5 v6.5-rc4 v6.5-rc3 linus/master v6.5-rc5] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Dapeng-Mi/KVM-x86-pmu-Support-PMU-fixed-counter-3/20230809-030457 base: next-20230808 patch link: https://lore.kernel.org/r/20230808063111.1870070-9-dapeng1.mi%40linux.intel.com patch subject: [PATCH RFV v2 08/13] perf/core: Add new function perf_event_topdown_metrics() config: loongarch-allnoconfig (https://download.01.org/0day-ci/archive/20230809/[email protected]/config) compiler: loongarch64-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230809/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/linux/trace_events.h:10,
from include/trace/syscall.h:7, from include/linux/syscalls.h:90, from arch/loongarch/mm/cache.c:17:
>> include/linux/perf_event.h:1793:53: warning: 'struct td_metrics' declared inside parameter list will not be visible outside of this definition or declaration
1793 | struct td_metrics *value)
| ^~~~~~~~~~
--
In file included from include/linux/trace_events.h:10,
from include/trace/syscall.h:7, from include/linux/syscalls.h:90, from include/linux/entry-common.h:7, from arch/loongarch/mm/fault.c:13:
>> include/linux/perf_event.h:1793:53: warning: 'struct td_metrics' declared inside parameter list will not be visible outside of this definition or declaration
1793 | struct td_metrics *value)
| ^~~~~~~~~~
arch/loongarch/mm/fault.c:256:27: warning: no previous prototype for 'do_page_fault' [-Wmissing-prototypes]
256 | asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
| ^~~~~~~~~~~~~
vim +1793 include/linux/perf_event.h
1791
1792 static inline int perf_event_topdown_metrics(struct perf_event *event,
> 1793 struct td_metrics *value)
1794 {
1795 return 0;
1796 }
1797 #endif
1798
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 9/13 perf/x86/intel: Handle KVM virtual metrics event in perf system
In reply to Dapeng MiKVM creates a virtual metrics event to claim the PERF_METRICS MSR, but this virtual metrics event can't be recognized by perf system as it uses a different event code with known metrics events. We need to modify perf system code and make the KVM virtual metrics event can be recognized and processed by perf system.
The counter of virtual metrics event doesn't save the real count value like other normal events, instead it's used to store the raw data of PERF_METRICS MSR, so KVM can obtain the raw data of PERF_METRICS after the virtual metrics event is disabled.
--- arch/x86/events/intel/core.c | 37 ++++++++++++++++++++++++++++-------- arch/x86/events/perf_event.h | 9 ++++++++- 2 files changed, 37 insertions(+), 9 deletions(-)
arch/x86/events/intel/core.c +29 -8
@@ -2608,6 +2608,15 @@ static void __icl_update_topdown_event(struct perf_event *event, } } +static inline void __icl_update_vmetrics_event (struct perf_event *event,u64 metrics) +{ +/* +* For the guest metrics event, the count would be used to save +* the raw data of PERF_METRICS MSR. +*/ +local64_set (&event->count, metrics); +} +static void update_saved_topdown_regs (struct perf_event *event,u64 slots,u64 metrics,int metric_end) {
@@ -2627,6 +2636,17 @@ static void update_saved_topdown_regs(struct perf_event *event, u64 slots, } } +static inline void _intel_update_topdown_event (struct perf_event *event, +u64 slots,u64 metrics, +u64 last_slots,u64 last_metrics) +{ +if (is_vmetrics_event (event)) +__icl_update_vmetrics_event (event, metrics); +else +__icl_update_topdown_event (event, slots, metrics, + last_slots, last_metrics); +} +/* * Update all active Topdown events. *
@@ -2654,9 +2674,9 @@ static u64 intel_update_topdown_event(struct perf_event *event, int metric_end)if (!is_topdown_idx (idx))continue ; other = cpuc->events[idx]; -__icl_update_topdown_event (other, slots, metrics, - event ? event->hw.saved_slots :0 , - event ? event->hw.saved_metric :0 ); +_intel_update_topdown_event (other, slots, metrics, + event ? event->hw.saved_slots :0 , + event ? event->hw.saved_metric :0 ); }/*
@@ -2664,9 +2684,9 @@ static u64 intel_update_topdown_event(struct perf_event *event, int metric_end)* in active_mask e.g. x86_pmu_stop() */ if (event && !test_bit (event->hw.idx, cpuc->active_mask)) { -__icl_update_topdown_event (event, slots, metrics, - event->hw.saved_slots, - event->hw.saved_metric); +_intel_update_topdown_event (event, slots, metrics, + event->hw.saved_slots, + event->hw.saved_metric);/* * In x86_pmu_stop(), the event is cleared in active_mask first,
@@ -3847,8 +3867,9 @@ static int core_pmu_hw_config(struct perf_event *event)static bool is_available_metric_event (struct perf_event *event) { -return is_metric_event (event) && - event->attr.config <=INTEL_TD_METRIC_AVAILABLE_MAX ; +return (is_metric_event (event) && + event->attr.config <=INTEL_TD_METRIC_AVAILABLE_MAX ) || +is_vmetrics_event (event); }static inline bool is_mem_loads_event (struct perf_event *event)
arch/x86/events/perf_event.h +8 -1
@@ -105,9 +105,16 @@ static inline bool is_slots_event(struct perf_event *event)return (event->attr.config &INTEL_ARCH_EVENT_MASK ) ==INTEL_TD_SLOTS ; } +static inline bool is_vmetrics_event (struct perf_event *event) +{ +return (event->attr.config &INTEL_ARCH_EVENT_MASK ) == +INTEL_FIXED_VMETRICS_EVENT ; +} +static inline bool is_topdown_event (struct perf_event *event) { -return is_metric_event (event) ||is_slots_event (event); +return is_metric_event (event) ||is_slots_event (event) || +is_vmetrics_event (event); }struct amd_nb {
Signature · 1 line
2.34.1
PATCH v2 10/13 KVM: x86/pmu: Extend pmc_reprogram_counter() to create group events
In reply to Dapeng MiCurrent perf code creates a events group which contains a slots event that acts as group leader and multiple metric events to support the topdown perf metrics feature. To support the topdown metrics feature in KVM and reduce the changes for perf system at the same time, we follow this mature mechanism and create a events group in KVM. The events group contains a slots event which claims the fixed counter 3 and act as group leader as perf system requires, and a virtual metrics event which claims PERF_METRICS MSR. This events group would be scheduled as a whole by the perf system.
Unfortunately the function pmc_reprogram_counter() can only create a single event for every counter, so this change extends the function and makes it have the capability to create a events group.
--- arch/x86/include/asm/kvm_host.h | 11 +++++- arch/x86/kvm/pmu.c | 65 ++++++++++++++++++++++++++------- arch/x86/kvm/pmu.h | 22 ++++++++--- arch/x86/kvm/svm/pmu.c | 2 + arch/x86/kvm/vmx/pmu_intel.c | 4 ++ 5 files changed, 84 insertions(+), 20 deletions(-)
arch/x86/include/asm/kvm_host.h +10 -1
@@ -490,12 +490,12 @@ enum pmc_type {struct kvm_pmc {enum pmc_type type;u8 idx; +u8 max_nr_events;bool is_paused;bool intr;u64 counter;u64 prev_counter;u64 eventsel; -struct perf_event *perf_event;struct kvm_vcpu *vcpu;/* * only for creating or reusing perf_event,
@@ -503,6 +503,15 @@ struct kvm_pmc {* ctrl value for fixed counters. */ u64 current_config; +/* +* Non-leader events may need some extra information, +* this field can be used to store this information. +*/ +u64 extra_config; +union { +struct perf_event *perf_event; + DECLARE_FLEX_ARRAY(struct perf_event *, perf_events); + }; };/* More counters may conflict with other existing Architectural MSRs */
arch/x86/kvm/pmu.c +52 -13
116 lines not on this page · raw message
arch/x86/kvm/pmu.h +16 -6
@@ -74,21 +74,31 @@ static inline u64 pmc_read_counter(struct kvm_pmc *pmc)return counter &pmc_bitmask (pmc); } -static inline void pmc_release_perf_event (struct kvm_pmc *pmc) +static inline void pmc_release_perf_event (struct kvm_pmc *pmc,bool reset) { -if (pmc->perf_event) { -perf_event_release_kernel (pmc->perf_event); - pmc->perf_event =NULL ; - pmc->current_config =0 ; +unsigned int i; + +if (!pmc->perf_event) +return ; + +for (i =0 ; i < pmc->max_nr_events; i++) { +perf_event_release_kernel (pmc->perf_events[i]); + pmc->perf_events[i] =NULL ;pmc_to_pmu (pmc)->event_count--; } + +if (reset) { + pmc->current_config =0 ; + pmc->extra_config =0 ; + pmc->max_nr_events =1 ; + } }static inline void pmc_stop_counter (struct kvm_pmc *pmc) {if (pmc->perf_event) { pmc->counter =pmc_read_counter (pmc); -pmc_release_perf_event (pmc); +pmc_release_perf_event (pmc, true); } }
arch/x86/kvm/svm/pmu.c +2 -0
@@ -230,6 +230,8 @@ static void amd_pmu_init(struct kvm_vcpu *vcpu) pmu->gp_counters[i].vcpu = vcpu; pmu->gp_counters[i].idx = i; pmu->gp_counters[i].current_config =0 ; + pmu->gp_counters[i].extra_config =0 ; + pmu->gp_counters[i].max_nr_events =1 ; } }
arch/x86/kvm/vmx/pmu_intel.c +4 -0
@@ -628,6 +628,8 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu) pmu->gp_counters[i].vcpu = vcpu; pmu->gp_counters[i].idx = i; pmu->gp_counters[i].current_config =0 ; + pmu->gp_counters[i].extra_config =0 ; + pmu->gp_counters[i].max_nr_events =1 ; }for (i =0 ; i <KVM_PMC_MAX_FIXED ; i++) {
@@ -635,6 +637,8 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu) pmu->fixed_counters[i].vcpu = vcpu; pmu->fixed_counters[i].idx = i +INTEL_PMC_IDX_FIXED ; pmu->fixed_counters[i].current_config =0 ; + pmu->fixed_counters[i].extra_config =0 ; + pmu->fixed_counters[i].max_nr_events =1 ; } lbr_desc->records.nr =0 ;
Signature · 1 line
2.34.1
PATCH v2 11/13 KVM: x86/pmu: Support topdown perf metrics feature
In reply to Dapeng MiThis patch adds topdown perf metrics support for KVM. The topdown perf metrics is a feature on Intel CPUs which supports the TopDown Microarchitecture Analysis (TMA) Method. TMA is a structured analysis methodology to identify critical performance bottlenecks in out-of-order processors. The details about topdown metrics support on Intel processors can be found in section "Performance Metrics" of Intel's SDM.
Intel chips use fixed counter 3 and PERF_METRICS MSR together to support topdown metrics feature. Fix counter 3 counts the elapsed cpu slots, PERF_METRICS reports the topdown metrics percentage.
Generally speaking, KVM has no method to know guest is running a solo slots event counting/sampling or guest is profiling the topdown perf metrics if KVM only observes the fixed counter 3. Fortunately we know topdown metrics profiling always manipulate fixed counter 3 and PERF_METRICS MSR together with a fixed sequence, FIXED_CTR3 MSR is written firstly and then PERF_METRICS follows. So we can assume topdown metrics profiling is running in guest if KVM observes PERF_METRICS writing.
In current perf logic, an events group is required to handle the topdown metrics profiling, and the events group couples a slots event which acts events group leader and multiple metric events. To coordinate with the perf topdown metrics handing logic and reduce the code changes in KVM, we choose to follow current mature vPMU PMC emulation framework. The only difference is that we need to create a events group for fixed counter 3 and manipulate FIXED_CTR3 and PERF_METRICS MSRS together instead of a single event and only manipulating FIXED_CTR3 MSR.
When guest write PERF_METRICS MSR at first, KVM would create an event group which couples a slots event and a virtual metrics event. In this event group, slots event claims the fixed counter 3 HW resource and acts as group leader which is required by perf system. The virtual metrics event claims the PERF_METRICS MSR. This event group is just like the perf metrics events group on host and is scheduled by host perf system.
In this proposal, the count of slots event is calculated and emulated on host and returned to guest just like other normal counters, but there is a difference for the metrics event processing. KVM doesn't calculate the real count of topdown metrics, it just stores the raw data of PERF_METRICS MSR and directly returns the stored raw data to guest. Thus, guest can get the real HW PERF_METRICS data and guarantee the calculation accuracy of topdown metrics.
The whole procedure can be summarized as below.
1. KVM intercepts PERF_METRICS MSR writing and marks fixed counter 3 enter topdown profiling mode (set the max_nr_events of fixed counter 3 to 2) if it's not.
2. If the topdown metrics events group doesn't exist, create the events group firstly, and then update the saved slots count and metrics data of the group events with guest values. At last, enable the events and make the guest values are loaded into HW FIXED_CTR3 and PERF_METRICS MSRs.
3. Modify kvm_pmu_rdpmc() function to return PERF_METRICS MSR raw data to guest directly.
--- arch/x86/include/asm/kvm_host.h | 6 ++++ arch/x86/kvm/pmu.c | 62 +++++++++++++++++++++++++++++++-- arch/x86/kvm/pmu.h | 28 +++++++++++++++ arch/x86/kvm/vmx/capabilities.h | 1 + arch/x86/kvm/vmx/pmu_intel.c | 48 +++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.h | 5 +++ arch/x86/kvm/x86.c | 1 + 7 files changed, 149 insertions(+), 2 deletions(-)
arch/x86/include/asm/kvm_host.h +6 -0
@@ -487,6 +487,12 @@ enum pmc_type { KVM_PMC_FIXED, }; +enum topdown_events { +KVM_TD_SLOTS =0 , +KVM_TD_METRICS =1 , +KVM_TD_EVENTS_MAX =2 , +}; +struct kvm_pmc {enum pmc_type type;u8 idx;
arch/x86/kvm/pmu.c +60 -2
104 lines not on this page · raw message
arch/x86/kvm/pmu.h +28 -0
@@ -257,6 +257,34 @@ static inline bool pmc_is_globally_enabled(struct kvm_pmc *pmc)return test_bit (pmc->idx, (unsigned long *)&pmu->global_ctrl); } +static inline int pmc_is_topdown_metrics_used (struct kvm_pmc *pmc) +{ +return (pmc->idx ==INTEL_PMC_IDX_FIXED_SLOTS ) && + (pmc->max_nr_events ==KVM_TD_EVENTS_MAX ); +} + +static inline int pmc_is_topdown_metrics_active (struct kvm_pmc *pmc) +{ +return pmc_is_topdown_metrics_used (pmc) && + pmc->perf_events[KVM_TD_METRICS ]; +} + +static inline void pmc_update_topdown_metrics (struct kvm_pmc *pmc) +{ +struct perf_event *event; +int i; + +struct td_metrics td_metrics = { + .slots = pmc->counter, + .metric = pmc->extra_config, + }; + +for (i =0 ; i < pmc->max_nr_events; i++) { + event = pmc->perf_events[i]; +perf_event_topdown_metrics (event, &td_metrics); + } +} +void kvm_pmu_deliver_pmi (struct kvm_vcpu *vcpu);void kvm_pmu_handle_event (struct kvm_vcpu *vcpu);int kvm_pmu_rdpmc (struct kvm_vcpu *vcpu,unsigned pmc,u64 *data);
arch/x86/kvm/vmx/capabilities.h +1 -0
@@ -22,6 +22,7 @@ extern int __read_mostly pt_mode;#define PT_MODE_HOST_GUEST 1#define PMU_CAP_FW_WRITES (1ULL << 13) +#define PMU_CAP_PERF_METRICS BIT_ULL(15)#define PMU_CAP_LBR_FMT 0x3fstruct nested_vmx_msrs {
arch/x86/kvm/vmx/pmu_intel.c +48 -0
72 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.h +5 -0
@@ -670,6 +670,11 @@ static inline bool intel_pmu_lbr_is_enabled(struct kvm_vcpu *vcpu)return !!vcpu_to_lbr_records (vcpu)->nr; } +static inline bool intel_pmu_metrics_is_enabled (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.perf_capabilities &PMU_CAP_PERF_METRICS ; +} +void intel_pmu_cross_mapped_check (struct kvm_pmu *pmu);int intel_pmu_create_guest_lbr_event (struct kvm_vcpu *vcpu);void vmx_passthrough_lbr_msrs (struct kvm_vcpu *vcpu);
arch/x86/kvm/x86.c +1 -0
@@ -1463,6 +1463,7 @@ static const u32 msrs_to_save_pmu[] = {MSR_CORE_PERF_FIXED_CTR_CTRL ,MSR_CORE_PERF_GLOBAL_STATUS ,MSR_CORE_PERF_GLOBAL_CTRL ,MSR_CORE_PERF_GLOBAL_OVF_CTRL ,MSR_IA32_PEBS_ENABLE ,MSR_IA32_DS_AREA ,MSR_PEBS_DATA_CFG , +MSR_PERF_METRICS ,/* This part of MSRs should match KVM_INTEL_PMC_MAX_GENERIC. */ MSR_ARCH_PERFMON_PERFCTR0, MSR_ARCH_PERFMON_PERFCTR1,
Signature · 1 line
2.34.1
PATCH v2 12/13 KVM: x86/pmu: Handle PERF_METRICS overflow
In reply to Dapeng MiWhen the fixed counter 3 overflows, the PMU would also triggers an PERF_METRICS overflow subsequently. This patch handles the PERF_METRICS overflow case, it would inject an PMI into guest and set the PERF_METRICS overflow bit in PERF_GLOBAL_STATUS MSR after detecting PERF_METRICS overflow on host.
--- arch/x86/events/intel/core.c | 7 ++++++- arch/x86/kvm/pmu.c | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)
arch/x86/events/intel/core.c +6 -1
@@ -3042,8 +3042,13 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)* Intel Perf metrics */ if (__test_and_clear_bit (GLOBAL_STATUS_PERF_METRICS_OVF_BIT , (unsigned long *)&status)) { +struct perf_event *event = cpuc->events[GLOBAL_STATUS_PERF_METRICS_OVF_BIT ]; + handled++; -static_call (intel_pmu_update_topdown_event)(NULL ); +if (event &&is_vmetrics_event (event)) +READ_ONCE (event->overflow_handler)(event, &data, regs); +else +static_call (intel_pmu_update_topdown_event)(NULL ); }/*
arch/x86/kvm/pmu.c +15 -4
@@ -101,7 +101,7 @@ static void kvm_pmi_trigger_fn(struct irq_work *irq_work)kvm_pmu_deliver_pmi (vcpu); } -static inline void __kvm_perf_overflow (struct kvm_pmc *pmc,bool in_pmi) +static inline void __kvm_perf_overflow (struct kvm_pmc *pmc,bool in_pmi,bool metrics_of) {struct kvm_pmu *pmu =pmc_to_pmu (pmc);bool skip_pmi = false;
@@ -121,7 +121,11 @@ static inline void __kvm_perf_overflow(struct kvm_pmc *pmc, bool in_pmi) (unsigned long *)&pmu->global_status); } }else { -__set_bit (pmc->idx, (unsigned long *)&pmu->global_status); +if (metrics_of) +__set_bit (GLOBAL_STATUS_PERF_METRICS_OVF_BIT , + (unsigned long *)&pmu->global_status); +else +__set_bit (pmc->idx, (unsigned long *)&pmu->global_status); }if (!pmc->intr || skip_pmi)
@@ -141,11 +145,18 @@ static inline void __kvm_perf_overflow(struct kvm_pmc *pmc, bool in_pmi)kvm_make_request (KVM_REQ_PMI , pmc->vcpu); } +static inline bool is_vmetrics_event (struct perf_event *event) +{ +return (event->attr.config &INTEL_ARCH_EVENT_MASK ) == +INTEL_FIXED_VMETRICS_EVENT ; +} +static void kvm_perf_overflow (struct perf_event *perf_event,struct perf_sample_data *data,struct pt_regs *regs) {struct kvm_pmc *pmc = perf_event->overflow_handler_context; +bool metrics_of =is_vmetrics_event (perf_event);/* * Ignore overflow events for counters that are scheduled to be
@@ -155,7 +166,7 @@ static void kvm_perf_overflow(struct perf_event *perf_event,if (test_and_set_bit (pmc->idx,pmc_to_pmu (pmc)->reprogram_pmi))return ; -__kvm_perf_overflow (pmc, true); +__kvm_perf_overflow (pmc, true, metrics_of);kvm_make_request (KVM_REQ_PMU , pmc->vcpu); }
@@ -491,7 +502,7 @@ static void reprogram_counter(struct kvm_pmc *pmc) goto reprogram_complete;if (pmc->counter < pmc->prev_counter) -__kvm_perf_overflow (pmc, false); +__kvm_perf_overflow (pmc, false, false);if (eventsel &ARCH_PERFMON_EVENTSEL_PIN_CONTROL )printk_once ("kvm pmu: pin control bit is ignored\n" );
Signature · 1 line
2.34.1
PATCH v2 13/13 KVM: x86/pmu: Expose Topdown in MSR_IA32_PERF_CAPABILITIES
In reply to Dapeng MiTopdown support is enumerated via IA32_PERF_CAPABILITIES[bit 15]. Enable this bit for guest when the feature is available on host.
--- arch/x86/kvm/vmx/pmu_intel.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 2 ++ 2 files changed, 5 insertions(+)
arch/x86/kvm/vmx/pmu_intel.c +3 -0
@@ -614,6 +614,9 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) (((1ull << pmu->nr_arch_fixed_counters) - 1) << INTEL_PMC_IDX_FIXED)); pmu->global_ctrl_mask = counter_mask; +if (intel_pmu_metrics_is_enabled (vcpu)) + pmu->global_ctrl_mask &= ~(1ULL <<GLOBAL_CTRL_EN_PERF_METRICS ); +/* * GLOBAL_STATUS and GLOBAL_OVF_CONTROL (a.k.a. GLOBAL_STATUS_RESET) * share reserved bit definitions. The kernel just happens to use
arch/x86/kvm/vmx/vmx.c +2 -0
@@ -7831,6 +7831,8 @@ static u64 vmx_get_perf_capabilities(void) perf_cap &= ~PERF_CAP_PEBS_BASELINE ; } + perf_cap |= host_perf_cap &PMU_CAP_PERF_METRICS ; +return perf_cap; }
Signature · 1 line
2.34.1