Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp287409lqo; Thu, 9 May 2024 22:39:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjLQv6fsDee3+hw2VmNSlzQTB/akdXuk3liqxcUDZdLv0apfclAQ9pKpZq5FHEr3xk9d7Erkm1rYv78bkEdRWoVQGkEIXeTAKe8i7qCg== X-Google-Smtp-Source: AGHT+IF0MAHBY0PJFHbxHdhRBG47e0cR1H3QvsLVZen6Qbz6Kem/lY0hTKbc5oqvAmO8RWz01+bu X-Received: by 2002:ac2:5196:0:b0:516:cf0a:9799 with SMTP id 2adb3069b0e04-5220ff74bedmr783092e87.64.1715319565290; Thu, 09 May 2024 22:39:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715319565; cv=pass; d=google.com; s=arc-20160816; b=Cx6W/tLZ7xkdPJM72L8KPzc9j0/d2YWTTWdsP0hgyyYG+R+Kzs0NvLNaItlUM4bSXC NMTgPL1LdK0C7TQWbCnB9Fb6DbriDG6iirMa21ocoVfPv+Bys+xvYKhfivKQrTr4Jpcz otE7yMeK1owDBdj6uQ5vfEyvToCijBLNZBKFlnex71zHoLyQdK393YP4jmk9zbhGRVwb WsDRsYe+8eiRtQunpSU2RSiVI4OsbphdCSnNDTRkgSY+RggWhjkMok5cdCFKSxrKyKTB kp761ge4eKLNGstuLLgC0EnOM9O2vpqCuquubRAj8JHUxMOz7fgmkfZ/c1CYj1F1WG5p 1cBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=DWRbHF2FL8sVbDNcBMzaCLG3938X5gekbCQ/hc2HZYQ=; fh=jV1dcguCD0VGpqOQwDiA/X4/KTDIhvyb1iCWaTwB9eE=; b=M1sNaClSpt3z1LmiKpgICs2+BfJl1AQUx0JuGTqmd5QIGcfw+rElhriY8oaATu1TEk sWyVybNr3N0bzFGG8P/DjemG++Wx20o5bb+sWkNgFPzM55GDaFIDZNTpkGx/xz5gvR8M r6K3VFKyXj3/wLRZmsmSQba3mgQAFKdA8Q9e4dtLhYK3bUKUaqx1zzNyCo0T+YLNgcAP 1t1+/3gbQtDy5CNhwNHPFAS1KhGdsbDNKcd7ic6fITWAm1F2lk5Poz59KjdNHT0iecMT 82xfg1OrUT1ot15nnPvvmxt+qhE5/fmdShNj+Jx25bHCuBQAnwwaHhbR/C4IWeVQg7U2 X03w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ojo9ixwN; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175298-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c2d5319si1525490a12.216.2024.05.09.22.39.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 22:39:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ojo9ixwN; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175298-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D53CC1F21A57 for ; Fri, 10 May 2024 05:39:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F1E516132C; Fri, 10 May 2024 05:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ojo9ixwN" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A01111635B7 for ; Fri, 10 May 2024 05:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715319498; cv=none; b=b0UcKISdM6rZzywrHWHz9D5Uh5Mfx0A/bu0jCDfZpXxWRI9y1CL2OOxrrpnk8Aos5r1sRLDEwTjRrjf7TIFTYGAYB6dv0OhbEFzB6Ef2+3hVkJUgVyIEIYpllZMNgxn79ScJPoaggRw2QKxM+RSn3wQy1JivUFw+krkzH7X60DU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715319498; c=relaxed/simple; bh=pQ/ykMTJPVdVXsWcWvxI9IBewGKlSl0x/rod7UQD6Fo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=iEFjE6eW83U/G38jpMq0hlIqdclsNmKII9in2vhBZEVUXvBhlCBnqaIQ4e5qSKgwSRt5dCxUD5XSNZAxiMMcIJ1G9lMFqQy6i6UJ9OWGGc6Lt3LtRb6Am8YMSMpMYzq5WEyMfbhOhHGfwikdDi+5T8qdo1J4SuJ5QqDfgsbYygU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ojo9ixwN; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de54be7066bso2624697276.0 for ; Thu, 09 May 2024 22:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715319495; x=1715924295; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=DWRbHF2FL8sVbDNcBMzaCLG3938X5gekbCQ/hc2HZYQ=; b=Ojo9ixwNFyBnXHQIT9XIf7XkJuPpTf3Xu3/QOwcEHwIGChjsfGvwrTJN59z+SmspKf PgzqxBYd4Y8M0aKJjuLhOV8AucwfTy47Ia48KNFjnhCSSOF7PTljBgeFBD4KwPb4gcDe peBKaM+TaHA1Taz6LQi6tbTzIZFmXnvMWYNlzWjh7iMOlh9VUDB7lqG2gcuREsjCx3SJ rrwr4k3o+1fTMQye3yxUfupvuwRLdB/BFrXlNNQt1miYd272N4GpjkcT7pLmMwuHXPA8 zLCgKZDA94xlyCv1LAtMFIwBQf/sX/q/spb6JKUIhDfCSz8EzMMQvkqhl33BO55JzdMW FkJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715319495; x=1715924295; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DWRbHF2FL8sVbDNcBMzaCLG3938X5gekbCQ/hc2HZYQ=; b=tETDH4qGduHhqWL35JkBMsI0kWOROfwqTtrOcOiUQEKMYZzghFtJQoUcDrTxECAgS1 XyNb183Y6QxDZNRjIfBOK7FC32cXX8X2tUR6U2DVnlCGbEbIa14JNUY2QjSlFg/hFbfS 50BCmqhO91zoWzliBZCutZsIM6qaNruRpbqOXiA3zfjya5K/VhsXjUkfDiJS8d/z+xe6 gYLT6P5Lgjidyg1c2PCwZwz2DKHnz3xFeBvMLG9ngA9XHe0Inv7zY8Iuoa4H7w19ne0i op6gujQ1hk1FF0K6aVIuzezl5woKBO3M7XnS4JujMrjacBivfFQz9YDMtT0GptqFR1HL eqjg== X-Forwarded-Encrypted: i=1; AJvYcCWIhGnDHjSWc4LM1eU4UO01ConUgIE8rmr7AiVdxZefOzIsn6VgIXyDKPtm4fZQG6TyPg574IDnU9O2GzKTHdalVCdJ5BlUYMXbQOZl X-Gm-Message-State: AOJu0Ywen9yeNV5si1bwhi2tNo5eHZqwnAn7JolZXT2YJJtjBbSYlvZ+ bDIkD5oOVpfB8r38fIX/aCDQm+A3U4NFOERBzzm8Bq/PPdovhisqf7EKTcF1OhYPby1sX594YXz C4C7i5A== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:79ed:c375:51e3:ed39]) (user=irogers job=sendgmr) by 2002:a05:6902:728:b0:de5:319b:a226 with SMTP id 3f1490d57ef6-dee4f2c3b29mr452416276.1.1715319495565; Thu, 09 May 2024 22:38:15 -0700 (PDT) Date: Thu, 9 May 2024 22:37:05 -0700 In-Reply-To: <20240510053705.2462258-1-irogers@google.com> Message-Id: <20240510053705.2462258-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510053705.2462258-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Subject: [PATCH v3 5/5] perf evsel: Remove pmu_name From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Ravi Bangoria , James Clark , Yang Jihong , Ze Gao , Leo Yan , Song Liu , K Prateek Nayak , Kaige Ye , Yicong Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" "evsel->pmu_name" is only ever assigned a strdup of "pmu->name", a strdup of "evsel->pmu_name" or NULL. As such, prefer to use "pmu->name" directly and even to directly compare PMUs than PMU names. For safety, add some additional NULL tests. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/evsel.c | 4 ++-- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/evlist.c | 3 ++- tools/perf/util/evsel.c | 7 ------- tools/perf/util/evsel.h | 3 +-- tools/perf/util/metricgroup.c | 4 ++-- tools/perf/util/parse-events.c | 1 - tools/perf/util/stat-shadow.c | 10 +++++----- tools/perf/util/stat.c | 2 +- 9 files changed, 14 insertions(+), 22 deletions(-) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c index 1eaae8819c5e..fe8a817d2061 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -84,7 +84,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size) return scnprintf(bf, size, "%s", event_name); return scnprintf(bf, size, "%s/%s/", - evsel->pmu_name ? evsel->pmu_name : "cpu", + evsel->pmu ? evsel->pmu->name : "cpu", event_name); } @@ -129,7 +129,7 @@ int arch_evsel__open_strerror(struct evsel *evsel, char *msg, size_t size) return 0; if (!evsel->core.attr.precise_ip && - !(evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3))) + !(evsel->pmu && !strncmp(evsel->pmu->name, "ibs", 3))) return 0; /* More verbose IBS errors. */ diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 993e482f094c..c7c0edf3d4ca 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -730,7 +730,7 @@ static int test__checkevent_pmu_events(struct evlist *evlist) TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->core.nr_entries); TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->core.attr.type || - strcmp(evsel->pmu_name, "cpu")); + strcmp(evsel->pmu->name, "cpu")); TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index de498ba5ac1c..2e3f4f876792 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2504,7 +2504,8 @@ void evlist__uniquify_name(struct evlist *evlist) else attributes = empty_attributes; - if (asprintf(&new_name, "%s/%s/%s", pos->pmu_name, pos->name, attributes + 1)) { + if (asprintf(&new_name, "%s/%s/%s", pos->pmu ? "" : pos->pmu->name, + pos->name, attributes + 1)) { free(pos->name); pos->name = new_name; } else { diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index dfdb60c7a364..96b545f4d8b0 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -292,7 +292,6 @@ void evsel__init(struct evsel *evsel, evsel->metric_events = NULL; evsel->per_pkg_mask = NULL; evsel->collect_stat = false; - evsel->pmu_name = NULL; evsel->group_pmu_name = NULL; evsel->skippable = false; evsel->alternate_hw_config = PERF_COUNT_HW_MAX; @@ -390,11 +389,6 @@ struct evsel *evsel__clone(struct evsel *orig) if (evsel->group_name == NULL) goto out_err; } - if (orig->pmu_name) { - evsel->pmu_name = strdup(orig->pmu_name); - if (evsel->pmu_name == NULL) - goto out_err; - } if (orig->group_pmu_name) { evsel->group_pmu_name = strdup(orig->group_pmu_name); if (evsel->group_pmu_name == NULL) @@ -1481,7 +1475,6 @@ void evsel__exit(struct evsel *evsel) zfree(&evsel->group_name); zfree(&evsel->name); zfree(&evsel->filter); - zfree(&evsel->pmu_name); zfree(&evsel->group_pmu_name); zfree(&evsel->unit); zfree(&evsel->metric_id); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 46e3589314f1..2f99cc8bfa7d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -72,7 +72,6 @@ struct evsel { struct { char *name; char *group_name; - const char *pmu_name; const char *group_pmu_name; #ifdef HAVE_LIBTRACEEVENT struct tep_event *tp_format; @@ -169,7 +168,7 @@ struct evsel { unsigned long open_flags; int precise_ip_original; - /* for missing_features */ + /* The PMU the event is from. Used for missing_features, PMU name, etc. */ struct perf_pmu *pmu; }; diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 9be406524617..b0700db6e1cc 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -297,8 +297,8 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, struct expr_id_data *val_ptr; /* Don't match events for the wrong hybrid PMU. */ - if (!all_pmus && ev->pmu_name && evsel__is_hybrid(ev) && - strcmp(ev->pmu_name, pmu)) + if (!all_pmus && ev->pmu && evsel__is_hybrid(ev) && + strcmp(ev->pmu->name, pmu)) continue; /* * Check for duplicate events with the same name. For diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index c72e1722b1fb..01d502d802ee 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -265,7 +265,6 @@ __add_event(struct list_head *list, int *idx, evsel->core.is_pmu_core = pmu ? pmu->is_core : false; evsel->auto_merge_stats = auto_merge_stats; evsel->pmu = pmu; - evsel->pmu_name = pmu ? strdup(pmu->name) : NULL; evsel->alternate_hw_config = alternate_hw_config; if (name) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index ffdd53a07654..7bf39b069c5b 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -566,7 +566,7 @@ static void perf_stat__print_metricgroup_header(struct perf_stat_config *config, { bool need_full_name = perf_pmus__num_core_pmus() > 1; static const char *last_name; - static const char *last_pmu; + static const struct perf_pmu *last_pmu; char full_name[64]; /* @@ -577,21 +577,21 @@ static void perf_stat__print_metricgroup_header(struct perf_stat_config *config, * different metric events. */ if (last_name && !strcmp(last_name, name)) { - if (!need_full_name || !strcmp(last_pmu, evsel->pmu_name)) { + if (!need_full_name || last_pmu != evsel->pmu) { out->print_metricgroup_header(config, ctxp, NULL); return; } } - if (need_full_name) - scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu_name); + if (need_full_name && evsel->pmu) + scnprintf(full_name, sizeof(full_name), "%s (%s)", name, evsel->pmu->name); else scnprintf(full_name, sizeof(full_name), "%s", name); out->print_metricgroup_header(config, ctxp, full_name); last_name = name; - last_pmu = evsel->pmu_name; + last_pmu = evsel->pmu; } /** diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 0bd5467389e4..7c2ccdcc3fdb 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -553,7 +553,7 @@ static bool evsel__is_alias(struct evsel *evsel_a, struct evsel *evsel_b) if (evsel__is_clock(evsel_a) != evsel__is_clock(evsel_b)) return false; - return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name); + return evsel_a->pmu != evsel_b->pmu; } static void evsel__merge_aliases(struct evsel *evsel) -- 2.45.0.118.g7fe29c98d7-goog