public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix initialization of runqueues
@ 2006-08-02 12:27 Samuel Thibault
  2006-08-02 15:24 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Samuel Thibault @ 2006-08-02 12:27 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel

Hi,

There's an odd thing about the nr_active field in arrays of runqueue_t:
it is actually never initialized to 0!...  This doesn't yet trigger a
bug probably because the way runqueues are allocated make it so that
it is already initialized to 0, but that's not a safe way.  Here is a
patch:

Initialize to zero the nr_active field of arrays of runqueues.
(fixes future potential dynamic allocation of runqueues).

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

--- linux-2.6.17-orig/kernel/sched.c	2006-06-18 19:22:40.000000000 +0200
+++ linux/kernel/sched.c	2006-08-02 14:23:02.000000000 +0200
@@ -6132,6 +6132,7 @@
 
 		for (j = 0; j < 2; j++) {
 			array = rq->arrays + j;
+			array->nr_active = 0;
 			for (k = 0; k < MAX_PRIO; k++) {
 				INIT_LIST_HEAD(array->queue + k);
 				__clear_bit(k, array->bitmap);

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

* Re: [PATCH] Fix initialization of runqueues
  2006-08-02 12:27 [PATCH] Fix initialization of runqueues Samuel Thibault
@ 2006-08-02 15:24 ` Ingo Molnar
  2006-08-02 16:57   ` Samuel Thibault
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2006-08-02 15:24 UTC (permalink / raw)
  To: Samuel Thibault, linux-kernel


* Samuel Thibault <samuel.thibault@ens-lyon.org> wrote:

> Hi,
> 
> There's an odd thing about the nr_active field in arrays of 
> runqueue_t: it is actually never initialized to 0!...  This doesn't 
> yet trigger a bug probably because the way runqueues are allocated 
> make it so that it is already initialized to 0, but that's not a safe 
> way.  Here is a patch:

we do rely on zero initialization of bss (and percpu) data in a number 
of places.

	Ingo

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

* Re: [PATCH] Fix initialization of runqueues
  2006-08-02 15:24 ` Ingo Molnar
@ 2006-08-02 16:57   ` Samuel Thibault
  2006-08-03 15:07     ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Samuel Thibault @ 2006-08-02 16:57 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-kernel

Ingo Molnar, le Wed 02 Aug 2006 17:24:19 +0200, a écrit :
> 
> * Samuel Thibault <samuel.thibault@ens-lyon.org> wrote:
> 
> > Hi,
> > 
> > There's an odd thing about the nr_active field in arrays of 
> > runqueue_t: it is actually never initialized to 0!...  This doesn't 
> > yet trigger a bug probably because the way runqueues are allocated 
> > make it so that it is already initialized to 0, but that's not a safe 
> > way.  Here is a patch:
> 
> we do rely on zero initialization of bss (and percpu) data in a number 
> of places.

The rest of runqueue initialization doesn't rely on that, and as
a result people might think that it is safe to allocate runqueues
dynamically.

Samuel

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

* Re: [PATCH] Fix initialization of runqueues
  2006-08-02 16:57   ` Samuel Thibault
@ 2006-08-03 15:07     ` Steven Rostedt
  2006-08-03 18:26       ` Samuel Thibault
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2006-08-03 15:07 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: Ingo Molnar, linux-kernel

On Wed, 2006-08-02 at 18:57 +0200, Samuel Thibault wrote:
> Ingo Molnar, le Wed 02 Aug 2006 17:24:19 +0200, a écrit :
> > 
> > * Samuel Thibault <samuel.thibault@ens-lyon.org> wrote:
> > 
> > > Hi,
> > > 
> > > There's an odd thing about the nr_active field in arrays of 
> > > runqueue_t: it is actually never initialized to 0!...  This doesn't 
> > > yet trigger a bug probably because the way runqueues are allocated 
> > > make it so that it is already initialized to 0, but that's not a safe 
> > > way.  Here is a patch:
> > 
> > we do rely on zero initialization of bss (and percpu) data in a number 
> > of places.
> 
> The rest of runqueue initialization doesn't rely on that, and as
> a result people might think that it is safe to allocate runqueues
> dynamically.

I don't buy the "safe to allocate runqueues dynamically" bit since they
are local to sched.c and if you do do that (I did for a customer once)
you better know what you're doing.

That said, ...

Hmm, Ingo I guess he's right on the first part:

<sched_init snipit>

		rq->nr_running = 0;
[...]

#ifdef CONFIG_SMP
		rq->sd = NULL;
		for (j = 1; j < 3; j++)
			rq->cpu_load[j] = 0;
		rq->active_balance = 0;
		rq->push_cpu = 0;
		rq->migration_thread = NULL;
</sched_init snipit>


So I guess we should add his zero initializer, or we should remove all
the other zero initializers.  Either way, we should be consistent.

-- Steve



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

* Re: [PATCH] Fix initialization of runqueues
  2006-08-03 15:07     ` Steven Rostedt
@ 2006-08-03 18:26       ` Samuel Thibault
  0 siblings, 0 replies; 5+ messages in thread
From: Samuel Thibault @ 2006-08-03 18:26 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Ingo Molnar, linux-kernel

Steven Rostedt, le Thu 03 Aug 2006 11:07:37 -0400, a écrit :
> On Wed, 2006-08-02 at 18:57 +0200, Samuel Thibault wrote:
> > Ingo Molnar, le Wed 02 Aug 2006 17:24:19 +0200, a écrit :
> > > 
> > > * Samuel Thibault <samuel.thibault@ens-lyon.org> wrote:
> > > 
> > > > Hi,
> > > > 
> > > > There's an odd thing about the nr_active field in arrays of 
> > > > runqueue_t: it is actually never initialized to 0!...  This doesn't 
> > > > yet trigger a bug probably because the way runqueues are allocated 
> > > > make it so that it is already initialized to 0, but that's not a safe 
> > > > way.  Here is a patch:
> > > 
> > > we do rely on zero initialization of bss (and percpu) data in a number 
> > > of places.
> > 
> > The rest of runqueue initialization doesn't rely on that, and as
> > a result people might think that it is safe to allocate runqueues
> > dynamically.
> 
> I don't buy the "safe to allocate runqueues dynamically" bit since they
> are local to sched.c and if you do do that (I did for a customer once)
> you better know what you're doing.

Yes, but as you agreed, initializing some members to 0 and not others
doesn't help to know what you're doing :)

Samuel

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

end of thread, other threads:[~2006-08-03 18:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-02 12:27 [PATCH] Fix initialization of runqueues Samuel Thibault
2006-08-02 15:24 ` Ingo Molnar
2006-08-02 16:57   ` Samuel Thibault
2006-08-03 15:07     ` Steven Rostedt
2006-08-03 18:26       ` Samuel Thibault

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