]> Pileus Git - ~andy/linux/commitdiff
Merge branch 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Sep 2013 15:18:19 +0000 (08:18 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Sep 2013 15:18:19 +0000 (08:18 -0700)
Pull core/locking changes from Ingo Molnar:
 "Main changes:

   - another mutex optimization, from Davidlohr Bueso

   - improved lglock lockdep tracking, from Michel Lespinasse

   - [ assorted smaller updates, improvements, cleanups. ]"

* 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  generic-ipi/locking: Fix misleading smp_call_function_any() description
  hung_task debugging: Print more info when reporting the problem
  mutex: Avoid label warning when !CONFIG_MUTEX_SPIN_ON_OWNER
  mutex: Do not unnecessarily deal with waiters
  mutex: Fix/document access-once assumption in mutex_can_spin_on_owner()
  lglock: Update lockdep annotations to report recursive local locks
  lockdep: Introduce lock_acquire_exclusive()/shared() helper macros

1  2 
kernel/mutex.c

diff --combined kernel/mutex.c
index a52ee7bb830d3fa9db3cf898a34c8212664ac8b7,98164a55a4dc677199418f8200701fca00ca824b..6d647aedffea494dec6b11d20fa222a05fd49f7f
@@@ -209,11 -209,13 +209,13 @@@ int mutex_spin_on_owner(struct mutex *l
   */
  static inline int mutex_can_spin_on_owner(struct mutex *lock)
  {
+       struct task_struct *owner;
        int retval = 1;
  
        rcu_read_lock();
-       if (lock->owner)
-               retval = lock->owner->on_cpu;
+       owner = ACCESS_ONCE(lock->owner);
+       if (owner)
+               retval = owner->on_cpu;
        rcu_read_unlock();
        /*
         * if lock->owner is not set, the mutex owner may have just acquired
@@@ -461,7 -463,7 +463,7 @@@ __mutex_lock_common(struct mutex *lock
                         * performed the optimistic spinning cannot be done.
                         */
                        if (ACCESS_ONCE(ww->ctx))
-                               break;
+                               goto slowpath;
                }
  
                /*
                owner = ACCESS_ONCE(lock->owner);
                if (owner && !mutex_spin_on_owner(lock, owner)) {
                        mspin_unlock(MLOCK(lock), &node);
-                       break;
+                       goto slowpath;
                }
  
                if ((atomic_read(&lock->count) == 1) &&
                 * the owner complete.
                 */
                if (!owner && (need_resched() || rt_task(task)))
-                       break;
+                       goto slowpath;
  
                /*
                 * The cpu_relax() call is a compiler barrier which forces
@@@ -513,6 -515,10 +515,10 @@@ slowpath
  #endif
        spin_lock_mutex(&lock->wait_lock, flags);
  
+       /* once more, can we acquire the lock? */
+       if (MUTEX_SHOW_NO_WAITER(lock) && (atomic_xchg(&lock->count, 0) == 1))
+               goto skip_wait;
        debug_mutex_lock_common(lock, &waiter);
        debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
  
        list_add_tail(&waiter.list, &lock->wait_list);
        waiter.task = task;
  
-       if (MUTEX_SHOW_NO_WAITER(lock) && (atomic_xchg(&lock->count, -1) == 1))
-               goto done;
        lock_contended(&lock->dep_map, ip);
  
        for (;;) {
                 * other waiters:
                 */
                if (MUTEX_SHOW_NO_WAITER(lock) &&
-                  (atomic_xchg(&lock->count, -1) == 1))
+                   (atomic_xchg(&lock->count, -1) == 1))
                        break;
  
                /*
                schedule_preempt_disabled();
                spin_lock_mutex(&lock->wait_lock, flags);
        }
+       mutex_remove_waiter(lock, &waiter, current_thread_info());
+       /* set it to 0 if there are no waiters left: */
+       if (likely(list_empty(&lock->wait_list)))
+               atomic_set(&lock->count, 0);
+       debug_mutex_free_waiter(&waiter);
  
- done:
+ skip_wait:
+       /* got the lock - cleanup and rejoice! */
        lock_acquired(&lock->dep_map, ip);
-       /* got the lock - rejoice! */
-       mutex_remove_waiter(lock, &waiter, current_thread_info());
        mutex_set_owner(lock);
  
        if (!__builtin_constant_p(ww_ctx == NULL)) {
-               struct ww_mutex *ww = container_of(lock,
-                                                     struct ww_mutex,
-                                                     base);
+               struct ww_mutex *ww = container_of(lock, struct ww_mutex, base);
                struct mutex_waiter *cur;
  
                /*
                 * This branch gets optimized out for the common case,
                 * and is only important for ww_mutex_lock.
                 */
                ww_mutex_lock_acquired(ww, ww_ctx);
                ww->ctx = ww_ctx;
  
                }
        }
  
-       /* set it to 0 if there are no waiters left: */
-       if (likely(list_empty(&lock->wait_list)))
-               atomic_set(&lock->count, 0);
        spin_unlock_mutex(&lock->wait_lock, flags);
-       debug_mutex_free_waiter(&waiter);
        preempt_enable();
        return 0;
  
  err:
@@@ -686,7 -683,7 +683,7 @@@ __ww_mutex_lock(struct ww_mutex *lock, 
        might_sleep();
        ret =  __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE,
                                   0, &ctx->dep_map, _RET_IP_, ctx);
 -      if (!ret && ctx->acquired > 0)
 +      if (!ret && ctx->acquired > 1)
                return ww_mutex_deadlock_injection(lock, ctx);
  
        return ret;
@@@ -702,7 -699,7 +699,7 @@@ __ww_mutex_lock_interruptible(struct ww
        ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE,
                                  0, &ctx->dep_map, _RET_IP_, ctx);
  
 -      if (!ret && ctx->acquired > 0)
 +      if (!ret && ctx->acquired > 1)
                return ww_mutex_deadlock_injection(lock, ctx);
  
        return ret;