Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3259405ybi; Mon, 10 Jun 2019 07:17:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+r8qQ/n1DrBfdUNFfi/mJLE4p6mcWmIyE3qoOMcutJu17I5TYashhzZlcMZ8P4zE4MMLA X-Received: by 2002:a63:4d5d:: with SMTP id n29mr16302191pgl.235.1560176270471; Mon, 10 Jun 2019 07:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560176270; cv=none; d=google.com; s=arc-20160816; b=ttF5p+dT4auGo0wkPvjlofocsHrrGzUmBbz8CtsxewBlorKskSJ85auDm9H6NTSgNE RRoR2I3PpLMhbVMn4QU0ta4k1G1vUvMLTcU1xmVTxFCQjBbcz5bs8oi4xzlHJFxZ2qY7 JHUVF/zkXP64sCXlQldWfaTeYx80ohZxSJ64l+DrRPf+Eb99rlFtPP6SjWw2kijHAh1c t9aY6l/2HozABdC9JZq+8hEo0rqlvuefW4vsb3+52nW/z4VnTDYYYYQqeNA6yolQ+t8N 86tbtloloKtbPJyqGLU+1bSU/wO0UsxJ3o0VjEPo+jGD6rmJcHfjRoQz3+88jbhs2aUE fj1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Ug2olLDrxnMuZeb4MpLS8zlFParCaA5kd+Iv55R9fKI=; b=q8BPCSkb0ip15CBG4q3zB3Qv7fylYgh9PPVl+KpIlxzeJeePvFDLAK5yEnpWa4A3MT iDUyzPWiwtxqiLclUNA+E23IwC8HluQEw2GFkHMuVykLCCmfYRSTLe5LJefZfdDLke4x p1nMzmXpYgPxR6JoYtJioo0ekl48N7F8Ki4fzTYBWFBQDwx8USLSQ2CiQxxIvVV3st6y 2h+3j6Qwu2A9smcPn4lcApQfOiZTSdURM7giirJao0jdLIqDYE07qnrWveom0kxLNjTs HKGeZW8VV13Ghu70q5QDPmA2gKVmbgBUjc0tNP431x2aQI8DHmnN6kQOkQ64xxsTPzTD PPTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si10074763pgi.123.2019.06.10.07.17.34; Mon, 10 Jun 2019 07:17:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390757AbfFJORV (ORCPT + 99 others); Mon, 10 Jun 2019 10:17:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38290 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390501AbfFJORV (ORCPT ); Mon, 10 Jun 2019 10:17:21 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BEA6C61980; Mon, 10 Jun 2019 14:17:20 +0000 (UTC) Received: from flask (unknown [10.43.2.83]) by smtp.corp.redhat.com (Postfix) with SMTP id 9A42819C59; Mon, 10 Jun 2019 14:17:18 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Mon, 10 Jun 2019 16:17:17 +0200 Date: Mon, 10 Jun 2019 16:17:17 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Liran Alon Subject: Re: [PATCH v3 2/3] KVM: X86: Implement PV sched yield hypercall Message-ID: <20190610141717.GA6604@flask> References: <1559178307-6835-1-git-send-email-wanpengli@tencent.com> <1559178307-6835-3-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1559178307-6835-3-git-send-email-wanpengli@tencent.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Jun 2019 14:17:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2019-05-30 09:05+0800, Wanpeng Li: > From: Wanpeng Li > > The target vCPUs are in runnable state after vcpu_kick and suitable > as a yield target. This patch implements the sched yield hypercall. > > 17% performance increasement of ebizzy benchmark can be observed in an > over-subscribe environment. (w/ kvm-pv-tlb disabled, testing TLB flush > call-function IPI-many since call-function is not easy to be trigged > by userspace workload). > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Liran Alon > Signed-off-by: Wanpeng Li > --- > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > @@ -7172,6 +7172,28 @@ void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu) > kvm_x86_ops->refresh_apicv_exec_ctrl(vcpu); > } > > +static void kvm_sched_yield(struct kvm *kvm, unsigned long dest_id) > +{ > + struct kvm_vcpu *target = NULL; > + struct kvm_apic_map *map = NULL; > + > + rcu_read_lock(); > + map = rcu_dereference(kvm->arch.apic_map); > + > + if (unlikely(!map) || dest_id > map->max_apic_id) > + goto out; > + > + if (map->phys_map[dest_id]->vcpu) { This should check for map->phys_map[dest_id]. > + target = map->phys_map[dest_id]->vcpu; > + rcu_read_unlock(); > + kvm_vcpu_yield_to(target); > + } > + > +out: > + if (!target) > + rcu_read_unlock(); Also, I find the following logic clearer { struct kvm_vcpu *target = NULL; struct kvm_apic_map *map; rcu_read_lock(); map = rcu_dereference(kvm->arch.apic_map); if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id]) target = map->phys_map[dest_id]->vcpu; rcu_read_unlock(); if (target) kvm_vcpu_yield_to(target); } thanks.