Re: [PATCH -tip/master 4/7] locking/mutex: Refactor optimistic spinning code
From: Jason Low
Date: Wed Jul 30 2014 - 11:19:05 EST
On Sun, 2014-07-27 at 22:18 -0700, Davidlohr Bueso wrote:
> +static bool mutex_optimistic_spin(struct mutex *lock,
> + struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
> +{
> + struct task_struct *task = current;
> +
> + if (!mutex_can_spin_on_owner(lock))
> + return false;
> +
> + if (!osq_lock(&lock->osq))
> + return false;
> +
> + while (true) {
> + struct task_struct *owner;
> +
> + if (use_ww_ctx && ww_ctx->acquired > 0) {
> + struct ww_mutex *ww;
> +
> + ww = container_of(lock, struct ww_mutex, base);
> + /*
> + * If ww->ctx is set the contents are undefined, only
> + * by acquiring wait_lock there is a guarantee that
> + * they are not invalid when reading.
> + *
> + * As such, when deadlock detection needs to be
> + * performed the optimistic spinning cannot be done.
> + */
> + if (ACCESS_ONCE(ww->ctx))
> + break;
> + }
> +
> + /*
> + * If there's an owner, wait for it to either
> + * release the lock or go to sleep.
> + */
> + owner = ACCESS_ONCE(lock->owner);
> + if (owner && !mutex_spin_on_owner(lock, owner))
> + break;
> +
> + /* Try to acquire the mutex if it is unlocked. */
> + if (mutex_try_to_acquire(lock)) {
Was it intended to remove the call to lock_acquired() which was
in the original code?
> + if (use_ww_ctx) {
> + struct ww_mutex *ww;
> + ww = container_of(lock, struct ww_mutex, base);
> +
> + ww_mutex_set_context_fastpath(ww, ww_ctx);
> + }
> +
> + mutex_set_owner(lock);
> + osq_unlock(&lock->osq);
> + return true;
> + }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/