Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp31086pxa; Thu, 13 Aug 2020 18:25:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRRUFO9hfY6FJFLndUiKZ9MNpKz7VswT6uvhiRYeMY99ATU0xGi/g/6oeHlLhFVUKjCSnA X-Received: by 2002:a05:6402:6cc:: with SMTP id n12mr118000edy.258.1597368342014; Thu, 13 Aug 2020 18:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597368342; cv=none; d=google.com; s=arc-20160816; b=rBdwweBZH5qvZ8lxH35Wy0MHxOVblq4Dm3pPHatEcL708XC3k+d46ctPY7/M3sue0S DNw0fAGhrTT6/r5O6XrShwIpTWiT242WsNHuIS/iwaPYwOWTLFHxpfhM/v9MDEujQKCu WxsXUgdTIHc7lbZ6iMMSYQQNaB6HBn/R/vgwKgQnrIL4Vn6nPqJ+p1JLx2FO212jyq6B 5NnGp8UwmDsb1/iSRsCYG85a6CSO3HAHbYsd28mcOPV/Kxo7lYmBacUhzQyAs76R80ZJ i2Rq4JKl78ZoPxA6mBBV3YI4SfYf103xPgKJUaQ6DPbU6pR5ItdibiVnqGjJRrOGaSDc nY4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=IX5RslWA46wpweAbgQ57gmLt6ipVQxHoGXyf3A3tVo8=; b=svJD63xLHpfheFnZkbSA2fgWyyWvvWjaIgXjhwN5U6uX7AnPi3qRpNQXBicPKhjWe7 6y2X4AV3dsppmR4ppHCVutuYQw1+CVzUw/SWhvrZxdVSHEuhdkjVtMcMfTmkFh3n5+E9 O8r9FEj8yESqOwravVUSoSykeJjMxhuXbGBz6GE0YWnBM3F1T275huwGksehcsBLZyOp 0luOsnYwMBpnLCYrxsIPhZlZwY7nyOmKmwQHK3CgaLhKIyrq7zVS+p3cGsC7X/u84wLC BajdyyWQdldNG7FrvQTw0wNf4SAduyK6IJegR46940+KUSe1doW5LQvDMo+eTr1xrY3s lFvQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce15si4933960edb.291.2020.08.13.18.25.15; Thu, 13 Aug 2020 18:25:42 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726568AbgHNBWg (ORCPT + 99 others); Thu, 13 Aug 2020 21:22:36 -0400 Received: from mga03.intel.com ([134.134.136.65]:14269 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726522AbgHNBWf (ORCPT ); Thu, 13 Aug 2020 21:22:35 -0400 IronPort-SDR: Jz0iNvqK0/ONNPF7GjF5CtVKMAaVAlxWLsg7YR2vl9q6LnIO+HUaqi7qkQu9aQXwDzoshkgbeW ILTwhwphwMcg== X-IronPort-AV: E=McAfee;i="6000,8403,9712"; a="154307771" X-IronPort-AV: E=Sophos;i="5.76,310,1592895600"; d="scan'208";a="154307771" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2020 18:22:34 -0700 IronPort-SDR: AwvoL0dfMrKxKVkoSjxStLaTvQn28OOXeb6ujMiEui2VGSYcNmsigFObyR9o2TDufW26j+Ss4D kaIrG4yBI14g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,310,1592895600"; d="scan'208";a="333283331" Received: from kbl-ppc.sh.intel.com ([10.239.159.55]) by FMSMGA003.fm.intel.com with ESMTP; 13 Aug 2020 18:22:32 -0700 From: Jin Yao To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, like.xu@linux.intel.com, Jin Yao Subject: [PATCH v3] perf parse-events: Set exclude_guest=1 for user-space counting Date: Fri, 14 Aug 2020 09:21:20 +0800 Message-Id: <20200814012120.16647-1-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently if we run 'perf record -e cycles:u', exclude_guest=0. But it doesn't make sense in most cases that we request for user-space counting but we also get the guest report. Of course, we also need to consider perf kvm usage case that authorized perf users on the host may only want to count guest user space events. For example, perf kvm --guest record -e cycles:u When we have 'exclude_guest=1' for perf kvm usage, we may get nothing from guest events. To keep perf semantics consistent and clear, this patch sets exclude_guest=1 for user-space counting but except for perf kvm usage. Before: perf record -e cycles:u ./div perf evlist -v cycles:u: ..., exclude_kernel: 1, exclude_hv: 1, ... After: perf record -e cycles:u ./div perf evlist -v cycles:u: ..., exclude_kernel: 1, exclude_hv: 1, exclude_guest: 1, ... Before: perf kvm --guest record -e cycles:u -vvv perf_event_attr: size 120 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|ID|CPU|PERIOD read_format ID disabled 1 inherit 1 exclude_kernel 1 exclude_hv 1 freq 1 sample_id_all 1 After: perf kvm --guest record -e cycles:u -vvv perf_event_attr: size 120 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|ID|CPU|PERIOD read_format ID disabled 1 inherit 1 exclude_kernel 1 exclude_hv 1 freq 1 sample_id_all 1 For Before/After, exclude_guest are both 0 for perf kvm usage. perf test 6 6: Parse event definition strings : Ok Signed-off-by: Jin Yao --- v3: --- For perf kvm, if we have 'exclude_guest=1', we can't get guest events. So we don't set 'exclude_guest=1' for perf kvm. v2: --- Fix the 'perf test 6' failure. tools/perf/tests/parse-events.c | 4 ++-- tools/perf/util/parse-events.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 7f9f87a470c3..aae0fd9045c1 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -719,7 +719,7 @@ static int test__group2(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); @@ -842,7 +842,7 @@ static int test__group3(struct evlist *evlist __maybe_unused) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 9f7260e69113..ff4c23d2a0f3 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -37,6 +37,7 @@ #include "util/evsel_config.h" #include "util/event.h" #include "util/pfm.h" +#include "perf.h" #define MAX_NAME_LEN 100 @@ -1794,6 +1795,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str, if (*str == 'u') { if (!exclude) exclude = eu = ek = eh = 1; + if (!exclude_GH && !perf_guest) + eG = 1; eu = 0; } else if (*str == 'k') { if (!exclude) -- 2.17.1