From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ai2em-0000TS-TK for qemu-devel@nongnu.org; Mon, 21 Mar 2016 12:26:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ai2eh-00017t-6l for qemu-devel@nongnu.org; Mon, 21 Mar 2016 12:26:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ai2eh-00017b-1O for qemu-devel@nongnu.org; Mon, 21 Mar 2016 12:26:11 -0400 References: <1458577386-9984-1-git-send-email-alex.bennee@linaro.org> <1458577386-9984-2-git-send-email-alex.bennee@linaro.org> From: Paolo Bonzini Message-ID: <56F0209E.6090706@redhat.com> Date: Mon, 21 Mar 2016 17:26:06 +0100 MIME-Version: 1.0 In-Reply-To: <1458577386-9984-2-git-send-email-alex.bennee@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v1 1/2] cpus: don't use atomic_read for vm_clock_warp_start List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, sbruno@freebsd.org, Richard Henderson , Peter Crosthwaite On 21/03/2016 17:23, Alex Benn=C3=A9e wrote: > 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. The variable documentation says this is meant to be protected by > vm_clock_seqlock so lets just move the code into that section. This neglects the fact that there is a comment explaining the code, so Because the variable is protected by vm_clock_seqlock, we check its value inside a seqlock critical section. is better. In addition, I would prefer if you used seqlock_read_*. Paolo > All other references to vm_clock_warp_start are already protected by th= e > seqlock. >=20 > Signed-off-by: Alex Benn=C3=A9e > --- > cpus.c | 12 ++++-------- > 1 file changed, 4 insertions(+), 8 deletions(-) >=20 > diff --git a/cpus.c b/cpus.c > index 23cf7aa..2fd5381 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -338,15 +338,10 @@ static int64_t qemu_icount_round(int64_t count) > =20 > static void icount_warp_rt(void) > { > - /* The icount_warp_timer is rescheduled soon after vm_clock_warp_s= tart > - * changes from -1 to another value, so the race here is okay. > - */ > - if (atomic_read(&vm_clock_warp_start) =3D=3D -1) { > - return; > - } > + bool check_clock =3D false; > =20 > seqlock_write_lock(&timers_state.vm_clock_seqlock); > - if (runstate_is_running()) { > + if (vm_clock_warp_start !=3D -1 && runstate_is_running()) { > int64_t clock =3D REPLAY_CLOCK(REPLAY_CLOCK_VIRTUAL_RT, > cpu_get_clock_locked()); > int64_t warp_delta; > @@ -362,11 +357,12 @@ static void icount_warp_rt(void) > warp_delta =3D MIN(warp_delta, delta); > } > timers_state.qemu_icount_bias +=3D warp_delta; > + check_clock =3D true; > } > vm_clock_warp_start =3D -1; > seqlock_write_unlock(&timers_state.vm_clock_seqlock); > =20 > - if (qemu_clock_expired(QEMU_CLOCK_VIRTUAL)) { > + if (check_clock && qemu_clock_expired(QEMU_CLOCK_VIRTUAL)) { > qemu_clock_notify(QEMU_CLOCK_VIRTUAL); > } > }