From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [lttng-dev] [URCU PATCH 3/3] call_rcu: use wfcqueue, eliminate false-sharing
Date: Mon, 8 Oct 2012 10:49:16 -0400 [thread overview]
Message-ID: <20121008144916.GA29352@Krystal> (raw)
In-Reply-To: <507243E9.8010604@cn.fujitsu.com>
* Lai Jiangshan (laijs at cn.fujitsu.com) wrote:
> On 10/02/2012 10:16 PM, Mathieu Desnoyers wrote:
> > Eliminate false-sharing between call_rcu (enqueuer) and worker threads
> > on the queue head and tail.
> >
> > Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> > ---
> > diff --git a/tests/Makefile.am b/tests/Makefile.am
> > index 81718bb..c92bbe6 100644
> > --- a/tests/Makefile.am
> > +++ b/tests/Makefile.am
> > @@ -30,14 +30,14 @@ if COMPAT_FUTEX
> > COMPAT+=$(top_srcdir)/compat_futex.c
> > endif
> >
> > -URCU=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfqueue.c $(COMPAT)
> > -URCU_QSBR=$(top_srcdir)/urcu-qsbr.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfqueue.c $(COMPAT)
> > +URCU=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfcqueue.c $(COMPAT)
> > +URCU_QSBR=$(top_srcdir)/urcu-qsbr.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfcqueue.c $(COMPAT)
> > # URCU_MB uses urcu.c but -DRCU_MB must be defined
> > -URCU_MB=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfqueue.c $(COMPAT)
> > +URCU_MB=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfcqueue.c $(COMPAT)
> > # URCU_SIGNAL uses urcu.c but -DRCU_SIGNAL must be defined
> > -URCU_SIGNAL=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfqueue.c $(COMPAT)
> > -URCU_BP=$(top_srcdir)/urcu-bp.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfqueue.c $(COMPAT)
> > -URCU_DEFER=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfqueue.c $(COMPAT)
> > +URCU_SIGNAL=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfcqueue.c $(COMPAT)
> > +URCU_BP=$(top_srcdir)/urcu-bp.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfcqueue.c $(COMPAT)
> > +URCU_DEFER=$(top_srcdir)/urcu.c $(top_srcdir)/urcu-pointer.c $(top_srcdir)/wfcqueue.c $(COMPAT)
> >
> > URCU_COMMON_LIB=$(top_builddir)/liburcu-common.la
> > URCU_LIB=$(top_builddir)/liburcu.la
> > diff --git a/urcu-call-rcu-impl.h b/urcu-call-rcu-impl.h
> > index 13b24ff..cf65992 100644
> > --- a/urcu-call-rcu-impl.h
> > +++ b/urcu-call-rcu-impl.h
> > @@ -21,6 +21,7 @@
> > */
> >
> > #define _GNU_SOURCE
> > +#define _LGPL_SOURCE
> > #include <stdio.h>
> > #include <pthread.h>
> > #include <signal.h>
> > @@ -35,7 +36,7 @@
> > #include <sched.h>
> >
> > #include "config.h"
> > -#include "urcu/wfqueue.h"
> > +#include "urcu/wfcqueue.h"
> > #include "urcu-call-rcu.h"
> > #include "urcu-pointer.h"
> > #include "urcu/list.h"
> > @@ -46,7 +47,14 @@
> > /* Data structure that identifies a call_rcu thread. */
> >
> > struct call_rcu_data {
> > - struct cds_wfq_queue cbs;
> > + /*
> > + * Align the tail on cache line size to eliminate false-sharing
> > + * with head.
> > + */
> > + struct cds_wfcq_tail __attribute__((aligned(CAA_CACHE_LINE_SIZE))) cbs_tail;
> > + /* Alignment on cache line size will add padding here */
> > +
> > + struct cds_wfcq_head cbs_head;
>
>
> wrong here. In this code, cbs_tail and cbs_head are in the same cache line.
>
> ---
>
> struct call_rcu_data {
> struct cds_wfcq_tail cbs_tail;
> struct cds_wfcq_head __attribute__((aligned(CAA_CACHE_LINE_SIZE))) cbs_head;
> /* other fields, can move some fields up to use the room between tail and head */
> };
>
> # cat test.c
>
> struct a {
> int __attribute__((aligned(64))) i;
> int j;
> };
> struct b {
> int i;
> int __attribute__((aligned(64))) j;
> };
>
> void main(void)
> {
> printf("%d,%d\n", sizeof(struct a), sizeof(struct b));
> }
>
> # ./a.out
> 64,128
>
Good point! While we are there, I notice that the "qlen" count, kept for
debugging, is causing false-sharing too. I wonder if we should split
this counter in two counters: nr_enqueue and nr_dequeue, which would sit
in two different cache lines ? It's mainly Paul who cares about this
counter. Thoughts ?
Here is the fix to the problem you noticed above:
commit b9f893b69fbc31baea418794938f4eb74cc4923a
Author: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
Date: Mon Oct 8 10:44:38 2012 -0400
Fix urcu-call-rcu-impl.h: false-sharing
> > struct call_rcu_data {
> > - struct cds_wfq_queue cbs;
> > + /*
> > + * Align the tail on cache line size to eliminate false-sharing
> > + * with head.
> > + */
> > + struct cds_wfcq_tail __attribute__((aligned(CAA_CACHE_LINE_SIZE))) cbs_tail;
> > + /* Alignment on cache line size will add padding here */
> > +
> > + struct cds_wfcq_head cbs_head;
>
>
> wrong here. In this code, cbs_tail and cbs_head are in the same cache line.
Reported-by: Lai Jiangshan <laijs at cn.fujitsu.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
Thanks!
Mathieu
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2012-10-08 14:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-02 14:13 [lttng-dev] [URCU PATCH 0/3] wait-free concurrent queues (wfcqueue) Mathieu Desnoyers
2012-10-02 14:14 ` [lttng-dev] [URCU PATCH 1/3] wfcqueue: implement concurrency-efficient queue Mathieu Desnoyers
2012-10-08 15:47 ` Paolo Bonzini
2012-10-08 16:15 ` Mathieu Desnoyers
2012-10-08 16:33 ` Paolo Bonzini
2012-10-08 18:10 ` Mathieu Desnoyers
2012-10-10 2:56 ` Lai Jiangshan
2012-10-10 4:50 ` Mathieu Desnoyers
2012-10-02 14:15 ` [lttng-dev] [URCU PATCH 2/3] wfcqueue test Mathieu Desnoyers
2012-10-02 14:16 ` [lttng-dev] [URCU PATCH 3/3] call_rcu: use wfcqueue, eliminate false-sharing Mathieu Desnoyers
2012-10-08 3:09 ` Lai Jiangshan
2012-10-08 14:49 ` Mathieu Desnoyers [this message]
2012-10-08 15:10 ` Paul E. McKenney
2012-10-08 16:03 ` Mathieu Desnoyers
2012-10-03 18:28 ` [lttng-dev] [rp] [URCU PATCH 0/3] wait-free concurrent queues (wfcqueue) Paul E. McKenney
2012-10-03 21:04 ` Mathieu Desnoyers
2012-10-04 18:51 ` Paul E. McKenney
2012-10-08 3:33 ` Lai Jiangshan
2012-10-08 15:07 ` Mathieu Desnoyers
2012-10-10 2:53 ` Lai Jiangshan
2012-10-10 4:59 ` Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121008144916.GA29352@Krystal \
--to=mathieu.desnoyers@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox