public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Chris Metcalf <cmetcalf@mellanox.com>
To: Torvald Riegel <triegel@redhat.com>
Cc: David Miller <davem@davemloft.net>, <carlos@redhat.com>,
	<adhemerval.zanella@linaro.org>, <andreas@gaisler.com>,
	<libc-alpha@sourceware.org>, <software@gaisler.com>
Subject: Re: Remove sparcv8 support
Date: Thu, 10 Nov 2016 18:22:00 -0000	[thread overview]
Message-ID: <17b6735b-7376-bb70-5b70-c53fa6fb2c87@mellanox.com> (raw)
In-Reply-To: <1478797727.7146.1013.camel@localhost.localdomain>

On 11/10/2016 12:08 PM, Torvald Riegel wrote:
> Looking at tile's atomic-machine.h files again, it seems we're not
> actually enforcing that atomic stores are atomic wrt. the CAS
> implementation in the kernel.
> The default implementation for atomic_store_relaxed in include/atomic.h
> does a plain memory store instead of falling back to exchange.  This is
> the right approach by default, I think, because that's what
> pre-C11-concurrency code in glibc does (ie, there's no abstraction for
> an atomic store at all, and plain memory accesses are used).
>
> However, if we emulate CAS with locks or such in the kernel, atomic
> stores need to synchronize with the CAS.  This would mean that all archs
> such as tile or sparc that do that have to define atomic_store_relaxed
> to fix this (at least for code converted to using C11 atomics, all
> nonconverted code might still do the wrong thing).

Note that our mainstream tilegx architecture has full atomic support, so
this is only applicable to the older tilepro architecture.

2016-11-10  Chris Metcalf  <cmetcalf@mellanox.com>

     * sysdeps/tile/tilepro/atomic-machine.h (atomic_store_relaxed)
     (atomic_store_acquire): Provide tilepro-specific implementations.

diff --git a/sysdeps/tile/tilepro/atomic-machine.h b/sysdeps/tile/tilepro/atomic-machine.h
index 702e17d77db7..5365929c940a 100644
--- a/sysdeps/tile/tilepro/atomic-machine.h
+++ b/sysdeps/tile/tilepro/atomic-machine.h
@@ -83,6 +83,16 @@ int __atomic_update_32 (volatile int *mem, int mask, int addend)
    ({ __typeof (mask) __att1_v = (mask);                 \
      __atomic_update ((mem), ~__att1_v, __att1_v); })

+/*
+ * We must use the kernel atomics for atomic_store, since otherwise an
+ * unsynchronized store could become visible after another core's
+ * kernel-atomic implementation had read the memory word in question,
+ * but before it had written the updated value to it, which would
+ * cause the unsynchronized store to be lost.
+ */
+#define atomic_store_relaxed(mem, val) atomic_exchange_acq (mem, val)
+#define atomic_store_release(mem, val) atomic_exchange_rel (mem, val)
+
  #include <sysdeps/tile/atomic-machine.h>

  #endif /* atomic-machine.h */

-- 
Chris Metcalf, Mellanox Technologies
http://www.mellanox.com

  reply	other threads:[~2016-11-10 18:22 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-20 19:47 Adhemerval Zanella
2016-10-20 20:56 ` David Miller
2016-10-21  9:02 ` Andreas Larsson
2016-10-21 13:13   ` Adhemerval Zanella
2016-10-21 15:03     ` David Miller
2016-10-24 17:14       ` Torvald Riegel
2016-10-24 17:25   ` Torvald Riegel
2016-10-24 17:43     ` Adhemerval Zanella
2016-10-25 14:34       ` Andreas Larsson
2016-10-25 14:45         ` Adhemerval Zanella
2016-10-26 14:46           ` Andreas Larsson
2016-10-26 18:03             ` Adhemerval Zanella
2016-10-26 18:47               ` David Miller
2016-10-26 19:39                 ` Adhemerval Zanella
2016-10-27 10:54                 ` Torvald Riegel
2016-10-27 14:36                   ` Carlos O'Donell
2016-11-07 16:38                     ` David Miller
2016-11-07 21:21                       ` Sam Ravnborg
2016-11-08  1:06                         ` David Miller
2016-11-09  5:49                           ` Sam Ravnborg
2016-11-10 23:33                             ` David Miller
2016-11-09 17:08                       ` Torvald Riegel
2016-11-09 17:16                         ` David Miller
2016-11-10  5:05                           ` Torvald Riegel
2016-11-10 16:41                           ` Chris Metcalf
2016-11-10 17:08                             ` Torvald Riegel
2016-11-10 18:22                               ` Chris Metcalf [this message]
2016-11-10 23:38                                 ` Torvald Riegel
2016-10-27 10:38             ` Torvald Riegel
2016-11-01 15:27               ` Andreas Larsson
2016-10-25 14:34     ` Andreas Larsson
2016-10-25 16:22       ` Torvald Riegel

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=17b6735b-7376-bb70-5b70-c53fa6fb2c87@mellanox.com \
    --to=cmetcalf@mellanox.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=andreas@gaisler.com \
    --cc=carlos@redhat.com \
    --cc=davem@davemloft.net \
    --cc=libc-alpha@sourceware.org \
    --cc=software@gaisler.com \
    --cc=triegel@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).