Re: [PATCH V6 06/14] perf/x86/intel: Use switch in intel_pmu_disable/enable_event
From: Liang, Kan
Date: Mon Jul 20 2020 - 15:02:58 EST
On 7/20/2020 12:22 PM, Peter Zijlstra wrote:
On Fri, Jul 17, 2020 at 07:05:46AM -0700, kan.liang@xxxxxxxxxxxxxxx wrote:
From: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
Many items are checked in the intel_pmu_disable/enable_event. More items
will be added later, e.g. perf metrics events.
Use switch, which is more efficient, to replace the if-else.
Perhaps explain how; does this actually generate a jump-table?
As my understanding, some optimizing compilers may compile a switch
statement into a jump-table. So it depends.
Another advantage of switch statement is to improve the readability of
the code. I think I missed it in the commit message.
I will change the commit message as below in V7.
"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.
Also, some optimizing compilers may compile a switch statement into a
jump-table which is more efficient than if-else.
Use switch to replace the if-else in the intel_pmu_disable/enable_event()."
Thanks,
Kan