From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752749AbbCJMhr (ORCPT ); Tue, 10 Mar 2015 08:37:47 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:57066 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbbCJMhp (ORCPT ); Tue, 10 Mar 2015 08:37:45 -0400 Date: Tue, 10 Mar 2015 13:37:40 +0100 From: Peter Zijlstra To: Sebastian Andrzej Siewior Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Maarten Lankhorst , Mike Galbraith Subject: Re: [PATCH 2/3] locking: ww_mutex: Allow to use rt_mutex instead of mutex for the baselock Message-ID: <20150310123740.GA2896@worktop.programming.kicks-ass.net> References: <1425056229-22326-1-git-send-email-bigeasy@linutronix.de> <1425056229-22326-3-git-send-email-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1425056229-22326-3-git-send-email-bigeasy@linutronix.de> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 27, 2015 at 05:57:08PM +0100, Sebastian Andrzej Siewior wrote: > +static int __sched __mutex_lock_check_stamp(struct rt_mutex *lock, > + struct ww_acquire_ctx *ctx) > +{ > +#ifdef CONFIG_WW_MUTEX_RTMUTEX > + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock); > + struct ww_acquire_ctx *hold_ctx = ACCESS_ONCE(ww->ctx); > + > + if (!hold_ctx) > + return 0; > + > + if (unlikely(ctx == hold_ctx)) > + return -EALREADY; > + > + if (ctx->stamp - hold_ctx->stamp <= LONG_MAX && > + (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) { > +#ifdef CONFIG_DEBUG_MUTEXES > + DEBUG_LOCKS_WARN_ON(ctx->contending_lock); > + ctx->contending_lock = ww; > +#endif > + return -EDEADLK; > + } > +#endif > + return 0; > +} So IIRC this is the function that checks who gets wounded (and gets to do the whole retry thing), right? So for the RT case, I think we should extend it to not (primarily) be a FIFO thing, but also consider the priority of the tasks involved. Maybe a little something like: if (hold_ctx->task->prio < ctx->task->prio) return -EDEADLOCK; before the timestamp check; although I suppose we should also add a deadline test in case both prios are -1.