Re: Patch 2/6 introduce helper infrastructure

From: Andi Kleen
Date: Thu Jan 27 2005 - 05:55:52 EST


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.

I think it would be better to just get a global random number
for each mm as it is created and then run a fast PRNG with that
state. Maybe even make it per task to improve performance on
multithreaded programs. Or alternatively per cpu state with
different starting points.

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