Re: Patch 2/6 introduce helper infrastructure

From: Andi Kleen
Date: Thu Jan 27 2005 - 07:29:23 EST


On Thu, Jan 27, 2005 at 11:58:29AM +0000, Arjan van de Ven wrote:
> On Thu, Jan 27, 2005 at 11:41:33AM +0100, Andi Kleen wrote:
> > Arjan van de Ven <arjan@xxxxxxxxxxxxx> writes:
> > > +unsigned int get_random_int(void)
> > > +{
> > > + static unsigned int val = 0;
> > > +
> > > + val += current->pid + jiffies;
> >
> > Shouldn't there be some kind of locking for this? It's random,
> > but still random corruption sounds a bit too random.
> >
> > Also you probably have a very hot cache line here, which
> > may hurt on the bigger machines.
>
>
> actually the static was ther from a previous revision where the ip rng was
> compiled out at times so it needed some RNG characteristic. Patch below just
> removes the static; it's good enough.

I guess the per MM prng would be still faster, but it's probably
not worth tweaking unless it shows up as a problem.

> + if (end <= start + len)
> + return 0;
> + return PAGE_ALIGN(get_random_int() % range + start);

Division through variable is often quite slow, it would be good if you
avoided it somehow.

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/