On 30/08/2019 10:42, Christoffer Dall wrote: > On Fri, Aug 30, 2019 at 09:42:50AM +0100, Steven Price wrote: >> Implement the service call for configuring a shared structure between a >> VCPU and the hypervisor in which the hypervisor can write the time >> stolen from the VCPU's execution time by other tasks on the host. >> >> The hypervisor allocates memory which is placed at an IPA chosen by user >> space. The hypervisor then updates the shared structure using >> kvm_put_guest() to ensure single copy atomicity of the 64-bit value >> reporting the stolen time in nanoseconds. >> >> Whenever stolen time is enabled by the guest, the stolen time counter is >> reset. >> >> The stolen time itself is retrieved from the sched_info structure >> maintained by the Linux scheduler code. We enable SCHEDSTATS when >> selecting KVM Kconfig to ensure this value is meaningful. >> >> Signed-off-by: Steven Price <steven.price@xxxxxxx> [...] >> +int kvm_update_stolen_time(struct kvm_vcpu *vcpu, bool init) >> +{ >> + struct kvm *kvm = vcpu->kvm; >> + u64 steal; >> + u64 steal_le; >> + u64 offset; >> + int idx; >> + u64 base = vcpu->arch.steal.base; >> + >> + if (base == GPA_INVALID) >> + return -ENOTSUPP; >> + >> + /* Let's do the local bookkeeping */ >> + steal = vcpu->arch.steal.steal; >> + steal += current->sched_info.run_delay - vcpu->arch.steal.last_steal; >> + vcpu->arch.steal.last_steal = current->sched_info.run_delay; >> + vcpu->arch.steal.steal = steal; >> + >> + steal_le = cpu_to_le64(steal); >> + idx = srcu_read_lock(&kvm->srcu); >> + if (init) { >> + struct pvclock_vcpu_stolen_time init_values = { >> + .revision = 0, >> + .attributes = 0 >> + }; >> + kvm_write_guest(kvm, base, &init_values, >> + sizeof(init_values)); >> + } >> + offset = offsetof(struct pvclock_vcpu_stolen_time, stolen_time); >> + kvm_put_guest(kvm, base + offset, steal_le, u64); > > Let's hope we don't have thousands of memslots through which we have to > do a linear scan on every vcpu load after this. If that were the case, > I think the memslot search path would have to be updated anyhow. Yes I'm not sure with the current memslot implementation it is actually beneficial to split up the stolen time structures into separate memslots. But there's nothing requiring the use of so many memslots. If this is really a problem it would be possible to implement a memslot-caching kvm_put_guest(), but I'd want to wait until someone shows there's actually a problem first. > Otherwise looks reasonable to me. Great, thanks for the review. Steve _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm