From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752337AbbCJMoT (ORCPT ); Tue, 10 Mar 2015 08:44:19 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:59488 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083AbbCJMoR (ORCPT ); Tue, 10 Mar 2015 08:44:17 -0400 Date: Tue, 10 Mar 2015 13:43:52 +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: <20150310124352.GB2896@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: > +#ifdef CONFIG_WW_MUTEX_RTMUTEX > +static void ww_mutex_lock_acquired(struct ww_mutex *ww, > + struct ww_acquire_ctx *ww_ctx) > +{ > +#ifdef CONFIG_DEBUG_MUTEXES > + /* > + * If this WARN_ON triggers, you used ww_mutex_lock to acquire, > + * but released with a normal mutex_unlock in this call. > + * > + * This should never happen, always use ww_mutex_unlock. > + */ > + DEBUG_LOCKS_WARN_ON(ww->ctx); > + > + /* > + * Not quite done after calling ww_acquire_done() ? > + */ > + DEBUG_LOCKS_WARN_ON(ww_ctx->done_acquire); > + > + if (ww_ctx->contending_lock) { > + /* > + * After -EDEADLK you tried to > + * acquire a different ww_mutex? Bad! > + */ > + DEBUG_LOCKS_WARN_ON(ww_ctx->contending_lock != ww); > + > + /* > + * You called ww_mutex_lock after receiving -EDEADLK, > + * but 'forgot' to unlock everything else first? > + */ > + DEBUG_LOCKS_WARN_ON(ww_ctx->acquired > 0); > + ww_ctx->contending_lock = NULL; > + } > + > + /* > + * Naughty, using a different class will lead to undefined behavior! > + */ > + DEBUG_LOCKS_WARN_ON(ww_ctx->ww_class != ww->ww_class); > +#endif > + ww_ctx->acquired++; > +} > +#endif > +#ifdef CONFIG_WW_MUTEX_RTMUTEX > +static int ww_mutex_deadlock_injection(struct ww_mutex *lock, > + struct ww_acquire_ctx *ctx) > +{ > +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH > + unsigned tmp; > + > + if (ctx->deadlock_inject_countdown-- == 0) { > + tmp = ctx->deadlock_inject_interval; > + if (tmp > UINT_MAX/4) > + tmp = UINT_MAX; > + else > + tmp = tmp*2 + tmp + tmp/2; > + > + ctx->deadlock_inject_interval = tmp; > + ctx->deadlock_inject_countdown = tmp; > + ctx->contending_lock = lock; > + > + ww_mutex_unlock(lock); > + > + return -EDEADLK; > + } > +#endif > + > + return 0; > +} AFAICT these functions are identical in both cases, should we stuff them in a common file instead of copy/pasting them?