From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqyh7-0002f6-5t for qemu-devel@nongnu.org; Fri, 15 Apr 2016 04:01:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqyh0-0001fJ-U8 for qemu-devel@nongnu.org; Fri, 15 Apr 2016 04:01:37 -0400 Date: Fri, 15 Apr 2016 15:23:22 +1000 From: David Gibson Message-ID: <20160415052322.GN18218@voom.redhat.com> References: <1460042594-8056-1-git-send-email-mark.cave-ayland@ilande.co.uk> <1460042594-8056-4-git-send-email-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8MZM6zh5Bb05FW+3" Content-Disposition: inline In-Reply-To: <1460042594-8056-4-git-send-email-mark.cave-ayland@ilande.co.uk> Subject: Re: [Qemu-devel] [RFC 3/4] target-ppc: synchronise tb_offset with KVM host on machine start List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mark Cave-Ayland Cc: aik@ozlabs.ru, agraf@suse.de, qemu-ppc@nongnu.org, qemu-devel@nongnu.org --8MZM6zh5Bb05FW+3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Apr 07, 2016 at 04:23:13PM +0100, Mark Cave-Ayland wrote: > Recalculate the tb_offset between the guest and host, applying it to all = CPUs > when (re)starting the virtual machine. This has the effect of providing a > near-seamless virtual timebase for KVM guests that support > KVM_REG_PPC_TB_OFFSET. >=20 > Signed-off-by: Mark Cave-Ayland The upshot of this is to make the timebase effectively stop when the guest is stopped, yes? It's not entirely clear that that's the correct choice. The timebase is supposed to represent wall clock time. For debugging of a virtual machine it's sometimes useful to stop it, but I don't know that that should be the default behaviour. I'm also not clear if this includes stops due to migration or savevm/restore or anything else not explicitly requested as a stop by the user / management layer. Those cases absolutely should not stop the timebase, since that will cause the guest's system clock to get out of sync with wall clock time. I'm wondering if we're going to need another option that controls if the timebase is tied to QEMU_CLOCK_REALTIME or QEMU_CLOCK_VIRTUAL (analagous to clock=3Dhost or clock=3Dvm for the RTC). > --- > hw/ppc/ppc.c | 41 ++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 40 insertions(+), 1 deletion(-) >=20 > diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c > index ccdca5d..39e15b1 100644 > --- a/hw/ppc/ppc.c > +++ b/hw/ppc/ppc.c > @@ -1345,12 +1345,51 @@ PowerPCCPU *ppc_get_vcpu_by_dt_id(int cpu_dt_id) > } > =20 > /* Generic PPC machine */ > +static void _ppc_update_timebase(PPCMachineState *pms) > +{ > + /* Update guest timebase offset with respect to host */ > + int64_t tb_off, new_tb_off; > + int i; > + =20 > + PowerPCCPU *first_ppc_cpu =3D POWERPC_CPU(first_cpu); =20 > + tb_off =3D first_ppc_cpu->env.tb_env->tb_offset; > + =20 > + new_tb_off =3D muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), > + first_ppc_cpu->env.tb_env->tb_freq, NANOSECONDS_PER_SEC= OND) + > + tb_off - cpu_get_host_ticks(); > + =20 > + //fprintf(stderr, "tb_off: %" PRIx64 " new_tb_off: %" PRIx64 "\n",= tb_off, new_tb_off); > + =20 > + /* Set new offset to all CPUs */ > + for (i =3D 0; i < smp_cpus; i++) { > + PowerPCCPU *pcpu =3D POWERPC_CPU(qemu_get_cpu(i)); > + pcpu->env.tb_env->tb_offset =3D new_tb_off; > + } > +} > + > +static void ppc_machine_change_state(void *opaque, int running, RunState= state) > +{ > + PPCMachineState *s =3D opaque; > + > + if (running && kvm_enabled()) { =20 > + _ppc_update_timebase(s); > + } > +} > + > +static void ppc_machine_class_init(ObjectClass *oc, void *data) > +{ > + PPCMachineState *s =3D g_malloc0(sizeof(PPCMachineState)); > + =20 > + qemu_add_vm_change_state_handler(ppc_machine_change_state, s); > +} > + > static const TypeInfo ppc_machine_info =3D { > .name =3D TYPE_PPC_MACHINE, > .parent =3D TYPE_MACHINE, > .abstract =3D true, > .instance_size =3D sizeof(PPCMachineState), > - .class_size =3D sizeof(PPCMachineClass) > + .class_size =3D sizeof(PPCMachineClass), > + .class_init =3D ppc_machine_class_init > }; > =20 > static void ppc_machine_register_types(void) --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --8MZM6zh5Bb05FW+3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXEHrKAAoJEGw4ysog2bOSR5gP/3GryZ6c91Zywnsp6wMF6U+Y 81ho+ruxZXjsYI0epUA7Qf0mGffJyUhhs3Lxy0Fv7m6yesKG53LG5kjwZ3nfS7Z0 PWJ06qetfirw0UxogZeLtqD6F4Ik+zeefkCjaZoVbcIV243sFtAq31JAFEMC5QOu EgZywfv9FyF95u6TbhhHqFtNL2+cfeJV0WF8dZYxXBcB821m4TCoX5bO9twGKX8x gcbqnsN+VDw4/SWtpSyU+8bSCa7FUaahOu5pCW1r8zVy60jLgGgXRL2yLqFu2EfK p5151eepxxEJDtHcchWHSVr3LmdV92YOiyRyQAklwl/ZL2EBKN5Jk2pZ4nIMCY2b MVDiOxoujp8Usnuh1MLu1ajW0Fn/ADPn1U2oboqqtGbfGkEDmU0ngppbD05SHwze sONrPkpOallHDmMSg0idgIDOIk6ynWOfIoWK2HZ+LYoYZjYT+dheeFHS8aWzsPIJ ULiSczI0hkU7IhE0IUixa4ZkF9t5Emvx3C2zh7riiqFmWnb1eCVT7LI25ki/bhNR y/BE80u1P8FYJS7ZUz23QKn2vrUNYXzmKWl+kMhSV9Q6z4pdC+v4wN5qAcUsI3Be 1gtDE9EgVfLRLz4MkuRrNcSMVhsQ07qhhN2puyk7qvfrT1AeIHsQ+TAZkRitotSS g7IjuSe4RdYeUleiiMzM =XpF3 -----END PGP SIGNATURE----- --8MZM6zh5Bb05FW+3--