From: Joerg Roedel <joro@8bytes.org>
To: Avi Kivity <avi@redhat.com>
Cc: Joerg Roedel <joerg.roedel@amd.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Zachary Amsden <zamsden@redhat.com>,
kvm@vger.kernel.org
Subject: Re: [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz
Date: Thu, 24 Mar 2011 11:41:06 +0100 [thread overview]
Message-ID: <20110324104106.GG18867@8bytes.org> (raw)
In-Reply-To: <4D8B198C.9020502@redhat.com>
On Thu, Mar 24, 2011 at 12:14:36PM +0200, Avi Kivity wrote:
> On 03/24/2011 09:40 AM, Joerg Roedel wrote:
>> This patch implements two new vm-ioctls to get and set the
>> virtual_tsc_khz if the machine supports tsc-scaling. Setting
>> the tsc-frequency is only possible before userspace creates
>> any vcpu.
>>
>>
>> +4.54 KVM_SET_TSC_KHZ
>> +
>> +Capability: KVM_CAP_TSC_CONTROL
>> +Architectures: x86
>> +Type: vm ioctl
>> +Parameters: __u32 (in)
>> +Returns: 0 on success, -1 on error
>> +
>> +Specifies the tsc frequency for the virtual machine. This IOCTL must be
>> +used before any vcpu is created. The unit of the frequency is KHz.
>
> Should it not be a vcpu ioctl?
The idea was that a vm ioctl will make sure that all vcpus in one vm
have the same tsc frequency. With a vm ioctl we force this. So the tsc
fequency is basically a vm capability which is mirrored into each vcpu
data structure for performance reasons.
> Need to return an error if the frequency cannot be accommodated. In
> theory we need to provide the range of supported frequencies, but we can
> live without it (and it will be very difficult to provide if we take
> accuracy into account).
Yes, -EINVAL is reported if the frequency can not be accomodated. But
userspace can't find out the lower or upper bounds of the valid range.
>
>> +
>> +4.55 KVM_GET_TSC_KHZ
>> +
>> +Capability: KVM_CAP_GET_TSC_KHZ
>> +Architectures: x86
>> +Type: vm ioctl
>> +Parameters: __u32 (out)
>> +Returns: 0 on success, -1 on error
>> +
>> +Returns the tsc frequency of the guest. The unit of the return value is
>> +KHz. If the host has unstable tsc this ioctl return an error.
>
> Which error?
>
> (it's important since this is an expected error, unlike most others)
>
>> @@ -3580,6 +3591,52 @@ long kvm_arch_vm_ioctl(struct file *filp,
>> r = 0;
>> break;
>> }
>> + case KVM_SET_TSC_KHZ: {
>> + u32 user_tsc_khz;
>> +
>> + if (!kvm_has_tsc_control)
>> + break;
>> +
>> + r = -EFAULT;
>> + if (copy_from_user(&user_tsc_khz, argp, sizeof(__u32)))
>> + goto out;
>
> Can just use the input value (arg) instead of copy_from_user().
>
>> +
>> + r = -EINVAL;
>> + if (user_tsc_khz< kvm_min_guest_tsc_khz ||
>> + user_tsc_khz> kvm_max_guest_tsc_khz)
>
> <= and >= are probably safer.
Right, I'll change it.
>
>> + goto out;
>> +
>> + mutex_lock(&kvm->lock);
>> + /*
>> + * We force the tsc frequency to be set before any
>> + * vcpu is created
>> + */
>> + if (atomic_read(&kvm->online_vcpus)> 0) {
>> + mutex_unlock(&kvm->lock);
>> + goto out;
>> + }
>> +
>> + kvm_arch_set_tsc_khz(kvm, user_tsc_khz);
>> +
>> + mutex_unlock(&kvm->lock);
>
> Making these vcpu ioctls will remove the locking.
>
>> +
>> + r = 0;
>> + goto out;
>> + }
>> + case KVM_GET_TSC_KHZ: {
>> + u32 vtsc_khz = kvm->arch.virtual_tsc_khz;
>> +
>> + r = -EIO;
>> + if (check_tsc_unstable())
>> + goto out;
>> +
>> + r = -EFAULT;
>> + if (copy_to_user(argp,&vtsc_khz, sizeof(__u32)))
>> + goto out;
>
> And an ordinary return here.
Okay, I'll change that. But I would prefer to keep this as a vm ioctl. A
vcpu ioctl might be more flexible but I doubt anybody has a use-case for
different tsc_khz values in one VM.
Joerg
next prev parent reply other threads:[~2011-03-24 10:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-24 7:40 [PATCH 0/6][RESEND] TSC scaling support for KVM v2 Joerg Roedel
2011-03-24 7:40 ` [PATCH 1/6] KVM: SVM: Implement infrastructure for TSC_RATE_MSR Joerg Roedel
2011-03-24 9:51 ` Avi Kivity
2011-03-24 9:58 ` Joerg Roedel
2011-03-24 7:40 ` [PATCH 2/6] KVM: X86: Let kvm-clock report the right tsc frequency Joerg Roedel
2011-03-24 9:58 ` Avi Kivity
2011-03-24 7:40 ` [PATCH 3/6] KVM: X86: Make tsc_delta calculation a function of guest tsc Joerg Roedel
2011-03-24 7:40 ` [PATCH 4/6] KVM: SVM: Propagate requested TSC frequency on vcpu init Joerg Roedel
2011-03-24 10:04 ` Avi Kivity
2011-03-24 10:21 ` Joerg Roedel
2011-03-24 10:30 ` Avi Kivity
2011-03-24 7:40 ` [PATCH 5/6] KVM: X86: Delegate tsc-offset calculation to architecture code Joerg Roedel
2011-03-24 7:40 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
2011-03-24 10:14 ` Avi Kivity
2011-03-24 10:41 ` Joerg Roedel [this message]
2011-03-24 10:44 ` Avi Kivity
2011-03-24 10:47 ` Joerg Roedel
-- strict thread matches above, loose matches on Subject: below --
2011-03-25 8:44 [PATCH 0/6] TSC scaling support for KVM v3 Joerg Roedel
2011-03-25 8:44 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
2011-03-15 9:36 [PATCH 0/6] TSC scaling support for KVM v2 Joerg Roedel
2011-03-15 9:36 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
2011-02-09 17:29 [PATCH 0/6] KVM support for TSC scaling Joerg Roedel
2011-02-09 17:29 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
2011-02-13 15:12 ` Avi Kivity
2011-02-21 17:17 ` Roedel, Joerg
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=20110324104106.GG18867@8bytes.org \
--to=joro@8bytes.org \
--cc=avi@redhat.com \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=zamsden@redhat.com \
/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.