Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp695980lqh; Sat, 4 May 2024 20:16:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX80+hpiUGkmk40SEVQyxJzKTWWPf6v1uORg5N5hY2Df/GAkifR30buGhjjmJEUvbGcPEvcbmKr0Kgg7eNxc6I3XnPoERhtJkhR7q5w5A== X-Google-Smtp-Source: AGHT+IHWWlAoVUqImM/ecHzbhwbL2q7NX7njzTFCEnUkasGV4B5ae9G9i5FFW252EZMJq2nld6wz X-Received: by 2002:a05:622a:15c1:b0:43a:c8ce:4405 with SMTP id d1-20020a05622a15c100b0043ac8ce4405mr7359153qty.59.1714879017565; Sat, 04 May 2024 20:16:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714879017; cv=pass; d=google.com; s=arc-20160816; b=MPLObSzY+sRopAE5ZkAcFYli4v/o15SoTzj2GzQ945SXl/TqSSPwi6/vpr1DyvmkvO mqzBCiN1HEihRa1z3kG74InKAACVSOvy040j7hv4+gdIcZRNDqHcg+zqMFU9nKh73+U/ yN93ijzgRmlW9DZiqH8kw0gmBELD6rIFKptKRK0IlmAl9wsFQRKURSlwQYkpwsmSGuSu 9t4qE8pGFf3qTzNpViTg0VETm0IYioridNq46CAIE9Izzw/mG0AzDf4ifqtkOupOr5eZ U81mW7CcidgGrGANuyIobElY5O8cBPu8wbHzX8xuaobD17qmx9bGkUPrg9N1cDkjuFwF M5HA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=y9Pfav0quSIEBt1s01RsF3dX+AGp20N2u3wa4HFJbkI=; fh=R6ery9wCV5K/u2vIrlb6UlWpY7ypeIHaofCwKyjjGkk=; b=e63uKCFY5Sfd9nOcSEHgZtFTWp4WoWQZJ7gnPYG39utMRzCj/e44mWAzWRc3whjZOj GDe9REqx9CyQLGu4e3k1p7vDIpuS6XDseYNbxoq1Zf/CUVeUWoefUgm4RSk6M46odygS BCLgbViOOEZx2opJaCQYxc7dckJkM6MUIvMFlITZ+wzUKPy6vX4hgiQBdXbGxgul9u+G 41MMYJoVkH2k2g8msGzRvXGA/Q3hC1cKjtRouDuzX9Lr6Yj0BseD0JH2xWwIkU65ri7U G98VJCn0Shkgw3w7K+aIyDfKeGMDCEbMEVGJG5K+MIx9tQtxBLNEI4WgG6D6s3vuuKPi Cx4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=L58Nzq2X; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-168873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168873-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t13-20020a05622a148d00b0043ae78d53bdsi6630382qtx.106.2024.05.04.20.16.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 20:16:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=L58Nzq2X; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-168873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168873-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 44F731C208C2 for ; Sun, 5 May 2024 03:16:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 386C14690; Sun, 5 May 2024 03:16:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L58Nzq2X" 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 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-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-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 struct perf_pmu *pmu, { struct parse_events_term *term; int pmu_name_len = skip_duplicate_pmus - ? pmu_name_len_no_suffix(pmu->name, /*num=*/NULL) + ? pmu_name_len_no_suffix(pmu->name) : (int)strlen(pmu->name); int used = snprintf(buf, len, "%.*s/%s", pmu_name_len, pmu->name, alias->name); @@ -1805,7 +1805,7 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, info.pmu_name = event->pmu_name ?: pmu->name; pmu_name_len = skip_duplicate_pmus - ? pmu_name_len_no_suffix(info.pmu_name, /*num=*/NULL) + ? pmu_name_len_no_suffix(info.pmu_name) : (int)strlen(info.pmu_name); info.alias = 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; static void pmu_read_sysfs(bool core_only); -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; orig_len = len = strlen(str); - /* 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--; - if (len > 0 && len != orig_len && str[len - 1] == '_') { - if (num) - *num = strtoul(&str[len], NULL, 10); + if (len > 0 && len != orig_len && str[len - 1] == '_') return len - 1; - } + return orig_len; } +int pmu_name_cmp(const char *lhs_pmu_name, const char *rhs_pmu_name) +{ + unsigned long lhs_num = 0, rhs_num = 0; + int lhs_pmu_name_len = pmu_name_len_no_suffix(lhs_pmu_name); + int rhs_pmu_name_len = pmu_name_len_no_suffix(rhs_pmu_name); + int ret = strncmp(lhs_pmu_name, rhs_pmu_name, + lhs_pmu_name_len < rhs_pmu_name_len ? lhs_pmu_name_len : rhs_pmu_name_len); + + if (lhs_pmu_name_len != rhs_pmu_name_len || ret != 0 || lhs_pmu_name_len == 0) + return ret; + + if (lhs_pmu_name_len + 1 < (int)strlen(lhs_pmu_name)) + lhs_num = strtoul(&lhs_pmu_name[lhs_pmu_name_len + 1], NULL, 16); + if (rhs_pmu_name_len + 1 < (int)strlen(rhs_pmu_name)) + rhs_num = 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, const char *name) static int pmus_cmp(void *priv __maybe_unused, const struct list_head *lhs, const struct list_head *rhs) { - unsigned long lhs_num = 0, rhs_num = 0; struct perf_pmu *lhs_pmu = container_of(lhs, struct perf_pmu, list); struct perf_pmu *rhs_pmu = container_of(rhs, struct perf_pmu, list); - const char *lhs_pmu_name = lhs_pmu->name ?: ""; - const char *rhs_pmu_name = rhs_pmu->name ?: ""; - int lhs_pmu_name_len = pmu_name_len_no_suffix(lhs_pmu_name, &lhs_num); - int rhs_pmu_name_len = pmu_name_len_no_suffix(rhs_pmu_name, &rhs_num); - int ret = strncmp(lhs_pmu_name, rhs_pmu_name, - lhs_pmu_name_len < rhs_pmu_name_len ? lhs_pmu_name_len : rhs_pmu_name_len); - if (lhs_pmu_name_len != rhs_pmu_name_len || ret != 0 || lhs_pmu_name_len == 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 ?: ""); } /* Add all pmus in sysfs to pmu list: */ @@ -300,11 +303,11 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu) pmu_read_sysfs(/*core_only=*/false); pmu = list_prepare_entry(pmu, &core_pmus, list); } else - last_pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "", NULL); + last_pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: ""); if (use_core_pmus) { list_for_each_entry_continue(pmu, &core_pmus, list) { - int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "", /*num=*/NULL); + int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: ""); if (last_pmu_name_len == 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 = list_prepare_entry(pmu, &other_pmus, list); } list_for_each_entry_continue(pmu, &other_pmus, list) { - int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: "", /*num=*/NULL); + int pmu_name_len = pmu_name_len_no_suffix(pmu->name ?: ""); if (last_pmu_name_len == 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 = STRBUF_INIT, .num_formats = 0, }; - int len = pmu_name_len_no_suffix(pmu->name, /*num=*/NULL); + int len = pmu_name_len_no_suffix(pmu->name); const char *desc = "(see 'man perf-list' or 'man perf-record' on how to encode it)"; 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 +#include +#include + struct perf_pmu; struct print_callbacks; -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); void perf_pmus__destroy(void); -- 2.45.0.rc1.225.g2a3ae87e7f-goog