* [PATCH] sched: simplify sched_init_numa()
@ 2025-07-19 21:07 Yury Norov
2025-07-21 8:32 ` Srikar Dronamraju
0 siblings, 1 reply; 4+ messages in thread
From: Yury Norov @ 2025-07-19 21:07 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
Cc: Yury Norov
From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
The function opencodes for_each_set_bit() macro.
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
kernel/sched/topology.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index b958fe48e020..7dc3c79aa480 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -1932,10 +1932,9 @@ void sched_init_numa(int offline_node)
return;
}
- for (i = 0, j = 0; i < nr_levels; i++, j++) {
- j = find_next_bit(distance_map, NR_DISTANCE_VALUES, j);
- distances[i] = j;
- }
+ for_each_set_bit(j, distance_map, NR_DISTANCE_VALUES)
+ distances[i++] = j;
+
rcu_assign_pointer(sched_domains_numa_distance, distances);
bitmap_free(distance_map);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sched: simplify sched_init_numa()
2025-07-19 21:07 [PATCH] sched: simplify sched_init_numa() Yury Norov
@ 2025-07-21 8:32 ` Srikar Dronamraju
2025-08-19 8:52 ` Valentin Schneider
0 siblings, 1 reply; 4+ messages in thread
From: Srikar Dronamraju @ 2025-07-21 8:32 UTC (permalink / raw)
To: Yury Norov
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, linux-kernel
* Yury Norov <yury.norov@gmail.com> [2025-07-19 17:07:51]:
> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
>
> The function opencodes for_each_set_bit() macro.
>
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> ---
> kernel/sched/topology.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index b958fe48e020..7dc3c79aa480 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -1932,10 +1932,9 @@ void sched_init_numa(int offline_node)
> return;
> }
>
> - for (i = 0, j = 0; i < nr_levels; i++, j++) {
> - j = find_next_bit(distance_map, NR_DISTANCE_VALUES, j);
> - distances[i] = j;
> - }
> + for_each_set_bit(j, distance_map, NR_DISTANCE_VALUES)
> + distances[i++] = j;
> +
Dont we need to reset the value of i;
Also now we may be iterating for NR_DISTANCE_VALUES instead of nr_levels.
It should be okay, since NR_DISTANCE_VALUES is just 8.
> rcu_assign_pointer(sched_domains_numa_distance, distances);
>
> bitmap_free(distance_map);
> --
> 2.43.0
>
--
Thanks and Regards
Srikar Dronamraju
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched: simplify sched_init_numa()
2025-07-21 8:32 ` Srikar Dronamraju
@ 2025-08-19 8:52 ` Valentin Schneider
2025-08-19 14:14 ` Yury Norov
0 siblings, 1 reply; 4+ messages in thread
From: Valentin Schneider @ 2025-08-19 8:52 UTC (permalink / raw)
To: Srikar Dronamraju, Yury Norov
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
linux-kernel
On 21/07/25 14:02, Srikar Dronamraju wrote:
> * Yury Norov <yury.norov@gmail.com> [2025-07-19 17:07:51]:
>
>> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
>>
>> The function opencodes for_each_set_bit() macro.
>>
>> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
>> ---
>> kernel/sched/topology.c | 7 +++----
>> 1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
>> index b958fe48e020..7dc3c79aa480 100644
>> --- a/kernel/sched/topology.c
>> +++ b/kernel/sched/topology.c
>> @@ -1932,10 +1932,9 @@ void sched_init_numa(int offline_node)
>> return;
>> }
>>
>> - for (i = 0, j = 0; i < nr_levels; i++, j++) {
>> - j = find_next_bit(distance_map, NR_DISTANCE_VALUES, j);
>> - distances[i] = j;
>> - }
>> + for_each_set_bit(j, distance_map, NR_DISTANCE_VALUES)
>> + distances[i++] = j;
>> +
>
> Dont we need to reset the value of i;
>
That.
> Also now we may be iterating for NR_DISTANCE_VALUES instead of nr_levels.
> It should be okay, since NR_DISTANCE_VALUES is just 8.
>
DISTANCE_BITS is 8, NR_DISTANCE_VALUES is 1 << 8 aka 256.
But here the use of for_each_set_bit() means we'll get just one extra
iteration compared to using `nr_levels`. That said, since we *have* to
compute `nr_levels` to allocate sched_domains_numa_distance, IMO we're not
gaining much by using for_each_set_bit() here.
>> rcu_assign_pointer(sched_domains_numa_distance, distances);
>>
>> bitmap_free(distance_map);
>> --
>> 2.43.0
>>
>
> --
> Thanks and Regards
> Srikar Dronamraju
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sched: simplify sched_init_numa()
2025-08-19 8:52 ` Valentin Schneider
@ 2025-08-19 14:14 ` Yury Norov
0 siblings, 0 replies; 4+ messages in thread
From: Yury Norov @ 2025-08-19 14:14 UTC (permalink / raw)
To: Valentin Schneider
Cc: Srikar Dronamraju, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, linux-kernel
On Tue, Aug 19, 2025 at 10:52:19AM +0200, Valentin Schneider wrote:
> On 21/07/25 14:02, Srikar Dronamraju wrote:
> > * Yury Norov <yury.norov@gmail.com> [2025-07-19 17:07:51]:
> >
> >> From: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> >>
> >> The function opencodes for_each_set_bit() macro.
> >>
> >> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
> >> ---
> >> kernel/sched/topology.c | 7 +++----
> >> 1 file changed, 3 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> >> index b958fe48e020..7dc3c79aa480 100644
> >> --- a/kernel/sched/topology.c
> >> +++ b/kernel/sched/topology.c
> >> @@ -1932,10 +1932,9 @@ void sched_init_numa(int offline_node)
> >> return;
> >> }
> >>
> >> - for (i = 0, j = 0; i < nr_levels; i++, j++) {
> >> - j = find_next_bit(distance_map, NR_DISTANCE_VALUES, j);
> >> - distances[i] = j;
> >> - }
> >> + for_each_set_bit(j, distance_map, NR_DISTANCE_VALUES)
> >> + distances[i++] = j;
> >> +
> >
> > Dont we need to reset the value of i;
> >
>
> That.
Yes we need.
> > Also now we may be iterating for NR_DISTANCE_VALUES instead of nr_levels.
> > It should be okay, since NR_DISTANCE_VALUES is just 8.
> >
>
> DISTANCE_BITS is 8, NR_DISTANCE_VALUES is 1 << 8 aka 256.
I mistaken this DISTANCE_BITS vs NR_DISTANCE_VALUES. The first one is
8, so we can benefit from small_const_nbits() optimization. But we
actually iterate over NR_DISTANCE_VALUES - and no benefit for using
it over nr_levels.
> But here the use of for_each_set_bit() means we'll get just one extra
> iteration compared to using `nr_levels`. That said, since we *have* to
> compute `nr_levels` to allocate sched_domains_numa_distance, IMO we're not
> gaining much by using for_each_set_bit() here.
I'm not sure I understand that. If we switch the loop terminator to
nr_levels, the for_each() will be the exact functional equivalent.
I'll get back to this function shortly and send v2.
Thanks for the discussion.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-19 14:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-19 21:07 [PATCH] sched: simplify sched_init_numa() Yury Norov
2025-07-21 8:32 ` Srikar Dronamraju
2025-08-19 8:52 ` Valentin Schneider
2025-08-19 14:14 ` Yury Norov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).