From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932398AbcGOJjf (ORCPT ); Fri, 15 Jul 2016 05:39:35 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:59980 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751009AbcGOJjc (ORCPT ); Fri, 15 Jul 2016 05:39:32 -0400 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: xinhui@linux.vnet.ibm.com Subject: Re: [PATCH v2 2/5] locking/pvqspinlock: Fix missed PV wakeup problem To: Peter Zijlstra , Waiman Long References: <1464713631-1066-1-git-send-email-Waiman.Long@hpe.com> <1464713631-1066-3-git-send-email-Waiman.Long@hpe.com> <20160715084732.GF30921@twins.programming.kicks-ass.net> Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Boqun Feng , Scott J Norton , Douglas Hatch From: Pan Xinhui Date: Fri, 15 Jul 2016 17:39:46 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160715084732.GF30921@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16071509-8235-0000-0000-000008CB6003 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16071509-8236-0000-0000-0000331F41DD Message-Id: <3c5d5c29-7956-572f-2638-b85299c72432@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-07-15_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607150108 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 16/7/15 16:47, Peter Zijlstra 写道: > > So the reason I never get around to this is because the patch stinks. > > It simply doesn't make sense... Remember, the harder you make a reviewer > work the less likely the review will be done. > > Present things in clear concise language and draw a picture. > > On Tue, May 31, 2016 at 12:53:48PM -0400, Waiman Long wrote: >> Currently, calling pv_hash() and setting _Q_SLOW_VAL is only >> done once for any pv_node. It is either in pv_kick_node() or in >> pv_wait_head_or_lock(). > > So far so good.... > >> Because of lock stealing, a pv_kick'ed node is >> not guaranteed to get the lock before the spinning threshold expires >> and has to call pv_wait() again. As a result, the new lock holder >> won't see _Q_SLOW_VAL and so won't wake up the sleeping vCPU. > waiman, it might be "as a result, the head node will not really enter wait state because ->locked is not_Q_SLOW_VAL, the pv_wait will return directly." > *brain melts* what!? pv_kick'ed node reads like pv_kick_node() and that > doesn't make any kind of sense. > > I'm thinking you're trying to say this: > > > CPU0 CPU1 CPU2 > > __pv_queued_spin_unlock_slowpath() > ... > smp_store_release(&l->locked, 0); > __pv_queued_spin_lock_slowpath() > ... > pv_queued_spin_steal_lock() > cmpxchg(&l->locked, 0, _Q_LOCKED_VAL) == 0 > > > pv_wait_head_or_lock() > > pv_kick(node->cpu); ----------------------> pv_wait(&l->locked, _Q_SLOW_VAL); > > __pv_queued_spin_unlock() > cmpxchg(&l->locked, _Q_LOCKED_VAL, 0) == _Q_LOCKED_VAL > > for () { > trylock_clear_pending(); > cpu_relax(); > } > > pv_wait(&l->locked, _Q_SLOW_VAL); > > > Which is indeed 'bad', but not fatal, note that the later pv_wait() will > not in fact go wait, since l->locked will _not_ be _Q_SLOW_VAL. > hi, Peter the problem is that "this later pv_wait will do nothing as l->locked is not _Q_SLOW_VAL", So it is not paravirt friendly then. we will go into the trylock loop again and again until the lock is unlocked. So if we are kicked by the unlock_slowpath, and the lock is stealed by someone else, we need hash its node again and set l->locked to _Q_SLOW_VAL, then enter pv_wait. but I am worried about lock stealing. could the node in the queue starve for a long time? I notice the latency of pv_wait on an over-commited guest can be bigger than 300us. I have not seen such starving case, but I think it is possible to happen. thanks xinhui > Is this indeed the 3 CPU scenario you tried to describe in a scant 4 > lines of text, or is there more to it? >