perf/x86/intel: Use switch in intel_pmu_disable/enable_event
authorKan Liang <kan.liang@linux.intel.com>
Thu, 23 Jul 2020 17:11:09 +0000 (10:11 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 18 Aug 2020 14:34:36 +0000 (16:34 +0200)
commit58da7dbe6f036fefe504a4bb452afbd39bba73f7
treed4ff8a79da69b742f5d51d50d1254f148e4952b3
parentbbdbde2a415d9f479803266cae6fb0c1a9f6c80e
perf/x86/intel: Use switch in intel_pmu_disable/enable_event

Currently, the if-else is used in the intel_pmu_disable/enable_event to
check the type of an event. It works well, but with more and more types
added later, e.g., perf metrics, compared to the switch statement, the
if-else may impair the readability of the code.

There is no harm to use the switch statement to replace the if-else
here. Also, some optimizing compilers may compile a switch statement
into a jump-table which is more efficient than if-else for a large
number of cases. The performance gain may not be observed for now,
because the number of cases is only 5, but the benefits may be observed
with more and more types added in the future.

Use switch to replace the if-else in the intel_pmu_disable/enable_event.

If the idx is invalid, print a warning.

For the case INTEL_PMC_IDX_FIXED_BTS in intel_pmu_disable_event, don't
need to check the event->attr.precise_ip. Use return for the case.

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200723171117.9918-7-kan.liang@linux.intel.com
arch/x86/events/intel/core.c