lkml.org 
[lkml]   [2023]   [Oct]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 2/3] perf/arm-cmn: Rework DTC counters (again)
From
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.

\
 
 \ /
  Last update: 2023-10-23 16:15    [W:0.095 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site