From nobody Wed Dec 17 19:03:18 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 D272B42072 for ; Wed, 15 May 2024 06:01:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752883; cv=none; b=mCUgT5EEQhECeZrzY4n1CeFz0QkjwVeeU9S/mxqKadGYh5ogYSVfE+tfR//aG0WCxgCSsoXCzwEKh6Dnn1VbUQ5obtRqt6wu+TIwttFR73iqGn7oJ9iD+ZVQaIhE/lpl375qn3xqIb7emwERigMpfsbr08+NZ/q3YVkTLGFo8cI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752883; c=relaxed/simple; bh=mdAbZwia40YUgM/YG3gJYj7KVhAqiovVt5CXsLbGBkA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jZ1/ekVSNCAnN6vUMSOlwFyvnJ2pyau7lqWqvcAeZFKeBy2vTBjECgjcHaHN5wRGMQfFqDHwWKTBiEAgcx/1ahaElmFbFan2Wh/xZhjonoB6nEoCMoWdTUoETQSv7vtKsLztAdM/bJgvlMvwpK10ipkLIZEmDq5JVqwswFaCpKQ= 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=T+3I02+w; arc=none smtp.client-ip=209.85.128.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="T+3I02+w" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be4b79115so123845097b3.1 for ; Tue, 14 May 2024 23:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715752880; x=1716357680; 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=RSFAVnYA+bmwN3ZaYvT5Qc1d7lQFs3CfsIrqrW0emKY=; b=T+3I02+we8cc4pKvmXNHB7WNLE3yer6Qc0VA186M6gxLLMbAqa0uI5rlHV1WY0ZZq5 f1kLCIHYr6VxK5T7SwwMslc63hk33xghOLErIOXpWtXe+JCdItGXdWZMb1+6T4fY/mTL Ypyc0a7ybJTr5uTh29hy8Po/6LMe/9h1GJ5mRXjz044/9ny9y6tshmdpbxQiR7cwWqu+ JQVy23JeXw0RdzPm408YItYZTka+RKgsP1uI0elUMAoT/yOkoI3v2dka64b2h2hiIxTw WOJMTgxpyD0lvRA6T1R8Qo0g07WSPZCcpoVzCJtEVH17mCg1Wh1LlVBnbvMen0vygaid 3n6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715752880; x=1716357680; 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=RSFAVnYA+bmwN3ZaYvT5Qc1d7lQFs3CfsIrqrW0emKY=; b=Qp6bsqNI6dbxJZaI1H5UafJLwsZJaIOpQQAp7hCy84xX3/mL6/OJFYGd98gkz4LSAH 8lEozyqlikoo2Vx74BBHsHhkkvbvOcTGME1EKSoxV4k7b6p7jILTHbEJVeB4wYDZEvuA R2llcxY8LbBiEwmaHxoHvZjkXFmctH0hv1OhwJdZlgssaVZHABqTzHm/4otL49LmpMCH 51O1REEZ7K6497zOgZPSuI7g8H8qzx5W6IThm+5PS75daezB1owRmDpztUOZNGMnlsFG +dMtBl8H9UpcH/YtuEvKi3k00yFjB6oXDkr+c4Hgom8UdvQX0S5iUKg3+hYZdfcCAtFp /ytQ== X-Forwarded-Encrypted: i=1; AJvYcCUv+6uLoaPbMX9x+sIBnuhkWP58V66D8U+vxcNLLRlicbqYSq2svBxRwQAGvjep36Arz1h2D6inVY2DrHciXxZOUle2TFDZHZyXYqJC X-Gm-Message-State: AOJu0YyeUNi7h0qCB1tgqFhsTNfXRIgBozHO1j7CqlWOinxg0Pdjd4g9 L2JxNnANoT98BM6EdxtltdlvCbyKwWLEI1KVVsVE51HcJjugMQSlr/oF+aKtGmUvtQvz70tk/ie jm+nPUg== X-Google-Smtp-Source: AGHT+IGR44nRuzOXgB672uu60Tn0MEOIkOJRxSBxIV50k3vIl3dn0pKPSn8SHsILqKISrql+NRTSYIEtt0U1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bac3:cca1:c362:572]) (user=irogers job=sendgmr) by 2002:a05:690c:380f:b0:61b:e678:2591 with SMTP id 00721157ae682-622aff9c02cmr41297157b3.4.1715752879941; Tue, 14 May 2024 23:01:19 -0700 (PDT) Date: Tue, 14 May 2024 23:01:13 -0700 In-Reply-To: <20240515060114.3268149-1-irogers@google.com> Message-Id: <20240515060114.3268149-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240515060114.3268149-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v6 1/2] perf pmus: Sort/merge/aggregate PMUs like mrvl_ddr_pmu From: Ian Rogers To: Tuan Phan , Robin Murphy , Thomas Richter , Bhaskara Budiredla , Bharat Bhushan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Ravi Bangoria , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , Stephane Eranian Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The mrvl_ddr_pmu is uncore and has a hexadecimal address suffix while the previous PMU sorting/merging code assumes uncore PMU names start with uncore_ and have a decimal suffix. Because of the previous assumption it isn't possible to wildcard the mrvl_ddr_pmu. Modify pmu_name_len_no_suffix but also remove the suffix number out argument, this is because we don't know if a suffix number of say 100 is in hexadecimal or decimal. As the only use of the suffix number is in comparisons, it is safe there to compare the values as hexadecimal. Modify perf_pmu__match_ignoring_suffix so that hexadecimal suffixes are ignored. Only allow hexadecimal suffixes to be greater than length 2 (ie 3 or more) so that S390's cpum_cf PMU doesn't lose its suffix. Change the return type of pmu_name_len_no_suffix to size_t to workaround GCC incorrectly determining the result could be negative. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/pmu.c | 33 +++++++++++++-------- tools/perf/util/pmus.c | 67 ++++++++++++++++++++++++------------------ tools/perf/util/pmus.h | 7 ++++- 3 files changed, 65 insertions(+), 42 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 888ce9912275..c94a91645b21 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -856,26 +856,34 @@ __weak const struct pmu_metrics_table *pmu_metrics_ta= ble__find(void) */ static bool perf_pmu__match_ignoring_suffix(const char *pmu_name, const ch= ar *tok) { - const char *p; + const char *p, *suffix; + bool has_hex =3D false; =20 if (strncmp(pmu_name, tok, strlen(tok))) return false; =20 - p =3D pmu_name + strlen(tok); + suffix =3D p =3D pmu_name + strlen(tok); if (*p =3D=3D 0) return true; =20 - if (*p =3D=3D '_') + if (*p =3D=3D '_') { ++p; + ++suffix; + } =20 /* Ensure we end in a number */ while (1) { - if (!isdigit(*p)) + if (!isxdigit(*p)) return false; + if (!has_hex) + has_hex =3D !isdigit(*p); if (*(++p) =3D=3D 0) break; } =20 + if (has_hex) + return (p - suffix) > 2; + return true; } =20 @@ -1788,10 +1796,10 @@ static char *format_alias(char *buf, int len, const= struct perf_pmu *pmu, const struct perf_pmu_alias *alias, bool skip_duplicate_pmus) { struct parse_events_term *term; - int pmu_name_len =3D skip_duplicate_pmus - ? pmu_name_len_no_suffix(pmu->name, /*num=3D*/NULL) - : (int)strlen(pmu->name); - int used =3D snprintf(buf, len, "%.*s/%s", pmu_name_len, pmu->name, alias= ->name); + size_t pmu_name_len =3D skip_duplicate_pmus + ? pmu_name_len_no_suffix(pmu->name) + : strlen(pmu->name); + int used =3D snprintf(buf, len, "%.*s/%s", (int)pmu_name_len, pmu->name, = alias->name); =20 list_for_each_entry(term, &alias->terms.terms, list) { if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR) @@ -1828,13 +1836,12 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, = bool skip_duplicate_pmus, pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { - size_t buf_used; - int pmu_name_len; + size_t buf_used, pmu_name_len; =20 info.pmu_name =3D event->pmu_name ?: pmu->name; pmu_name_len =3D skip_duplicate_pmus - ? pmu_name_len_no_suffix(info.pmu_name, /*num=3D*/NULL) - : (int)strlen(info.pmu_name); + ? pmu_name_len_no_suffix(info.pmu_name) + : strlen(info.pmu_name); info.alias =3D NULL; if (event->desc) { info.name =3D event->name; @@ -1859,7 +1866,7 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, info.encoding_desc =3D buf + buf_used; parse_events_terms__to_strbuf(&event->terms, &sb); buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%.*s/%s/", pmu_name_len, info.pmu_name, sb.buf) + 1; + "%.*s/%s/", (int)pmu_name_len, info.pmu_name, sb.buf) + 1; info.topic =3D event->topic; info.str =3D sb.buf; info.deprecated =3D event->deprecated; diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index b9b4c5eb5002..63b9cf9ccfa7 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -40,31 +40,52 @@ static bool read_sysfs_all_pmus; =20 static void pmu_read_sysfs(bool core_only); =20 -int pmu_name_len_no_suffix(const char *str, unsigned long *num) +size_t pmu_name_len_no_suffix(const char *str) { int orig_len, len; + bool has_hex_digits =3D false; =20 orig_len =3D len =3D strlen(str); =20 - /* Non-uncore PMUs have their full length, for example, i915. */ - if (!strstarts(str, "uncore_")) - return len; - - /* - * Count trailing digits and '_', if '_{num}' suffix isn't present use - * the full length. - */ - while (len > 0 && isdigit(str[len - 1])) + /* Count trailing digits. */ + while (len > 0 && isxdigit(str[len - 1])) { + if (!isdigit(str[len - 1])) + has_hex_digits =3D true; len--; + } =20 if (len > 0 && len !=3D orig_len && str[len - 1] =3D=3D '_') { - if (num) - *num =3D strtoul(&str[len], NULL, 10); - return len - 1; + /* + * There is a '_{num}' suffix. For decimal suffixes any length + * will do, for hexadecimal ensure more than 2 hex digits so + * that S390's cpum_cf PMU doesn't match. + */ + if (!has_hex_digits || (orig_len - len) > 2) + return len - 1; } + /* Use the full length. */ return orig_len; } =20 +int pmu_name_cmp(const char *lhs_pmu_name, const char *rhs_pmu_name) +{ + unsigned long lhs_num =3D 0, rhs_num =3D 0; + size_t lhs_pmu_name_len =3D pmu_name_len_no_suffix(lhs_pmu_name); + size_t rhs_pmu_name_len =3D pmu_name_len_no_suffix(rhs_pmu_name); + int ret =3D strncmp(lhs_pmu_name, rhs_pmu_name, + lhs_pmu_name_len < rhs_pmu_name_len ? lhs_pmu_name_len : rhs_pmu_name_l= en); + + if (lhs_pmu_name_len !=3D rhs_pmu_name_len || ret !=3D 0 || lhs_pmu_name_= len =3D=3D 0) + return ret; + + if (lhs_pmu_name_len + 1 < strlen(lhs_pmu_name)) + lhs_num =3D strtoul(&lhs_pmu_name[lhs_pmu_name_len + 1], NULL, 16); + if (rhs_pmu_name_len + 1 < strlen(rhs_pmu_name)) + rhs_num =3D strtoul(&rhs_pmu_name[rhs_pmu_name_len + 1], NULL, 16); + + return lhs_num < rhs_num ? -1 : (lhs_num > rhs_num ? 1 : 0); +} + void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; @@ -167,20 +188,10 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, co= nst char *name) static int pmus_cmp(void *priv __maybe_unused, const struct list_head *lhs, const struct list_head *rhs) { - unsigned long lhs_num =3D 0, rhs_num =3D 0; struct perf_pmu *lhs_pmu =3D container_of(lhs, struct perf_pmu, list); struct perf_pmu *rhs_pmu =3D container_of(rhs, struct perf_pmu, list); - const char *lhs_pmu_name =3D lhs_pmu->name ?: ""; - const char *rhs_pmu_name =3D rhs_pmu->name ?: ""; - int lhs_pmu_name_len =3D pmu_name_len_no_suffix(lhs_pmu_name, &lhs_num); - int rhs_pmu_name_len =3D pmu_name_len_no_suffix(rhs_pmu_name, &rhs_num); - int ret =3D strncmp(lhs_pmu_name, rhs_pmu_name, - lhs_pmu_name_len < rhs_pmu_name_len ? lhs_pmu_name_len : rhs_pmu_name_l= en); - - if (lhs_pmu_name_len !=3D rhs_pmu_name_len || ret !=3D 0 || lhs_pmu_name_= len =3D=3D 0) - return ret; =20 - return lhs_num < rhs_num ? -1 : (lhs_num > rhs_num ? 1 : 0); + return pmu_name_cmp(lhs_pmu->name ?: "", rhs_pmu->name ?: ""); } =20 /* Add all pmus in sysfs to pmu list: */ @@ -300,11 +311,11 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicat= es(struct perf_pmu *pmu) pmu_read_sysfs(/*core_only=3D*/false); pmu =3D list_prepare_entry(pmu, &core_pmus, list); } else - last_pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", NULL); + last_pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: ""); =20 if (use_core_pmus) { list_for_each_entry_continue(pmu, &core_pmus, list) { - int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", /*num=3D*/= NULL); + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: ""); =20 if (last_pmu_name_len =3D=3D pmu_name_len && !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) @@ -316,7 +327,7 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicates= (struct perf_pmu *pmu) pmu =3D list_prepare_entry(pmu, &other_pmus, list); } list_for_each_entry_continue(pmu, &other_pmus, list) { - int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: "", /*num=3D*/N= ULL); + int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: ""); =20 if (last_pmu_name_len =3D=3D pmu_name_len && !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) @@ -566,7 +577,7 @@ void perf_pmus__print_raw_pmu_events(const struct print= _callbacks *print_cb, voi .long_string =3D STRBUF_INIT, .num_formats =3D 0, }; - int len =3D pmu_name_len_no_suffix(pmu->name, /*num=3D*/NULL); + int len =3D pmu_name_len_no_suffix(pmu->name); const char *desc =3D "(see 'man perf-list' or 'man perf-record' on how t= o encode it)"; =20 if (!pmu->is_core) diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 9d4ded80b8e9..bdbff02324bb 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -2,10 +2,15 @@ #ifndef __PMUS_H #define __PMUS_H =20 +#include +#include + struct perf_pmu; struct print_callbacks; =20 -int pmu_name_len_no_suffix(const char *str, unsigned long *num); +size_t pmu_name_len_no_suffix(const char *str); +/* Exposed for testing only. */ +int pmu_name_cmp(const char *lhs_pmu_name, const char *rhs_pmu_name); =20 void perf_pmus__destroy(void); =20 --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 19:03:18 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 DFDC543ABE for ; Wed, 15 May 2024 06:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752884; cv=none; b=K3AQ+1qFVwnn3FAtXQ3e75bNj/qHzeFK8bNmp5jEO0NXyfseurL1By+0KCpxhZ1nv8NIFnXvTA0hZgmFIkkGejovEYvSwyTTNAWarM8uEZPwfIfPzBKwAqVQ0Y9lbvBr/Sz92X+yK8Ls7X/UR+EEZ6KNEs+cJbQFgV4N6dAceTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715752884; c=relaxed/simple; bh=SUmGhn7U8Bhn0LJUMjbbdvaJXGbSc6Bswuda7N7OrT4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Po7FulMkvq6RVPBesX2lLsebrwYaS+QQ8AQXdTkeBJU42VXykBBPPR0NMhhtpq3fNEj9zJmW/uVAXp/VkiQphCWenKI/qIdIANA4RqZsRXZxk3oD1NtWLA3lstmC1HtlHrcjZr681AJ4MmcZYRT8u4OFGW088RiLdkjct7XwuBY= 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=lHYXIAKo; arc=none smtp.client-ip=209.85.128.201 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="lHYXIAKo" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61bed763956so120103767b3.3 for ; Tue, 14 May 2024 23:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715752882; x=1716357682; 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=kbt3+oOgWiYhvdlIPoeQ0dzOgUp0iTplIsC7hc2pJ+U=; b=lHYXIAKofUYWwYfcakeEYAxQphwSmk20PXmItI3ckRjKSnHFBmTuf5AjefUEpXkgYL qmn3yw0+kX8kB6Abr1rPx98KsMNmskAf+xLlhLYlthqD6UavTQsmIcPs0XY3j0wnlRp3 lbodQzaj3ImeY1PCmCNBEazuYuef1CmisiCmjrlpwm6LcfvZaehxhtSemTVqk2XgWfVe MeG2zQH8nnfKwagk/BLqaTDxszAtP774M6htaI8BXO64bJNgEfutnefJ3gvXss6/LbKG KEGOV1AnE+qBgsDPkmBLSPenms3hbqLuM9irVIraX+/l2C2aMbTcHOOwY9BuOcr6IAHD wcag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715752882; x=1716357682; 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=kbt3+oOgWiYhvdlIPoeQ0dzOgUp0iTplIsC7hc2pJ+U=; b=UbjISbEFKqzXSKwBFxwbvh8bIAy/tP2xxdUtndk1cTRjZDjR9WO2EyN4Z89/1tyLDM 3N3depdGN1A0roQq7+bWCyM2nhb+2MO+/yEDNTMNMsUTZHgWdnpgWH4aza0pycZgxWtm kUGRJA7qbuymiUmkZZ80f7mItocOVnEV8ragSz05PbIcYCnfYefgjPwsHP/h349ClXmx FbCAYWmRftTIamvuPdA2ueO01EIBDU+L7OQNvVRj6vFllb51ldWSN4E5SvrKWPRelkXu 5CfjM+TDoKvlfKgcGxtJitXFo+t3FmLholPY9o4DrAMR7xjYs/nnRGybs4blB2PfmIrF Z4eA== X-Forwarded-Encrypted: i=1; AJvYcCWxirttK6M7/XFG8T2fs4hpH8yD0kWWnUM7tUFP9B/Avgy3/EOcxn0alKxVw3plWPNAqI7k6uZRXQkTPwlAwmo+fYZVrmb0knKaG7y/ X-Gm-Message-State: AOJu0YwgMh5H8L6XUZ2oYSjWo4g9u7Q45FiAJ3nh2s6+KxwMEsPeXl6X TrfV/ufnFJ8Sr08Zj31MORRrSKtgQA5DSHEy8jamiw2QqnNTcaLyletRSTgN21/3fcOCIOP1NJW M/i1JmA== X-Google-Smtp-Source: AGHT+IEYbruynMzwQTf+H5YajmkeOApfArgyEh3Z0hkcdqCiUJOLMAgirPQdXuz0xbnoJkwoe34enSuu9/dP X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bac3:cca1:c362:572]) (user=irogers job=sendgmr) by 2002:a05:6902:149:b0:de5:5225:c3a4 with SMTP id 3f1490d57ef6-dee4f304cb7mr3523816276.7.1715752882040; Tue, 14 May 2024 23:01:22 -0700 (PDT) Date: Tue, 14 May 2024 23:01:14 -0700 In-Reply-To: <20240515060114.3268149-1-irogers@google.com> Message-Id: <20240515060114.3268149-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240515060114.3268149-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v6 2/2] perf tests: Add some pmu core functionality tests From: Ian Rogers To: Tuan Phan , Robin Murphy , Thomas Richter , Bhaskara Budiredla , Bharat Bhushan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Ravi Bangoria , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Will Deacon , Stephane Eranian Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Test behavior of PMU names and comparisons wrt suffixes using Intel uncore_cha, marvell mrvl_ddr_pmu and S390's cpum_cf as examples. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/pmu.c | 99 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index 06cc0e46cb28..cc88b5920c3e 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -3,6 +3,7 @@ #include "evsel.h" #include "parse-events.h" #include "pmu.h" +#include "pmus.h" #include "tests.h" #include "debug.h" #include "fncache.h" @@ -340,10 +341,108 @@ static int test__pmu_event_names(struct test_suite *= test __maybe_unused, return ret; } =20 +static const char * const uncore_chas[] =3D { + "uncore_cha_0", + "uncore_cha_1", + "uncore_cha_2", + "uncore_cha_3", + "uncore_cha_4", + "uncore_cha_5", + "uncore_cha_6", + "uncore_cha_7", + "uncore_cha_8", + "uncore_cha_9", + "uncore_cha_10", + "uncore_cha_11", + "uncore_cha_12", + "uncore_cha_13", + "uncore_cha_14", + "uncore_cha_15", + "uncore_cha_16", + "uncore_cha_17", + "uncore_cha_18", + "uncore_cha_19", + "uncore_cha_20", + "uncore_cha_21", + "uncore_cha_22", + "uncore_cha_23", + "uncore_cha_24", + "uncore_cha_25", + "uncore_cha_26", + "uncore_cha_27", + "uncore_cha_28", + "uncore_cha_29", + "uncore_cha_30", + "uncore_cha_31", +}; + +static const char * const mrvl_ddrs[] =3D { + "mrvl_ddr_pmu_87e1b0000000", + "mrvl_ddr_pmu_87e1b1000000", + "mrvl_ddr_pmu_87e1b2000000", + "mrvl_ddr_pmu_87e1b3000000", + "mrvl_ddr_pmu_87e1b4000000", + "mrvl_ddr_pmu_87e1b5000000", + "mrvl_ddr_pmu_87e1b6000000", + "mrvl_ddr_pmu_87e1b7000000", + "mrvl_ddr_pmu_87e1b8000000", + "mrvl_ddr_pmu_87e1b9000000", + "mrvl_ddr_pmu_87e1ba000000", + "mrvl_ddr_pmu_87e1bb000000", + "mrvl_ddr_pmu_87e1bc000000", + "mrvl_ddr_pmu_87e1bd000000", + "mrvl_ddr_pmu_87e1be000000", + "mrvl_ddr_pmu_87e1bf000000", +}; + +static int test__name_len(struct test_suite *test __maybe_unused, int subt= est __maybe_unused) +{ + TEST_ASSERT_VAL("cpu", pmu_name_len_no_suffix("cpu") =3D=3D strlen("cpu")= ); + TEST_ASSERT_VAL("i915", pmu_name_len_no_suffix("i915") =3D=3D strlen("i91= 5")); + TEST_ASSERT_VAL("cpum_cf", pmu_name_len_no_suffix("cpum_cf") =3D=3D strle= n("cpum_cf")); + for (size_t i =3D 0; i < ARRAY_SIZE(uncore_chas); i++) { + TEST_ASSERT_VAL("Strips uncore_cha suffix", + pmu_name_len_no_suffix(uncore_chas[i]) =3D=3D + strlen("uncore_cha")); + } + for (size_t i =3D 0; i < ARRAY_SIZE(mrvl_ddrs); i++) { + TEST_ASSERT_VAL("Strips mrvl_ddr_pmu suffix", + pmu_name_len_no_suffix(mrvl_ddrs[i]) =3D=3D + strlen("mrvl_ddr_pmu")); + } + return TEST_OK; +} + +static int test__name_cmp(struct test_suite *test __maybe_unused, int subt= est __maybe_unused) +{ + TEST_ASSERT_EQUAL("cpu", pmu_name_cmp("cpu", "cpu"), 0); + TEST_ASSERT_EQUAL("i915", pmu_name_cmp("i915", "i915"), 0); + TEST_ASSERT_EQUAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_cf"), 0); + TEST_ASSERT_VAL("i915", pmu_name_cmp("cpu", "i915") < 0); + TEST_ASSERT_VAL("i915", pmu_name_cmp("i915", "cpu") > 0); + TEST_ASSERT_VAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_ce") > 0); + TEST_ASSERT_VAL("cpum_cf", pmu_name_cmp("cpum_cf", "cpum_d0") < 0); + for (size_t i =3D 1; i < ARRAY_SIZE(uncore_chas); i++) { + TEST_ASSERT_VAL("uncore_cha suffixes ordered lt", + pmu_name_cmp(uncore_chas[i-1], uncore_chas[i]) < 0); + TEST_ASSERT_VAL("uncore_cha suffixes ordered gt", + pmu_name_cmp(uncore_chas[i], uncore_chas[i-1]) > 0); + } + for (size_t i =3D 1; i < ARRAY_SIZE(mrvl_ddrs); i++) { + TEST_ASSERT_VAL("mrvl_ddr_pmu suffixes ordered lt", + pmu_name_cmp(mrvl_ddrs[i-1], mrvl_ddrs[i]) < 0); + TEST_ASSERT_VAL("mrvl_ddr_pmu suffixes ordered gt", + pmu_name_cmp(mrvl_ddrs[i], mrvl_ddrs[i-1]) > 0); + } + return TEST_OK; +} + static struct test_case tests__pmu[] =3D { TEST_CASE("Parsing with PMU format directory", pmu_format), TEST_CASE("Parsing with PMU event", pmu_events), TEST_CASE("PMU event names", pmu_event_names), + TEST_CASE("PMU name combining", name_len), + TEST_CASE("PMU name comparison", name_cmp), { .name =3D NULL, } }; =20 --=20 2.45.0.rc1.225.g2a3ae87e7f-goog