Thread (28 messages) 28 messages, 4 authors, 2019-07-17

Re: [PATCH v3 3/5] locking/qspinlock: Introduce CNA into the slow path of qspinlock

From: Alex Kogan <hidden>
Date: 2019-07-17 14:53:17
Also in: linux-arch, lkml

On Jul 17, 2019, at 4:59 AM, Peter Zijlstra [off-list ref] wrote:

On Wed, Jul 17, 2019 at 10:39:44AM +0200, Peter Zijlstra wrote:
quoted
On Tue, Jul 16, 2019 at 08:47:24PM +0200, Peter Zijlstra wrote:
quoted
quoted
My primary concern was readability; I find the above suggestion much
more readable. Maybe it can be written differently; you'll have to play
around a bit.
static void cna_splice_tail(struct cna_node *cn, struct cna_node *head, struct cna_node *tail)
{
	struct cna_node *list;

	/* remove [head,tail] */
	WRITE_ONCE(cn->mcs.next, tail->mcs.next);
	tail->mcs.next = NULL;

	/* stick [head,tail] on the secondary list tail */
	if (cn->mcs.locked <= 1) {
		/* create secondary list */
		head->tail = tail;
		cn->mcs.locked = head->encoded_tail;
	} else {
		/* add to tail */
		list = (struct cna_node *)decode_tail(cn->mcs.locked);
		list->tail->next = head;
		list->tail = tail;
	}
}

static struct cna_node *cna_find_next(struct mcs_spinlock *node)
{
	struct cna_node *cni, *cn = (struct cna_node *)node;
	struct cna_node *head, *tail = NULL;

	/* find any next lock from 'our' node */
	for (head = cni = (struct cna_node *)READ_ONCE(cn->mcs.next);
	     cni && cni->node != cn->node;
	     tail = cni, cni = (struct cna_node *)READ_ONCE(cni->mcs.next))
		;
I think we can do away with those READ_ONCE()s, at this point those
pointers should be stable. But please double check.
I think we can get rid of WRITE_ONCE above and the first READ_ONCE, as the 
“first” next pointer (in the node of the current lock holder) is stable at this
point, and is not read / written concurrently. We do need the second READ_ONCE
as we traverse the list and can come across a next pointer being changed.

— Alex
quoted
	/* when found, splice any skipped locks onto the secondary list */
	if (cni && tail)
		cna_splice_tail(cn, head, tail);

	return cni;
}

How's that?

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help