Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3364018pxb; Fri, 5 Nov 2021 14:29:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqEsrayd+AISiaNpGjMU3DwpRydlVXbG2yTKmIbL6MU94YQrWVIY3YdnVdrsat9NRHT2Hd X-Received: by 2002:a17:906:3b54:: with SMTP id h20mr2954457ejf.468.1636147751028; Fri, 05 Nov 2021 14:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636147751; cv=none; d=google.com; s=arc-20160816; b=QGF5JCWcC+SfkNWSOkk7DuJTnr9+kCLUbvWHaHAxJfmxCzZQVdtlVG5bfAORA2PM20 sAZmj7CoWdueBjrlA+0XskCy8b7ci59GqQkMMeQTs1ZwRyBehYxXUL3inu696YLP5y6y GntrWsSfmGA9nxoAnEALlgJhuKN7pTAb49ibdoTyfdeGJLKEPSWXvIPS7Kb8ZNPKbu/e ihbQADOQKkGLtMjr2/CtD7JnQpNTeLR/pgQJuSBC2wQSw5rNkEatxa0Fw6PLKZUhUOn3 nnzXZQbpeQbUoXBYfRVW2+Jd68cX3buIBKX+EyeBDrs22YhwoB77Mjh4dFprSXvRbvn5 ipQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=sdBRipuhd/DnnvTp2K6X1I90WSvK4UoQDH9TPK1ZEYc=; b=c2fbAA5+x33YmVG7H95H2Bb3DqmIQP+I4YgxNAe81TXfZKYqOG/5sz4C0Z2CfTUR/Z QDn3NpxpLl9ZCVQj2bf0R0uCCFFLx/a/EODSRNUa8fUHyuBDm+1jh142qaTKnMTmIgcm WMl5kHbuK11kyO577HT0VIZnX26JDgoohq0XcDe9i1Xi2Bj2YkY5cYJ7ejCOdAT44BB8 l6pypTChZzoZ/tJ9odW2ohbDqHrKQb9ceTd2+21dGS5pG/LgQDiJxur5F+AbtnL+hR5D I+sNzqZEv/iYXPfoyxFtxyP02f++5m8kry3qIWldJE+QLs2+WXeg3LQdpKpj5TXjSyeM u9yw== 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=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 qn18si5708370ejb.220.2021.11.05.14.28.45; Fri, 05 Nov 2021 14:29:11 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234453AbhKESDX (ORCPT + 99 others); Fri, 5 Nov 2021 14:03:23 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:44574 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbhKESDW (ORCPT ); Fri, 5 Nov 2021 14:03:22 -0400 Received: by mail-lf1-f44.google.com with SMTP id y26so20250895lfa.11 for ; Fri, 05 Nov 2021 11:00:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sdBRipuhd/DnnvTp2K6X1I90WSvK4UoQDH9TPK1ZEYc=; b=aMgtr3tZ05Ompywz5n7xguWZ0wIJQVp2OHiBKHLJGbgGX8KftBPyqldjn9hCc9XrHZ V62r2I+iUA0HiN32gRhSIHvuR+L+dRNnCTAATYsaRQ37S4qdQ1h2WE+ffg2oCaM+8iHJ FmgWhHskqmAHjCwnnuJA+TWsuYCjgiVYoHVhL7/ePsYYy8tS6E04n+bkdq3DoBEC0cLa 3b8uy5ybmvovk93qccv1cahVdbhAmcoSYAt773WDa9QTyWzhyBJ0qq7SZeAzqMNjwPth rJUE4uP9Ag/5nVq0CTj+x5c9f9yw6oQHNt7B1sxGMho3jNkCRNs3U46Bq1JC0dABx7SA NZew== X-Gm-Message-State: AOAM533aC5jB7ryQAgYgZNErPWn8BeouG4orFpr4qzK+uc+wv2Vy9flW D3mga1UFK8K606J8yI+/jZPUBprqoPHg9sIIs6g= X-Received: by 2002:a05:6512:1515:: with SMTP id bq21mr54570057lfb.71.1636135241059; Fri, 05 Nov 2021 11:00:41 -0700 (PDT) MIME-Version: 1.0 References: <20211029224929.379505-1-namhyung@kernel.org> <20211103072112.32312-1-ravi.bangoria@amd.com> In-Reply-To: <20211103072112.32312-1-ravi.bangoria@amd.com> From: Namhyung Kim Date: Fri, 5 Nov 2021 11:00:29 -0700 Message-ID: Subject: Re: [PATCH v3] perf evsel: Fix missing exclude_{host,guest} setting To: Ravi Bangoria Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Ingo Molnar , Peter Zijlstra , linux-kernel , Andi Kleen , Ian Rogers , Stephane Eranian , Kim Phillips Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Wed, Nov 3, 2021 at 12:22 AM Ravi Bangoria wrote: > > > The current logic for the perf missing feature has a bug that it can > > wrongly clear some modifiers like G or H. Actually some PMUs don't > > support any filtering or exclusion while others do. But we check it > > as a global feature. > > (Sorry to pitch in bit late) > > AMD has one more problem on a similar line. On AMD, non-precise and > precise sampling are provided by core and IBS pmu respectively. Plus, > core pmu has filtering capability but IBS does not. Perf by default > sets precise_ip=3 and exclude_guest=1 and goes on decreasing precise_ip > with exclude_guest set until perf_event_open() succeeds. This is > causing perf to always fallback to core pmu (non-precise mode) even if > it's perfectly feasible to do precise sampling. Do you guys think this > problem should also be addressed while designing solution for Namhyung's > patch or solve it seperately like below patch: > > ---><--- > > From 48808299679199c39ff737a30a7f387669314fd7 Mon Sep 17 00:00:00 2001 > From: Ravi Bangoria > Date: Tue, 2 Nov 2021 11:01:12 +0530 > Subject: [PATCH] perf/amd/ibs: Don't set exclude_guest by default > > Perf tool sets exclude_guest by default while calling perf_event_open(). > Because IBS does not have filtering capability, it always gets rejected > by IBS PMU driver and thus perf falls back to non-precise sampling. Fix > it by not setting exclude_guest by default on AMD. > > Before: > $ sudo ./perf record -C 0 -vvv true |& grep precise > precise_ip 3 > decreasing precise_ip by one (2) > precise_ip 2 > decreasing precise_ip by one (1) > precise_ip 1 > decreasing precise_ip by one (0) > > After: > $ sudo ./perf record -C 0 -vvv true |& grep precise > precise_ip 3 > decreasing precise_ip by one (2) > precise_ip 2 > > Reported-by: Kim Phillips > Signed-off-by: Ravi Bangoria It'd be nice if it can cover explicit -e cycles:pp as well. Anyway, Acked-by: Namhyung Kim Thanks, Namhyung > --- > tools/perf/arch/x86/util/evsel.c | 23 +++++++++++++++++++++++ > tools/perf/util/evsel.c | 12 +++++++----- > tools/perf/util/evsel.h | 1 + > 3 files changed, 31 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c > index 2f733cdc8dbb..7841a49ce856 100644 > --- a/tools/perf/arch/x86/util/evsel.c > +++ b/tools/perf/arch/x86/util/evsel.c > @@ -1,8 +1,31 @@ > // SPDX-License-Identifier: GPL-2.0 > #include > +#include > #include "util/evsel.h" > +#include "util/env.h" > +#include "linux/string.h" > > void arch_evsel__set_sample_weight(struct evsel *evsel) > { > evsel__set_sample_bit(evsel, WEIGHT_STRUCT); > } > + > +void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr) > +{ > + struct perf_env env = {0}; > + > + if (!perf_env__cpuid(&env)) > + return; > + > + /* > + * On AMD, precise cycles event sampling internally uses IBS pmu. > + * But IBS does not have filtering capabilities and perf by default > + * sets exclude_guest = 1. This makes IBS pmu event init fail and > + * thus perf ends up doing non-precise sampling. Avoid it by clearing > + * exclude_guest. > + */ > + if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD")) > + attr->exclude_guest = 0; > + > + free(env.cpuid); > +} > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index dbfeceb2546c..0b4267d4bb38 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -294,7 +294,7 @@ static bool perf_event_can_profile_kernel(void) > return perf_event_paranoid_check(1); > } > > -struct evsel *evsel__new_cycles(bool precise, __u32 type, __u64 config) > +struct evsel *evsel__new_cycles(bool precise __maybe_unused, __u32 type, __u64 config) > { > struct perf_event_attr attr = { > .type = type, > @@ -305,18 +305,16 @@ struct evsel *evsel__new_cycles(bool precise, __u32 type, __u64 config) > > event_attr_init(&attr); > > - if (!precise) > - goto new_event; > - > /* > * Now let the usual logic to set up the perf_event_attr defaults > * to kick in when we return and before perf_evsel__open() is called. > */ > -new_event: > evsel = evsel__new(&attr); > if (evsel == NULL) > goto out; > > + arch_evsel__fixup_new_cycles(&evsel->core.attr); > + > evsel->precise_max = true; > > /* use asprintf() because free(evsel) assumes name is allocated */ > @@ -1047,6 +1045,10 @@ void __weak arch_evsel__set_sample_weight(struct evsel *evsel) > evsel__set_sample_bit(evsel, WEIGHT); > } > > +void __weak arch_evsel__fixup_new_cycles(struct perf_event_attr *attr __maybe_unused) > +{ > +} > + > /* > * The enable_on_exec/disabled value strategy: > * > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h > index 1f7edfa8568a..764e54c6a23d 100644 > --- a/tools/perf/util/evsel.h > +++ b/tools/perf/util/evsel.h > @@ -277,6 +277,7 @@ void __evsel__reset_sample_bit(struct evsel *evsel, enum perf_event_sample_forma > void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier); > > void arch_evsel__set_sample_weight(struct evsel *evsel); > +void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr); > > int evsel__set_filter(struct evsel *evsel, const char *filter); > int evsel__append_tp_filter(struct evsel *evsel, const char *filter); > -- > 2.27.0 >