Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp306048pxu; Fri, 23 Oct 2020 00:51:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIrqHdsCtwM05QolacLpTLrHijWBxnbm6kz66m5rjdsyXx+cPzFagUNR8Ud2uliBu7Y/v0 X-Received: by 2002:a17:906:881:: with SMTP id n1mr750964eje.502.1603439489821; Fri, 23 Oct 2020 00:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603439489; cv=none; d=google.com; s=arc-20160816; b=Ug2NuelxAPEoR1S2lJnEbNmblrgG/CjDOAw+Vc3oTRv4Go56Aj8m6NJ7zfIXDt1o8J iRT1itEdOIlyLll+9Y3o2EPfkWPrkaieXjh9OQHcAN2qQGCffj6cwHuiGn/W84PIDQ+n SnwTAxvmlGC2e2DR1VKnVKQ4URfSoEStClx/st39TCxRjDYjqn3UwXtq3eUJovy4czSz GYIzUR1GD+eZfwQbVDb3qBqaSR5f38uAz40NamUlpD83j1234eJAyp5IQ1+MZ7R0l+cT f8tWHlAr01u0U4aJ091IQqy4AR/sn0uV5qygSz7FKJ9aiLdljZABlwBNkRPyoL3/THcN 4X3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=q84jJ3bGQh9hixZvKUeeIGN3DtugPKTamoF/dyrHLFI=; b=b4dDo/nfM1Ozt3OW+XKyt36W2fLQxLAQQllyS/QQqVk2faxvYQSMXNDeyQUDtd+eb2 PhNRzt1OaiXQZ/7JLsyJI9tIHWyrGtwXVdRWSSt7RICN6jyuzMycDRpWySMtVB76vk7j XSOekFi5Y8I3rCvUKWOnGX3CgauVanyck8X39i7akxIP/CzfBtHmgVFH1sH/2nuAPtnJ +OtKNBKV155EkWYVTCCRksTmNckW1JpvZFtXmqb8/1ec+7aC1uvX0d7yNFXMAhMsBqvi +JLlkepk+3fZhwT9Z+c0yrk5TNyJdREr3nuS8ekGCywDnMh7XAYG/emz0FEknmNFpZdG e5IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tz+FVd1p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si374568edq.207.2020.10.23.00.51.07; Fri, 23 Oct 2020 00:51:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tz+FVd1p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S374834AbgJWDaX (ORCPT + 99 others); Thu, 22 Oct 2020 23:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S374833AbgJWDaW (ORCPT ); Thu, 22 Oct 2020 23:30:22 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD0CDC0613CE for ; Thu, 22 Oct 2020 20:30:22 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id m11so120974qvt.11 for ; Thu, 22 Oct 2020 20:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=q84jJ3bGQh9hixZvKUeeIGN3DtugPKTamoF/dyrHLFI=; b=tz+FVd1pN36tw1bBQmvqr+Y2n0MIU+W7R+izbV8oJ8fgeAKPZoplKAvJcLYPYctDkN FiltZT50WLAaR4aspJVHloJjO6Yw1L1Qo2/gY707fc0byoSUHUFN4+yUOfmvLN7b7BLf dFvtLW5stbWzfFZn3avsXzwdQ5dlSZJ8ADvMW8xLX8kg/cMUonSvv0jYUXn/Y7Ax8PvG 3hAzTfDOVNGkgm+apl6pysVZC+xovU7QLo3krg1eUDk/srcG7SOLFJaiJleL6ahNbCxA DCkMacJ9RvSY6jYKBxMbCsMGmthYVsXsNzmhdmF9SZIZlLoeQ+5G6/o8OcyIVvsEkQaw U9Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=q84jJ3bGQh9hixZvKUeeIGN3DtugPKTamoF/dyrHLFI=; b=OGH7ukdI+iC02kYrIrJkewFLf4nAWaatwdzdj+GMIrpGqTU0ybXU+stql9i4KbyPJa ZHaxqQzhlmfMIBQmBU9vujaLTqmnxRv1GXc4o1b+YtiCeuwWGJfKyy38czv9soVLF1xs k+dTLivyB+23pv/ZwIAxE5eTurbjdAaOpZOhDI6b/fIuBnVLYjEmLW1hmn7kiUpmXRdu texLNxXSfPxoVFTwPPQoAeLx9WeNNZoMfZkB/uRG3ZBtxWbxMmuqkncOoWSosJP1yBlh GMi5LSKB2wGdmX9mw2M2XuFOjpcpbc0nIcKLMsfp5O/PXJhseLgVzu12FTiArLh+H4i0 x3zA== X-Gm-Message-State: AOAM530pEXVg0qPRKlfeFp7lo9IUyTE1WJW5dQvnoTt2E0bvk5sI0YWc yhHe8A9JOplYFxPrCakty+M4wxpMCLdD Sender: "joshdon via sendgmr" X-Received: from joshdon.svl.corp.google.com ([2620:15c:2cd:202:a28c:fdff:fee1:cc86]) (user=joshdon job=sendgmr) by 2002:a05:6214:122a:: with SMTP id p10mr488108qvv.0.1603423821912; Thu, 22 Oct 2020 20:30:21 -0700 (PDT) Date: Thu, 22 Oct 2020 20:29:43 -0700 In-Reply-To: <20201023032944.399861-1-joshdon@google.com> Message-Id: <20201023032944.399861-2-joshdon@google.com> Mime-Version: 1.0 References: <20201023032944.399861-1-joshdon@google.com> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog Subject: [PATCH 2/3] kvm: better handling for kvm halt polling From: Josh Don To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , "David S. Miller" , Jakub Kicinski Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Paolo Bonzini , Eric Dumazet , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Josh Don , Xi Wang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the new functions prepare_to_busy_poll() and friends to kvm_vcpu_block. The busy polling cpu will be considered an idle target during wake up balancing. cpu_relax is also added to the polling loop to improve the performance of other hw threads sharing the busy polling core. Suggested-by: Xi Wang Signed-off-by: Josh Don Signed-off-by: Xi Wang --- virt/kvm/kvm_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index cf88233b819a..8f818f0fc979 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2772,7 +2772,9 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns); ++vcpu->stat.halt_attempted_poll; + prepare_to_busy_poll(); /* also disables preemption */ do { + cpu_relax(); /* * This sets KVM_REQ_UNHALT if an interrupt * arrives. @@ -2781,10 +2783,12 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu) ++vcpu->stat.halt_successful_poll; if (!vcpu_valid_wakeup(vcpu)) ++vcpu->stat.halt_poll_invalid; + end_busy_poll(false); goto out; } poll_end = cur = ktime_get(); - } while (single_task_running() && ktime_before(cur, stop)); + } while (continue_busy_poll() && ktime_before(cur, stop)); + end_busy_poll(false); } prepare_to_rcuwait(&vcpu->wait); -- 2.29.0.rc1.297.gfa9743e501-goog