From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 1/3] kvm-s390: Implement the directed yield (diag 9c) hypervisor call for KVM Date: Tue, 24 Apr 2012 15:04:08 +0300 Message-ID: <4F9696B8.8080108@redhat.com> References: <1335252285-54213-1-git-send-email-borntraeger@de.ibm.com> <1335252285-54213-2-git-send-email-borntraeger@de.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Marcelo Tossati , Carsten Otte , Alexander Graf , Jens Freimann , Cornelia Huck , Heiko Carstens , Martin Schwidefsky , Heinz Graalfs , KVM , Konstantin Weitz To: Christian Borntraeger Return-path: Received: from mx1.redhat.com ([209.132.183.28]:56108 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752790Ab2DXMEl (ORCPT ); Tue, 24 Apr 2012 08:04:41 -0400 In-Reply-To: <1335252285-54213-2-git-send-email-borntraeger@de.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On 04/24/2012 10:24 AM, Christian Borntraeger wrote: > From: Konstantin Weitz > > This patch implements the directed yield hypercall found on other > System z hypervisors. It delegates execution time to the virtual cpu > specified in the instruction's parameter. > > Useful to avoid long spinlock waits in the guest. > > > diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h > index 7343872..dd17537 100644 > --- a/arch/s390/include/asm/kvm_host.h > +++ b/arch/s390/include/asm/kvm_host.h > @@ -148,6 +148,7 @@ struct kvm_vcpu_stat { > u32 instruction_sigp_restart; > u32 diagnose_10; > u32 diagnose_44; > + u32 diagnose_9c; > }; > > struct kvm_s390_io_info { > diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c > index a353f0e..8991009 100644 > --- a/arch/s390/kvm/diag.c > +++ b/arch/s390/kvm/diag.c > @@ -53,6 +53,48 @@ static int __diag_time_slice_end(struct kvm_vcpu *vcpu) > return 0; > } > > +static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu) > +{ > + struct kvm *kvm = vcpu->kvm; > + struct kvm_vcpu *tcpu; > + int tid; > + int i; > + > + tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4]; > + vcpu->stat.diagnose_9c++; > + VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d", tid); > + > + if (tid == vcpu->vcpu_id) > + return 0; > + > + kvm_for_each_vcpu(i, tcpu, kvm) { > + if (tcpu->vcpu_id == tid) { Can two vcpus match the same tid? > + struct task_struct *task = NULL; > + struct pid *pid; > + rcu_read_lock(); > + pid = rcu_dereference(tcpu->pid); > + if (pid) > + task = get_pid_task(tcpu->pid, PIDTYPE_PID); > + rcu_read_unlock(); > + if (!task) > + break; > + if (task->flags & PF_VCPU) { > + put_task_struct(task); > + break; > + } > + vcpu_put(vcpu); > + if (yield_to(task, 1)) { > + vcpu_load(vcpu); vcpu_put()/_load()s are unneeded here, preempt notifiers will automatically call kvm_arch_vcpu_put()/_load() if we schedule. > + put_task_struct(task); > + return 0; > + } > + vcpu_load(vcpu); > + put_task_struct(task); > + } > + } > + return 0; > +} > + > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index d30c835..fd98914 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -74,6 +74,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { > { "instruction_sigp_restart", VCPU_STAT(instruction_sigp_restart) }, > { "diagnose_10", VCPU_STAT(diagnose_10) }, > { "diagnose_44", VCPU_STAT(diagnose_44) }, > + { "diagnose_9c", VCPU_STAT(diagnose_9c) }, > { NULL } > }; > We're switching to tracepoints instead of homebrewed statistics. It's in feature-removal-schedule.txt already. It's okay to add them now, but please prepare for their removal. -- error compiling committee.c: too many arguments to function