Re: [PATCH 3/7] sched/topology: Introduce for_each_node_numadist() iterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 13, 2025 at 11:02:44AM -0500, Yury Norov wrote:
...
> > Cc: Yury Norov <yury.norov@xxxxxxxxx>
> > Signed-off-by: Andrea Righi <arighi@xxxxxxxxxx>
> 
> Suggested-by: Yury Norov [NVIDIA] <yury.norov@xxxxxxxxx>

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




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux