All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: Haozhong Zhang <haozhong.zhang@intel.com>
Cc: <qemu-devel@nongnu.org>, Eduardo Habkost <ehabkost@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Peter Maydell <peter.maydell@linaro.org>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Aurelien Jarno <aurelien@aurel32.net>,
	Leon Alrae <leon.alrae@imgtec.com>,
	Alexander Graf <agraf@suse.de>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	Cornelia Huck <cornelia.huck@de.ibm.com>, <kvm@vger.kernel.org>,
	<qemu-ppc@nongnu.org>
Subject: Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated
Date: Mon, 2 Nov 2015 09:40:18 +0000	[thread overview]
Message-ID: <20151102094018.GE22011@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <1446456403-29909-3-git-send-email-haozhong.zhang@intel.com>

[-- Attachment #1: Type: text/plain, Size: 4503 bytes --]

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.
> 
> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> ---
>  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(+)
> 
> 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_entry *route,
>  
>  int kvm_arch_msi_data_to_gsi(uint32_t data);
>  
> +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);
>  
> 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 = arg;
>  
> +    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 == 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 = 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 = X86_CPU(cs);
> +    CPUX86State *env = &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 = env->tsc_khz;
> +    } else if (!env->tsc_khz_saved) {
> +        r = 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 = 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)
>  
>      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;
> +}
> -- 
> 2.4.8
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: James Hogan <james.hogan@imgtec.com>
To: Haozhong Zhang <haozhong.zhang@intel.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Eduardo Habkost <ehabkost@redhat.com>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel@nongnu.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Alexander Graf <agraf@suse.de>,
	qemu-ppc@nongnu.org, Cornelia Huck <cornelia.huck@de.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Leon Alrae <leon.alrae@imgtec.com>,
	Aurelien Jarno <aurelien@aurel32.net>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated
Date: Mon, 2 Nov 2015 09:40:18 +0000	[thread overview]
Message-ID: <20151102094018.GE22011@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <1446456403-29909-3-git-send-email-haozhong.zhang@intel.com>

[-- Attachment #1: Type: text/plain, Size: 4503 bytes --]

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.
> 
> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> ---
>  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(+)
> 
> 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_entry *route,
>  
>  int kvm_arch_msi_data_to_gsi(uint32_t data);
>  
> +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);
>  
> 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 = arg;
>  
> +    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 == 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 = 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 = X86_CPU(cs);
> +    CPUX86State *env = &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 = env->tsc_khz;
> +    } else if (!env->tsc_khz_saved) {
> +        r = 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 = 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)
>  
>      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;
> +}
> -- 
> 2.4.8
> 

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-11-02  9:40 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02  9:26 [PATCH v3 0/3] target-i386: save/restore vcpu's TSC rate during migration Haozhong Zhang
2015-11-02  9:26 ` [Qemu-devel] " Haozhong Zhang
2015-11-02  9:26 ` [PATCH v3 1/3] target-i386: add a subsection for migrating vcpu's TSC rate Haozhong Zhang
2015-11-02  9:26   ` [Qemu-devel] " Haozhong Zhang
2015-11-11 14:16   ` Eduardo Habkost
2015-11-11 14:16     ` Eduardo Habkost
2015-11-11 14:27     ` Haozhong Zhang
2015-11-11 14:27       ` [Qemu-devel] " Haozhong Zhang
2015-11-13  2:23       ` Haozhong Zhang
2015-11-13  2:23         ` [Qemu-devel] " Haozhong Zhang
2015-11-13 15:21         ` Eduardo Habkost
2015-11-13 15:21           ` [Qemu-devel] " Eduardo Habkost
2015-11-16  0:10           ` Haozhong Zhang
2015-11-16  0:10             ` Haozhong Zhang
2015-11-02  9:26 ` [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated Haozhong Zhang
2015-11-02  9:26   ` [Qemu-devel] " Haozhong Zhang
2015-11-02  9:40   ` James Hogan [this message]
2015-11-02  9:40     ` James Hogan
2015-11-02 13:26     ` Haozhong Zhang
2015-11-02 13:26       ` [Qemu-devel] " Haozhong Zhang
2015-11-05  8:05     ` Christian Borntraeger
2015-11-05  8:05       ` [Qemu-devel] " Christian Borntraeger
2015-11-05  8:14       ` Haozhong Zhang
2015-11-05  8:14         ` [Qemu-devel] " Haozhong Zhang
2015-11-04 21:42   ` Eduardo Habkost
2015-11-04 21:42     ` [Qemu-devel] " Eduardo Habkost
2015-11-05  1:30     ` Haozhong Zhang
2015-11-05  1:30       ` [Qemu-devel] " Haozhong Zhang
2015-11-05 16:05       ` Eduardo Habkost
2015-11-05 16:05         ` [Qemu-devel] " Eduardo Habkost
2015-11-06  2:32         ` haozhong.zhang
2015-11-06  2:32           ` [Qemu-devel] " haozhong.zhang
2015-11-06 15:12           ` Eduardo Habkost
2015-11-06 15:12             ` [Qemu-devel] " Eduardo Habkost
2015-11-09  0:33             ` haozhong.zhang
2015-11-09  0:33               ` [Qemu-devel] " haozhong.zhang
2015-11-09 16:01               ` Eduardo Habkost
2015-11-09 16:01                 ` [Qemu-devel] " Eduardo Habkost
2015-11-09 16:37                 ` Dr. David Alan Gilbert
2015-11-09 16:37                   ` [Qemu-devel] " Dr. David Alan Gilbert
2015-11-10  1:08                 ` Haozhong Zhang
2015-11-10  1:08                   ` [Qemu-devel] " Haozhong Zhang
2015-11-11 14:54                   ` Eduardo Habkost
2015-11-11 14:54                     ` [Qemu-devel] " Eduardo Habkost
2015-11-11 15:35                     ` Haozhong Zhang
2015-11-11 15:35                       ` [Qemu-devel] " Haozhong Zhang
2015-11-10 16:57                 ` Haozhong Zhang
2015-11-10 16:57                   ` [Qemu-devel] " Haozhong Zhang
2015-11-11 15:23                   ` Eduardo Habkost
2015-11-11 15:23                     ` [Qemu-devel] " Eduardo Habkost
2015-11-11 15:33                     ` Haozhong Zhang
2015-11-11 15:33                       ` [Qemu-devel] " Haozhong Zhang
2015-11-02  9:26 ` [PATCH v3 3/3] target-i386: load the migrated vcpu's TSC rate Haozhong Zhang
2015-11-02  9:26   ` [Qemu-devel] " Haozhong Zhang
2015-11-05 16:10   ` Eduardo Habkost
2015-11-05 16:10     ` [Qemu-devel] " Eduardo Habkost
2015-11-06  2:32     ` Haozhong Zhang
2015-11-06  2:32       ` [Qemu-devel] " Haozhong Zhang
2015-11-06 15:15       ` Eduardo Habkost
2015-11-06 15:15         ` [Qemu-devel] " Eduardo Habkost

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=20151102094018.GE22011@jhogan-linux.le.imgtec.org \
    --to=james.hogan@imgtec.com \
    --cc=agraf@suse.de \
    --cc=aurelien@aurel32.net \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=haozhong.zhang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=leon.alrae@imgtec.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.