[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z64ejV9BvcN_mMXh@gpd3>
Date: Thu, 13 Feb 2025 17:32:13 +0100
From: Andrea Righi <arighi@...dia.com>
To: Yury Norov <yury.norov@...il.com>
Cc: Tejun Heo <tj@...nel.org>, David Vernet <void@...ifault.com>,
Changwoo Min <changwoo@...lia.com>, Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>,
Ben Segall <bsegall@...gle.com>, Mel Gorman <mgorman@...e.de>,
Valentin Schneider <vschneid@...hat.com>,
Joel Fernandes <joel@...lfernandes.org>, Ian May <ianm@...dia.com>,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 3/7] sched/topology: Introduce for_each_node_numadist()
iterator
On Thu, Feb 13, 2025 at 11:02:44AM -0500, Yury Norov wrote:
...
> > Cc: Yury Norov <yury.norov@...il.com>
> > Signed-off-by: Andrea Righi <arighi@...dia.com>
>
> Suggested-by: Yury Norov [NVIDIA] <yury.norov@...il.com>
Ok.
>
> > ---
> > include/linux/topology.h | 30 ++++++++++++++++++++++++++++++
> > 1 file changed, 30 insertions(+)
> >
> > diff --git a/include/linux/topology.h b/include/linux/topology.h
> > index 52f5850730b3e..932d8b819c1b7 100644
> > --- a/include/linux/topology.h
> > +++ b/include/linux/topology.h
> > @@ -261,6 +261,36 @@ sched_numa_hop_mask(unsigned int node, unsigned int hops)
> > }
> > #endif /* CONFIG_NUMA */
> >
> > +/**
> > + * for_each_node_numadist() - iterate over nodes in increasing distance
> > + * order, starting from a given node
> > + * @node: the iteration variable and the starting node.
> > + * @unvisited: a nodemask to keep track of the unvisited nodes.
> > + *
> > + * This macro iterates over NUMA node IDs in increasing distance from the
> > + * starting @node and yields MAX_NUMNODES when all the nodes have been
> > + * visited.
> > + *
> > + * Note that by the time the loop completes, the @unvisited nodemask will
> > + * be fully cleared, unless the loop exits early.
> > + *
> > + * The difference between for_each_node() and for_each_node_numadist() is
> > + * that the former allows to iterate over nodes in numerical order, whereas
> > + * the latter iterates over nodes in increasing order of distance.
> > + *
> > + * This complexity of this iterator is O(N^2), where N represents the
> > + * number of nodes, as each iteration involves scanning all nodes to
> > + * find the one with the shortest distance.
> > + *
> > + * Requires rcu_lock to be held.
> > + */
> > +#define for_each_node_numadist(node, unvisited) \
> > + for (int start = (node), \
> > + node = nearest_node_nodemask((start), &(unvisited)); \
> > + node < MAX_NUMNODES; \
> > + node_clear(node, (unvisited)), \
> > + node = nearest_node_nodemask((start), &(unvisited)))
>
> the 'node' should be protected with braces inside the macro, the start should
> not because you declare it just inside. Also, the 'start' is a common word,
> so there's a chance that you'll mask out already existing 'start' in the scope.
> Maybe __start, or simply __s?
Right, will also fix this (good thing I needed to send a new version
anyway, because the test robot found a build bug). :)
Thanks!
-Andrea
Powered by blists - more mailing lists