Re: recursive spinlocks. Shoot.

From: Nikita Danilov (Nikita@Namesys.COM)
Date: Fri May 23 2003 - 02:22:11 EST


Robert White writes:
> This will, hopefully, be my out-comment on this thread.
>

[...]

>
> 4) All locks (spin or otherwise) should obviously be held for the shortest
> amount of time reasonably possible which still produces the correct result.
>
> If this needs explaining... 8-)

It surely does.

Consider two loops:

(1)

spin_lock(&lock);
list_for_each_entry(item, ...) {
  do something with item;
}
spin_unlock(&lock);

versus

(2)

list_for_each_entry(item, ...) {
  spin_lock(&lock);
  do something with item;
  spin_unlock(&lock);
}

and suppose they both are equally correct. Now, in (2) total amount of
time &lock is held is smaller than in (1), but (2) will usually perform
worse on SMP, because:

. spin_lock() is an optimization barrier

. taking even un-contended spin lock is an expensive operation, because
of the cache coherency issues.

>

[...]

>
> Rob.
>

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



This archive was generated by hypermail 2b29 : Fri May 23 2003 - 22:00:53 EST