Skip to content

Commit be857b7

Browse files
Thomas RichterAlexander Gordeev
authored andcommitted
s390/cpumf: Handle events cycles and instructions identical
Events CPU_CYCLES and INSTRUCTIONS can be submitted with two different perf_event attribute::type values: - PERF_TYPE_HARDWARE: when invoked via perf tool predefined events name cycles or cpu-cycles or instructions. - pmu->type: when invoked via perf tool event name cpu_cf/CPU_CYLCES/ or cpu_cf/INSTRUCTIONS/. This invocation also selects the PMU to which the event belongs. Handle both type of invocations identical for events CPU_CYLCES and INSTRUCTIONS. They address the same hardware. The result is different when event modifier exclude_kernel is also set. Invocation with event modifier for user space event counting fails. Output before: # perf stat -e cpum_cf/cpu_cycles/u -- true Performance counter stats for 'true': <not supported> cpum_cf/cpu_cycles/u 0.000761033 seconds time elapsed 0.000076000 seconds user 0.000725000 seconds sys # Output after: # perf stat -e cpum_cf/cpu_cycles/u -- true Performance counter stats for 'true': 349,613 cpum_cf/cpu_cycles/u 0.000844143 seconds time elapsed 0.000079000 seconds user 0.000800000 seconds sys # Fixes: 6a82e23 ("s390/cpumf: Adjust registration of s390 PMU device drivers") Signed-off-by: Thomas Richter <[email protected]> Acked-by: Sumanth Korikkar <[email protected]> [[email protected] corrected commit ID of Fixes commit] Signed-off-by: Alexander Gordeev <[email protected]>
1 parent af2debd commit be857b7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

arch/s390/kernel/perf_cpum_cf.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,26 @@ static int __hw_perf_event_init(struct perf_event *event, unsigned int type)
516516
return err;
517517
}
518518

519+
/* Events CPU_CYLCES and INSTRUCTIONS can be submitted with two different
520+
* attribute::type values:
521+
* - PERF_TYPE_HARDWARE:
522+
* - pmu->type:
523+
* Handle both type of invocations identical. They address the same hardware.
524+
* The result is different when event modifiers exclude_kernel and/or
525+
* exclude_user are also set.
526+
*/
527+
static int cpumf_pmu_event_type(struct perf_event *event)
528+
{
529+
u64 ev = event->attr.config;
530+
531+
if (cpumf_generic_events_basic[PERF_COUNT_HW_CPU_CYCLES] == ev ||
532+
cpumf_generic_events_basic[PERF_COUNT_HW_INSTRUCTIONS] == ev ||
533+
cpumf_generic_events_user[PERF_COUNT_HW_CPU_CYCLES] == ev ||
534+
cpumf_generic_events_user[PERF_COUNT_HW_INSTRUCTIONS] == ev)
535+
return PERF_TYPE_HARDWARE;
536+
return PERF_TYPE_RAW;
537+
}
538+
519539
static int cpumf_pmu_event_init(struct perf_event *event)
520540
{
521541
unsigned int type = event->attr.type;
@@ -525,7 +545,7 @@ static int cpumf_pmu_event_init(struct perf_event *event)
525545
err = __hw_perf_event_init(event, type);
526546
else if (event->pmu->type == type)
527547
/* Registered as unknown PMU */
528-
err = __hw_perf_event_init(event, PERF_TYPE_RAW);
548+
err = __hw_perf_event_init(event, cpumf_pmu_event_type(event));
529549
else
530550
return -ENOENT;
531551

0 commit comments

Comments
 (0)