[PATCH] sched/rt: Slightly optimize 'init_rt_rq()'

From: Christophe JAILLET
Date: Sun Nov 14 2021 - 11:16:20 EST


'MAX_RT_PRIO' is 100. Instead of clearing bits in 'array->bitmap' one at a
time, use 'bitmap_clear()' which will do the same but much faster

Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
Not sure that this patch is really of any use, but it is the occasion for
me to spot that there seems to be an off by one in the rt scheduler.

'array->bitmap' is MAX_RT_PRIO+1 long. (see [1])
The last bit seems to be reserved as a sentinel.

Shouldn't this sentinel, in the code above, be set as:
__set_bit(MAX_RT_PRIO + 1, array->bitmap);
?

I don't know if it is an issue or not, but it looks odd to me.

[1]: https://elixir.bootlin.com/linux/latest/source/kernel/sched/sched.h#L254
---
kernel/sched/rt.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index bb945f8faeca..fc2e9c5e874a 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -81,10 +81,9 @@ void init_rt_rq(struct rt_rq *rt_rq)
int i;

array = &rt_rq->active;
- for (i = 0; i < MAX_RT_PRIO; i++) {
+ for (i = 0; i < MAX_RT_PRIO; i++)
INIT_LIST_HEAD(array->queue + i);
- __clear_bit(i, array->bitmap);
- }
+ bitmap_clear(array->bitmap, 0, MAX_RT_PRIO);
/* delimiter for bitsearch: */
__set_bit(MAX_RT_PRIO, array->bitmap);

--
2.30.2