Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp747610lqo; Fri, 10 May 2024 13:44:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVBllOQMfpqU6EHx9CqCvq200LKddwyGsEpAsMDrshajXd5XIaPGhA4kTVlDdLOnGN21NZGuC5lHX3WwqLoLYGqEUee8P1s9LoibFWJfg== X-Google-Smtp-Source: AGHT+IGyFhb4xQtfj06R0OHKcjptfcYK+mPGF+g1dl3uusAV20pQbQ/xJp3ju49MA82LzqTBjlL4 X-Received: by 2002:a17:902:d511:b0:1eb:e40:3e07 with SMTP id d9443c01a7336-1ef441a76acmr44323485ad.62.1715373848049; Fri, 10 May 2024 13:44:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715373848; cv=pass; d=google.com; s=arc-20160816; b=wNZzOekVfQd8YL02mzEN+en6ZK/cWjd+1YW6SGMk+eABb1u8xR8ZvXES8npTSNiTbW qXgnyFdhT90Fpkw7I8L0gF/sKETq9u6Se26pf72EKOtk9SulB+o0xr5rIZ1Dk3lbG+6B 3EuUUWrz7fcQ/LFR6+JRF0cIsiBCl66DLF2bVeUt25JdsJ97sb7T1COL8JEw25Dc3NzL rWGD6yGu57lqx8XjuSdNg+ITWdKCys/Gi/L654OSwYPqgp/ZkfpDj+6aZPSzWCd8aYQ1 6cU1iQUGDhHj/8PuuGhPCZJvhCCsqECH9CiaEnPqhCtbJAzlvYpO5kzm3DzHf4qKGv8E p5RQ== 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=p0Cd7G0GKoxhRORjevFmtxdm76EPV8+O9ixryuU5taE=; fh=EONh0UUdvHjsLKyYHdqBZqdNHtsnLgcR5UwB9TmlzBw=; b=jgDkR7JdKsz6IUA8mPD8IrJbTZW3P5pis+qpD0y/nCR7nUu3g6qlMN3rchhsy1FQTf jUdXmzQUrl3gc4MFlyDt9+U5DUkpTuXnicBo8UwdQQGnms9QjF7OMkzG9aq2RGuuNnXM CTuHcFfIjh3Z769QxExwvOn8P3KQkwRh/Te1e2eUYQhlK1wluFTSTtVM6rNQjJy58Bzh VLV9yNeQkMAz9dhvjinvxsQ56rMoWRxCXo5witsp2IuaNlRG2G0/FR7a5kn/2xHYceiW kClFpk8v4hap9IZFqHWQ/0HytZxd+WYP3sPYpB9eYE4lD/Kg1c5lZTn8KpRiVquCiPnc tlRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jVo6MiJM; 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-176175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176175-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c3687cesi41534385ad.633.2024.05.10.13.44.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 13:44:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jVo6MiJM; 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-176175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176175-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id AA946B243D9 for ; Fri, 10 May 2024 20:42:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A3154F613; Fri, 10 May 2024 20:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jVo6MiJM" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 92A41D2E5 for ; Fri, 10 May 2024 20:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715373729; cv=none; b=hAzdacfDs4REauHbuilxhScONlgEwSZWs6dHJ511VQALZDiQ+6WKE84fRtlzd4pdtGMqk5QlzDZ69bI5JvK1JzepwRvksU84X/r6oeKZaiypphl9BAyXxBniMv5Pvy2cIKxB2wbPTo6zMQihtU12qGCcvo9JDwoy9MIBnPxzgSY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715373729; c=relaxed/simple; bh=QaYvzBIYVoTMRj+JIXivj0EzwL27B7dR6rs7UcMotrY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=bfNkvC2ja4EfzitqwK7T7CEvJ3mNSywoXFMfqmZSPrqZ2qur3UEyBDS1z+DQCr7Jf02O7S1OdNnRBi5PjfMWll3MPhoyn2Uqd8sF328l9RWUmsAaku7OC92ZchSpJ7k8rZfhnb2/9LTff6d19JAKY70C5QZTTRwRxX+8/4BD4Eo= 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=jVo6MiJM; arc=none smtp.client-ip=209.85.214.169 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-pl1-f169.google.com with SMTP id d9443c01a7336-1ee5f3123d8so10615ad.1 for ; Fri, 10 May 2024 13:42:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715373727; x=1715978527; 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=p0Cd7G0GKoxhRORjevFmtxdm76EPV8+O9ixryuU5taE=; b=jVo6MiJMnq2GCAOmV65UYSWhG4EVnD1+7XL8LhJ6l8K8S2GutlM/N2fNOh5Gx8kgoP SBsn6BcEj7OfeAO3ACwZ28O9OtJ3k7Mf9mN/2eGBmjcHHCIgZcNrglcNb3OvGjFFvLMD c3O/q4l+ENussk+9e0VGAqRFunyqoiRgA80qvrmHwQTiCodpw5KodCxWHujVdXxoaYKO mnIRQmN/g7WZhXpdPR66Re2Uu0wx65TObyEwUowSqbQN3EIhG+os8X1xghwQ8TUJnp3l kQfJt2Uuiv5FPJptWtvIIJwExo5VbklkXYkS/Q9uevMmAsvSBiBYOXRqBvCMcbxBJZq9 uU3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715373727; x=1715978527; 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=p0Cd7G0GKoxhRORjevFmtxdm76EPV8+O9ixryuU5taE=; b=CTpUJuotI+TI4hCK2zE9BJZAOxmdb9ymRDc1+sap78eN13U9eOiIM3dUBCnLQz4Vum 6uRR7lGOTWzHM+a6sK8cF69UcahBQe6lH1wweQpBK+dWfZ5RGomxvy2fG+BQjMal0OFC XJId2m7FLcLzlnOjeuUqKI/pHv7nwrR0e0//ZjAkLZOMhTtzQaUV/95XO5yxKppwWSzB ePrGQq2yUoUdUsy+HG5SjON4v0Rr8eMxzHXDiNbdLUoIkR2Mh5PGXO3AIsv5Ay6z4RMz fnyMqWJPrH/r+ooBwpslYw990cAW9UnZG1od6NqdMTW8qiXSNCGIuAE3qhV7xTth9+9Q 849w== X-Forwarded-Encrypted: i=1; AJvYcCVTDcjonTKowV5XnQwRMeW7O6tOY1oMw7Rq4OVuqjwbubIPibhDWf4XJfBrnGh6bI4C++ES5+a2Sk3BkKlcXSLGk7ezQsp5FPFT92wI X-Gm-Message-State: AOJu0YxMZTbjzNTqVDY5DnNLvs4tLly8T0waPpaaaOhyiSiZyf7hZWKE n2A+3K+xBrxsghi6lSBXpcL8JU8ivvpBBnQkPeIK+WWHPQRycnxC6KvIdciEM2pNyft1JMNfsFr AUMDfgrL5Rb0eaqEMzeaUZa1+xjOSirDl1QU1 X-Received: by 2002:a17:903:11cf:b0:1e5:d3d2:1af1 with SMTP id d9443c01a7336-1f060c06f36mr39135ad.25.1715373726467; Fri, 10 May 2024 13:42:06 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240510024729.1075732-1-justin.he@arm.com> <20240510024729.1075732-3-justin.he@arm.com> In-Reply-To: From: Ian Rogers Date: Fri, 10 May 2024 13:41:55 -0700 Message-ID: Subject: Re: [PATCH 2/2] perf pmu: Fix num_events calculation To: Justin He , John Garry 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" , nd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, May 9, 2024 at 11:52=E2=80=AFPM Justin He wrote= : > > Hi, Ian > > > -----Original Message----- > > From: Ian Rogers > > Sent: Friday, May 10, 2024 2:17 PM > > 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 > > Subject: Re: [PATCH 2/2] perf pmu: Fix num_events calculation > > > > On Thu, May 9, 2024 at 7:47=E2=80=AFPM Jia He wrote= : > > > > > > When pe is NULL in the function perf_pmu__new_alias(), the total > > > number of events is added to loaded_json_aliases. However, if > > > pmu->events_table is NULL and cpu_aliases_added is false, the > > > calculation for the events number in perf_pmu__num_events() is incorr= ect. > > > > > > Then cause the error report after "perf list": > > > Unexpected event > > smmuv3_pmcg_3f062/smmuv3_pmcg_3f062/transaction// > > > > > > Fix it by adding loaded_json_aliases in the calculation under the > > > mentioned conditions. > > > > > > Test it also with "perf bench internals pmu-scan" and there is no > > > regression. > > > > > > Fixes: e6ff1eed3584 ("perf pmu: Lazily add JSON events") > > > Signed-off-by: Jia He > > > --- > > > tools/perf/util/pmu.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index > > > a1eef7b2e389..a53224e2ce7e 100644 > > > --- a/tools/perf/util/pmu.c > > > +++ b/tools/perf/util/pmu.c > > > @@ -1639,6 +1639,8 @@ size_t perf_pmu__num_events(struct perf_pmu > > *pmu) > > > nr +=3D pmu->loaded_json_aliases; > > > else if (pmu->events_table) > > > nr +=3D > > pmu_events_table__num_events(pmu->events_table, > > > pmu) - pmu->loaded_json_aliases; > > > + else > > > + nr +=3D pmu->loaded_json_aliases; > > > > Thanks for working on this! The "struct pmu_event *pe" in new_alias is = an entry > > from the json data, and "pmu->events_table" should NULL if there is no = json > > data. I believe the code is assuming that these lines aren't necessary = as it > > shouldn't be possible to load json data if the json events table doesn'= t exist for > > the PMU - if there is no json data then loaded_json_aliases should be 0= and no > > addition is necessary. I'm wondering why this case isn't true for you. > On my Armv8a N2 server, "pmu->events_table" is NULL because perf_pmu__fin= d_events_table() > return NULL. > > I also noticed that pmu->loaded_json_aliases is *not* 0. The missing addi= ng calculation will cause > perf_pmu__num_events() less than normal case and will trigger latter chec= k failure in > perf_pmus__print_pmu_events__callback(). > At last, perf list will report many lines similar as: > Unexpected event smmuv3_pmcg_3f062/smmuv3_pmcg_3f062/transaction// The issue is the sys events which currently are ARM only. Here is an lldb stack trace: ``` frame #6: 0x0000aaaaabc9b49c perf`__assert_fail(assertion=3D"pmu->events_table", file=3D"tools/perf/util/pmu.c", line=3D522, function=3D"int perf_pmu__new_alias(struct perf_pmu *, const char *, const char *, const char *, FILE *, const struct pmu_event *)") frame #7: 0x0000aaaaab41e018 perf`perf_pmu__new_alias(pmu=3D0x00007377e7e09b40, name=3D"hnf_brd_snoops_sent", desc=3D"Counts number of multicast snoops sent (not including SF back invalidation)", val=3D"eventid=3D9,type=3D5", val_fd=3D0x0000000000000000, pe=3D0x0000ffffffffde88) at pmu.c:522:3 frame #8: 0x0000aaaaab4175cc perf`pmu_add_sys_aliases_iter_fn(pe=3D0x0000ffffffffde88, table=3D0x0000aaaaac299bb0, vdata=3D0x00007377e7e09b40) at pmu.c:939:3 frame #9: 0x0000aaaaaaf6d000 perf`pmu_events_table__for_each_event_pmu(table=3D0x0000aaaaac299bb0, pmu=3D0x0000aaaaac299238, fn=3D(perf`pmu_add_sys_aliases_iter_fn at pmu.c:931), data=3D0x00007377e7e09b40) at pmu-events.c:5994:23 frame #10: 0x0000aaaaaaf6cd78 perf`pmu_events_table__for_each_event(table=3D0x0000aaaaac299bb0, pmu=3D0x0000000000000000, fn=3D(perf`pmu_add_sys_aliases_iter_fn at pmu.c:931), data=3D0x00007377e7e09b40) at pmu-events.c:6057:23 frame #11: 0x0000aaaaaaf6ec44 perf`pmu_for_each_sys_event(fn=3D(perf`pmu_add_sys_aliases_iter_fn at pmu.c:931), data=3D0x00007377e7e09b40) at pmu-events.c:6295:27 frame #12: 0x0000aaaaab41738c perf`pmu_add_sys_aliases(pmu=3D0x00007377e7e09b40) at pmu.c:955:2 frame #13: 0x0000aaaaab4179fc perf`perf_pmu__lookup(pmus=3D0x0000aaaaac500970, dirfd=3D34, name=3D"arm_cmn_0") at pmu.c:1037:2 frame #14: 0x0000aaaaab4242d0 perf`perf_pmu__find2(dirfd=3D34, name=3D"arm_cmn_0") at pmus.c:161:9 frame #15: 0x0000aaaaab421614 perf`pmu_read_sysfs(core_only=3Dfalse) at pmus.c:209:3 frame #16: 0x0000aaaaab42278c perf`perf_pmus__scan_skip_duplicates(pmu=3D0x0000000000000000) at pmus.c:297:3 frame #17: 0x0000aaaaab422078 perf`perf_pmus__print_pmu_events(print_cb=3D0x0000ffffffffec68, print_state=3D0x0000ffffffffecd0) at pmus.c:462:16 frame #18: 0x0000aaaaab425d9c perf`print_events(print_cb=3D0x0000ffffffffec68, print_state=3D0x0000ffffffffecd0) at print-events.c:409:2 frame #19: 0x0000aaaaab093ef0 perf`cmd_list(argc=3D0, argv=3D0x0000fffffffff340) at builtin-list.c:592:3 frame #20: 0x0000aaaaaaf5b490 perf`run_builtin(p=3D0x0000aaaaac4e8220, argc=3D1, argv=3D0x0000fffffffff340) at perf.c:349:11 frame #21: 0x0000aaaaaaf5a3e0 perf`handle_internal_command(argc=3D1, argv=3D0x0000fffffffff340) at perf.c:402:8 frame #22: 0x0000aaaaaaf5b1a0 perf`run_argv(argcp=3D0x0000fffffffff1c8, argv=3D0x0000fffffffff1c0) at perf.c:446:2 frame #23: 0x0000aaaaaaf59f44 perf`main(argc=3D1, argv=3D0x0000fffffffff340) at perf.c:562:3 ``` As such the fix here is incomplete. There may be both sys json events (detected by PMU/id name) and CPU json events (detected by CPUID). I'm looking into a fix. Thanks, Ian > -- > Cheers, > Justin (Jia He)