From nobody Mon Feb 9 19:32:14 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 8266F4428 for ; Sun, 5 May 2024 03:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714878994; cv=none; b=qKkXQgV4BxS3Iuifc67wmoMg4KEtT+oAmrx20QYTmXVqVfk+Pr2szGbjcKWZn+po74BOxTtKh1fXL/MNQxd3Cy39XjMBhOMxu95/TKlOJorSuE88+spAzKYfoy7vYaNtPROZ6VvHzJ37FxJfUD1FQ1S7bgw5TOaA9ClY6BPQ6Ls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714878994; c=relaxed/simple; bh=5gTI/vLvfoRDkE1HNBi49R/WzRbm6XNb8vEM3hPtW9A=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ciFOhrmLMjzxs1aKhfzcAE40tlUs/0pTgEC7ETL0XTv/js128Hr9NmSCJIyiiYx7k7rRbqKilWmMx32Aks+mTmEjd1dB2UxmURwbCbaHXanfZthBYgsc6zDiTk3251rbwAmTnhFxz+RN6njTAUMAL19PHuV5hWslFCOSVNfZF6s= 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=L58Nzq2X; arc=none smtp.client-ip=209.85.219.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="L58Nzq2X" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de603db5d6aso2396744276.2 for ; Sat, 04 May 2024 20:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714878991; x=1715483791; 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=y9Pfav0quSIEBt1s01RsF3dX+AGp20N2u3wa4HFJbkI=; b=L58Nzq2XkJVQepA8rvY7e9iLe/RzJl79EMXqn0HtMsYSWqXpKrpzp/Vug722RbUcRz xcDoZnuBLqrcwF9JPzi/vVUIL9qY/xVNvpbNySrYvicfMzZkCli4OVZjVdaBrZ8zoUy+ Iyx1fD69rPADFOR2edb00m/p1rpvFX2jHusWLFZYHs1lP+jfw6AUq77PDiEq8vkEUTu7 KjSUXrhvMjKsCCtlAljSEBreRS47Wi45u7497mUPkngr+T8LlT60PQqG6BGaDv7PZj3o wTJzowCcJXC49RPaUzbPjAgOOwf0Ba11yXzLLO7u9XAmz4x9erVRe1NQFAAnVVeprWE/ 0/zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714878991; x=1715483791; 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=y9Pfav0quSIEBt1s01RsF3dX+AGp20N2u3wa4HFJbkI=; b=iFO5GLlzzRwBFtRE2SOPdsgiGrtvw/g6o6L4W6U+iMJ/+o5UyqIiadM6gW5DGd6HLe ZhlWdFyG5p6pfdpkj/wO+a7sNk/0DcUwbEfiE7+7nJxGnFPKgyNIC5EFiDe2gKaXv2e2 VCyGwB1BuMcxm70DK+wzutT/cKUph78btHWErhq0LF7jhhsECsOyMTu6sT3t3Z4lQ7xO r4A0HI+5KXdUeo5D3GOm6z183ReKlBTfE0YzvN7a3a1iYpeIOyHTsSwwpAqh8xLACUIJ bp6HGJ/YytpoQekedRvfZiL/SHsTO2oq5Ozih/chubW0HSaEAK1gS+HOrbZdva+5JYM4 JA8Q== X-Forwarded-Encrypted: i=1; AJvYcCUaeO4X/3U1RjhdWsbxkps9R+quYhRMAjWQh70jqHz1lR760gCAFQrbcrlOsPRnDCPdsQiaid7mLJVPB0q2PmBCsrXyaNaHU7rSRI1g X-Gm-Message-State: AOJu0YxL1Du3heUMRJOJ7Xu5eJZpliPbslp9nrWogIrc9e62YTaV0jKg t+/A8W5fp4i43xNr1HA9LawyudKgPGUFmG3qOkRruKP2tpSg+s/4DvZYVl7Z70V/NlLRSdeov6N 9Nly+hA== X-Google-Smtp-Source: AGHT+IHL6ErOFm2phIaHoqIJrQBH+wqH5JjnNJbq3AhDW42lZTQAeFnc79quGqZKw72nV1iUKB+tniB2KVHF X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:566d:1f52:f5f5:c8ec]) (user=irogers job=sendgmr) by 2002:a25:ad9b:0:b0:de5:9f2c:c17c with SMTP id z27-20020a25ad9b000000b00de59f2cc17cmr2086132ybi.9.1714878990839; Sat, 04 May 2024 20:16:30 -0700 (PDT) Date: Sat, 4 May 2024 20:16:23 -0700 In-Reply-To: <20240505031624.299361-1-irogers@google.com> Message-Id: <20240505031624.299361-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: <20240505031624.299361-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v3 1/2] perf pmus: Sort/merge/aggregate PMUs like mrvl_ddr_pmu From: Ian Rogers To: 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 10 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. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 4 ++-- tools/perf/util/pmus.c | 53 ++++++++++++++++++++++-------------------- tools/perf/util/pmus.h | 7 +++++- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b3b072feef02..32e5a73273d7 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1761,7 +1761,7 @@ static char *format_alias(char *buf, int len, const s= truct perf_pmu *pmu, { struct parse_events_term *term; int pmu_name_len =3D skip_duplicate_pmus - ? pmu_name_len_no_suffix(pmu->name, /*num=3D*/NULL) + ? pmu_name_len_no_suffix(pmu->name) : (int)strlen(pmu->name); int used =3D snprintf(buf, len, "%.*s/%s", pmu_name_len, pmu->name, alias= ->name); =20 @@ -1805,7 +1805,7 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, =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) + ? pmu_name_len_no_suffix(info.pmu_name) : (int)strlen(info.pmu_name); info.alias =3D NULL; if (event->desc) { diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index b9b4c5eb5002..28cfa7adbfd7 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -40,31 +40,44 @@ 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) +int pmu_name_len_no_suffix(const char *str) { int orig_len, len; =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])) + while (len > 0 && isxdigit(str[len - 1])) len--; =20 - if (len > 0 && len !=3D orig_len && str[len - 1] =3D=3D '_') { - if (num) - *num =3D strtoul(&str[len], NULL, 10); + if (len > 0 && len !=3D orig_len && str[len - 1] =3D=3D '_') return len - 1; - } + 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; + int lhs_pmu_name_len =3D pmu_name_len_no_suffix(lhs_pmu_name); + int 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 < (int)strlen(lhs_pmu_name)) + lhs_num =3D strtoul(&lhs_pmu_name[lhs_pmu_name_len + 1], NULL, 16); + if (rhs_pmu_name_len + 1 < (int)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 +180,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); =20 - if (lhs_pmu_name_len !=3D rhs_pmu_name_len || ret !=3D 0 || lhs_pmu_name_= len =3D=3D 0) - return ret; - - 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 +303,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 +319,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 +569,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..69d64fbd4259 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); +int 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 Mon Feb 9 19:32:14 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 3E2F11860 for ; Sun, 5 May 2024 03:16:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714878995; cv=none; b=cTxA1kFYK6i6GldhnWZSskpgdX7UtARGWaAkuVVhD1r0kLg9yVdii5i0O6KkcpSIt+XtA7a7hQbGjwfLfGR7hd7hCgB194sN2lUtBanlpFQMNcbn0Sqa27MqmP8Kcq5zjOUBAHiOTnMXPRAws5XzN/tfqKZZbDl+N3AoAppCUgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714878995; c=relaxed/simple; bh=ZqgY35o/fk0bLnsVALiDz04OFwN2vLWcQGzxkdCX1FY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=RXy1Ci9mQS6ofpAYWX+wQFTGPs4N+XeKdl1tsAx+iq/e6jn1Ncs4LZ+p5hrcrf6u/WGffMrlWMOUWJjfU3bB6jvC1ZSPXjNKLfzP49hE2pPtHvVBEMGLRv9kc7Of8X2f9pynb1l758NbsTDM7DDA+wgqbOWaEYj3pvm2FxDGjU4= 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=miD7pyWo; arc=none smtp.client-ip=209.85.219.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="miD7pyWo" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de610854b8bso1872808276.0 for ; Sat, 04 May 2024 20:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714878993; x=1715483793; 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=UzxYDdoMX/MwVDQpnBzTgXoLHHZdpOpA7oIIBJp7WqY=; b=miD7pyWoPQL1FKdbloQ2g9+SxFeLFDOX2YOXf58gBPTUREQG3GnarABFMrOiVTQxhh H8FYfBhug/8AQaiQNhjNPtxSnjB5uozdVACSCtKtvwnFCWNbpFYMJAXDbDw1XP/f93Xe Db96IFUsLar3QKCInwVuwEFnlh8XJTpZCW9P8FMg1lOoPN4Eoj3mz2sqtb43ZcdNdJ2g GNwMm+vx0qPFf7xMg8ys3Be/IqZ01aufGY3njeNpc2qyxr10Y0WxQ185z7gBIw9zeSWl atcf4ckI2NRyk08p9FRmpmOF2ZG8bAauQsUXOQipjBh5uc/xX9WjwEt9A84KvGk0jiLw Pe3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714878993; x=1715483793; 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=UzxYDdoMX/MwVDQpnBzTgXoLHHZdpOpA7oIIBJp7WqY=; b=UdWL2zrgZub3Lq+S78oMeU3JtRr0d2ToBHw6s9DKYbT2xCJqTGo2+Oq3cNcEqrjDZv C9nwWy7KMt/o0LG5s/JBt1w13GhYuwuxLu8uE5A9DTCyguyr+Gqlus98jlXUR1YX6J7i Xp3XwZjjas4Tycqh15Nkd2lttvX4Wje0qv62RAJRVPefLFWgjj/fORtqFeHBskKDO5AS dVXwL6DIBSreNEhIriAmfP/FvmBEKY1gVFZBsIMvJhbChbfkRDXpjf07kPNZq4DEIedU 2eWS4FzJX6u+hSks5zPOKbxWrLcktt0Ydf94wCKXNtRn5Shl/w6cg05rfFSiOHTCcwuu O6GA== X-Forwarded-Encrypted: i=1; AJvYcCX7eJbEy9Bu/b+bRpj7ju8rQ+95IJt+uoKLAwCgRklZta8A1yRYjM2PPmmlw44u34zGSiPRbE7m6OpDk6g1gDbylRFXp1GtJgIxZaZR X-Gm-Message-State: AOJu0Yx1tq6rHUjEoijkAv9xW49n2A0qWr5STYbKaF0/3d100BDLn4bn +8nmguAZ5UFCb4g8Y2UumvkYQmxfQX0vTUk8of7KwG8rfjEL5jmiEEZX7q2Hq4a3P7NPw9WP4xr n2N6UPA== X-Google-Smtp-Source: AGHT+IHiW7JCLhJ0L+bmMS4hqEn7sIM8MKJJl5+O+guFA42KbGM05jCD1bE8R6vzIGRdfIQsF5+Q587gx8d/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:566d:1f52:f5f5:c8ec]) (user=irogers job=sendgmr) by 2002:a05:6902:72b:b0:dc6:dfd9:d423 with SMTP id l11-20020a056902072b00b00dc6dfd9d423mr996413ybt.3.1714878993136; Sat, 04 May 2024 20:16:33 -0700 (PDT) Date: Sat, 4 May 2024 20:16:24 -0700 In-Reply-To: <20240505031624.299361-1-irogers@google.com> Message-Id: <20240505031624.299361-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: <20240505031624.299361-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v3 2/2] perf tests: Add some pmu core functionality tests From: Ian Rogers To: 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 and marvell mrvl_ddr_pmu as examples. Signed-off-by: Ian Rogers --- tools/perf/tests/pmu.c | 95 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index 06cc0e46cb28..9dc77f29f723 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,104 @@ 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_EQUAL("cpu", pmu_name_len_no_suffix("cpu"), (int)strlen("cpu"= )); + TEST_ASSERT_EQUAL("i915", pmu_name_len_no_suffix("i915"), (int)strlen("i9= 15")); + for (size_t i =3D 0; i < ARRAY_SIZE(uncore_chas); i++) { + TEST_ASSERT_EQUAL("Strips uncore_cha suffix", + pmu_name_len_no_suffix(uncore_chas[i]), + (int)strlen("uncore_cha")); + } + for (size_t i =3D 0; i < ARRAY_SIZE(mrvl_ddrs); i++) { + TEST_ASSERT_EQUAL("Strips mrvl_ddr_pmu suffix", + pmu_name_len_no_suffix(mrvl_ddrs[i]), + (int)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_VAL("i915", pmu_name_cmp("cpu", "i915") < 0); + TEST_ASSERT_VAL("i915", pmu_name_cmp("i915", "cpu") > 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