From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752011AbcFZHMu (ORCPT ); Sun, 26 Jun 2016 03:12:50 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56346 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750940AbcFZHMs convert rfc822-to-8bit (ORCPT ); Sun, 26 Jun 2016 03:12:48 -0400 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: xinhui@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Content-Type: text/plain; charset=gb2312 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: [PATCH 2/2] locking/osq: Drop the overload of osq_lock() From: panxinhui In-Reply-To: <1466937715-6683-3-git-send-email-xinhui.pan@linux.vnet.ibm.com> Date: Sun, 26 Jun 2016 15:12:47 +0800 Cc: panxinhui , linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, boqun.feng@gmail.com Content-Transfer-Encoding: 8BIT References: <1466937715-6683-1-git-send-email-xinhui.pan@linux.vnet.ibm.com> <1466937715-6683-3-git-send-email-xinhui.pan@linux.vnet.ibm.com> To: Pan Xinhui X-Mailer: Apple Mail (2.3124) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062607-0044-0000-0000-000001B9F21E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062607-0045-0000-0000-00000501ABC9 Message-Id: <9749BFB3-8E12-407C-9466-5125AFACB493@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-06-26_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-1606260079 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 在 2016年6月26日,18:41,Pan Xinhui 写道: > > An over-committed guest with more vCPUs than pCPUs has a heavy overload > in osq_lock(). > > This is because vCPU A hold the osq lock and yield out, vCPU B wait > per_cpu node->locked to be set. IOW, vCPU B wait vCPU A to run and > unlock the osq lock. > > So lets also use neet_yield_to() to detect if we need stop the spinning > > Signed-off-by: Pan Xinhui > --- > kernel/locking/osq_lock.c | 18 +++++++++++++++--- > 1 file changed, 15 insertions(+), 3 deletions(-) > > diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c > index 05a3785..4287603 100644 > --- a/kernel/locking/osq_lock.c > +++ b/kernel/locking/osq_lock.c > @@ -21,6 +21,11 @@ static inline int encode_cpu(int cpu_nr) > return cpu_nr + 1; > } > > +static inline int node_cpu(struct optimistic_spin_node *node) > +{ > + return node->cpu - 1; > +} > + > static inline struct optimistic_spin_node *decode_cpu(int encoded_cpu_val) > { > int cpu_nr = encoded_cpu_val - 1; > @@ -84,9 +89,10 @@ osq_wait_next(struct optimistic_spin_queue *lock, > bool osq_lock(struct optimistic_spin_queue *lock) > { > struct optimistic_spin_node *node = this_cpu_ptr(&osq_node); > - struct optimistic_spin_node *prev, *next; > + struct optimistic_spin_node *prev, *next, *prev_old; > int curr = encode_cpu(smp_processor_id()); > int old; > + unsigned int yield_count; > > node->locked = 0; > node->next = NULL; > @@ -114,14 +120,20 @@ bool osq_lock(struct optimistic_spin_queue *lock) > * guaranteed their existence -- this allows us to apply > * cmpxchg in an attempt to undo our queueing. > */ > - > + prev_old = prev; > + yield_count = vcpu_get_yield_count(node_cpu(prev)); > while (!READ_ONCE(node->locked)) { > /* > * If we need to reschedule bail... so we can block. > */ > - if (need_resched()) > + if (need_resched() || > + need_yield_to(node_cpu(prev), yield_count)) > goto unqueue; > > + prev = READ_ONCE(node->prev); > + if (prev != prev_old) > + yield_count = vcpu_get_yield_count(node_cpu(prev)); > + OK, one mistake , should be if (prev != prev_old) { prev_old = prev; yield_count = vcpu_get_yield_count(node_cpu(prev)); } > cpu_relax_lowlatency(); > } > return true; > -- > 2.4.11 >