Re: [PATCH v5 2/3] sched/topology: Introduce for_each_numa_hop_mask()

From: Andy Shevchenko
Date: Fri Oct 21 2022 - 09:17:36 EST


On Fri, Oct 21, 2022 at 01:19:26PM +0100, Valentin Schneider wrote:
> The recently introduced sched_numa_hop_mask() exposes cpumasks of CPUs
> reachable within a given distance budget, wrap the logic for iterating over
> all (distance, mask) values inside an iterator macro.

...

> #ifdef CONFIG_NUMA
> -extern const struct cpumask *sched_numa_hop_mask(int node, int hops);
> +extern const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int hops);
> #else
> -static inline const struct cpumask *sched_numa_hop_mask(int node, int hops)
> +static inline const struct cpumask *
> +sched_numa_hop_mask(unsigned int node, unsigned int hops)
> {
> - if (node == NUMA_NO_NODE && !hops)
> - return cpu_online_mask;
> -
> return ERR_PTR(-EOPNOTSUPP);
> }
> #endif /* CONFIG_NUMA */

I didn't get how the above two changes are related to the 3rd one which
introduces a for_each type of macro.

If you need change int --> unsigned int, perhaps it can be done in a separate
patch.

The change inside inliner I dunno about. Not an expert.

...

> +#define for_each_numa_hop_mask(mask, node) \
> + for (unsigned int __hops = 0; \
> + /* \
> + * Unsightly trickery required as we can't both initialize \
> + * @mask and declare __hops in for()'s first clause \
> + */ \
> + mask = __hops > 0 ? mask : \
> + node == NUMA_NO_NODE ? \
> + cpu_online_mask : sched_numa_hop_mask(node, 0), \
> + !IS_ERR_OR_NULL(mask); \

> + __hops++, \
> + mask = sched_numa_hop_mask(node, __hops))

This can be unified with conditional, see for_each_gpio_desc_with_flag() as
example how.

--
With Best Regards,
Andy Shevchenko