[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20090315185406.GA19737@elte.hu>
Date: Sun, 15 Mar 2009 19:54:07 +0100
From: Ingo Molnar <mingo@...e.hu>
To: Sam Ravnborg <sam@...nborg.org>
Cc: Geert Uytterhoeven <geert@...ux-m68k.org>,
linux-kbuild <linux-kbuild@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
Roman Zippel <zippel@...ux-m68k.org>
Subject: Re: [PATCH 2/2] kconfig: improve seed in randconfig
* Sam Ravnborg <sam@...nborg.org> wrote:
> On Sun, Mar 15, 2009 at 11:53:03AM +0100, Geert Uytterhoeven wrote:
> > On Sun, Mar 15, 2009 at 11:28, Sam Ravnborg <sam@...nborg.org> wrote:
> > > 'make randconfig' uses glibc's rand function, and the seed of
> > > that PRNG is set via:
> > >
> > > srand(time(NULL));
> > >
> > > But 'time()' only increases once every second - freezing the
> > > randconfig result within a single second.
> > >
> > > My Nehalem testbox does randconfig much faster than 1 second
> > > and i have a few scripts that do 'randconfig until condition X'
> > > loops.
> > >
> > > Those scripts currently waste a lot of CPU time due to randconfig
> > > changing its seed only once per second currently.
> > >
> > > Change the seed to be micrseconds based. (I checked the statistical
> > > spread of the seed - the now.tv_sec*now.tv_usec multiplication
> > > there further improves it.)
> >
> > > + gettimeofday(&now, NULL);
> > > +
> > > + seed = (unsigned int)(now.tv_sec*now.tv_usec);
> >
> > Just wondering: may there be some platforms that don't offer microsecond
> > resolution, and tv_usec is always zero?
> That would indeed be bad for the seed.
> Googling did not turn up anything.
doing:
seed = (unsigned int)((now.tv_sec+1)*(now.tv_usec+1));
ought to settle any practical doubts.
Ing
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists