public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,  Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 James Clark <james.clark@linaro.org>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	 GuoHan Zhao <zhaoguohan@kylinos.cn>,
	Colin Ian King <colin.i.king@gmail.com>,
	 linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1] perf pmu: Replace starts_with with strstarts
Date: Tue,  3 Mar 2026 10:52:16 -0800	[thread overview]
Message-ID: <20260303185216.897944-1-irogers@google.com> (raw)

linux/string.h provides strstarts that matches the starts_with
function. For style and consistency reasons remove the starts_with
functions and use strstarts.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/arch/x86/util/pmu.c | 12 ++++--------
 tools/perf/util/drm_pmu.c      | 36 +++++++++++++++-------------------
 2 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c
index a3f96221758d..4ea4d022c9c3 100644
--- a/tools/perf/arch/x86/util/pmu.c
+++ b/tools/perf/arch/x86/util/pmu.c
@@ -5,6 +5,7 @@
 #include <dirent.h>
 #include <fcntl.h>
 #include <linux/stddef.h>
+#include <linux/string.h>
 #include <linux/perf_event.h>
 #include <linux/zalloc.h>
 #include <api/fs/fs.h>
@@ -71,11 +72,6 @@ static int snc_nodes_per_l3_cache(void)
 	return snc_nodes;
 }
 
-static bool starts_with(const char *str, const char *prefix)
-{
-	return !strncmp(prefix, str, strlen(prefix));
-}
-
 static int num_chas(void)
 {
 	static bool checked_chas;
@@ -93,7 +89,7 @@ static int num_chas(void)
 
 		while ((dent = io_dir__readdir(&dir)) != NULL) {
 			/* Note, dent->d_type will be DT_LNK and so isn't a useful filter. */
-			if (starts_with(dent->d_name, "uncore_cha_"))
+			if (strstarts(dent->d_name, "uncore_cha_"))
 				num_chas++;
 		}
 		close(fd);
@@ -305,9 +301,9 @@ void perf_pmu__arch_init(struct perf_pmu *pmu)
 			else
 				pmu->mem_events = perf_mem_events_intel;
 		} else if (x86__is_intel_graniterapids()) {
-			if (starts_with(pmu->name, "uncore_cha_"))
+			if (strstarts(pmu->name, "uncore_cha_"))
 				gnr_uncore_cha_imc_adjust_cpumask_for_snc(pmu, /*cha=*/true);
-			else if (starts_with(pmu->name, "uncore_imc_"))
+			else if (strstarts(pmu->name, "uncore_imc_"))
 				gnr_uncore_cha_imc_adjust_cpumask_for_snc(pmu, /*cha=*/false);
 		}
 	}
diff --git a/tools/perf/util/drm_pmu.c b/tools/perf/util/drm_pmu.c
index b48a375e4584..b8badae7015c 100644
--- a/tools/perf/util/drm_pmu.c
+++ b/tools/perf/util/drm_pmu.c
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <linux/unistd.h>
 #include <linux/kcmp.h>
+#include <linux/string.h>
 #include <linux/zalloc.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
@@ -129,11 +130,6 @@ static struct drm_pmu *add_drm_pmu(struct list_head *pmus, char *line, size_t li
 }
 
 
-static bool starts_with(const char *str, const char *prefix)
-{
-	return !strncmp(prefix, str, strlen(prefix));
-}
-
 static int add_event(struct drm_pmu_event **events, int *num_events,
 		     const char *line, enum drm_pmu_unit unit, const char *desc)
 {
@@ -174,7 +170,7 @@ static int read_drm_pmus_cb(void *args, int fdinfo_dir_fd, const char *fd_name)
 	}
 
 	while (io__getline(&io, &line, &line_len) > 0) {
-		if (starts_with(line, "drm-driver:")) {
+		if (strstarts(line, "drm-driver:")) {
 			drm = add_drm_pmu(pmus, line, line_len);
 			if (!drm)
 				break;
@@ -184,59 +180,59 @@ static int read_drm_pmus_cb(void *args, int fdinfo_dir_fd, const char *fd_name)
 		 * Note the string matching below is alphabetical, with more
 		 * specific matches appearing before less specific.
 		 */
-		if (starts_with(line, "drm-active-")) {
+		if (strstarts(line, "drm-active-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_BYTES,
 				  "Total memory active in one or more engines");
 			continue;
 		}
-		if (starts_with(line, "drm-cycles-")) {
+		if (strstarts(line, "drm-cycles-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_CYCLES,
 				"Busy cycles");
 			continue;
 		}
-		if (starts_with(line, "drm-engine-capacity-")) {
+		if (strstarts(line, "drm-engine-capacity-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_CAPACITY,
 				"Engine capacity");
 			continue;
 		}
-		if (starts_with(line, "drm-engine-")) {
+		if (strstarts(line, "drm-engine-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_NS,
 				  "Utilization in ns");
 			continue;
 		}
-		if (starts_with(line, "drm-maxfreq-")) {
+		if (strstarts(line, "drm-maxfreq-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_HZ,
 				  "Maximum frequency");
 			continue;
 		}
-		if (starts_with(line, "drm-purgeable-")) {
+		if (strstarts(line, "drm-purgeable-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_BYTES,
 				  "Size of resident and purgeable memory buffers");
 			continue;
 		}
-		if (starts_with(line, "drm-resident-")) {
+		if (strstarts(line, "drm-resident-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_BYTES,
 				  "Size of resident memory buffers");
 			continue;
 		}
-		if (starts_with(line, "drm-shared-")) {
+		if (strstarts(line, "drm-shared-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_BYTES,
 				  "Size of shared memory buffers");
 			continue;
 		}
-		if (starts_with(line, "drm-total-cycles-")) {
+		if (strstarts(line, "drm-total-cycles-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_BYTES,
 				  "Total busy cycles");
 			continue;
 		}
-		if (starts_with(line, "drm-total-")) {
+		if (strstarts(line, "drm-total-")) {
 			add_event(&events, &num_events, line, DRM_PMU_UNIT_BYTES,
 				  "Size of shared and private memory");
 			continue;
 		}
-		if (verbose > 1 && starts_with(line, "drm-") &&
-		    !starts_with(line, "drm-client-id:") &&
-		    !starts_with(line, "drm-pdev:"))
+		if (verbose > 1 && strstarts(line, "drm-") &&
+		    !strstarts(line, "drm-client-id:") &&
+		    !strstarts(line, "drm-pdev:"))
 			pr_debug("Unhandled DRM PMU fdinfo line match '%s'\n", line);
 	}
 	if (drm) {
@@ -261,7 +257,7 @@ bool drm_pmu__have_event(const struct perf_pmu *pmu, const char *name)
 {
 	struct drm_pmu *drm = container_of(pmu, struct drm_pmu, pmu);
 
-	if (!starts_with(name, "drm-"))
+	if (!strstarts(name, "drm-"))
 		return false;
 
 	for (int i = 0; i < drm->num_events; i++) {
-- 
2.53.0.473.g4a7958ca14-goog


             reply	other threads:[~2026-03-03 18:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 18:52 Ian Rogers [this message]
2026-03-03 20:18 ` [PATCH v1] perf pmu: Replace starts_with with strstarts Arnaldo Carvalho de Melo
2026-03-04 21:48 ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260303185216.897944-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=colin.i.king@gmail.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=zhaoguohan@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox