From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtBbN-0000fp-8i for qemu-devel@nongnu.org; Mon, 02 Nov 2015 04:40:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtBbJ-0000qi-6N for qemu-devel@nongnu.org; Mon, 02 Nov 2015 04:40:33 -0500 Date: Mon, 2 Nov 2015 09:40:18 +0000 From: James Hogan Message-ID: <20151102094018.GE22011@jhogan-linux.le.imgtec.org> References: <1446456403-29909-1-git-send-email-haozhong.zhang@intel.com> <1446456403-29909-3-git-send-email-haozhong.zhang@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="r7U+bLA8boMOj+mD" Content-Disposition: inline In-Reply-To: <1446456403-29909-3-git-send-email-haozhong.zhang@intel.com> Subject: Re: [Qemu-devel] [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Haozhong Zhang Cc: Peter Maydell , Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , Marcelo Tosatti , qemu-devel@nongnu.org, "Dr. David Alan Gilbert" , Christian Borntraeger , Alexander Graf , qemu-ppc@nongnu.org, Cornelia Huck , Paolo Bonzini , Leon Alrae , Aurelien Jarno , Richard Henderson --r7U+bLA8boMOj+mD Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 02, 2015 at 05:26:42PM +0800, Haozhong Zhang wrote: > The value of the migrated vcpu's TSC rate is determined as below. > 1. If a TSC rate is specified by the cpu option 'tsc-freq', then this > user-specified value will be used. > 2. If neither a user-specified TSC rate nor a migrated TSC rate is > present, we will use the TSC rate from KVM (returned by > KVM_GET_TSC_KHZ). > 3. Otherwise, we will use the migrated TSC rate. >=20 > Signed-off-by: Haozhong Zhang > --- > include/sysemu/kvm.h | 2 ++ > kvm-all.c | 1 + > target-arm/kvm.c | 5 +++++ > target-i386/kvm.c | 33 +++++++++++++++++++++++++++++++++ > target-mips/kvm.c | 5 +++++ > target-ppc/kvm.c | 5 +++++ > target-s390x/kvm.c | 5 +++++ > 7 files changed, 56 insertions(+) >=20 > diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h > index 461ef65..0ec8b98 100644 > --- a/include/sysemu/kvm.h > +++ b/include/sysemu/kvm.h > @@ -328,6 +328,8 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_e= ntry *route, > =20 > int kvm_arch_msi_data_to_gsi(uint32_t data); > =20 > +int kvm_arch_setup_tsc_khz(CPUState *cpu); > + > int kvm_set_irq(KVMState *s, int irq, int level); > int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg); > =20 > diff --git a/kvm-all.c b/kvm-all.c > index c442838..1ecaf04 100644 > --- a/kvm-all.c > +++ b/kvm-all.c > @@ -1757,6 +1757,7 @@ static void do_kvm_cpu_synchronize_post_init(void *= arg) > { > CPUState *cpu =3D arg; > =20 > + kvm_arch_setup_tsc_khz(cpu); Sorry if this is a stupid question, but why aren't you doing this from the i386 kvm_arch_put_registers when level =3D=3D KVM_PUT_FULL_STATE, rather than introducing x86 specifics to the generic KVM api? Cheers James > kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE); > cpu->kvm_vcpu_dirty =3D false; > } > diff --git a/target-arm/kvm.c b/target-arm/kvm.c > index 79ef4c6..a724f6d 100644 > --- a/target-arm/kvm.c > +++ b/target-arm/kvm.c > @@ -614,3 +614,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) > { > return (data - 32) & 0xffff; > } > + > +int kvm_arch_setup_tsc_khz(CPUState *cs) > +{ > + return 0; > +} > diff --git a/target-i386/kvm.c b/target-i386/kvm.c > index 64046cb..aae5e58 100644 > --- a/target-i386/kvm.c > +++ b/target-i386/kvm.c > @@ -3034,3 +3034,36 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) > { > abort(); > } > + > +int kvm_arch_setup_tsc_khz(CPUState *cs) > +{ > + X86CPU *cpu =3D X86_CPU(cs); > + CPUX86State *env =3D &cpu->env; > + int r; > + > + /* > + * Prepare vcpu's TSC rate to be migrated. > + * > + * - If the user specifies the TSC rate by cpu option 'tsc-freq', > + * we will use the user-specified value. > + * > + * - If there is neither user-specified TSC rate nor migrated TSC > + * rate, we will ask KVM for the TSC rate by calling > + * KVM_GET_TSC_KHZ. > + * > + * - Otherwise, if there is a migrated TSC rate, we will use the > + * migrated value. > + */ > + if (env->tsc_khz) { > + env->tsc_khz_saved =3D env->tsc_khz; > + } else if (!env->tsc_khz_saved) { > + r =3D kvm_vcpu_ioctl(cs, KVM_GET_TSC_KHZ); > + if (r < 0) { > + fprintf(stderr, "KVM_GET_TSC_KHZ failed\n"); > + return r; > + } > + env->tsc_khz_saved =3D r; > + } > + > + return 0; > +} > diff --git a/target-mips/kvm.c b/target-mips/kvm.c > index 12d7db3..fb26d7e 100644 > --- a/target-mips/kvm.c > +++ b/target-mips/kvm.c > @@ -687,3 +687,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) > { > abort(); > } > + > +int kvm_arch_setup_tsc_khz(CPUState *cs) > +{ > + return 0; > +} > diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c > index ac70f08..c429f0c 100644 > --- a/target-ppc/kvm.c > +++ b/target-ppc/kvm.c > @@ -2510,3 +2510,8 @@ int kvmppc_enable_hwrng(void) > =20 > return kvmppc_enable_hcall(kvm_state, H_RANDOM); > } > + > +int kvm_arch_setup_tsc_khz(CPUState *cs) > +{ > + return 0; > +} > diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c > index c3be180..db5d436 100644 > --- a/target-s390x/kvm.c > +++ b/target-s390x/kvm.c > @@ -2248,3 +2248,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) > { > abort(); > } > + > +int kvm_arch_setup_tsc_khz(CPUState *cs) > +{ > + return 0; > +} > --=20 > 2.4.8 >=20 --r7U+bLA8boMOj+mD Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWNy+CAAoJEGwLaZPeOHZ6eS8QALpkRPoVk7PoGSyV4xbU27El a31up36EGSLNcJ0HHKvX+pXicQpHQs05Qs4BnGQgqT/xxmwwnLmXvd8aNrImQLgy aYbrio8eUPyCZ6o0OcleCxfQqDsRmvKX601vQb9Mnm1Qn8Z75g8md0AKZnPDyrgd hvemY3QAmEkReJmCy2Bt6iSWO5XBeZn0UbhlH6L+L2/IGpSplSTad0ohrq5sSKbq X0Tq8XlpJVGMrnzI0suHT3JY90+A1yQshfOXjxZitMbODsEjrJaoFsnJD8nEcaNu MeDJ7EpfjCFLKuGZuCb/o3xPLQbgdSPfZIV6LYBlek3zvdHDmWbVJgV+7ZRpttNh kiaKZPGNC+MIAZ/7B0iohwBEWK2dNruIYQM2xfwyheTh+efsI2riSQA44vdCChcO L/psodmjMj11UYFy9dyQCqS8F1a5OvnEjRe94EAvF3ZflJdgcsn23T3mVVfpUAmZ rGMjO9T1bt6ibhB7W8tLOUyzWG9fMvv0PrFd3uU7ySHxptgC4tj3gKNMbEy438U4 Xrva+3I8yUIcFRFs+tX6/e2HgsLz//WAwEXfiECVbaLPQAIepjPbdEbyvV2aBN0K SdaYreuHhSKwtzK7a9zVJgvTkobJlHHV3NKbS4ViXFofsWA9cB5bkZ8/6HFhnK19 gkDDOxpSOVjWmwapaDFB =PrTq -----END PGP SIGNATURE----- --r7U+bLA8boMOj+mD--