Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1581620imu; Wed, 12 Dec 2018 00:09:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/WmmkEw6eVqjol9sPinZw8p1N6AGiuNtKtt/hvfJSGPmpbZAxm/xkyKCk3nkhJNvD7xSp3r X-Received: by 2002:a63:e545:: with SMTP id z5mr17411407pgj.195.1544602156979; Wed, 12 Dec 2018 00:09:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544602156; cv=none; d=google.com; s=arc-20160816; b=uZqmmqEeUIyMqWx6/cNI46re4lM1IYYoEseyh4c00tUZKMKi/gQ87uYktsd7EcCNk7 nlaNdfi/xcAu+ZiR/TMl1mFZdMx2Pfkt27CHOTMm6uH38rK2tl5VtXRkO9h3i7nkGwRy VoBg2TjgQ2fBPV0nsmVggUW3VMNFPhOT13ts8JjBXDjrhLGTAKWduwJYxhJpd7xYmo8+ YQxdbYZ+wHC9aT6N+C0ALVMg4N9poNHvIVgytRMZT3awrzvfqZLp9JahzH9IxE7TmJ6+ haUBSwx6P+HCJRVTLPEkD1G2g72dSPHuoRu2r+dEi/7vch2fGtqLUGjkuF0YOvufK5Kk X7dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=w31Eg3s/rGaLNnAdvrE+Hnhr8WkskzUJoQnGKyrb550=; b=L+4cxDSwDIoZ/1MNM0/TYpqvaddXHnNSG1wnz/UhHysnfBLtYPoVR8Jl+tVMHXAr0I M8irNNV8si381Yr26T3Rg3pq5CsLEcd/Pnz/pmDhcpSsKGVpzMhIHwCxERchGwsG818H sHbQwVU9ME/cppnWV0KkwqJMKo2lZ+dEVVW2zi2KvE4Zc4B89GAgjD4pWyMjBaD0Kswv 1B7HTRbCxhP2cBdQEvllPLF3hH+kn7N5Xt5tLk8RKYl8g1lDAkV5fMGdie1klLfG90gh PSdsj7LyIuM6NP5Ag+srb59RqPUAG8MAPvasN0SJYKICoc7ercKPQx9Mf3sWG2jZG/3Y 5+FQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a190si13376557pgc.423.2018.12.12.00.09.01; Wed, 12 Dec 2018 00:09:16 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726694AbeLLIHp (ORCPT + 99 others); Wed, 12 Dec 2018 03:07:45 -0500 Received: from foss.arm.com ([217.140.101.70]:35342 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726007AbeLLIHp (ORCPT ); Wed, 12 Dec 2018 03:07:45 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3DFED80D; Wed, 12 Dec 2018 00:07:44 -0800 (PST) Received: from localhost (e113682-lin.copenhagen.arm.com [10.32.144.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CAE0F3F614; Wed, 12 Dec 2018 00:07:43 -0800 (PST) Date: Wed, 12 Dec 2018 09:07:42 +0100 From: Christoffer Dall To: Andrew Murray Cc: Michael Ellerman , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Shawn Guo , Sascha Hauer , Will Deacon , Mark Rutland , Benjamin Herrenschmidt , Thomas Gleixner , Borislav Petkov , x86@kernel.org, linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joerg Roedel , "paulus@samba.org" Subject: Re: [PATCH 10/10] perf/doc: update design.txt for exclude_{host|guest} flags Message-ID: <20181212080742.GA30263@e113682-lin.lund.arm.com> References: <1542363853-13849-1-git-send-email-andrew.murray@arm.com> <1542363853-13849-11-git-send-email-andrew.murray@arm.com> <87pnv00yuf.fsf@concordia.ellerman.id.au> <20181120133202.GH35798@e119886-lin.cambridge.arm.com> <87bm5sxqya.fsf@concordia.ellerman.id.au> <20181211135903.GG13393@e119886-lin.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181211135903.GG13393@e119886-lin.cambridge.arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 11, 2018 at 01:59:03PM +0000, Andrew Murray wrote: > On Tue, Dec 11, 2018 at 10:06:53PM +1100, Michael Ellerman wrote: > > [ Reviving old thread. ] > > > > Andrew Murray writes: > > > On Tue, Nov 20, 2018 at 10:31:36PM +1100, Michael Ellerman wrote: > > >> Andrew Murray writes: > > >> > > >> > Update design.txt to reflect the presence of the exclude_host > > >> > and exclude_guest perf flags. > > >> > > > >> > Signed-off-by: Andrew Murray > > >> > --- > > >> > tools/perf/design.txt | 4 ++++ > > >> > 1 file changed, 4 insertions(+) > > >> > > > >> > diff --git a/tools/perf/design.txt b/tools/perf/design.txt > > >> > index a28dca2..7de7d83 100644 > > >> > --- a/tools/perf/design.txt > > >> > +++ b/tools/perf/design.txt > > >> > @@ -222,6 +222,10 @@ The 'exclude_user', 'exclude_kernel' and 'exclude_hv' bits provide a > > >> > way to request that counting of events be restricted to times when the > > >> > CPU is in user, kernel and/or hypervisor mode. > > >> > > > >> > +Furthermore the 'exclude_host' and 'exclude_guest' bits provide a way > > >> > +to request counting of events restricted to guest and host contexts when > > >> > +using virtualisation. > > >> > > >> How does exclude_host differ from exclude_hv ? > > > > > > I believe exclude_host / exclude_guest are intented to distinguish > > > between host and guest in the hosted hypervisor context (KVM). > > > > OK yeah, from the perf-list man page: > > > > u - user-space counting > > k - kernel counting > > h - hypervisor counting > > I - non idle counting > > G - guest counting (in KVM guests) > > H - host counting (not in KVM guests) > > > > > Whereas exclude_hv allows to distinguish between guest and > > > hypervisor in the bare-metal type hypervisors. > > > > Except that's exactly not how we use them on powerpc :) > > > > We use exclude_hv to exclude "the hypervisor", regardless of whether > > it's KVM or PowerVM (which is a bare-metal hypervisor). > > > > We don't use exclude_host / exclude_guest at all, which I guess is a > > bug, except I didn't know they existed until this thread. > > > > eg, in a KVM guest: > > > > $ perf record -e cycles:G /bin/bash -c "for i in {0..100000}; do :;done" > > $ perf report -D | grep -Fc "dso: [hypervisor]" > > 16 > > > > > > > In the case of arm64 - if VHE extensions are present then the host > > > kernel will run at a higher privilege to the guest kernel, in which > > > case there is no distinction between hypervisor and host so we ignore > > > exclude_hv. But where VHE extensions are not present then the host > > > kernel runs at the same privilege level as the guest and we use a > > > higher privilege level to switch between them - in this case we can > > > use exclude_hv to discount that hypervisor role of switching between > > > guests. > > > > I couldn't find any arm64 perf code using exclude_host/guest at all? > > Correct - but this is in flight as I am currently adding support for this > see [1]. > > > > > And I don't see any x86 code using exclude_hv. > > I can't find any either. > > > > > But maybe that's OK, I just worry this is confusing for users. > > There is some extra context regarding this where exclude_guest/exclude_host > was added, see [2] and where exclude_hv was added, see [3] > > Generally it seems that exclude_guest/exclude_host relies upon switching > counters off/on on guest/host switch code (which works well in the nested > virt case). Whereas exclude_hv tends to rely solely on hardware capability > based on privilege level (which works well in the bare metal case where > the guest doesn't run at same privilege as the host). > > I think from the user perspective exclude_hv allows you to see your overhead > if you are a guest (i.e. work done by bare metal hypervisor associated with > you as the guest). Whereas exclude_guest/exclude_host doesn't allow you to > see events above you (i.e. the kernel hypervisor) if you are the guest... > > At least that's how I read this, I've copied in others that may provide > more authoritative feedback. > > [1] https://lists.cs.columbia.edu/pipermail/kvmarm/2018-December/033698.html > [2] https://www.spinics.net/lists/kvm/msg53996.html > [3] https://lore.kernel.org/patchwork/patch/143918/ > I'll try to answer this in a different way, based on previous discussions with Joerg et al. who introduced these flags. Assume no support for nested virtualization as a first approximation: If you are running as a guest: - exclude_hv: stop counting events when the hypervisor runs - exclude_host: has no effect - exclude_guest: has no effect If you are running as a host/hypervisor: - exclude_hv: has no effect - exclude_host: only count events when the guest is running - exclude_guest: only count events when the host is running With nested virtualization, you get the natural union of the above. **This has nothing to do with the design of the hypervisor such as the ARM non-VHE KVM which splits its execution across EL1 and EL2 -- those are both considered host from the point of view of Linux as a hypervisor using KVM, and both considered hypervisor from the point of view of a guest.** Thanks, Christoffer