Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7166232ybp; Wed, 16 Oct 2019 04:55:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxngvsfDkxkzfZj2uvBsmL1ACKP8NPV/lTatMb1rRnAiKZ+5vzfMRh3Sez4dJl0z2+X9NLG X-Received: by 2002:a05:6402:1548:: with SMTP id p8mr38612365edx.43.1571226915213; Wed, 16 Oct 2019 04:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571226915; cv=none; d=google.com; s=arc-20160816; b=ZbDIp7sm4IgNHk/Fc5Zbp4Vkd+Onrw6T9B5TgptGabFHC13EVrwBVmE9xuV/+elGHX Piarfgbc9Tczr1jdvwrC+Jclx9EDYGx1BoLHb5a+rms1URkPo4BcHF0jK8y1d6XVY6d1 Kq6hLMVfkY0oHgQGbddb6hsqr4V8MhTZlE1W/WVQkWTsyg8RZaR0ui8Ei7nK4FCanLUy 7GuXGSsOFmPNEVEFc18p2CRo9wjQUCxeHpVOZaKhjIP+szHVvjmupgjMuwKNwg0WXn/P tOLqktr92dyEUFOiRyjYudlxh5HkvFlqYasPR/grW4J0I+Uz1brP9eB8EzaYsnjoHNuP p11g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=N+9zhD6sQkjtyZn9LozIr63oV0xoTG40KqwCVlYDKHM=; b=xLoGkRmQmDrdNAABi7ef1FU8SK7xRxwJmvw0lZE9WGxUl5OGUbhSjkykQPr9VA0EMm lZpx0DnAZGYhJutjVomwyqc/XBIfqAoLKlxPpquFiVDFK09uZzE/3AOeap264gL9LY4n uaPt2EFFfnUCoAUdhxvbIG9rJQFXwdIsWwMncaS2DO3ihvh0zWUtych8SBr00YRrF7fp RqHAuvttoDOzIrGEBLfiywxp+WfJDOLWfDvIBuD23dMKX8l7cIr6qgxSqNQx42MY1xeO cP+ytAFDCpYumK9lrI7rcRmP8Bvjf4dydqZIcPt1MsGI6l7YwkHBEEnqE0y8z0HT2SP3 +SSw== 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 ok21si15241038ejb.95.2019.10.16.04.54.52; Wed, 16 Oct 2019 04:55:15 -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 S2389424AbfJPHHm (ORCPT + 99 others); Wed, 16 Oct 2019 03:07:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59028 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389242AbfJPHHl (ORCPT ); Wed, 16 Oct 2019 03:07:41 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 227348666C for ; Wed, 16 Oct 2019 07:07:41 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id o10so11265408wrm.22 for ; Wed, 16 Oct 2019 00:07:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=N+9zhD6sQkjtyZn9LozIr63oV0xoTG40KqwCVlYDKHM=; b=D9zr6l7JKbNusCi5zgJ6K9cD5+HgDlLIiUwtty+qEaLktej6uX/rdRwS7SYpYuoe8c VC4dX12QmSSdlKjqaWuI0G6XNzyOzInedRseiEofEYjGz3me7CTCmQm4+x6aLNoEqqkd 9p+9bbEC6NknomSBB5EOtUsevqA6cltDa+I2F4SdiYCpGaS+/TveAwSDNoeBed3G+5+V ZIfvFppKp3Xm9lR9sFwOqQhtFVe9ZhSjejSJQAKt8GshqGO/uJT2Z0zQxUhuY70saP1A +fJ6vW+goGJ2xVynbsn9R2BCIbYRSTXewaxxlHhCm9f5p6sVWtuLMfz3zf833IDaYOGu GHfw== X-Gm-Message-State: APjAAAWZeH6QhqsDkFhYTskJZhgkiFz1el/0U6E49nO6GaD1ZYiKBJxh MXnP9ub2wQ/7tl7K1U9qWvUg0fxG/NYuzM139CyZ9sVHB2XXcIDESfIq9bkHx8dEYFql025boIE +03JpFd8qVgOrSxBFbiiRPOJz X-Received: by 2002:adf:8295:: with SMTP id 21mr1239232wrc.14.1571209659471; Wed, 16 Oct 2019 00:07:39 -0700 (PDT) X-Received: by 2002:adf:8295:: with SMTP id 21mr1239207wrc.14.1571209659089; Wed, 16 Oct 2019 00:07:39 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:ddc7:c53c:581a:7f3e? ([2001:b07:6468:f312:ddc7:c53c:581a:7f3e]) by smtp.gmail.com with ESMTPSA id a9sm2047772wmf.14.2019.10.16.00.07.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Oct 2019 00:07:38 -0700 (PDT) Subject: Re: [PATCH 12/14] KVM: retpolines: x86: eliminate retpoline from vmx.c exit handlers To: Andrea Arcangeli Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vitaly Kuznetsov , Sean Christopherson References: <20190928172323.14663-1-aarcange@redhat.com> <20190928172323.14663-13-aarcange@redhat.com> <933ca564-973d-645e-fe9c-9afb64edba5b@redhat.com> <20191015164952.GE331@redhat.com> <870aaaf3-7a52-f91a-c5f3-fd3c7276a5d9@redhat.com> <20191015203516.GF331@redhat.com> <20191015234229.GC6487@redhat.com> From: Paolo Bonzini Message-ID: <27cc0d6b-6bd7-fcaf-10b4-37bb566871f8@redhat.com> Date: Wed, 16 Oct 2019 09:07:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191015234229.GC6487@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/10/19 01:42, Andrea Arcangeli wrote: > On Wed, Oct 16, 2019 at 12:22:31AM +0200, Paolo Bonzini wrote: >> Oh come on. 0.9 is not 12-years old. virtio 1.0 is 3.5 years old >> (March 2016). Anything older than 2017 is going to use 0.9. > > Sorry if I got the date wrong, but still I don't see the point in > optimizing for legacy virtio. I can't justify forcing everyone to > execute that additional branch for inb/outb, in the attempt to make > legacy virtio faster that nobody should use in combination with > bleeding edge KVM in the host. Yet you would add CPUID to the list even though it is not even there in your benchmarks, and is *never* invoked in a hot path by *any* sane program? Some OSes have never gotten virtio 1.0 drivers. OpenBSD only got it earlier this year. >> Your tables give: >> >> Samples Samples% Time% Min Time Max time Avg time >> HLT 101128 75.33% 99.66% 0.43us 901000.66us 310.88us >> HLT 118474 19.11% 95.88% 0.33us 707693.05us 43.56us >> >> If "avg time" means the average time to serve an HLT vmexit, I don't >> understand how you can have an average time of 0.3ms (1/3000th of a >> second) and 100000 samples per second. Can you explain that to me? > > I described it wrong, the bpftrace record was a sleep 5, not a sleep > 1. The pipe loop was sure a sleep 1. It still doesn't add up. 0.3ms / 5 is 1/15000th of a second; 43us is 1/25000th of a second. Do you have multiple vCPU perhaps? > The issue is that in production you get a flood more of those with > hundred of CPUs, so the exact number doesn't move the needle. > This just needs to be frequent enough that the branch cost pay itself off, > but the sure thing is that HLT vmexit will not go away unless you execute > mwait in guest mode by isolating the CPU in the host. The number of vmexits doesn't count (for HLT). What counts is how long they take to be serviced, and as long as it's 1us or more the optimization is pointless. Consider these pictures w/o optimization with optimization ---------------------- ------------------------- 0us vmexit vmexit 500ns retpoline call vmexit handler directly 600ns retpoline kvm_vcpu_check_block() 700ns retpoline kvm_vcpu_check_block() 800ns kvm_vcpu_check_block() kvm_vcpu_check_block() 900ns kvm_vcpu_check_block() kvm_vcpu_check_block() ... 39900ns kvm_vcpu_check_block() kvm_vcpu_check_block() 40000ns kvm_vcpu_check_block() kvm_vcpu_check_block() Unless the interrupt arrives exactly in the few nanoseconds that it takes to execute the retpoline, a direct handling of HLT vmexits makes *absolutely no difference*. >> Again: what is the real workload that does thousands of CPUIDs per second? > > None, but there are always background CPUID vmexits while there are > never inb/outb vmexits. > > So the cpuid retpoline removal has a slight chance to pay for the cost > of the branch, the inb/outb retpoline removal cannot pay off the cost > of the branch. Please stop considering only the exact configuration of your benchmarks. There are known, valid configurations where outb is a very hot vmexit. Thanks, Paolo