Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp838589lqo; Fri, 10 May 2024 17:55:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVdqyJaoTlnFUVms7ZBc4H8qUOmw8N5WZmNQHr8xo6lmim6c3c0peOkSuKEgk/PjdmSQyEKPrkQrveD1meOw9kzfo8B/pkSlECOAknrZQ== X-Google-Smtp-Source: AGHT+IFV3ApGkVR2/i97/Hbn+pMlAw6neBYFBetp54ae8glFgVTo9zQ9nZ9iRfErtFOeZzvvgpsK X-Received: by 2002:a05:6214:53c9:b0:6a0:c162:2a2a with SMTP id 6a1803df08f44-6a16816a5e3mr47280416d6.21.1715388952355; Fri, 10 May 2024 17:55:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715388952; cv=pass; d=google.com; s=arc-20160816; b=lRPms4LfX4V0XHd614LJq4211Y7WMZDhm/6P/6bxmzNCroXj/YrbXMuCKiEq9WXPLs 3MkuqgZrE87HQS/Ne3xuoOJAzA91JCfVTjtWj/RA2U0+1HivF+fviHNniBzvGUeU83W4 wdRtKCWh9gZdYTAyciRWjk0wTH/ARXPPgMS7g9d6P41O6Ku+3zB3Uf3EuXi8wqWfmZoE rUWmR0hWn8wiEaTJTVm+2/fLa0Hh89xKsrKlJijOVPxl0J1nnb1lI/aQcsKL2hHmJrLD e0AymMAwwpt5hjufut8jIzgfz7RWcP8HBscTkPaoeoHa7HgoCskMWevm8wK0n1hNgo+s TsXg== 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=IpkRXiISMgxYRyuOPXk0L2m29umqlNK9saYU4NgbZio=; fh=AJZBNtgjYqX8P+fuoLU50bx9sJX+9WCj06oCpgs5Fvg=; b=kpjJXLw+KIkF6Nrt0Rc19QXZ//62wOV2i74D9UTcxCzRRwN+IqzhhRdH0torLnmc0H dyUDbHwYb5MOeM8zONvacucduM7YPZQUHvXC8MmcLrJ+Z8ZuuFqhEaMVPSfPgIwii4W4 a2UKpfJ66JD70gu+Dx7+An66ucTRGbhEh/89dNWpUjZOgQWpNYiEgcFOJD5KWlaY4Pi7 4oGYYgKgIvEo1xffYPUV7KdwEuyZRzhJ59+9FFbDe+y3IuGYon69qYDKjwc8jnJVb0Tl MMgNCbVhP1HbNGU44ln480Q17HCYidD/I2oxUVhI+Y/qpVoK2S/AJFyWkHFbPmvzoUZi r+3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ORbM1vOT; 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-176348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176348-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 6a1803df08f44-6a15f29a943si49317426d6.271.2024.05.10.17.55.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 17:55:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176348-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=ORbM1vOT; 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-176348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176348-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 0A2281C21430 for ; Sat, 11 May 2024 00:55:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E8BC12B8B; Sat, 11 May 2024 00:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ORbM1vOT" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 CE4195677C for ; Sat, 11 May 2024 00:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715388645; cv=none; b=kKbbCJO18DQ/Qsg5IXaCWbiifdHKUEMgayGQVtmV5xK1N/aRdaXN5i0RPrdtjOnZiYLw4c1AR/qDhibYuotZza3RtdSrlRjrK6TEPzfYdo7nXfWZlzfjTDYbGxq4NA6fYJ8oV6YAO0wHgCvumXXjdOzwOu/tXAOreKiqZOLfG20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715388645; c=relaxed/simple; bh=29H2ZkSMqUh1NQ71nR4QuJZPnSHhxyUdN/R3ZAzv+1o=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=hMSuzydAjk0LbMnuCgD17t9/3y6hggk9OkeNhkAqhbl3A2j8vPp6069h4k19ghUP5dPmawccIqV6TWaz5+icMlAF7YBxjwT7Fhi7Qk34QBYNeNnNXvFcJAnaNerCzY4P8bQyetSudKgC5TwJx4DVgz3WZVUvjJETNKIErPQRSFk= 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=ORbM1vOT; arc=none smtp.client-ip=209.85.214.175 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-f175.google.com with SMTP id d9443c01a7336-1ee0ccf9c2fso63215ad.0 for ; Fri, 10 May 2024 17:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715388643; x=1715993443; 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=IpkRXiISMgxYRyuOPXk0L2m29umqlNK9saYU4NgbZio=; b=ORbM1vOTcuBEwUq19USCMObHIovAN0Q1ZSiXVGHEHcmMgllH3vczMCgVCRS2AT1S1r wKg5n4zADa9Sr6PAzTdWU7rrxUKKjQ7qEeqdqhQyJPDjwO+zs+A8mWO1B0D2+d9SNWf1 U3pbN+gfBBu9YQBLlDJ112V0Hv74dTWwaTjYJ45chEQgi+hRb+rhrdcNAzwqjAYIFIhZ Xq1qzFGer4tRG4IJKLVVJ7JTSKbjgJ9lllEaIRVRyxOnv4D4boSkj7An4YO2tVWyzCtG guKjoQbFlLBr/Y1zbvnwAT/I5RvminqsZah7hNSddTz4hsSBpDIULSrAPb5azrYad8/G AHmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715388643; x=1715993443; 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=IpkRXiISMgxYRyuOPXk0L2m29umqlNK9saYU4NgbZio=; b=MaPKpVxTb2xxiJcAj34g+Kdw4oknPw8y7MB31qyeIY2Fk20nCLZWacL5msctfcZtAg Hxt6t2djX18L3rwWSCGSMfDDYnZakQ/Lx229wOgKJPdiKD0orAigLLvvkrWVIe+LeDNk 3NuStPzBHaKMFZPRJApkbtaNbQYSK7045QekrLhvlinkgprwpV+8b2lwD7kLPuNpZJJX EDl3C95/sOjgB6UjSFQmHL3oPX/VGhqtuk72E6mYmXqHUOV/dO83DOJeB/qkJbGs4r1S fwzHqpRtu383pXUJHOivi9FL14agtkHXxmNVYGUGMtr/s5A+39JdyOcUlLRLGUkbTfHg D/AQ== X-Forwarded-Encrypted: i=1; AJvYcCXMX/G+7kfNrvQ8yqr0fpuShBBTvIi02cZPu9sH4PXPkuYd34zKXLgF03KPyz0bgS7GMZ6b05RNH4lQUE3wsY1DM3FZl7sicOfIW4tr X-Gm-Message-State: AOJu0YxHCzL9euGTjgZ3NlFMpmBjopZsQhF05zRKB2EvHRiwUcjFtpUr KWtdusnIgTNSCValav01NZucOLbzK1MuOni1WTz1hPr9NPIdrWTt4fyMgD5QA5OwJVNmGnlyHYA J+tzq9jXX+dcQPfvlZbIPiAVC4QgORiwh9P0F X-Received: by 2002:a17:903:124b:b0:1e8:6551:e83c with SMTP id d9443c01a7336-1f060bba9c6mr501885ad.25.1715388642768; Fri, 10 May 2024 17:50:42 -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 17:50:29 -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 Fri, May 10, 2024 at 1:41=E2=80=AFPM Ian Rogers wro= te: > > On Thu, May 9, 2024 at 11:52=E2=80=AFPM Justin He wro= te: > > > > 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 wro= te: > > > > > > > > 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 inco= rrect. > > > > > > > > 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 i= s an entry > > > from the json data, and "pmu->events_table" should NULL if there is n= o json > > > data. I believe the code is assuming that these lines aren't necessar= y as it > > > shouldn't be possible to load json data if the json events table does= n'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__f= ind_events_table() > > return NULL. > > > > I also noticed that pmu->loaded_json_aliases is *not* 0. The missing ad= ding calculation will cause > > perf_pmu__num_events() less than normal case and will trigger latter ch= eck 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. Patch sent: https://lore.kernel.org/lkml/20240511003601.2666907-1-irogers@google.com/ Thanks, Ian > Thanks, > Ian > > > -- > > Cheers, > > Justin (Jia He)