From: Avi Kivity <avi@qumranet.com>
To: Glauber de Oliveira Costa <gcosta@redhat.com>
Cc: linux-kernel@vger.kernel.org, jeremy@goop.org,
aliguori@us.ibm.com, kvm-devel@lists.sourceforge.net,
hollisb@us.ibm.com
Subject: Re: kvmclock - the host part.
Date: Wed, 07 Nov 2007 15:59:45 +0200 [thread overview]
Message-ID: <4731C4D1.7040101@qumranet.com> (raw)
In-Reply-To: <4731B8C3.6090409@redhat.com>
Glauber de Oliveira Costa wrote:
>>> void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu)
>>> {
>>> + vcpu->time_needs_update = 1;
>>>
>>>
>> Why here and not in __vcpu_run()? It isn't timer irq related.
>>
> Because my plan was exactly, updating it at each timer interrupt.
>
I think kvm_inject_pending_timer_irqs() is called every __vcpu_run(), so
your cunning plan has been foiled.
Did you mean each guest interrupt of host interrupt?
> There's a trade off between
> updating every run (hopefully more precision, but more overhead), versus
> updating at timer irqs, or other events.
>
> What would you prefer?
>
I think that we should update it every time a heavyweight exit has been
taken. That takes care of the tradeoff quite nicely -- heavyweight
exits are already dog slow.
>
>
>>> + /* Updating the tsc count is the first thing we do */
>>> + kvm_get_msr(vcpu, MSR_IA32_TIME_STAMP_COUNTER, &vcpu->hv_clock.last_tsc);
>>> + ktime_get_ts(&ts);
>>> + vcpu->hv_clock.now_ns = ts.tv_nsec + (NSEC_PER_SEC * (u64)ts.tv_sec);
>>> + vcpu->hv_clock.wc_sec = get_seconds();
>>> + vcpu->hv_clock.version++;
>>> +
>>> + clock_addr = vcpu->clock_addr;
>>> + memcpy(clock_addr, &vcpu->hv_clock, sizeof(vcpu->hv_clock));
>>> + mark_page_dirty(vcpu->kvm, vcpu->clock_gfn);
>>>
>>>
>> Just use kvm_write_guest().
>>
> Too slow. Updating guest time, even only in timer interrupts, was a too
> frequent operation, and the kmap / kunmap (atomic) at every iteration
> deemed the whole thing
> unusable.
>
kvm_write_guest() will eventually be a copy_to_user(), so you need not
fear the overhead.
>>>
>>> + ret = 0;
>>> switch (nr) {
>>> + case KVM_HCALL_REGISTER_CLOCK: {
>>> + struct kvm_vcpu *dst_vcpu;
>>> +
>>> + if (!((a1 < KVM_MAX_VCPUS) && (vcpu->kvm->vcpus[a1]))) {
>>> + ret = -KVM_EINVAL;
>>> + break;
>>> + }
>>> +
>>> + dst_vcpu = vcpu->kvm->vcpus[a1];
>>>
>>>
>> What if !dst_vcpu? What about locking?
>>
>> Suggest simply using vcpu. Every guest cpu can register its own
>>
> Earlier version had a check for !dst_vcpu, you are absolutely right.
>
> Locking was not a problem in practice, because these operations are done
> serialized, by the same cpu.
>
Think evil guest that cares not for the well-being of the host.
> This hypercall is called by cpu_up, which, at least in the beginning,
> it's called by cpu0. And that's why each vcpu cannot register its own.
> (And why we don't need locking).
>
> Well, theorectically each vcpu do can register its own clocksource, it
> will just be a little bit more complicated, we have to fire out an IPI,
> and have the other cpu to catch it, and call the hypercall.
>
>
Can it not be done via the processor startup sequence? Then there's no
need for ipis and locking.
I imagine a normal guest initializes the apic in the same way.
> But I honestly don't like it.
> Usually, the cpu leaves start_secondary with a clock already registered,
> so the kernel relies on it.
>
>
>>> + dst_vcpu->clock_page = gfn_to_page(vcpu->kvm, a0 >> PAGE_SHIFT);
>>>
>>>
>> Shift right? Why?
>>
> a0 is not a gfn, but a physical address.
>
What if the guest wants to place it in address 5GB? That's unlikely for
Linux and Windows, but let's do it right anyway.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2007-11-07 14:00 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-06 22:18 KVM paravirt clocksource - Take 3 out of <put your number here> Glauber de Oliveira Costa
2007-11-06 22:18 ` Glauber de Oliveira Costa
2007-11-06 22:18 ` include files for kvmclock Glauber de Oliveira Costa
2007-11-06 22:18 ` Glauber de Oliveira Costa
2007-11-06 21:35 ` [kvm-devel] " Glauber de Oliveira Costa
2007-11-06 21:35 ` Glauber de Oliveira Costa
2007-11-07 5:55 ` [kvm-devel] " Avi Kivity
2007-11-07 5:55 ` Avi Kivity
2007-11-07 5:58 ` [kvm-devel] " Jeremy Fitzhardinge
2007-11-07 5:58 ` Jeremy Fitzhardinge
2007-11-07 12:49 ` [kvm-devel] " Glauber de Oliveira Costa
2007-11-07 12:49 ` Glauber de Oliveira Costa
2007-11-06 22:18 ` kvmclock - the host part Glauber de Oliveira Costa
2007-11-06 22:18 ` Glauber de Oliveira Costa
2007-11-06 22:18 ` kvmclock implementation, the guest part Glauber de Oliveira Costa
2007-11-06 22:18 ` Glauber de Oliveira Costa
2007-11-07 5:50 ` kvmclock - the host part Avi Kivity
2007-11-07 5:50 ` Avi Kivity
2007-11-07 13:08 ` Glauber de Oliveira Costa
2007-11-07 13:08 ` Glauber de Oliveira Costa
2007-11-07 13:59 ` Avi Kivity [this message]
2007-11-06 22:50 ` include files for kvmclock Jeremy Fitzhardinge
2007-11-06 22:50 ` Jeremy Fitzhardinge
2007-11-06 22:58 ` Glauber de Oliveira Costa
2007-11-06 22:58 ` Glauber de Oliveira Costa
2007-11-07 8:16 ` [kvm-devel] " Akio Takebe
2007-11-07 8:16 ` Akio Takebe
2007-11-07 13:16 ` [kvm-devel] " Glauber de Oliveira Costa
2007-11-07 13:16 ` Glauber de Oliveira Costa
2007-11-07 13:27 ` [kvm-devel] " Akio Takebe
2007-11-07 13:27 ` Akio Takebe
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=4731C4D1.7040101@qumranet.com \
--to=avi@qumranet.com \
--cc=aliguori@us.ibm.com \
--cc=gcosta@redhat.com \
--cc=hollisb@us.ibm.com \
--cc=jeremy@goop.org \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/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.