lkml.org 
[lkml]   [2019]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 3/5] locking/qspinlock: Introduce CNA into the slow path of qspinlock
On Fri, Mar 29, 2019 at 11:20:04AM -0400, Alex Kogan wrote:
> +static inline void pass_mcs_lock(struct mcs_spinlock *node,
> + struct mcs_spinlock *next)
> +{
> + struct mcs_spinlock *succ = NULL;
> +
> + succ = find_successor(node);
> +
> + if (succ) {
> + arch_mcs_spin_unlock_contended(&succ->locked, node->locked);
> + } else if (node->locked > 1) {
> + /*
> + * If the secondary queue is not empty, pass the lock
> + * to the first node in that queue.
> + */
> + succ = MCS_NODE(node->locked);
> + succ->tail->next = next;
> + arch_mcs_spin_unlock_contended(&succ->locked, 1);
> + } else {
> + /*
> + * Otherwise, pass the lock to the immediate successor
> + * in the main queue.
> + */
> + arch_mcs_spin_unlock_contended(&next->locked, 1);
> + }
> +}

Note that something like:

static inline void
pass_mcs_lock(struct mcs_spinlock *node, struct mcs_spinlock *next)
{
struct mcs_spinlock *succ = NULL;
uintptr_t *var = &next->locked;
uintptr_t val = 1;

succ = find_successor(node);
if (succ) {
var = &succ->locked;
val = node->locked;
} else if (node->locked > 1) {
succ = MCS_NODE(node->locked);
succ->tail->next = next; /* WRITE_ONCE() !?!? */
var = &node->locked;
}

arch_mcs_spin_unlock_contended(var, val);
}

is shorter and generates much better code if
arch_mcs_spin_unlock_contended() is asm volatile ().

\
 
 \ /
  Last update: 2019-04-01 11:21    [W:0.027 / U:8.620 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site