Re: [PATCH] netfilter: use per-cpu spinlock rather than RCU

Linus Torvalds
2009-04-13T19:28:10Z

On Mon, 13 Apr 2009, Martin Josefsson wrote:
>
> Doesn't spin_lock() result in a pipeline flush on x86?

It's about 20-40 cycles when cached and uncontended, with some outliers
(50+ cycles on P4, 12 cycles on some AMD opterons).

So it's not a big deal if you actually hit that case.

> iirc there was a benchmark in an RCU paper that tested using per cpu
> spin_locks and the result was that it didn't scale well at all.

Spinlocks scale wonderfully well if you only touch them on one CPU.

Of course, if you truly only touch them on one CPU they are pointless, but
a "all normal code only touches the local CPU spinlock, the really odd
cases take all locks" approach works fine. It makes the uncommon case
really quite slow, but if it truly is uncommon, that's fine.

Linus