Re: [PATCH v6 5/6] locking/pvqspinlock: Allow 1 lock stealing attempt

From: Waiman Long
Date: Thu Sep 17 2015 - 11:08:51 EST


On 09/16/2015 11:01 AM, Peter Zijlstra wrote:
On Tue, Sep 15, 2015 at 11:29:14AM -0400, Waiman Long wrote:

Only the queue head vCPU will be in pv_wait_head() spinning to acquire the
lock.
But what will guarantee fwd progress for the lock that is the head?

Suppose CPU0 becomes head and enters the /* claim the lock */ loop.

Then CPU1 comes in, steals it in pv_wait_head(). CPU1 releases, CPU1
re-acquires and _again_ steals in pv_wait_head(), etc..

All the while CPU0 doesn't go anywhere.


That can't happen. For a given lock, there can only be 1 queue head spinning on the lock at any instance in time. If CPU0 was the head, another CPU could not become head until CPU0 got the lock and pass the MCS lock bit to the next one in the queue. As I said in earlier mail, the only place where lock stealing can happen is in the pv_queued_spin_trylock_unfair() function where I purposely inserted a cpu_relax() to allow an actively spinning queue head CPU a better chance of getting the lock. Once a CPU enters the queue. It won't try to acquire the lock until it becomes the head and there is one and only one head.

Cheers,
Longman
--
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/