Messages in this thread | | | Date | Tue, 10 Mar 2015 13:43:52 +0100 | From | Peter Zijlstra <> | Subject | Re: [PATCH 2/3] locking: ww_mutex: Allow to use rt_mutex instead of mutex for the baselock |
| |
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?
| |