Re: [patch] timer/hrtimer: take per cpu locks in sane order

Matt Mackall
2007-03-04T23:37:54Z

On Fri, Mar 02, 2007 at 11:47:52PM +0100, Heiko Carstens wrote:
> /*
> + * Locks two spinlocks l1 and l2.
> + * l1_first indicates if spinlock l1 should be taken first.
> + */
> +static inline void double_spin_lock(spinlock_t *l1, spinlock_t *l2,
> + bool l1_first)
> + __acquires(l1)
> + __acquires(l2)
> +{
> + if (l1_first) {
> + spin_lock(l1);
> + spin_lock(l2);
> + } else {
> + spin_lock(l2);
> + spin_lock(l1);
> + }
> +}

Two observations:

- We probably don't want people using this for locks that aren't
explicitly in the same level of the hierarchy. The name should
somehow indicate that. Something like spin_lock_siblings()?

- And once we know that, we can internally impose a natural stable
ordering on them based on their addresses, eliminating the third
argument and the need to duplicate the ordering calculation.

--
Mathematics is the supreme nostalgia of our time.