Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp938075pxp; Wed, 16 Mar 2022 21:58:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhepIKXAk7P1kP/Y2X9UQaBmMHA4akysl5k5RWFwwdSU9wgW251mnz/+MXJp2VjzP4WmuV X-Received: by 2002:a17:903:2288:b0:153:bfbe:7354 with SMTP id b8-20020a170903228800b00153bfbe7354mr3353493plh.112.1647493132926; Wed, 16 Mar 2022 21:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647493132; cv=none; d=google.com; s=arc-20160816; b=KtRt36+J5Yz0Ge7SiHkpzcITm+5Vm5Ts17ou9GUurHmSXsr3XSrW1aTzmvuH2B2iim 4KPxkyhSNuZF0slOQIhhG1EsUgAf2Rou+F9BOdvdsR2mIN9J+FqW5SgZBFiiuaqbQUqM GdY7/M6ou5fz+VG6RRfevWp57/5SyNNPyb+VSkRLphI/vOrP/W5hZRGd1oM7hjuR+9Ud uAh1BmGqN5qzJAxvWGx1xxBtCG4AToPQwvfPoJuyfTdYOO0h6KBVue/EaRn1YprLlEk8 UfF8aR3TheuRiR0k7GsSyko6F1abZZ0ZkVXUYVfIzFKrNmQbBPEjZP2YyjIrxnCmAw0i zCYQ== 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:dkim-signature; bh=5HAPVMUD1lxYCnamxONVJx9ic0StEWbLmBaj3VaUmNk=; b=f85tKG62zMrYjJ0V8Io5AhnWMW7brOu/aiYOX0OauqS5nId/Xv56OVX/68+x8QPqSO ndDeWaicjLYUxTorY1Rx2BD97kSQhj36DA8TbaNM2fN2l7YhGMGYjX8/UtTGcC5nsa+3 eczLdFbR8IOHi89gCkkKK7k4/dr+f+WPukMlcdu3i8CE67PnI5IzsgwSzzZhYb5W4aUd DlBsRK103W3tXrCuU4QhLEMlaHgq5sH2UpbtqnvrB45UUPXuQmHvIHQPt1amR5QvnBIQ CJdPugiOAqSlpv7gbUl3iFYP7kDhEQqENl87mZfH88BfdOZcDbgjzTm2yFmXUzkKoY1r OlEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ASCtFuer; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s65-20020a17090a69c700b001bf020c5dafsi6737037pjj.32.2022.03.16.21.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ASCtFuer; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2A3F3187B8D; Wed, 16 Mar 2022 21:14:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344373AbiCOCDP (ORCPT + 99 others); Mon, 14 Mar 2022 22:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245677AbiCOCDN (ORCPT ); Mon, 14 Mar 2022 22:03:13 -0400 Received: from mail-vk1-xa35.google.com (mail-vk1-xa35.google.com [IPv6:2607:f8b0:4864:20::a35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E56FF13CE8 for ; Mon, 14 Mar 2022 19:02:02 -0700 (PDT) Received: by mail-vk1-xa35.google.com with SMTP id i18so9355784vkr.13 for ; Mon, 14 Mar 2022 19:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5HAPVMUD1lxYCnamxONVJx9ic0StEWbLmBaj3VaUmNk=; b=ASCtFuerHqUmD1H8gbfpEbjk+0bDByLuwQg02wRbxMokEiwqIBprAIOG9M7v0UOg8f tLPsebpL6ksJeTGw5U1p7vUDgJ707RXr4zdGeBZJa/7o9tJW2H7D/Bops/w5X8Ssrp5w 6MooG/t+9b8UA36JLp1D8K+U9cVyNTDlBXbt2QmSaKxE/dYoin7Ykvbs2gXj3ZAVECXm irpc+Pu2OOdn9jZ4xicXGIEeTZCckmNxCjhP1XeoKsn7NFkm1Se4meNoCyIDrFjiWqzQ 2CftgPWQQPjptp+fyT1bSJj+a4+oBV//KA8WiuHisDDNu6d384sJ1GZWrKy/KB+6beFc sEiQ== 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=5HAPVMUD1lxYCnamxONVJx9ic0StEWbLmBaj3VaUmNk=; b=zUqRFtYLEjbfCkkplZUApL/W8YLGuNC651A4tVi0MTUlg6fQy6KqIy1JJBXegcj/kS wuo5EDDFYT/ymSLtvXwzOzpGiT8AsapTLIOUHEoCmCq/TRSDUCvpOzK9btn9wRQBd8zO lfVDQ2ZgJqLvr/69TBRkTv6lGUuSBVTLSHyODYmMg2yElao3ud3GuabxEAz4vjxZIdgP 34P/sGHLHaqQJbrbN3zfpz3mH/mLC1DlkTZH6QfbRv0/0hcwmXCaIqOPZlTUToV+80TG 8bw3YDZanFZwr0zTSYWhalKOPO/yzJZ26+Dc8g2r/HfJEHHxhifLOEmWnsMNe8eGdKUg fwjQ== X-Gm-Message-State: AOAM531dQvtZjnauxzjAb6BkNyUgiHEa2oBLvNsbWAfyvx6xAO4GAZHK oOV1oi9Jlaqtr/43dgNVaRfr6Tw5xK9xDuziRKqMNuyVxhoSZg== X-Received: by 2002:a1f:348a:0:b0:32d:34f:7941 with SMTP id b132-20020a1f348a000000b0032d034f7941mr10374403vka.13.1647309721755; Mon, 14 Mar 2022 19:02:01 -0700 (PDT) MIME-Version: 1.0 References: <20220208211637.2221872-1-eranian@google.com> <20220208211637.2221872-11-eranian@google.com> In-Reply-To: <20220208211637.2221872-11-eranian@google.com> From: Stephane Eranian Date: Mon, 14 Mar 2022 19:01:49 -0700 Message-ID: Subject: Re: [PATCH v6 10/12] perf tools: Improve IBS error handling To: linux-kernel@vger.kernel.org Cc: peterz@infradead.org, kim.phillips@amd.com, acme@redhat.com, jolsa@redhat.com, songliubraving@fb.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kim, On Tue, Feb 8, 2022 at 1:17 PM Stephane Eranian wrote: > > From: Kim Phillips > > improve the error message returned on failed perf_event_open() on AMD when > using IBS. > > Output of executing 'perf record -e ibs_op// true' BEFORE this patch: > > The sys_perf_event_open() syscall returned with 22 (Invalid argument)for event (ibs_op//u). > /bin/dmesg | grep -i perf may provide additional information. > > Output after: > > AMD IBS cannot exclude kernel events. Try running at a higher privilege level. > > Output of executing 'sudo perf record -e ibs_op// true' BEFORE this patch: > > Error: > The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (ibs_op//). > /bin/dmesg | grep -i perf may provide additional information. > > Output after: > > Error: > AMD IBS may only be available in system-wide/per-cpu mode. Try using -a, or -C and workload affinity > > Signed-off-by: Kim Phillips > Cc: Arnaldo Carvalho de Melo > Cc: Alexander Shishkin > Cc: Boris Ostrovsky > Cc: Ian Rogers > Cc: Ingo Molnar > Cc: Jiri Olsa > Cc: Joao Martins > Cc: Konrad Rzeszutek Wilk > Cc: Mark Rutland > Cc: Michael Petlan > Cc: Namhyung Kim > Cc: Peter Zijlstra > Cc: Robert Richter > Cc: Stephane Eranian > --- > tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index 22d3267ce294..d42f63a484df 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -2847,9 +2847,22 @@ static bool find_process(const char *name) > return ret ? false : true; > } > > +static bool is_amd(const char *arch, const char *cpuid) > +{ > + return arch && !strcmp("x86", arch) && cpuid && strstarts(cpuid, "AuthenticAMD"); > +} > + > +static bool is_amd_ibs(struct evsel *evsel) > +{ > + return evsel->core.attr.precise_ip || !strncmp(evsel->pmu_name, "ibs", 3); > +} > + > int evsel__open_strerror(struct evsel *evsel, struct target *target, > int err, char *msg, size_t size) > { > + struct perf_env *env = evsel__env(evsel); > + const char *arch = perf_env__arch(env); > + const char *cpuid = perf_env__cpuid(env); This code dies for me on the latest tip.git because env = NULL and perf_env_cpuid() is broken for NULL argument. I don't quite know where this env global variable is set but I hope there is a better way of doing this, maybe using the evsel__env() function in the same util/evsel.c file. Similarly, the is_amd_ibs() suffers from a NULL pointer dereference because evsel->pmu_name maybe NULL: $ perf record -e rc2 ..... causes a NULL pmu_name. Could you please send me an updated version to integrate with the branch sampling code? Thanks. > > char sbuf[STRERR_BUFSIZE]; > int printed = 0, enforced = 0; > > @@ -2949,6 +2962,17 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target, > return scnprintf(msg, size, > "Invalid event (%s) in per-thread mode, enable system wide with '-a'.", > evsel__name(evsel)); > + if (is_amd(arch, cpuid)) { > + if (is_amd_ibs(evsel)) { > + if (evsel->core.attr.exclude_kernel) > + return scnprintf(msg, size, > + "AMD IBS can't exclude kernel events. Try running at a higher privilege level."); > + if (!evsel->core.system_wide) > + return scnprintf(msg, size, > + "AMD IBS may only be available in system-wide/per-cpu mode. Try using -a, or -C and workload affinity"); > + } > + } > + > break; > case ENODATA: > return scnprintf(msg, size, "Cannot collect data source with the load latency event alone. " > -- > 2.35.0.263.gb82422642f-goog >