Skip to content

Commit 2ac4980

Browse files
YuryNorovkuba-moo
authored andcommitted
lib/cpumask: update comment for cpumask_local_spread()
Now that we have an iterator-based alternative for a very common case of using cpumask_local_spread for all cpus in a row, it's worth to mention that in comment to cpumask_local_spread(). Signed-off-by: Yury Norov <yury.norov@gmail.com> Reviewed-by: Valentin Schneider <vschneid@redhat.com> Reviewed-by: Tariq Toukan <tariqt@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2acda57 commit 2ac4980

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

lib/cpumask.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,29 @@ void __init free_bootmem_cpumask_var(cpumask_var_t mask)
114114
* @i: index number
115115
* @node: local numa_node
116116
*
117-
* This function selects an online CPU according to a numa aware policy;
118-
* local cpus are returned first, followed by non-local ones, then it
119-
* wraps around.
117+
* Returns online CPU according to a numa aware policy; local cpus are returned
118+
* first, followed by non-local ones, then it wraps around.
120119
*
121-
* It's not very efficient, but useful for setup.
120+
* For those who wants to enumerate all CPUs based on their NUMA distances,
121+
* i.e. call this function in a loop, like:
122+
*
123+
* for (i = 0; i < num_online_cpus(); i++) {
124+
* cpu = cpumask_local_spread(i, node);
125+
* do_something(cpu);
126+
* }
127+
*
128+
* There's a better alternative based on for_each()-like iterators:
129+
*
130+
* for_each_numa_hop_mask(mask, node) {
131+
* for_each_cpu_andnot(cpu, mask, prev)
132+
* do_something(cpu);
133+
* prev = mask;
134+
* }
135+
*
136+
* It's simpler and more verbose than above. Complexity of iterator-based
137+
* enumeration is O(sched_domains_numa_levels * nr_cpu_ids), while
138+
* cpumask_local_spread() when called for each cpu is
139+
* O(sched_domains_numa_levels * nr_cpu_ids * log(nr_cpu_ids)).
122140
*/
123141
unsigned int cpumask_local_spread(unsigned int i, int node)
124142
{

0 commit comments

Comments
 (0)