Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
[...]
> 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;
> +        }

The lack of KVM_CAP_GET_TSC_KHZ should make QEMU abort, unless the user
is explicitly requesting a more strict mode where the TSC frequency will
be guaranteed to never change.

> +        env->tsc_khz_saved = r;
> +    }

Why do you need a separate tsc_khz_saved field, and don't simply use
tsc_khz? It would have the additional feature of letting QMP clients
query the current TSC rate by asking for the tsc-freq property on CPU
objects.


> +
> +    return 0;
> +}

-- 
Eduardo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux