Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757486AbcK3OLv (ORCPT ); Wed, 30 Nov 2016 09:11:51 -0500 Received: from mail.fireflyinternet.com ([109.228.58.192]:51536 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754198AbcK3OLl (ORCPT ); Wed, 30 Nov 2016 09:11:41 -0500 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Date: Wed, 30 Nov 2016 14:10:45 +0000 From: Chris Wilson To: Nicolai =?iso-8859-1?Q?H=E4hnle?= Cc: linux-kernel@vger.kernel.org, Nicolai =?iso-8859-1?Q?H=E4hnle?= , Peter Zijlstra , Ingo Molnar , Maarten Lankhorst , Daniel Vetter , dri-devel@lists.freedesktop.org Subject: Re: [PATCH 05/11] locking/ww_mutex: Add waiters in stamp order Message-ID: <20161130141045.GR23336@nuc-i3427.alporthouse.com> Mail-Followup-To: Chris Wilson , Nicolai =?iso-8859-1?Q?H=E4hnle?= , linux-kernel@vger.kernel.org, Nicolai =?iso-8859-1?Q?H=E4hnle?= , Peter Zijlstra , Ingo Molnar , Maarten Lankhorst , Daniel Vetter , dri-devel@lists.freedesktop.org References: <1480335612-12069-1-git-send-email-nhaehnle@gmail.com> <1480335612-12069-6-git-send-email-nhaehnle@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1480335612-12069-6-git-send-email-nhaehnle@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1596 Lines: 56 On Mon, Nov 28, 2016 at 01:20:06PM +0100, Nicolai H?hnle wrote: > From: Nicolai H?hnle > > Add regular waiters in stamp order. Keep adding waiters that have no > context in FIFO order and take care not to starve them. > > While adding our task as a waiter, back off if we detect that there is a > waiter with a lower stamp in front of us. > > Make sure to call lock_contended even when we back off early. I'm hitting [ 86.202749] WARNING: CPU: 1 PID: 813 at ./include/linux/ww_mutex.h:292 stress_inorder_work+0x436/0x4b5 [test_ww_mutex] [ 86.202885] DEBUG_LOCKS_WARN_ON(!ctx->contending_lock) which if I understand correctly is due to > +static inline int __sched > +__ww_mutex_add_waiter(struct mutex_waiter *waiter, > + struct mutex *lock, > + struct ww_acquire_ctx *ww_ctx) > +{ > + if (ww_ctx) { > + struct mutex_waiter *cur; > + > + /* > + * Add the waiter before the first waiter with a higher stamp. > + * Waiters without a context are skipped to avoid starving > + * them. > + */ > + list_for_each_entry(cur, &lock->wait_list, list) { > + if (!cur->ww_ctx) > + continue; > + > + if (__ww_mutex_stamp_after(ww_ctx, cur->ww_ctx)) { > + /* Back off immediately if necessary. */ > + if (ww_ctx->acquired > 0) > + return -EDEADLK; not setting ww_ctx->contending_lock here. > + > + continue; > + } > + > + list_add_tail(&waiter->list, &cur->list); > + return 0; > + } > + } > + > + list_add_tail(&waiter->list, &lock->wait_list); > + return 0; > +} -- Chris Wilson, Intel Open Source Technology Centre