From nobody Thu Apr 9 18:03:28 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 472B23D3CEA for ; Tue, 3 Mar 2026 18:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772563945; cv=none; b=ro4mBFrWv7JDrBKyqYq1BdKP1RzYH7DAnjepNEvSYqIaV2+q7fBVq4sRDWsb7Z0sgjawIfrRyjpTabV3wUj5A56Yj7YGIKzA8XZp1i660fSe5/mhR3Wvo9DYAZyW3pQhs5JmNUJHU+VKP0Rt5AC68WMIQs1hn9RU57oNRm2yh6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772563945; c=relaxed/simple; bh=jujyNQhe35vEW8DfQ6ZvNvgsRBTq8IEp0gNEu52yk1o=; h=Date:Mime-Version:Message-ID:Subject:From:To:Content-Type; b=es5UFsHVclk2ExfY/Nu37+5FYxKvoMQLiYtV0J9LUdEu+muBGtLPg2UrpJ7hItJhUdISU237lplQBNzFO+cRIwrPY6pisllr9XTTB1fIHhI6z5B0wmgnEot+3RnzxvEUamuWHH52rbuloJrJQ7HkJSJrnk6e58LkSvlJyx97t0M= 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=YkUdtxPY; arc=none smtp.client-ip=74.125.82.74 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YkUdtxPY" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-1273886efc6so5830241c88.1 for ; Tue, 03 Mar 2026 10:52:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772563941; x=1773168741; darn=vger.kernel.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lb2WNe2kvehO4G5MCS1us7ljbs0iGwZqyjdd2kiT00Y=; b=YkUdtxPY2gIpXwaaRZkDqqPSJX5CIcVr733ItjwzjsHCZ9EHmdiwbnH+jlU4Zye0Fl dRPf+TJlTZh2KQ+a0W6v00d4mN+dwvSdzmlQH/bHuVlYi1wL1Lc6y+M8adsbnerJHTaz 6Y1wKvYLDrGV3DA6UcS6qaso2FkDnklXF/fdOiCajrk6wjBVfojp4XteUrMYmzERQVou fC9PO4UnCBEdqf6i2ipBW+ZiQ+R20sHloapkHE6GpOR/XnNs/eK/7zZj/K/zR0kLWhfj M2TBLfvtos1nSk1Gn3vpXTdfY+OojwLO9VC2OmLWdoAMOa1kdD1/yHbHoiYtFvKzlRko zT9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772563941; x=1773168741; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lb2WNe2kvehO4G5MCS1us7ljbs0iGwZqyjdd2kiT00Y=; b=nP7AQWLUn7ijB5uOWjxHwP3r9GPuEVHXO6uPDEZu0LpeWdj/HXDVVSgIkJWMy/+NOB lG44Z8/hVAdrmvuwQfAo3IZh/KkKIbDH2TSy8w/7RjDuOD8zoQkJZkij3JHw87dOuU3U iK1pOEpXaVVnTz9UU5u7yaq/XXtJl+Swkj6aQscKNV+LuByTKlDsoz9wIDuX0ygwHzHm IF5lXpUO2ySFw+xZMDNjCuUOAudk/e82r7ikNpubyBeCD1a9E5qlbk8KBZeK8iSPP4Hq eM1oNBWozRtxcWQ1zjNZj8CmxHViuPX04ebFn9yzeEcfLyKZFDy2UzwC4OqE7OdyFQNp 0daw== X-Forwarded-Encrypted: i=1; AJvYcCVRfoLLFNjO8Au6y4m1cTdl59v6NhBuaMPttaAxJ20cFi6nyvtJTnaqAvoFqPHPDwxEKjEY5HjDttRqQlg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5yOncrwvZKtopqBY4TN7X87zx6fd+Y0CpQfCHvjYOcq1LbURB BozT8ai73Vl/AHJsS0tFG5dolDMR57sa89vIuzTxSoQqTgAnzMHQsBiNOVwmsGHh/4FSb4e+jvV 5C/Gvllng/A== X-Received: from dlbcq13.prod.google.com ([2002:a05:7022:248d:b0:127:337f:890]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:a81:b0:123:3584:de4b with SMTP id a92af1059eb24-1278fc1f998mr6900450c88.29.1772563940902; Tue, 03 Mar 2026 10:52:20 -0800 (PST) Date: Tue, 3 Mar 2026 10:52:16 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260303185216.897944-1-irogers@google.com> Subject: [PATCH v1] perf pmu: Replace starts_with with strstarts From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Ravi Bangoria , GuoHan Zhao , Colin Ian King , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Arnaldo Carvalho de Melo --- 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 #include #include +#include #include #include #include @@ -71,11 +72,6 @@ static int snc_nodes_per_l3_cache(void) return snc_nodes; } =20 -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) =20 while ((dent =3D io_dir__readdir(&dir)) !=3D 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 =3D 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=3D*/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=3D*/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 #include #include +#include #include #include #include @@ -129,11 +130,6 @@ static struct drm_pmu *add_drm_pmu(struct list_head *p= mus, char *line, size_t li } =20 =20 -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) } =20 while (io__getline(&io, &line, &line_len) > 0) { - if (starts_with(line, "drm-driver:")) { + if (strstarts(line, "drm-driver:")) { drm =3D add_drm_pmu(pmus, line, line_len); if (!drm) break; @@ -184,59 +180,59 @@ static int read_drm_pmus_cb(void *args, int fdinfo_di= r_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, co= nst char *name) { struct drm_pmu *drm =3D container_of(pmu, struct drm_pmu, pmu); =20 - if (!starts_with(name, "drm-")) + if (!strstarts(name, "drm-")) return false; =20 for (int i =3D 0; i < drm->num_events; i++) { --=20 2.53.0.473.g4a7958ca14-goog