From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: will.deacon@arm.com, Andy.Glew@imgtec.com,
Leonid.Yegoshin@imgtec.com, peterz@infradead.org,
linux-arch@vger.kernel.org, arnd@arndb.de, davem@davemloft.net,
linux-arm-kernel@lists.infradead.org,
linux-metag@vger.kernel.org, linux-mips@linux-mips.org,
linux-xtensa@linux-xtensa.org, linuxppc-dev@lists.ozlabs.org
Cc: graham.whaley@gmail.com, torvalds@linux-foundation.org,
hpa@zytor.com, mingo@kernel.org
Subject: Writes, smp_wmb(), and transitivity?
Date: Mon, 15 Feb 2016 09:58:25 -0800 [thread overview]
Message-ID: <20160215175825.GA15878@linux.vnet.ibm.com> (raw)
Hello!
Some architectures provide local transitivity for a chain of threads doing
writes separated by smp_wmb(), as exemplified by the litmus tests below.
The pattern is that each thread writes to a its own variable, does an
smp_wmb(), then writes a different value to the next thread's variable.
I don't know of a use of this, but if everyone supports it, it might
be good to mandate it. Status quo is that smp_wmb() is non-transitive,
so it currently isn't supported.
Anyone know of any architectures that do -not- support this?
Assuming all architectures -do- support this, any arguments -against-
officially supporting it in Linux?
Thanx, Paul
------------------------------------------------------------------------
Two threads:
int a, b;
void thread0(void)
{
WRITE_ONCE(a, 1);
smp_wmb();
WRITE_ONCE(b, 2);
}
void thread1(void)
{
WRITE_ONCE(b, 1);
smp_wmb();
WRITE_ONCE(a, 2);
}
/* After all threads have completed and the dust has settled... */
BUG_ON(a == 1 && b == 1);
Three threads:
int a, b, c;
void thread0(void)
{
WRITE_ONCE(a, 1);
smp_wmb();
WRITE_ONCE(b, 2);
}
void thread1(void)
{
WRITE_ONCE(b, 1);
smp_wmb();
WRITE_ONCE(c, 2);
}
void thread2(void)
{
WRITE_ONCE(c, 1);
smp_wmb();
WRITE_ONCE(a, 2);
}
/* After all threads have completed and the dust has settled... */
BUG_ON(a == 1 && b == 1 && c == 1);
Four threads:
int a, b, c, d;
void thread0(void)
{
WRITE_ONCE(a, 1);
smp_wmb();
WRITE_ONCE(b, 2);
}
void thread1(void)
{
WRITE_ONCE(b, 1);
smp_wmb();
WRITE_ONCE(c, 2);
}
void thread2(void)
{
WRITE_ONCE(c, 1);
smp_wmb();
WRITE_ONCE(d, 2);
}
void thread3(void)
{
WRITE_ONCE(d, 1);
smp_wmb();
WRITE_ONCE(a, 2);
}
/* After all threads have completed and the dust has settled... */
BUG_ON(a == 1 && b == 1 && c == 1 && d == 1);
And so on...
WARNING: multiple messages have this Message-ID (diff)
From: paulmck@linux.vnet.ibm.com (Paul E. McKenney)
To: linux-arm-kernel@lists.infradead.org
Subject: Writes, smp_wmb(), and transitivity?
Date: Mon, 15 Feb 2016 09:58:25 -0800 [thread overview]
Message-ID: <20160215175825.GA15878@linux.vnet.ibm.com> (raw)
Hello!
Some architectures provide local transitivity for a chain of threads doing
writes separated by smp_wmb(), as exemplified by the litmus tests below.
The pattern is that each thread writes to a its own variable, does an
smp_wmb(), then writes a different value to the next thread's variable.
I don't know of a use of this, but if everyone supports it, it might
be good to mandate it. Status quo is that smp_wmb() is non-transitive,
so it currently isn't supported.
Anyone know of any architectures that do -not- support this?
Assuming all architectures -do- support this, any arguments -against-
officially supporting it in Linux?
Thanx, Paul
------------------------------------------------------------------------
Two threads:
int a, b;
void thread0(void)
{
WRITE_ONCE(a, 1);
smp_wmb();
WRITE_ONCE(b, 2);
}
void thread1(void)
{
WRITE_ONCE(b, 1);
smp_wmb();
WRITE_ONCE(a, 2);
}
/* After all threads have completed and the dust has settled... */
BUG_ON(a == 1 && b == 1);
Three threads:
int a, b, c;
void thread0(void)
{
WRITE_ONCE(a, 1);
smp_wmb();
WRITE_ONCE(b, 2);
}
void thread1(void)
{
WRITE_ONCE(b, 1);
smp_wmb();
WRITE_ONCE(c, 2);
}
void thread2(void)
{
WRITE_ONCE(c, 1);
smp_wmb();
WRITE_ONCE(a, 2);
}
/* After all threads have completed and the dust has settled... */
BUG_ON(a == 1 && b == 1 && c == 1);
Four threads:
int a, b, c, d;
void thread0(void)
{
WRITE_ONCE(a, 1);
smp_wmb();
WRITE_ONCE(b, 2);
}
void thread1(void)
{
WRITE_ONCE(b, 1);
smp_wmb();
WRITE_ONCE(c, 2);
}
void thread2(void)
{
WRITE_ONCE(c, 1);
smp_wmb();
WRITE_ONCE(d, 2);
}
void thread3(void)
{
WRITE_ONCE(d, 1);
smp_wmb();
WRITE_ONCE(a, 2);
}
/* After all threads have completed and the dust has settled... */
BUG_ON(a == 1 && b == 1 && c == 1 && d == 1);
And so on...
next reply other threads:[~2016-02-15 17:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-15 17:58 Paul E. McKenney [this message]
2016-02-15 17:58 ` Writes, smp_wmb(), and transitivity? Paul E. McKenney
2016-02-15 18:58 ` Will Deacon
2016-02-15 18:58 ` Will Deacon
2016-02-15 20:35 ` Paul E. McKenney
2016-02-15 20:35 ` Paul E. McKenney
2016-02-16 9:53 ` Will Deacon
2016-02-16 9:53 ` Will Deacon
2016-02-16 11:13 ` Paul E. McKenney
2016-02-16 11:13 ` Paul E. McKenney
2016-02-16 18:59 ` Linus Torvalds
2016-02-16 18:59 ` Linus Torvalds
[not found] ` <CA+55aFxaQEvDrzecmZUQ5QfKzU4ei6E-+NpsW5hYp3ouaLP98g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-16 19:36 ` Paul E. McKenney
2016-02-16 19:36 ` Paul E. McKenney
2016-02-16 19:36 ` Paul E. McKenney
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=20160215175825.GA15878@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=Andy.Glew@imgtec.com \
--cc=Leonid.Yegoshin@imgtec.com \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=graham.whaley@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-metag@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.