Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755605AbcDNSrg (ORCPT ); Thu, 14 Apr 2016 14:47:36 -0400 Received: from mail-by2on0105.outbound.protection.outlook.com ([207.46.100.105]:58592 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754815AbcDNSre (ORCPT ); Thu, 14 Apr 2016 14:47:34 -0400 Authentication-Results: linux.vnet.ibm.com; dkim=none (message not signed) header.d=none;linux.vnet.ibm.com; dmarc=none action=none header.from=hpe.com; Message-ID: <570FE5B6.50307@hpe.com> Date: Thu, 14 Apr 2016 14:47:18 -0400 From: Waiman Long User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130109 Thunderbird/10.0.12 MIME-Version: 1.0 To: Pan Xinhui CC: Peter Zijlstra , Ingo Molnar , , Scott J Norton , Douglas Hatch Subject: Re: [PATCH] locking/pvqspinlock: Add lock holder CPU argument to pv_wait() References: <1460581160-46187-1-git-send-email-Waiman.Long@hpe.com> <570F6487.8070706@linux.vnet.ibm.com> <570FAA72.5090302@linux.vnet.ibm.com> In-Reply-To: <570FAA72.5090302@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [72.71.243.58] X-ClientProxiedBy: CO2PR06CA049.namprd06.prod.outlook.com (10.141.242.49) To DF4PR84MB0313.NAMPRD84.PROD.OUTLOOK.COM (10.162.193.27) X-MS-Office365-Filtering-Correlation-Id: ed741125-eb66-4424-6f8f-08d36495393b X-Microsoft-Exchange-Diagnostics: 1;DF4PR84MB0313;2:JtNg9zsFWLGUaiy2+7S6cMr0qL56+AXF3iRtkCr1aGx2z5hL/IkiRuQsIDeFZBPGnn/Fo1aFlPkWwAuBY3qbNkCzidAkxS6rhtH+bmkpy+Fftl2MqkAstt+HlBH19dFh6C8+nedjgGh5VFlmLioPI9+/dkPkWSIlPFTn3lg0U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5bkDmZ2Djd56Xa9a97VTTq0yg8VFFicENdfzhVlCyOOaoDC+MOsTSN5b4/mwPFYaWQmzaC4icwP6VVt5xrcjUdA6HhLDGGoHroQrHPUDFJGiRznyCfqDD8vPZ2Lf04/R9FDnztVdlnAJJBz4Dht3lXEu/9CySId3NPraURxLlEi0Iwe4VLe1CfyjECCYHkZ99QtTHxtH2oZlxphO+U3r1HrVhE0Tte5q/CsrqxEuOtVWNRgbSbAS55xQH X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:DF4PR84MB0313;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0313; X-Forefront-PRVS: 0912297777 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(377454003)(51234002)(24454002)(47776003)(86362001)(1096002)(586003)(65956001)(66066001)(3846002)(65806001)(6116002)(36756003)(50466002)(230700001)(117156001)(5008740100001)(4326007)(2906002)(64126003)(42186005)(83506001)(23676002)(76176999)(110136002)(189998001)(2950100001)(54356999)(65816999)(50986999)(4001350100001)(33656002)(77096005)(81166005)(92566002)(5004730100002);DIR:OUT;SFP:1102;SCL:1;SRVR:DF4PR84MB0313;H:[192.168.142.157];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtERjRQUjg0TUIwMzEzOzIzOkF4TzZKaklXcXdKWStVcWxzWEJaRHlWbzk4?= =?utf-8?B?SENXbFljSG1TaTJvL3hxWXNpTVh1dVMzanA2K200ZW9uQWNPOXlIUmkybXgv?= =?utf-8?B?aThGc0RyRDN6KzY4UjFOVTFEWTV0ZzhPVmxXcElyVUZMaDV5b2oxUHdyLzFv?= =?utf-8?B?VVhDcDVmQWFEbnhQZjlXSGxuY3ZNeDNsVEo1TUwwT2s5N1dBdXFOdkpKcFdh?= =?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QmRuUWFmVEps?= =?utf-8?B?SzJmSC9hTlVEMGlOZXR2SXhOVHQ2N21aN2RXVFJmRW5qYnExaS9sS1NjZ2Rk?= =?utf-8?B?RmFrNzRHWFVNcDlqNEhmNFlTeUxVbzJ1MHZhNldpTFBqVjY1RjNQMkQvWktq?= =?utf-8?B?ZTY0Mm12Qy9zUGRlN1g3RmpDVEthaUxNNXpxY05NYis5cU9TQkY4ZW1uVkll?= =?utf-8?B?N2VSMTBmZ1AvUFZ6cEtMOUUxRkNnUmV6VjRwNjVPU1RIWFV1YUdYa2V5YktJ?= =?utf-8?B?dlljNm9oWHB4U1hPRGpmY0dLOGw0TzlGeVJKcFdnPT0=?= X-Microsoft-Exchange-Diagnostics: 1;DF4PR84MB0313;5:HE+lJbfPxUk/cC5AZX+wajmvSwPO3JHraC1F0hTMCPKQxneAjOBcENGMADjSPdS9HUoHn+8k/7uwyIYFX1ii0Gk/IhBvayWbsYokPyXLb+He2Wx/xkfGO10ImuIz68BYVXZ3Oq1btO9B5a1oi9xN8w==;24:lTWiYHLP0f9h6s/XcvID5mFwixA4hWbHsMEX3a75hAc6StwmIjm9c8FCar5uJCST3Hyu+BdodT61astDWts7sbFGBtjiVk0PpkZk/1NRwUY= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2016 18:47:24.9659 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0313 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3782 Lines: 98 On 04/14/2016 10:34 AM, Pan Xinhui wrote: > hello, Waiman > I try your patch, thanks! > > also I do some improvement. > below code diff has been tested, it works for me. :) > > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > index ce2f75e..99f31e4 100644 > --- a/kernel/locking/qspinlock.c > +++ b/kernel/locking/qspinlock.c > @@ -248,7 +248,8 @@ static __always_inline void set_locked(struct qspinlock *lock) > */ > > static __always_inline void __pv_init_node(struct mcs_spinlock *node) { } > -static __always_inline void __pv_wait_node(struct mcs_spinlock *node, > +static __always_inline void __pv_wait_node(struct qspinlock *lock, > + struct mcs_spinlock *node, > struct mcs_spinlock *prev) { } > static __always_inline void __pv_kick_node(struct qspinlock *lock, > struct mcs_spinlock *node) { } > @@ -407,7 +408,7 @@ queue: > prev = decode_tail(old); > WRITE_ONCE(prev->next, node); > > - pv_wait_node(node, prev); > + pv_wait_node(lock, node, prev); > arch_mcs_spin_lock_contended(&node->locked); > > /* > diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h > index 01a6d16..75ccfd3 100644 > --- a/kernel/locking/qspinlock_paravirt.h > +++ b/kernel/locking/qspinlock_paravirt.h > @@ -255,6 +257,19 @@ static struct pv_node *pv_unhash(struct qspinlock *lock) > BUG(); > } > > +static struct pv_node *pv_hash_lookup(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) { > + if (READ_ONCE(he->lock) == lock) { > + return he->node; > + } > + } > + return NULL; > +} > + > /* > * Return true if when it is time to check the previous node which is not > * in a running state. > @@ -287,14 +303,17 @@ static void pv_init_node(struct mcs_spinlock *node) > * pv_kick_node() is used to set _Q_SLOW_VAL and fill in hash table on its > * behalf. > */ > -static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev) > +static void pv_wait_node(struct qspinlock *lock, struct mcs_spinlock *node, > + struct mcs_spinlock *prev) > { > struct pv_node *pn = (struct pv_node *)node; > struct pv_node *pp = (struct pv_node *)prev; > + struct pv_node *ph; > int waitcnt = 0; > int loop; > bool wait_early; > > + pn->prev_cpu = pp->cpu; > /* waitcnt processing will be compiled out if !QUEUED_LOCK_STAT */ > for (;; waitcnt++) { > for (wait_early = false, loop = SPIN_THRESHOLD; loop; loop--) { > @@ -322,7 +341,10 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev) > qstat_inc(qstat_pv_wait_node, true); > qstat_inc(qstat_pv_wait_again, waitcnt); > qstat_inc(qstat_pv_wait_early, wait_early); > - pv_wait(&pn->state, vcpu_halted); > + ph = pv_hash_lookup(lock); > + if (!ph) > + ph = pp; > + pv_wait(&pn->state, vcpu_halted, ph->prev_cpu); > } > > /* > > any comments are welcome. I put my patch here just for simplicity, or need I send it out in a new thread? > > thanks > xinhui > > I have sent out a v2 patch that incorporate your change with some minor twists. Cheers, Longman