From patchwork Thu Jun 8 23:23:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 105162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp612408vqr; Thu, 8 Jun 2023 16:54:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5TC3iTd+3cZ1k56hSl/0lqyjdkxkm+u6FNa5j/Emuo5Vsckaap4RpJFtgB+pBh2bBS8qDj X-Received: by 2002:a05:6a20:160d:b0:10b:d70d:f971 with SMTP id l13-20020a056a20160d00b0010bd70df971mr306167pzj.3.1686268469071; Thu, 08 Jun 2023 16:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686268469; cv=none; d=google.com; s=arc-20160816; b=RhWP233SR8tv+gliqQatwfYGD1oN3X47Fg+B7LJDmtKkvI8FlrqvFAEORc9B+WncRz yhMyAL6gylO/PzJmrvDHxLbaDWF5/QL7q1SKO0oK37+0yL1S4+eUcHelPNzqdXlsHbLb 4PCWtMi2fiA8zN9vGR8+JUsa85ap0tStv6xz5USkwFNsE9PSV7B7UGfgj8M4QtxvKfIz qkBExlcDRLRcMIkUCs0Upv4u+LL6UNxuXBnS9Fqnppgr3sVXKxYPUbkegTY12Xf+w6tv JKyFeEbkUNdIhfn/A95yL7jktC5s+YB+EhVsBO1kEj+z7BpwC+JuTBuT8srh5Klhgq0o t4KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=c9n2t88k5l25l+V1epjNXEK63vWDBxvkQoOlMhLNqLg=; b=J8o1I/I81E645LQ4cYgGyxCMVflfOsOOhte32ufpebmlgkmjKtwaMK2CZRwvf+564j Qh3yp4ZG6eUBDYz8bCg/jBCLjcq64DKTbE4V9rRN0/U9MnAgqX9fjv7R05wrJ3M7zuWT TcuHqlxPzNCZrl6hsBWick8k1ZSUmd6FWBjM7L8l3HFXUnugE04XPxb3TYtosT4Rpi2J cLJgqxj/Ue2WPxz+MnGGy6A+0aEP5DzznRl3Ro5O7rCLgK4UynM9nbz1hVNBsiOSu8pv 7bLmnEk8LO6canAgEZUssEr16FpX6a3Bef7/fS9ece1BZk8CybkbX+Ot2ucAJvMQsy6D qNKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=SBSIUhPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i65-20020a639d44000000b0053ef05fcf1esi1649151pgd.35.2023.06.08.16.54.17; Thu, 08 Jun 2023 16:54:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=SBSIUhPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237031AbjFHXYI (ORCPT + 99 others); Thu, 8 Jun 2023 19:24:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbjFHXYF (ORCPT ); Thu, 8 Jun 2023 19:24:05 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26A7730D3; Thu, 8 Jun 2023 16:24:04 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-662f0feafb2so894664b3a.1; Thu, 08 Jun 2023 16:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686266643; x=1688858643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=c9n2t88k5l25l+V1epjNXEK63vWDBxvkQoOlMhLNqLg=; b=SBSIUhPrRrc7qbYg1YEXXpBH7SlseeKKAdZu5PZyANs9ehltKLx93rcU4K/T2IoW8V VMkOv9UoLOZNzNxhiTKs9hualW+5WmRmRaScKP2n6jRjVmIjxkfazlqRtFKadnOlTT1m 3/1JVx4JnBxwz6hmyhSMT7Psd1DuwnOuslVgjwi5UyteRZEZFcR0F5SkljtKupuq42To QUI3qg96CIHYKLiAPgYzKrwwOekFkiCzqOtmp6RryNbXe5mK++CzHlDBDyo5Jj7qXmsi DR+8pgB7QBxIkehKh5KgI8izK1E5930J73WVWBLdA8e22Q3znZ1E8xEY6TFJBwioic50 YPpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686266643; x=1688858643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=c9n2t88k5l25l+V1epjNXEK63vWDBxvkQoOlMhLNqLg=; b=ECjxD05B3fVpA3NjeDIn6pPdf7mKkqoYJ+zX2YJqZzZSvL3ymU8nT4cUbWD9HjkiOE SzhB8MV4dEFqUaHtzJisdN6a83EawGYZe5/hmqfb4G+3FrwRW4nKP1dyW+iP/AAQpDao 0UrchXYaM9w+K0Rvk8IPPpBdgQm4fwintk0+IaF9whT9RaSyAYAKhrw7q4fdT+4RMgBF apcwbb3S3j0dTWf5lZ4G0EGT22JitG8k9mUhNfd3T3JUwzxH3MRKay3V/yW0zKnDchk3 aks8Bnt1tGcSCIy8A+FPEBR5d0O8FuhlHXUqQ18EaEehHApM/ROJhcsaGdUKEhTBodsn blmA== X-Gm-Message-State: AC+VfDxmZA185F8tjTgvjRjtzKTqBnmzbnswNnlBRiPhdS01er+RZ4qO mp8SiWB/mpXg6p7seM1mcec= X-Received: by 2002:a05:6a20:258b:b0:106:5dff:5db5 with SMTP id k11-20020a056a20258b00b001065dff5db5mr3887018pzd.1.1686266643452; Thu, 08 Jun 2023 16:24:03 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6700:7f00:c14c:6e39:cb7d:ad66]) by smtp.gmail.com with ESMTPSA id e18-20020a656792000000b0053f1d55676fsm1618203pgr.2.2023.06.08.16.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 16:24:03 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Stephane Eranian Subject: [PATCH 1/3] perf list: Check if libpfm4 event is supported Date: Thu, 8 Jun 2023 16:23:58 -0700 Message-ID: <20230608232400.3056312-2-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230608232400.3056312-1-namhyung@kernel.org> References: <20230608232400.3056312-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768180646095388793?= X-GMAIL-MSGID: =?utf-8?q?1768180646095388793?= Some of its event info cannot be used directly due to missing default attributes. Let's check if the event is supported before printing like we do for hw and cache events. Cc: Stephane Eranian Signed-off-by: Namhyung Kim Acked-by: Ian Rogers @google.com> --- tools/perf/util/pfm.c | 58 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c index 076aecc22c16..4c1024c343dd 100644 --- a/tools/perf/util/pfm.c +++ b/tools/perf/util/pfm.c @@ -13,6 +13,8 @@ #include "util/pmus.h" #include "util/pfm.h" #include "util/strbuf.h" +#include "util/cpumap.h" +#include "util/thread_map.h" #include #include @@ -123,6 +125,36 @@ int parse_libpfm_events_option(const struct option *opt, const char *str, return -1; } +static bool is_libpfm_event_supported(const char *name, struct perf_cpu_map *cpus, + struct perf_thread_map *threads) +{ + struct perf_pmu *pmu; + struct evsel *evsel; + struct perf_event_attr attr = {}; + bool result = true; + int ret; + + ret = pfm_get_perf_event_encoding(name, PFM_PLM0|PFM_PLM3, + &attr, NULL, NULL); + if (ret != PFM_SUCCESS) + return false; + + pmu = perf_pmus__find_by_type((unsigned int)attr.type); + evsel = parse_events__add_event(0, &attr, name, /*metric_id=*/NULL, pmu); + if (evsel == NULL) + return false; + + evsel->is_libpfm_event = true; + + if (evsel__open(evsel, cpus, threads) < 0) + result = false; + + evsel__close(evsel); + evsel__delete(evsel); + + return result; +} + static const char *srcs[PFM_ATTR_CTRL_MAX] = { [PFM_ATTR_CTRL_UNKNOWN] = "???", [PFM_ATTR_CTRL_PMU] = "PMU", @@ -146,6 +178,8 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state, { int j, ret; char topic[80], name[80]; + struct perf_cpu_map *cpus = perf_cpu_map__empty_new(1); + struct perf_thread_map *threads = thread_map__new_by_tid(0); strbuf_setlen(buf, 0); snprintf(topic, sizeof(topic), "pfm %s", pinfo->name); @@ -185,14 +219,15 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state, ainfo.name, ainfo.desc); } } - print_cb->print_event(print_state, - pinfo->name, - topic, - name, info->equiv, - /*scale_unit=*/NULL, - /*deprecated=*/NULL, "PFM event", - info->desc, /*long_desc=*/NULL, - /*encoding_desc=*/buf->buf); + + if (is_libpfm_event_supported(name, cpus, threads)) { + print_cb->print_event(print_state, pinfo->name, topic, + name, info->equiv, + /*scale_unit=*/NULL, + /*deprecated=*/NULL, "PFM event", + info->desc, /*long_desc=*/NULL, + /*encoding_desc=*/buf->buf); + } pfm_for_each_event_attr(j, info) { pfm_event_attr_info_t ainfo; @@ -215,6 +250,10 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state, print_attr_flags(buf, &ainfo); snprintf(name, sizeof(name), "%s::%s:%s", pinfo->name, info->name, ainfo.name); + + if (!is_libpfm_event_supported(name, cpus, threads)) + continue; + print_cb->print_event(print_state, pinfo->name, topic, @@ -225,6 +264,9 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state, /*encoding_desc=*/buf->buf); } } + + perf_cpu_map__put(cpus); + perf_thread_map__put(threads); } void print_libpfm_events(const struct print_callbacks *print_cb, void *print_state)