Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2193050lqo; Mon, 13 May 2024 10:19:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDLGewZqsoIBP0+3hBsR7h+6qrzyxKxyJUD/QY1+MIpyZ3n6zz6Khn3L7cbnJDaJIW9xLgnQxv/Ss378aVHYUoQSV9E1Abb+mSDS0duw== X-Google-Smtp-Source: AGHT+IHvDXsyovWBwbWwsTAvl+Nz/e8WpRea7nbqGBIk9ntai///LAnosKxvPqYrx65zRL1L/Ux5 X-Received: by 2002:a50:d795:0:b0:56a:ae8a:acc0 with SMTP id 4fb4d7f45d1cf-5734d5cc9c8mr7617458a12.21.1715620776582; Mon, 13 May 2024 10:19:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715620776; cv=pass; d=google.com; s=arc-20160816; b=DNEj3m0PRDw3DLvI4WO7hA/P8yrjtwix1SV73xz2lkeemlLPgPfuQT5TrAlJHLY3pI eMNiwsWtfYPLBCpuY5+KnQetXd/3bMpyhQyB6FzJMNJLAW7oanzhL1q/GR7i23FuEXId oj5mx5uuV0OJhV6cFUrwV1J6WxVwnwOdDm51f4SrUVucmkyIQ8PfUrxUs05f5H819fSz jS25gnfSBBj7kKe61G/087lyIubPKDPgzBazrbiRnmylxy8GSqL7jChgEQO0wjzaEPnc aj5vEKr8Q5IAnWr8ZdL6naMcdznp7it1OC/f7BOwJiahFu3N/L8HstzVUQC7gODeHBTs iHZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=+0LcTyeTsxJaPnZ45cfiBgAVI9jES1Y4g+ohTkoWGUw=; fh=TgXy0EEvJNNNOF/2lPz1NqrmDOaxc9pwcnfwNR11aG8=; b=H9dcsUKs7nJLKRD0uM9cwu/3ZMVBjtaM5NSQcnHWXEF2CxsAn98uri6QXyhuAgzGoi I5UysV8vydFMwJ4OI2soNboRSnZmxpmHyf2W9Y00SivBI5NSATY3UgJ1/BDQWMRk0PDc ZB40idk/YOSGdTCZINMmzYlYSzVRl9mXLQQnjjQPTxIfLX7i79KxGGRyUCiD4peMuJTN 3Gd1o2iYLZ4TQl62fpk+Y78beiCnSgltODnD8oQ/k1aruUMHp7VtbYnGAQu3SkyJke52 sVdCZf3ffLElXkzWqoQ/GoxvpHXfl62WdttljuR0421TgAe5OtHhnOyJ1HEWczbZLftM +kSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2Ei9j5Wg; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-177889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177889-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c2d5e4dsi5342578a12.325.2024.05.13.10.19.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 10:19:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2Ei9j5Wg; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-177889-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177889-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1FCFC1F25D16 for ; Mon, 13 May 2024 17:19:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4379020B34; Mon, 13 May 2024 17:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2Ei9j5Wg" Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) (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 62880208A1 for ; Mon, 13 May 2024 17:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715620768; cv=none; b=KkmIg59tqzo4u7KoJbQlzxsQVtofJl4SU3YN7cvn7vIBiPe+puUBUDP/MleOFEUVOCWLud3KelTDpgYiOBjTZzIgJnHmSBsXCsYI7KQz9vUkYR75NvwRR0EC0kPTKeFdtf3iHXbCnOhoebsHmCv26MHIiCyhqlkhSIc9B/9yiCk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715620768; c=relaxed/simple; bh=MJiVwiM18XryHUPJhid6EktmMnrxfcyKLI1aF/pSACw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Ud9MVXRTyzeyboerkoaZWDBpTXFcK+lInY94A4ZNLH3rFiQbYfkHG4mYeRsinSkAvKmAdP/PiTss638XQ/XGHP48jom/nvxzMdDtqyNvMOw71vNbJxLwUhUz5a0H28YQTYEi9L6ObwEkOKWI2N9+z1gRPjdzB92K/PBZmMUfwPU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2Ei9j5Wg; arc=none smtp.client-ip=209.85.166.172 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=google.com Received: by mail-il1-f172.google.com with SMTP id e9e14a558f8ab-36c6789b520so353765ab.1 for ; Mon, 13 May 2024 10:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715620765; x=1716225565; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+0LcTyeTsxJaPnZ45cfiBgAVI9jES1Y4g+ohTkoWGUw=; b=2Ei9j5Wg6O6/qB40/2aulFUIKXSQWn61xjUeF1fmhSS1aMrtu5QfaHTae9VZB2uY0Z /z3sgGReAHsJnMC1avCOSFjaEr2AKchf/Ku3bGZD/txcPm1kZEsKu9cMZoXhDRJwf/nh A5+rxzvBarfGhVJE6zfcjWtYTYkCPIr3kUdXHj+0tYYMGkHFtGjNWSdv2F9y2cte79QC H4OM56RbvsczCHHlWVwkoD2LePrxAYuhEMOxB3h+1W84ekzJIoU8uh9BvVuSbUyKIlox Ufo81MAKjO99hz/N3uqXsKuT94J3ZpgDjx8pCkWMBq7uswl2hcD0lxC5yb1pNDZSG7WM cWUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715620765; x=1716225565; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+0LcTyeTsxJaPnZ45cfiBgAVI9jES1Y4g+ohTkoWGUw=; b=Pi4zhVe3KnGcU6maxc9Ea0aNAQL0pkJBoLjQ7lXpcZ/FZJ63HOAp//gKjAdlfaIsuk vJe3HANIv/73EmVQPXh9ZPqiHVxI0smZ1gPjo2x0ZS8JOt+s7Je3XQtMEGYVNTuanILo A7t+haHM5/i5kOlremSujGoTrg4pUh00Z9kG+WU4jkYBIM4hsw8C9DR60ofKDUJG5KWR iiIG8VvT+cTe3B8uStv0T8FldsPzr5jMmme2GBlSO0kqObscxOfX3Uq3Sf+dO7zZCmFL Mp6kADaSPSz0ljhyNF7zYPncb0UY7NBmiAN8QkKLUz0DQFw76ULT9j5kf3R5rg0chDwy Okxw== X-Forwarded-Encrypted: i=1; AJvYcCWlMhLzpA8HCStQFKglt6z3UiqHToU3kHaO2iMxgsab1WT/nMJaEdG+oGclYutW3NzK1COS2xsLlyUornkvZZsg8ZztyOvFBnlJfM+1 X-Gm-Message-State: AOJu0YwmsnBwAQA+1YjQ273Mhg7zk1fGqvTvh00L7/76i6ZyqpjWioY7 uynpuzbgl1Ej0B5yF2ux4ohV1ES27tLDoGFddCqZR95O29Y5DH28YCpv7/VSF8DmMJ3lHJXH7Oi GfjOlVtYJ6N7/lh7LnvPHYc9DvTBghDAC5rBR X-Received: by 2002:a05:6e02:c71:b0:36c:5511:4a4a with SMTP id e9e14a558f8ab-36ccb8904ccmr4746675ab.6.1715620765372; Mon, 13 May 2024 10:19:25 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240511003601.2666907-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Mon, 13 May 2024 10:19:13 -0700 Message-ID: Subject: Re: [PATCH v1] perf pmu: Count sys and cpuid json events separately To: Justin He Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , James Clark , "linux-perf-users@vger.kernel.org" , "linux-kernel@vger.kernel.org" , John Garry Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, May 12, 2024 at 7:22=E2=80=AFPM Justin He wrote= : > > > > > -----Original Message----- > > From: Ian Rogers > > Sent: Saturday, May 11, 2024 8:36 AM > > To: Justin He ; Peter Zijlstra ; > > Ingo Molnar ; Arnaldo Carvalho de Melo > > ; Namhyung Kim ; Mark Rutland > > ; Alexander Shishkin > > ; Jiri Olsa ; Ian= Rogers > > ; Adrian Hunter ; Kan Lian= g > > ; James Clark ; > > linux-perf-users@vger.kernel.org; linux-kernel@vger.kernel.org; John Ga= rry > > > > Subject: [PATCH v1] perf pmu: Count sys and cpuid json events separatel= y > > > > Sys events are eagerly loaded as each event has a compat option that ma= y mean > > the event is or isn't associated with the PMU. These shouldn't be count= ed as > > loaded_json_events as that is used for json events matching the CPUID t= hat may > > or may not have been loaded. The mismatch causes issues on ARM64 that u= ses > > sys events. > > > > Reported-by: Jia He > > Closes: > > https://lore.kernel.org/lkml/20240510024729.1075732-1-justin.he@arm.com > > / > > Fixes: e6ff1eed3584 ("perf pmu: Lazily add JSON events") > > Signed-off-by: Ian Rogers > > --- > > tools/perf/util/pmu.c | 70 ++++++++++++++++++++++++++++++------------- > > tools/perf/util/pmu.h | 6 ++-- > > 2 files changed, 53 insertions(+), 23 deletions(-) > > > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index > > b3b072feef02..888ce9912275 100644 > > --- a/tools/perf/util/pmu.c > > +++ b/tools/perf/util/pmu.c > > @@ -36,6 +36,18 @@ struct perf_pmu perf_pmu__fake =3D { > > > > #define UNIT_MAX_LEN 31 /* max length for event unit name */ > > > > +enum event_source { > > + /* An event loaded from /sys/devices//events. */ > > + EVENT_SRC_SYSFS, > > + /* An event loaded from a CPUID matched json file. */ > > + EVENT_SRC_CPU_JSON, > > + /* > > + * An event loaded from a /sys/devices//identifier matched j= son > > + * file. > > + */ > > + EVENT_SRC_SYS_JSON, > > +}; > > + > > /** > > * struct perf_pmu_alias - An event either read from sysfs or builtin = in > > * pmu-events.c, created by parsing the pmu-events json files. > > @@ -521,7 +533,7 @@ static int update_alias(const struct pmu_event *pe, > > > > static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name, > > const char *desc, const char *val, FILE *= val_fd, > > - const struct pmu_event *pe) > > + const struct pmu_event *pe, enum event_so= urce src) > > { > > struct perf_pmu_alias *alias; > > int ret; > > @@ -574,25 +586,30 @@ static int perf_pmu__new_alias(struct perf_pmu > > *pmu, const char *name, > > } > > snprintf(alias->unit, sizeof(alias->unit), "%s", unit); > > } > > - if (!pe) { > > - /* Update an event from sysfs with json data. */ > > - struct update_alias_data data =3D { > > - .pmu =3D pmu, > > - .alias =3D alias, > > - }; > > - > > + switch (src) { > > + default: > > + case EVENT_SRC_SYSFS: > > alias->from_sysfs =3D true; > > if (pmu->events_table) { > > + /* Update an event from sysfs with json data. */ > > + struct update_alias_data data =3D { > > + .pmu =3D pmu, > > + .alias =3D alias, > > + }; > > if (pmu_events_table__find_event(pmu->events_tabl= e, pmu, > > name, > > update_alias, &d= ata) =3D=3D 0) > > - pmu->loaded_json_aliases++; > > + pmu->cpu_json_aliases++; > > } > > - } > > - > > - if (!pe) > > pmu->sysfs_aliases++; > > - else > > - pmu->loaded_json_aliases++; > > + break; > > + case EVENT_SRC_CPU_JSON: > > + pmu->cpu_json_aliases++; > > + break; > > + case EVENT_SRC_SYS_JSON: > > + pmu->sys_json_aliases++; > > + break; > > + > > + } > > list_add_tail(&alias->list, &pmu->aliases); > > return 0; > > } > > @@ -653,7 +670,8 @@ static int __pmu_aliases_parse(struct perf_pmu *pmu= , > > int events_dir_fd) > > } > > > > if (perf_pmu__new_alias(pmu, name, /*desc=3D*/ NULL, > > - /*val=3D*/ NULL, file, /*pe=3D*/ = NULL) < 0) > > + /*val=3D*/ NULL, file, /*pe=3D*/ = NULL, > > + EVENT_SRC_SYSFS) < 0) > > pr_debug("Cannot set up %s\n", name); > > fclose(file); > > } > > @@ -946,7 +964,8 @@ static int pmu_add_cpu_aliases_map_callback(const > > struct pmu_event *pe, { > > struct perf_pmu *pmu =3D vdata; > > > > - perf_pmu__new_alias(pmu, pe->name, pe->desc, pe->event, /*val_fd= =3D*/ > > NULL, pe); > > + perf_pmu__new_alias(pmu, pe->name, pe->desc, pe->event, /*val_fd= =3D*/ > > NULL, > > + pe, EVENT_SRC_CPU_JSON); > > return 0; > > } > > > > @@ -981,13 +1000,14 @@ static int pmu_add_sys_aliases_iter_fn(const str= uct > > pmu_event *pe, > > return 0; > > > > if (pmu_uncore_alias_match(pe->pmu, pmu->name) && > > - pmu_uncore_identifier_match(pe->compat, pmu->id))= { > > + pmu_uncore_identifier_match(pe->compat, pmu->id)) { > > perf_pmu__new_alias(pmu, > > pe->name, > > pe->desc, > > pe->event, > > /*val_fd=3D*/ NULL, > > - pe); > > + pe, > > + EVENT_SRC_SYS_JSON); > > } > > > > return 0; > > @@ -1082,6 +1102,12 @@ struct perf_pmu *perf_pmu__lookup(struct > > list_head *pmus, int dirfd, const char > > pmu->max_precise =3D pmu_max_precise(dirfd, pmu); > > pmu->alias_name =3D pmu_find_alias_name(pmu, dirfd); > > pmu->events_table =3D perf_pmu__find_events_table(pmu); > > + /* > > + * Load the sys json events/aliases when loading the PMU as each = event > > + * may have a different compat regular expression. We therefore c= an't > > + * know the number of sys json events/aliases without computing t= he > > + * regular expressions for them all. > > + */ > > pmu_add_sys_aliases(pmu); > > list_add_tail(&pmu->list, pmus); > > > > @@ -1739,12 +1765,14 @@ size_t perf_pmu__num_events(struct perf_pmu > > *pmu) > > size_t nr; > > > > pmu_aliases_parse(pmu); > > - nr =3D pmu->sysfs_aliases; > > + nr =3D pmu->sysfs_aliases + pmu->sys_json_aliases;; > > Nits: double ";", others lgtm. > > This fixes the error on the Arm N2 server: > Unexpected event smmuv3_pmcg_3f002/smmuv3_pmcg_3f002/transaction// > Unexpected event smmuv3_pmcg_3f042/smmuv3_pmcg_3f042/transaction// > Unexpected event smmuv3_pmcg_3f062/smmuv3_pmcg_3f062/transaction// > Unexpected event smmuv3_pmcg_3f402/smmuv3_pmcg_3f402/transaction// > Unexpected event smmuv3_pmcg_3f442/smmuv3_pmcg_3f442/transaction// > ..... > > Please feel free to add > Tested-by: Jia He Thanks Justin! I noticed Arnaldo has picked this up in the next tree: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/co= mmit/?h=3Dperf-tools-next&id=3Dd9c5f5f94c2d356fdf3503f7fcaf254512bc032d Would be great to add the Tested-by and address the ;; issue, good catch :-= ) Ian > -- > Cheers, > Justin (Jia He) > > > > if (pmu->cpu_aliases_added) > > - nr +=3D pmu->loaded_json_aliases; > > + nr +=3D pmu->cpu_json_aliases; > > else if (pmu->events_table) > > - nr +=3D pmu_events_table__num_events(pmu->events_table, p= mu) - > > pmu->loaded_json_aliases; > > + nr +=3D pmu_events_table__num_events(pmu->events_table, p= mu) - > > pmu->cpu_json_aliases; > > + else > > + assert(pmu->cpu_json_aliases =3D=3D 0); > > > > return pmu->selectable ? nr + 1 : nr; > > } > > diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index > > 561716aa2b25..b2d3fd291f02 100644 > > --- a/tools/perf/util/pmu.h > > +++ b/tools/perf/util/pmu.h > > @@ -123,8 +123,10 @@ struct perf_pmu { > > const struct pmu_events_table *events_table; > > /** @sysfs_aliases: Number of sysfs aliases loaded. */ > > uint32_t sysfs_aliases; > > - /** @sysfs_aliases: Number of json event aliases loaded. */ > > - uint32_t loaded_json_aliases; > > + /** @cpu_json_aliases: Number of json event aliases loaded specif= ic to the > > CPUID. */ > > + uint32_t cpu_json_aliases; > > + /** @sys_json_aliases: Number of json event aliases loaded matchi= ng the > > PMU's identifier. */ > > + uint32_t sys_json_aliases; > > /** @sysfs_aliases_loaded: Are sysfs aliases loaded from disk? */ > > bool sysfs_aliases_loaded; > > /** > > -- > > 2.45.0.118.g7fe29c98d7-goog > > IMPORTANT NOTICE: The contents of this email and any attachments are conf= idential and may also be privileged. If you are not the intended recipient,= please notify the sender immediately and do not disclose the contents to a= ny other person, use it for any purpose, or store or copy the information i= n any medium. Thank you.