From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 704B9C433EF for ; Tue, 15 Mar 2022 02:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344376AbiCOCDQ (ORCPT ); Mon, 14 Mar 2022 22:03:16 -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-Google-Smtp-Source: ABdhPJzxaZXYOAQeql12ZxZ/JtqGE7Wz+aqcct1Dy2jmWiwJoPI+Kv6RkcA7wDqdozyjaqYmJB9uYohDCh1r0Npne60= 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" 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 >