[PATCH 2/3] perf/arm-cmn: Rework DTC counters (again)

Robin Murphy robin.murphy at arm.com
Mon Oct 23 07:14:09 PDT 2023


On 2023-10-23 10:06, Mark Rutland wrote:
> On Fri, Oct 20, 2023 at 03:50:30PM -0700, Ilkka Koskinen wrote:
>> Hi Robin,
>>
>> I have one comment, otherwise the patch looks good to me.
> 
>>> +/* @i is the DTC number, @idx is the counter index on that DTC */
>>> +#define for_each_hw_dtc_idx(hw, i, idx) \
>>> +	for (int i = 0, idx; i < CMN_MAX_DTCS; i++) if ((idx = hw->dtc_idx[i]) >= 0)
>>
>> Isn't that "idx" unnecessary in the initialization?
> 
> That creates the 'idx' variable that's assigned to by `idx = hw->dtc_idx[i]`,
> so that is necessary.

Right, the intent is to take advantage of locally-scoped iterator 
variables since they're a nice thing, but completely-implicit 
definitions aren't so nice (at best they'd be surprising, at worst they 
could confusingly shadow existing variables in the outer scope), so the 
macro invoker still provides their names to at least give some visible 
context to their use within the loop body.

I guess this is still a fairly new paradigm since the C11 switch, and 
I'm not aware of any "standard" style for such iterator macros yet, so I 
just did what seemed most logical.

Thanks,
Robin.



More information about the linux-arm-kernel mailing list