linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/rt: Slightly optimize 'init_rt_rq()'
@ 2021-11-14 16:16 Christophe JAILLET
  2021-11-16 21:51 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-11-14 16:16 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET

'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@wanadoo.fr>
---
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sched/rt: Slightly optimize 'init_rt_rq()'
  2021-11-14 16:16 [PATCH] sched/rt: Slightly optimize 'init_rt_rq()' Christophe JAILLET
@ 2021-11-16 21:51 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2021-11-16 21:51 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	bsegall, mgorman, bristot, linux-kernel, kernel-janitors

On Sun, 14 Nov 2021 17:16:05 +0100
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> '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

I don't see this being an improvement as long as we need to keep the loop to
do the initialization of the list head.

> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> 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);

No.

The first bit is zero. The last bit in the bitmask is MAX_RT_PRIO. The
bitmask has MAX_RT_PRIO + 1 bits. Your __set_bit() above would be an off by
one error in overwriting the size of the bitmask.

-- Steve

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-16 21:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-14 16:16 [PATCH] sched/rt: Slightly optimize 'init_rt_rq()' Christophe JAILLET
2021-11-16 21:51 ` Steven Rostedt

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).