On 04/24/2012 03:55 PM, Christian Borntraeger wrote:
> From: Konstantin Weitz <[email protected]>
>
> 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.
>
>  
>  struct kvm_s390_io_info {
> diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
> index a353f0e..022962b 100644
> --- a/arch/s390/kvm/diag.c
> +++ b/arch/s390/kvm/diag.c
> @@ -53,6 +53,45 @@ 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) {
> +                     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;
> +                     }
> +                     if (yield_to(task, 1)) {
> +                             put_task_struct(task);
> +                             return 0;
> +                     }
> +                     put_task_struct(task);
> +             }
> +     }
> +     return 0;
> +}
> +
>

I think the code will me more readable, and less obvious that is was
copied from kvm_vcpu_on_spin(), if you put all the processing outside
the loop, except for matching the vpu itself.

So the code reads

   find a vcpu
   obtain the task
   do the yield

instead of looking like you're doing the processing for every vcpu.  The
loop is just a slow lookup which might some day be replaced by a table
lookup.

-- 
error compiling committee.c: too many arguments to function

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

Reply via email to