Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933603AbcCaUkQ (ORCPT ); Thu, 31 Mar 2016 16:40:16 -0400 Received: from mail-by2on0145.outbound.protection.outlook.com ([207.46.100.145]:7745 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932647AbcCaUkI (ORCPT ); Thu, 31 Mar 2016 16:40:08 -0400 Authentication-Results: infradead.org; dkim=none (message not signed) header.d=none;infradead.org; dmarc=none action=none header.from=hpe.com; Message-ID: <56FD8B1F.7070102@hpe.com> Date: Thu, 31 Mar 2016 16:39:59 -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: Peter Zijlstra CC: Ingo Molnar , , Linus Torvalds , Ding Tianhong , Jason Low , Davidlohr Bueso , "Paul E. McKenney" , Thomas Gleixner , Will Deacon , Tim Chen , Waiman Long Subject: Re: [PATCH v3 3/3] locking/mutex: Avoid missed wakeup of mutex waiter References: <1458668804-10138-1-git-send-email-Waiman.Long@hpe.com> <1458668804-10138-4-git-send-email-Waiman.Long@hpe.com> <20160329163654.GM3408@twins.programming.kicks-ass.net> In-Reply-To: <20160329163654.GM3408@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [72.71.243.178] X-ClientProxiedBy: SN1PR0701CA0031.namprd07.prod.outlook.com (10.162.96.41) To TU4PR84MB0320.NAMPRD84.PROD.OUTLOOK.COM (10.162.186.30) X-MS-Office365-Filtering-Correlation-Id: 80a5466a-4035-4828-c2ab-08d359a4a4df X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0320;2:dzjcmIzEx+Ce3rMvk8M2KIUmr2Gq5ZJJftx+QqEai4X6zBLz6okPsIokRhGzzyWJwdvzTOzJa37/IuGHBBH7HT6SMNtcx6fLiAKh1VQ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kb546+SwZrgcbdzW6BNYpoX2nebDpVK+jV+I9zTLti8oqKQV1ABRSsvnhxvYKZ+trcHrsQVrdxlCvXNcfBEgMPDgeuKzMKer/19bsYjWGfFxeyA3lJjX9cxWxRykbWwtqS6U+ZBizMOB6sunWaFBcGC5EVVvuqnrLZgM4vNBVb+fgY9cPTTzOLqd79PVy80vKxRq5Fo9jDFTqR2NlqqzKds7C9VbJynXl57bQwyRKeTGoja0LkrPTIk7vD7ETvBdjeYa3gGlscQFtzeFu/YByjgya/GCBjZepCDm/3jvtmcBk+gntT8gfGaYMlFzPNWcOWn+Ec8/PM2fY X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001);SRVR:TU4PR84MB0320;BCL:0;PCL:0;RULEID:;SRVR:TU4PR84MB0320; X-Forefront-PRVS: 0898A6E028 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(377454003)(24454002)(230700001)(4326007)(23756003)(92566002)(5004730100002)(42186005)(33656002)(86362001)(77096005)(83506001)(5008740100001)(110136002)(87266999)(117156001)(54356999)(2906002)(65816999)(81166005)(64126003)(2950100001)(66066001)(59896002)(65806001)(76176999)(4001350100001)(6116002)(47776003)(50986999)(189998001)(36756003)(3846002)(1096002)(586003)(65956001)(50466002)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:TU4PR84MB0320;H:[192.168.142.148];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?iso-8859-1?Q?1;TU4PR84MB0320;23:Ois7W7r+PSVa8F+UDO0VwZwZdURsSHYIykWdT50?= =?iso-8859-1?Q?uXvj4bZYeji9cWvGqPk4+bSCjAJDzwQ2laF0NnX3mb+X+YQolAatl7LZXX?= =?iso-8859-1?Q?/33XgxS5wwlTuOJ6191lMRpHf8T06GLf+dWhKNkb8PO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K/gEl0Hxa2DvLoRPK1GtM1tYJo1hg7LExGySQuS3AVSLXGu?= =?iso-8859-1?Q?/BtQX3mDgzACLmikdx7Am6WGQcqVREdf8jdEm04OlXwLo8kDaTX07yyqQ7?= =?iso-8859-1?Q?g5xnf?= X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0320;5:3GHlRA1IrAWbhs/xLZlmL3IgCJwNk1VubTg34rsyqAXEcC5nqv6YBrXJEkioqz1NVSrYnwPYLAcKNQHaBlak4MSpOaFvwmM4BwB4YSmFiGn0gEJAlUJUt0A4UDWRKzteZxJalljSXPTB8Hbfcousxg==;24:GrcgilF80WFVp8/PIUjoBowkejnCFdFiMVoDLJ2Za03X8bsItzkK4UZMDqmk40SPHuHuv2TtEhJpFWbymw7uoihuPN/2nIavGjRAbV7iMHk= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2016 20:40:05.1257 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: TU4PR84MB0320 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1287 Lines: 28 On 03/29/2016 12:36 PM, Peter Zijlstra wrote: > On Tue, Mar 22, 2016 at 01:46:44PM -0400, Waiman Long wrote: >> The current mutex code sets count to -1 and then sets the task >> state. This is the same sequence that the mutex unlock path is checking >> count and task state. That could lead to a missed wakeup even though >> the problem will be cleared when a new waiter enters the waiting queue. >> >> This patch reverses the order in the locking slowpath so that the task >> state is set first before setting the count. This should eliminate >> the potential missed wakeup and improve latency. > Is it really a problem though? > > So the 'race' is __mutex_lock_common() against > __mutex_fastpath_unlock(), and that is fully serialized as per the > atomic instructions. Either the fast unlock path does 1->0 and the lock > acquires, or the lock sets -1, at which the unlock fails and enters > __mutex_unlock_common_slowpath, which is fully serialised against > __mutex_lock_common by the lock->wait_lock. > > I agree that the code is nicer after your patch, but I don't actually > see a problem. You are right again. I think I missed the spinlock serialization part from my analysis. So this patch isn't really necessary. I can withdraw it or mark it as a cleanup. Cheers, Longman