public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Silly bitmap size accounting fix
@ 2006-05-12  8:31 Steven Rostedt
  2006-05-12  9:14 ` Ingo Molnar
  0 siblings, 1 reply; 11+ messages in thread
From: Steven Rostedt @ 2006-05-12  8:31 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: akpm, LKML


Ingo,

While explaining to a colleague why you defined BITMAP_SIZE in sched.c to:

#define BITMAP_SIZE ((((MAX_PRIO+1+7)/8)+sizeof(long)-1)/sizeof(long))

and not

#define BITMAP_SIZE ((((MAX_PRIO)/8)+sizeof(long))/sizeof(long))

It dawned on me that the MAX_PRIO+1 should really be just MAX_PRIO.

Priorities go from 0 to MAX_PRIO-1 so you only need to store MAX_PRIO
bits. As you probably know since you define the array in the run queue to
only queue[MAX_PRIO] and not [MAX_PRIO+1].

So on a normal system where long is 4 bytes we get:

MAX_PRIO = 140
sizeof(long) = 4
((((MAX_PRIO+1+7)/8)+sizeof(long)-1)/sizeof(long)) = 5

And with the new fix:

((((MAX_PRIO+7)/8)+sizeof(long)-1)/sizeof(long)) = 5

So the result is the same, and hence the "Silly" part in the subject.

But although this change really has no affect on the kernel, it is still
a correctness issue, and readability issue.  The +1+7 confuses people,
especially when the +1 is not needed.

Not to mention, for those that change the kernel to use their own priority
settings, it might waste one extra word (althought this is actually not
that big of a deal).

So for correctness and readability, I'm submitting this patch.

-- Steve

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Index: linux-2.6.17-rc3-mm1/kernel/sched.c
===================================================================
--- linux-2.6.17-rc3-mm1.orig/kernel/sched.c	2006-05-12 04:02:32.000000000 -0400
+++ linux-2.6.17-rc3-mm1/kernel/sched.c	2006-05-12 04:02:39.000000000 -0400
@@ -192,7 +192,7 @@ static inline unsigned int task_timeslic
  * These are the runqueue data structures:
  */

-#define BITMAP_SIZE ((((MAX_PRIO+1+7)/8)+sizeof(long)-1)/sizeof(long))
+#define BITMAP_SIZE ((((MAX_PRIO+7)/8)+sizeof(long)-1)/sizeof(long))

 typedef struct runqueue runqueue_t;


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

end of thread, other threads:[~2006-05-14  8:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-12  8:31 [PATCH] Silly bitmap size accounting fix Steven Rostedt
2006-05-12  9:14 ` Ingo Molnar
2006-05-13  1:37   ` Nick Piggin
2006-05-13 14:12     ` Steven Rostedt
2006-05-13 14:38       ` Nick Piggin
2006-05-13 14:53         ` Steven Rostedt
2006-05-13 14:56           ` Nick Piggin
2006-05-13 15:36       ` Takashi Iwai
2006-05-13 15:45         ` Nick Piggin
2006-05-13 15:59           ` Steven Rostedt
2006-05-14  8:13             ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox