mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pan Xinhui <xinhui@linux.vnet.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Waiman Long <Waiman.Long@hpe.com>, Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>
Subject: Re: [PATCH v2] locking/pvqspinlock: Add lock holder CPU argument to pv_wait()
Date: Wed, 20 Apr 2016 23:05:21 +0800	[thread overview]
Message-ID: <57179AB1.3080403@linux.vnet.ibm.com> (raw)
In-Reply-To: <20160420141819.GD3430@twins.programming.kicks-ass.net>



On 2016年04月20日 22:18, Peter Zijlstra wrote:
> On Wed, Apr 20, 2016 at 10:15:09PM +0800, Pan Xinhui wrote:
>>>> +static struct pv_node *pv_lookup_hash(struct qspinlock *lock)
>>>> +{
>>>> +	unsigned long offset, hash = hash_ptr(lock, pv_lock_hash_bits);
>>>> +	struct pv_hash_entry *he;
>>>> +
>>>> +	for_each_hash_entry(he, offset, hash) {
>>>> +		struct qspinlock *l = READ_ONCE(he->lock);
>>>> +
>>>> +		if (l == lock)
>>>
>>> The other loop writes:
>>>
>>> 		if (READ_ONCE(he->lock) == lock)
>>>
>> Maybe because we check l is NULL or not later. So save one load.
> 
> Ah duh, yes.
> 
>>>> +			return READ_ONCE(he->node);
>>>> +		/*
>>>> +		 * Presence of an empty slot signal the end of search. We
>>>> +		 * may miss the entry, but that will limit the amount of
>>>> +		 * time doing the search when the desired entry isn't there.
>>>> +		 */
>>>> +		else if (!l)
>>>> +			break;
>>>
>>> That 'else' is entirely pointless. Also, why isn't this: return NULL;
>>>
>>>> +	}
>>>> +	return NULL;
>>>
>>> and this BUG() ?
>>>
>> It's not a bug, the lock might not be stored in the hashtable. in unlock function, we will unhash the lock, then what will happen is:
> 
> It should be if the above becomes a return NULL, no?
> 
no, the lock might not be there, even if we search the whole hashtable.
Only pv_kick_node and pv_wait_head_or_lock will hash the lock. if both vcpu's state is vcpu_running, who will hash the lock on behalf of us?

Can pv_wait return without anyone kicking it? If yes, then this not a bug.

> If we can iterate the _entire_ hashtable, this lookup can be immensely
> expensive and we should not be doing it inside of a wait-loop.
> 

  reply	other threads:[~2016-04-20 15:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-14 18:41 Waiman Long
2016-04-20 12:08 ` Peter Zijlstra
2016-04-20 14:15   ` Pan Xinhui
2016-04-20 14:18     ` Peter Zijlstra
2016-04-20 15:05       ` Pan Xinhui [this message]
2016-04-20 14:19     ` Peter Zijlstra
2016-04-20 14:36       ` Pan Xinhui
2016-04-20 17:58         ` Waiman Long
2016-04-20 17:50       ` Waiman Long
2016-04-20 17:46   ` Waiman Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57179AB1.3080403@linux.vnet.ibm.com \
    --to=xinhui@linux.vnet.ibm.com \
    --cc=Waiman.Long@hpe.com \
    --cc=doug.hatch@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=scott.norton@hpe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome