Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757873AbcLPSNU (ORCPT ); Fri, 16 Dec 2016 13:13:20 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34297 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757015AbcLPSMy (ORCPT ); Fri, 16 Dec 2016 13:12:54 -0500 Subject: Re: [PATCH v2 05/11] locking/ww_mutex: Add waiters in stamp order To: Peter Zijlstra References: <1480601214-26583-1-git-send-email-nhaehnle@gmail.com> <1480601214-26583-6-git-send-email-nhaehnle@gmail.com> <20161206165544.GX3045@worktop.programming.kicks-ass.net> <20161216172026.GV3107@twins.programming.kicks-ass.net> Cc: linux-kernel@vger.kernel.org, =?UTF-8?Q?Nicolai_H=c3=a4hnle?= , Ingo Molnar , Maarten Lankhorst , Daniel Vetter , Chris Wilson , dri-devel@lists.freedesktop.org From: =?UTF-8?Q?Nicolai_H=c3=a4hnle?= Message-ID: <7cd1b4b7-da91-d5d5-8b00-5ebc907e95d6@gmail.com> Date: Fri, 16 Dec 2016 19:12:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20161216172026.GV3107@twins.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1879 Lines: 53 On 16.12.2016 18:20, Peter Zijlstra wrote: > On Fri, Dec 16, 2016 at 03:19:43PM +0100, Nicolai H?hnle wrote: >>>> @@ -716,7 +775,20 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, >>>> spin_unlock_mutex(&lock->wait_lock, flags); >>>> schedule_preempt_disabled(); >>>> >>>> - if (!first && __mutex_waiter_is_first(lock, &waiter)) { >>>> + if (use_ww_ctx && ww_ctx) { >>>> + /* >>>> + * Always re-check whether we're in first position. We >>>> + * don't want to spin if another task with a lower >>>> + * stamp has taken our position. >>>> + * >>>> + * We also may have to set the handoff flag again, if >>>> + * our position at the head was temporarily taken away. >>>> + */ >>>> + first = __mutex_waiter_is_first(lock, &waiter); >>>> + >>>> + if (first) >>>> + __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); >>>> + } else if (!first && __mutex_waiter_is_first(lock, &waiter)) { >>>> first = true; >>>> __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); >>>> } >>> >>> So the point is that !ww_ctx entries are 'skipped' during the insertion >>> and therefore, if one becomes first, it must stay first? >> >> Yes. Actually, it should be possible to replace all the cases of use_ww_ctx >> || first with ww_ctx. Similarly, all cases of use_ww_ctx && ww_ctx could be >> replaced by just ww_ctx. > > > I'm not seeing how "use_ww_ctx || first" -> "ww_ctx" works. My bad, missing the '|| first'. > And while > "use_ww_ctx && ww_ctx" -> "ww_ctx" is correct, it didn't work right on > some older GCCs, they choked on value propagation for ww_ctx and kept > emitting code even if we passed in NULL. Hence use_ww_ctx. Okay, I'll stick with use_ww_ctx. Thanks for the explanation. Nicolai > Arnd is now looking to raise the minimum supported GCC version, so maybe > we should look at that again if he gets anywhere. >