From nobody Fri Nov 29 05:50:00 2024 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 16121186287 for ; Wed, 25 Sep 2024 14:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727273762; cv=none; b=AysKAtqdPpYouwv3tbLe6UhxEchOLG8yJqNNX3okshw8f9TRDEvRYeHxW3ONN8nJkaNB5e0kloVCgOI7pF2LKaXMQFkDyfcBpdMqrIm5ut+HBnYvrdH4BwfuP58+cKXsD/RSYOma1Jx0fEJtk8e9avN+IzP0LEHafDEliDF0JlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727273762; c=relaxed/simple; bh=6mhXOrksKLDeBymgs/5Ql9HxyoVT/6Zbkj0VkP40K4o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a/6d4ib5riocubPER9rH1HlAaxyxUuhLNa3GWwxmjItB9Pq94MBALzh8KfmymD1Surk8ldzpMABdATEg1ZgvIpMAFgZotcINg1Sn74GIOhh0Y9RS0ciPFtSVsYH9M8Wi9mIo0LLnLDp/rb3Dv/5DxGYsdJ/+FX2eJuxsBhrWPCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=KRsnGrvd; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KRsnGrvd" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a8a7903cb7dso500907566b.3 for ; Wed, 25 Sep 2024 07:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727273758; x=1727878558; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IBxhdSiimmJPdeBGg5mCxKxx8TZpg3ftsjBjYSXP2zI=; b=KRsnGrvdLOFywvWgP/f3DivU/3S7mkDgNLIL+rCV1xFimzKLpbWI4dKU17EhIYAbCE FW7iibvZDTOM/qAz2x4yqu6BLsyIaEBQmEnp0sExqgdTk1pq2lDF4cEuN8Z40vq3CfpT 98Kc1qdSYcI7FZdHSLPVN0BDZiSHF+tdTUUUTasa0bk4n5qChFVMHrdHcFnpqxignrWx sxAugPGsYqMPhl2ouQsxkNQKNzftxPish6lZm7qdi5V9Tjpt3lpOI0sxYNkKt+TF6zLH CvKzJehHSRlvVmSPwtGUIPDUn8UHIp5fCQN1JndUToVyGGSdrUUnDQ7F367Z+8dgZKGq y5WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727273758; x=1727878558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IBxhdSiimmJPdeBGg5mCxKxx8TZpg3ftsjBjYSXP2zI=; b=vPinXqJH4/l0Dd66ywyp1PFvidTyhMNsRdQFjd/wP18sX57ZcJLacsDraqHoqFgnq7 Gh2fs6eJuG8XsTLg1WamcDMf7b2mmI89DA1woGWBWELV7G7IiCH7QL/HVnQunp70RIbh Maia7YH200vR6NeotTfEe84cMoyNl9SQZdBXSD6xR4ZebU2uhn2ElJgwXjAr9wj5fx7c nR4dSSMqEDfh1+d1+6m+JvtXfq1ApUtciTmqMpQwRT6m+AzwwrU+UYomlXKRH1/sNd/J oH+XQxL8DkZm+fI2vuU9R01Qt1+xPqV2AI2rcvqZQZgx6xpTLxDgqrChXAIqiezUFrbv CFIg== X-Forwarded-Encrypted: i=1; AJvYcCXAdovCsUK64T2YUNQNyyX8vVx+VN8d4PyMa/ryJRlUC+CH4+Rp2I3ud9cJ1kiNirY9OvunI+j1pX1gqyk=@vger.kernel.org X-Gm-Message-State: AOJu0YyUFDvW1u1Lg+Ol7oXVtPw71XUw599/H96+/FFwo5p7lOknIDxg bxcL1LO9SiHY0DUhXHqmjMhbTlo/2Bexnx8G2XUD8OPDV+23kfWYe4JH36skQmo= X-Google-Smtp-Source: AGHT+IHzJlbaW/aRUlTy/48E0YvqqoJ1gtf/cOF61SeUFZELQLHSQi8wTR27cAyrkUfJDG0JtmLyxg== X-Received: by 2002:a05:6402:40c5:b0:5c5:cb49:2f28 with SMTP id 4fb4d7f45d1cf-5c720610793mr3792764a12.4.1727273758188; Wed, 25 Sep 2024 07:15:58 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4968f4sm1888005a12.27.2024.09.25.07.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 07:15:57 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Athira Rajeev , Dominique Martinet , Yang Li , Colin Ian King , Yang Jihong , Howard Chu , Ze Gao , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 5/7] perf evsel: Remove pmu_name Date: Wed, 25 Sep 2024 15:13:43 +0100 Message-Id: <20240925141357.1033087-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925141357.1033087-1-james.clark@linaro.org> References: <20240925141357.1033087-1-james.clark@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ian Rogers "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. Acked-by: Namhyung Kim Signed-off-by: Ian Rogers [ Fix arm-spe.c usage of pmu_name and empty PMU name ] Acked-by: Kan Liang Signed-off-by: James Clark --- tools/perf/arch/arm64/util/arm-spe.c | 4 ++-- 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 +- 10 files changed, 16 insertions(+), 24 deletions(-) diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/u= til/arm-spe.c index 2be99fdf997d..59a85e6f3aa3 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -188,9 +188,9 @@ static int arm_spe_recording_options(struct auxtrace_re= cord *itr, =20 evlist__for_each_entry(evlist, evsel) { if (evsel__is_aux_event(evsel)) { - if (!strstarts(evsel->pmu_name, ARM_SPE_PMU_NAME)) { + if (!strstarts(evsel->pmu->name, ARM_SPE_PMU_NAME)) { pr_err("Found unexpected auxtrace event: %s\n", - evsel->pmu_name); + evsel->pmu->name); return -EINVAL; } opts->full_auxtrace =3D true; diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index 4a0229d601d4..eac22b449691 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, si= ze_t size) return scnprintf(bf, size, "%s", event_name); =20 return scnprintf(bf, size, "%s/%s/", - evsel->pmu_name ? evsel->pmu_name : "cpu", + evsel->pmu ? evsel->pmu->name : "cpu", event_name); } =20 @@ -129,7 +129,7 @@ int arch_evsel__open_strerror(struct evsel *evsel, char= *msg, size_t size) return 0; =20 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; =20 /* More verbose IBS errors. */ diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 9e3086d02150..78e999f03d2d 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 *e= vlist) =20 TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW =3D=3D 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 bace277fa77d..4835d5aa5c48 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2576,7 +2576,8 @@ void evlist__uniquify_name(struct evlist *evlist) else attributes =3D empty_attributes; =20 - 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 =3D new_name; } else { diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 00178643b198..56f3c2183437 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -296,7 +296,6 @@ void evsel__init(struct evsel *evsel, evsel->metric_events =3D NULL; evsel->per_pkg_mask =3D NULL; evsel->collect_stat =3D false; - evsel->pmu_name =3D NULL; evsel->group_pmu_name =3D NULL; evsel->skippable =3D false; evsel->alternate_hw_config =3D PERF_COUNT_HW_MAX; @@ -394,11 +393,6 @@ struct evsel *evsel__clone(struct evsel *orig) if (evsel->group_name =3D=3D NULL) goto out_err; } - if (orig->pmu_name) { - evsel->pmu_name =3D strdup(orig->pmu_name); - if (evsel->pmu_name =3D=3D NULL) - goto out_err; - } if (orig->group_pmu_name) { evsel->group_pmu_name =3D strdup(orig->group_pmu_name); if (evsel->group_pmu_name =3D=3D NULL) @@ -1497,7 +1491,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 cf6f11fdfd06..3e751ea769ac 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; @@ -184,7 +183,7 @@ struct evsel { unsigned long open_flags; int precise_ip_original; =20 - /* for missing_features */ + /* The PMU the event is from. Used for missing_features, PMU name, etc. */ struct perf_pmu *pmu; =20 /* For tool events */ diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 4dff3e925a47..9c6fa6b4f628 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; =20 /* 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 fcc4dab618be..e96cf13dc396 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -263,7 +263,6 @@ __add_event(struct list_head *list, int *idx, evsel->core.is_pmu_core =3D pmu ? pmu->is_core : false; evsel->auto_merge_stats =3D auto_merge_stats; evsel->pmu =3D pmu; - evsel->pmu_name =3D pmu ? strdup(pmu->name) : NULL; evsel->alternate_hw_config =3D alternate_hw_config; =20 if (name) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index dd709a731574..3ce756b8ede5 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -573,7 +573,7 @@ static void perf_stat__print_metricgroup_header(struct = perf_stat_config *config, { bool need_full_name =3D 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]; =20 /* @@ -584,21 +584,21 @@ static void perf_stat__print_metricgroup_header(struc= t 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 !=3D evsel->pmu) { out->print_metricgroup_header(config, ctxp, NULL); return; } } =20 - 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->nam= e); else scnprintf(full_name, sizeof(full_name), "%s", name); =20 out->print_metricgroup_header(config, ctxp, full_name); =20 last_name =3D name; - last_pmu =3D evsel->pmu_name; + last_pmu =3D evsel->pmu; } =20 /** 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, stru= ct evsel *evsel_b) if (evsel__is_clock(evsel_a) !=3D evsel__is_clock(evsel_b)) return false; =20 - return !!strcmp(evsel_a->pmu_name, evsel_b->pmu_name); + return evsel_a->pmu !=3D evsel_b->pmu; } =20 static void evsel__merge_aliases(struct evsel *evsel) --=20 2.34.1