qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org
Cc: "Peter Crosthwaite" <crosthwaite.peter@gmail.com>,
	qemu-devel@nongnu.org, sbruno@freebsd.org, pbonzini@redhat.com,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Richard Henderson" <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH v2 1/2] cpus: don't use atomic_read for vm_clock_warp_start
Date: Mon,  4 Apr 2016 15:35:48 +0100	[thread overview]
Message-ID: <1459780549-12942-2-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1459780549-12942-1-git-send-email-alex.bennee@linaro.org>

As vm_clock_warp_start is a 64 bit value this causes problems for the
compiler trying to come up with a suitable atomic operation on 32 bit
hosts. Because the variable is protected by vm_clock_seqlock, we check its
value inside a seqlock critical section.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
v2
  - use seqlock read instead wrapping inside the write sequence lock
---
 cpus.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/cpus.c b/cpus.c
index 8ae4777..cbeb1f6 100644
--- a/cpus.c
+++ b/cpus.c
@@ -338,10 +338,18 @@ static int64_t qemu_icount_round(int64_t count)
 
 static void icount_warp_rt(void)
 {
+    unsigned seq;
+    int64_t warp_start;
+
     /* The icount_warp_timer is rescheduled soon after vm_clock_warp_start
      * changes from -1 to another value, so the race here is okay.
      */
-    if (atomic_read(&vm_clock_warp_start) == -1) {
+    do {
+        seq = seqlock_read_begin(&timers_state.vm_clock_seqlock);
+        warp_start = vm_clock_warp_start;
+    } while (seqlock_read_retry(&timers_state.vm_clock_seqlock, seq));
+
+    if (warp_start == -1) {
         return;
     }
 
-- 
2.7.4

  reply	other threads:[~2016-04-04 14:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-04 14:35 [Qemu-devel] [PATCH v2 0/2] Fix for compile on FreeBSD/i386 (and others?) Alex Bennée
2016-04-04 14:35 ` Alex Bennée [this message]
2016-04-04 14:35 ` [Qemu-devel] [PATCH v2 2/2] include/qemu/atomic: add compile time asserts Alex Bennée
2016-04-04 14:44 ` [Qemu-devel] [PATCH v2 0/2] Fix for compile on FreeBSD/i386 (and others?) Paolo Bonzini
2016-04-04 14:56   ` Peter Maydell
2016-04-04 14:57     ` Paolo Bonzini
2016-04-04 18:10 ` Ed Maste
2016-04-04 19:26   ` Alex Bennée
2016-04-04 19:38     ` Peter Maydell

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=1459780549-12942-2-git-send-email-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=crosthwaite.peter@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sbruno@freebsd.org \
    /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).