Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1369130pxb; Fri, 21 Jan 2022 16:44:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzemKY5GllBjnItK/EdLRoQPT5819KRl0ix9N5UJFvcGC+OWRj0rcjMOZl4n6eTnFeiTe2M X-Received: by 2002:a17:903:1c2:b0:14a:586c:134f with SMTP id e2-20020a17090301c200b0014a586c134fmr6024278plh.14.1642812281825; Fri, 21 Jan 2022 16:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642812281; cv=none; d=google.com; s=arc-20160816; b=awPftyJukh++EtOX4KQlnoQ7tyr4Q5BgiDvVILRMSlrMwVS3m1ruz9BKv7/0E2Bn8/ M5ChQeaoKVlohjg+tQ05lq7h+BHsE37n8TSfKnAmtcaxghOSO3/n5QKpkJiIIli3Ad5c IVCI47rICRBEUh7MKwdOcfuH3IIGbt00Dfk94C9rt5Q4skkAagsnUuDrQu0NP8IA/iBY 5nR+WAN0QVbrPTPD43MnYCvDm0rddUFu5ZtG+pDuRyfeQ/LusQEHDLtfOywlXJJmgMIh cnKjyZ4H8XblRNW69VK5nC7gjav4JP84qmhuIggiuoDf7jhXpMHX2+KcJkn+fTvE1ewE 6bow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hdrnzFbdF5hXjL6FluafisxqN//Epf/ujbEewfLiw6w=; b=pLMMQBEV/wa7YxCwx7FcqPj+L3WYkYqyqPo5SqNur0Sg82i2dTmPuBolZWhI5tDZJx WHRzTfWxeYtQNtgTn12ViMArbsWLbrjcTtPsMMcUhLa3l0gNpl2L14zmgfFJXTwejo0C eBHQPoxWoDqxAAzEOqU6sg4rwKmePx6cTt9xPdMRtXzEeusLghMMWDjFnwJ9bhjxmplP TFC0zaodCJqMTQAekTQLKnEyZ/dqrf46rg5dliEFOusq2lp3+1JZIKYbPSXl6Hcs8aUh NKnVIMz8bUgTm50Q7L6am59pZU7Dee1KVyRG2lLOg5UBhsmBIcozzAUOqJsZywzkAab5 FPGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VVQqOz9u; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si8131498plg.443.2022.01.21.16.44.30; Fri, 21 Jan 2022 16:44:41 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=VVQqOz9u; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379802AbiAUJ5D (ORCPT + 99 others); Fri, 21 Jan 2022 04:57:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349787AbiAUJ5D (ORCPT ); Fri, 21 Jan 2022 04:57:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5DD3C061574 for ; Fri, 21 Jan 2022 01:57:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8142DB81F86 for ; Fri, 21 Jan 2022 09:57:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1095EC340E1; Fri, 21 Jan 2022 09:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642759020; bh=qR8VRYTCz1DGsP6TG4tf/9SSEqtJu9KSNoIFjCNdds4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VVQqOz9uMKa1SiorJ1jdHxE/y7sxPOPEm3xQTwwIF4pQMa8Z06Koa1fgjHD6ibvJO KpIi0ShE7YobgQo2mgLZdB/p/QguJP2oRrB9C6ZPVVYSxL85FctCWxzh6BnmVeVW3L mWicYzvXD+ChznQenltM/g0HDZ00Rfyovc9Zssd6G3CRJt2HRusynZJWwqP2dgI2hM CQFrVB4zotfL8X13KvEVfrOgRx0BRnl8YoVdHUEwT5GOrv10Oq8QxkDDgGU64iZZDC Inpu17W0k3lCYuVq+eqgaNWAoEzkVZj28aiicMRvvyzusY4EBximpqMDQEqbYyD9OS Y5YPrPCdU7itg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 3664640C99; Thu, 20 Jan 2022 12:47:27 -0300 (-03) Date: Thu, 20 Jan 2022 12:47:27 -0300 From: Arnaldo Carvalho de Melo To: Eric Lin Cc: Eduardo Habkost , Namhyung Kim , linux-kernel , Jiri Olsa , Alexander Shishkin , Mark Rutland , Ingo Molnar , Peter Zijlstra , Yao Jin , Greentime Hu , Paul Walmsley , Vincent Chen Subject: Re: About perf tool set exclude_guest = 1 on guest environment Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Thu, Jan 20, 2022 at 09:35:59PM +0800, Eric Lin escreveu: > On Wed, Jan 19, 2022 at 1:02 PM Namhyung Kim wrote: > > On Mon, Jan 17, 2022 at 8:05 PM Eric Lin wrote: > > > Currently, I run the perf command 'perf record -e branches:u ls' and > > > 'perf record -e branches ls'. It will set exclude_guest = 1 as below: > > > > > > # perf record -e branches:u ls > > > # perf evlist -v > > > branches:u: .., exclude_kernel: 1, exclude_hv: 1,, exclude_guest: 1, .. > > > > > > # perf record -e branches ls > > > # perf evlist -v > > > branches: ..., exclude_guest: 1, ... > > > > > > As I understand it, set exclude_guest =1 will not include guest counting. > > > May I ask if I run the above commands as a guest user, should the > > > architecture implementation ignore this exclude_guest flags and still > > > make perf can count guest events in Linux kernel? > > > > So do you want to run the command in the host? > > Then you can use both 'H' and 'G' modifiers like > > > > # perf record -e branches:HG ls > > > > or (for user-mode only) > > > > # perf record -e branches:uHG ls > > > > Actually, I want to run the commands in the guest. > But when I run the commands "perf record -e branches:u ls" and "perf > record -e branches ls", it will set exclude_guet = 1. > According to the documentation[1] exclude_guest definition, it should > not count guest events. > So, if I run these commands as a guest user can I get the profile data? > > [1] https://man7.org/linux/man-pages/man2/perf_event_open.2.html The tool shouldn't know that it is running in a guest, right? And the kernel, running on a guest should exclude its guests if attr.exclude_guest is set, not itself and its non-guest userland. So, before delving into how the kernel running on guest _actually_ handles attr.exclude_guest=1 behaves, what are the results you are getting from running perf on a guest? Lemme see... On a fedora:35 guest: [root@fedora ~]# perf record ls anaconda-ks.cfg perf.data [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.014 MB perf.data (3 samples) ] [root@fedora ~]# perf evlist -v cpu-clock:pppH: type: 1, size: 128, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 [root@fedora ~]# IIRC there is some extra magic to allow 'cycles' to be seen on the guest, but apart from that it seems to work. Eduardo, can you help us here? - Arnaldo