qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Richard Henderson <rth@twiddle.net>,
	Laurent Vivier <laurent@vivier.eu>,
	Aurelien Jarno <aurelien@aurel32.net>,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] target-sh4: add atomic tas
Date: Thu, 3 Nov 2016 18:52:15 +0100	[thread overview]
Message-ID: <3d88d6c0-6730-0db4-c109-a33b9165fb00@redhat.com> (raw)
In-Reply-To: <a4297cb1-d346-0883-f885-763e6f869401@twiddle.net>



On 03/11/2016 17:51, Richard Henderson wrote:
>>> Well, tas_test "runs without error with this change", I suppose it fails
>>> before?  In other words, is this patch enough to run multithreaded sh4
>>> programs with qemu-user?
>>
>> It should,:the problem was reported by Adrian (cc:) while compiling ghc
>> in qemu-sh4, but I have just tested the functionality with the softmmu
>> version, not the atomicity.
>>
>> Adrian, could you test this patch?
> 
> It's a start, but sh4 has an interesting scheme to implement atomic
> sequences via special values in the stack pointer.  E.g. xchg is
> 
>     mova    1f, r0
>     mov    sp, r1
>     mov    #(0f-1f), sp
> 0:    mov.l    mem, out
>     mov.l    in, mem
> 1:    mov    r1, sp
> 
> which is only atomic if you've got a UP kernel and have code in your
> interrupt entry point that recognizes the small negative value in SP to
> reset the PC as necessary.

UP kernel = no sane way to implement this in user-mode qemu?  Doing
pattern matching on negative sp moves and the instructions in between is
probably not sane, even though GCC always has:

- mov/mov for exchange
- mov/cmpeq/bf/mov for compare-and-swap
- mov/mov/op/mov for fetch-and-foo
- mov/mov/and/not/mov for fetch-and-nand
- mov/op/mov for foo-and-fetch
- mov/and/not/mov for nand-and-fetch

Another possibility is to treat the load as a LL and the store as a SC
(implemented in turn with cmpxchg+branch if it fails).  cmpxchg spans
two basic blocks, so maybe one also needs to look at r0 and sp in
cpu_get_tb_cpu_state...

Anyhow this patch seems like a bugfix.

Paolo

> For SH4A, there are proper load-locked/store-condition insns, but prior
> to that TAS was the only truly atomic insn.

  reply	other threads:[~2016-11-03 17:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03 14:07 [Qemu-devel] [PATCH v2] target-sh4: add atomic tas Laurent Vivier
2016-11-03 14:53 ` Richard Henderson
2016-11-03 15:32 ` Paolo Bonzini
2016-11-03 15:35   ` Laurent Vivier
2016-11-03 16:18     ` Paolo Bonzini
2016-11-03 16:21       ` Laurent Vivier
2016-11-03 16:51         ` Laurent Vivier
2016-11-03 16:51         ` Richard Henderson
2016-11-03 17:52           ` Paolo Bonzini [this message]
2016-11-03 19:15             ` Richard Henderson
2016-11-04  9:23         ` John Paul Adrian Glaubitz
2016-11-04  9:43           ` John Paul Adrian Glaubitz
2016-11-04  9:53             ` Laurent Vivier
2016-11-04 10:00               ` John Paul Adrian Glaubitz
2016-11-04 10:13                 ` Paolo Bonzini
2016-11-04 10:16                   ` John Paul Adrian Glaubitz
2016-11-04 10:52                     ` Paolo Bonzini
2016-11-04  0:02 ` Aurelien Jarno

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=3d88d6c0-6730-0db4-c109-a33b9165fb00@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 NNTP newsgroup(s).