Re: [PATCH] netfilter: save the hash of the tuple in the originaldirection for latter use

From: Changli Gao
Date: Tue Aug 17 2010 - 04:47:15 EST


On Tue, Aug 17, 2010 at 4:30 PM, Eric Dumazet <eric.dumazet@xxxxxxxxx> wrote:
>
> Three variables ?
>
> static atomic_t rnd __read_mostly;
>
> if (unlikely(!atomic_read(&rnd))) {
>        unsigned int val;
>
>        get_random_bytes(&val, sizeof(val));
>        if (!val)
>                val = 1;
>        atomic_cmpxchg(&rnd, 0, val);
> }
>


Good idea. However, atomic_t is a volatile variable, and it prevent
ILP. I think maybe it hurts the likely case. cmpxchg() is an atomic
operations, so is the bellow code better?

static unsigned long rnd __read_mostly;

if (unlikely(!rnd)) {
unsigned long val;

get_random_bytes(&val, sizeof(val));
if (!val)
val = 1;
cmpxchg(&rnd, 0, val);
}

Thanks.

--
Regards,
Changli Gao(xiaosuo@xxxxxxxxx)
--
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/