Re: [PATCH -tip] locking/rtmutex: Reduce top-waiter blocking on a lock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09/23/2016 09:28 PM, Davidlohr Bueso wrote:

+#ifdef CONFIG_RT_MUTEX_SPIN_ON_OWNER
+static bool rt_mutex_spin_on_owner(struct rt_mutex *lock,
+                   struct task_struct *owner)
+{
+    bool ret = true;
+
+    /*
+     * The last owner could have just released the lock,
+     * immediately try taking it again.
+     */
+    if (!owner)
+        goto done;
+
+    rcu_read_lock();
+    while (rt_mutex_owner(lock) == owner) {
+        /*
+         * Ensure we emit the owner->on_cpu, dereference _after_
+         * checking lock->owner still matches owner. If that fails,
+         * owner might point to freed memory. If it still matches,
+         * the rcu_read_lock() ensures the memory stays valid.
+         */
+        barrier();
+        if (!owner->on_cpu || need_resched()) {
+            ret = false;
+            break;
+        }
+
+        cpu_relax_lowlatency();
+    }
+    rcu_read_unlock();
+done:
+    return ret;
+}
+

One issue that I saw is that the spinner may no longer be the top waiter while spinning. Should we also check this condition in the spin loop?

Cheers,
Longman
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux