Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1318955lqb; Sat, 25 May 2024 16:34:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGzXR470t+JaO5SmKcmSBlgKCg09xNflbvmUFUzg5JYwJwXe++eqgHYWxnATdGW1jKucqkoaHQluos/Gwi8/ahnFkpw3ghCbYeeCMaHA== X-Google-Smtp-Source: AGHT+IFgA5hEMSEtXBKGJ0IOOgCj1LgZAhSYjViV1JsQHfPfTNvjJIIYK6I2OJGtDMXqmzY0Hwd+ X-Received: by 2002:a05:6a20:9155:b0:1b1:e35f:3efc with SMTP id adf61e73a8af0-1b212d4aed7mr6834271637.29.1716680080729; Sat, 25 May 2024 16:34:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716680080; cv=pass; d=google.com; s=arc-20160816; b=1ENw32VkDz4QRjo1L7oK1L9RX2po4FtYmZwVfGLOADHp2hG3w9aP9859RgCAgPar8b vkduQFY/1XsxEPMcCz84KE9SoiA518gfcJTVFGo6JNpzwxlQtp/4sIoxBj6+F6KGZumr qL0gDBV2ts4P5GQtEVbYt6ONd54/i17MlVVMrds5A4DYEkkZ3B0t49qSesRYVFAUvxRb 7xWpaKOvuzQyOScqJbOqCNF68v0GDgQhgpQIakt6Tqxs+uZDykL5UwwRpUL6ayWnEZrU O4W2Q2ttCw7J2OUZkc/eistZYS1Jqkq2ScTDFlfxmBPs43DJybIhEnfobsat+El7CWRi TJuQ== 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=VyDDv123oM7gFPBqZNEnU0l4e5csQD/v1tgVMBREQS8=; fh=nSGNC6XVXNzu9rnfEHsf6rq7z0qFalxe7cC/3fFXhGY=; b=ncYie41PB3U7qmzjXK/OajucxZFUlOnwpncFdgvWxnP17i7oYnahrzng+YJcNCn9lE qQUaq6tVl66T11Gazf4PHyLpb+lhbZSpin+2SJ8UPv+h7RS8j0ChZc2ygzdamTUFEK/1 B9po0QXkQhX7c923bDXUnH0IaB5OWuBNMxvBuMHFJQPYVH9SvL2WDhuOMIyBCdOeNf9a q4mJ6iJTV8B0foEarlzNxA50XhWvj6j+0bPCSVc2tc9HFyOmEELKZIVHGWFD0MJmiGsJ 2BOQzHOY6eZsRUvcIgpH4B8kTeVLCBGbqnZZ9ak+9EARbNjGeauFKfkt32cOqNNT22ap o/zQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hVTkRfwf; 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-189579-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189579-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 98e67ed59e1d1-2bdd9ed938csi1634097a91.22.2024.05.25.16.34.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 16:34:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189579-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=hVTkRfwf; 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-189579-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189579-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 16802B21102 for ; Sat, 25 May 2024 23:34:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3093A2FE29; Sat, 25 May 2024 23:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hVTkRfwf" Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (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 542D820DE7 for ; Sat, 25 May 2024 23:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716680069; cv=none; b=EA28FqyI8rMBu1n+Qg5abTTl1zyb76+ZPtIgt3AIKJh1mzOt7IR0ongjAaICl3k18zXEr1uYcLQb9bhQ23WcHDhmEG3Dqvt2Fi5RWoiGf0HAXOA/tPMtHCZc3gF1Wyc34/HkbK5RaOGR42q5pxNhnlcN1jFZi+POQ4kc9eYTXDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716680069; c=relaxed/simple; bh=uUzfAIJAN8UOtttIYoZiBPiN+mS3jw1s66mcLXazIvM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=GO7/ZjUSS9jKSJjWhmsh00o6RVbTfMF0lfV7vNJQGg+SLJq0BdQwd/HzfZ4rdjHirq622ZgFWdPnVaS2S8Awt0YMZvmuWpJ/0bgyOmdEPxeFa6gknLiHl0Ia+ZCtnmSNS+5jAnpg3qLjmnZ9YUYrZr3kYYUe4CF+EgAdGTefApE= 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=hVTkRfwf; arc=none smtp.client-ip=209.85.166.170 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-f170.google.com with SMTP id e9e14a558f8ab-36c6056f7bdso163945ab.0 for ; Sat, 25 May 2024 16:34:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716680066; x=1717284866; 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=VyDDv123oM7gFPBqZNEnU0l4e5csQD/v1tgVMBREQS8=; b=hVTkRfwfauw92SOS29Dqr0TUajj4TaI9BKrmERxWzvOT9Q9kiVwB/yLUjmDq/vLb0m MOoulP6dc5+D3kdZYEe8zUJ0sYxTu/dDYtKX32Kf//ifBOSjnWY8bWnkqXPXDURFdc8p doG5vZh+wslMAIyd3jQSBL4g1+jbKlnKThjq3ptXtxHNfdYqxhKpGlOHgac6dOvpEpAW woCM1BISCO82obdBZaAdg+6qVPJudwv5Fp/xbvjVexQU1sYK7FVSAa9K9MBxaVVA+Jw0 k7WEMuCH6X4bRt14NAlL1itab0yDiegqLMjnp21lzNlFhs0Mnrmhv2XgLEt6cTMx/MVE QsqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716680066; x=1717284866; 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=VyDDv123oM7gFPBqZNEnU0l4e5csQD/v1tgVMBREQS8=; b=TvJcnbRc0kYu2ZS9NXpCzzXogK3JE25qAJwqjRtXxMN0uX6rzcKHMXkZOYHgBh/AlI tB8Z+QTvdO+Rs9CnUZOmK7kp/gslE2K002OCha4x7jM30l9cg6bm88k88ztFcrVwuXPc X0bsMexPeiAtjDf6fEC7iqfRTbJPehoV4hjiKq7B7XdenWmJ2BIdPPTNASgG7pbRYmSQ A7jzm+vkqz4rOrFPMbmydddsV0zAMIyrnWAk9Dv0cw7enNEfKQWxEe96v4i+dPOWQ3pX RJuVQf/eI5wwwPcFgcPp8S6yZ6J4ErVumhF4ZgyGkog3ibE7eX66xKHaz9oIggZjfyCu lw4A== X-Forwarded-Encrypted: i=1; AJvYcCWhUuwUY9+jF9kSy1UDqxKN4ogoyWa3Qf0hb2Z/YP4il4bYX5UR0zVup/jKb6HH+g/Yvn8SAf4KI9M/tl0cEdZ/PP6vVtApV8xc4s8X X-Gm-Message-State: AOJu0YxCmu6DPND6DwtCksQOUE+yYtKZSVUx3v1/TPq5RAIJarMpL14Q XNvxUBzzvoVxaQmSALHh5EMztAxbzfQmVFPkjYADPyVa5rRX5JEfEVfF5kydfPxAqYprCc3G3WW FbZ/5L1cwebZyknwq3VE3KM83FbnmhESvHyIe X-Received: by 2002:a92:d38a:0:b0:36c:3046:a6ef with SMTP id e9e14a558f8ab-3738a706885mr2292555ab.12.1716680066259; Sat, 25 May 2024 16:34:26 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240521192614.3937942-1-acme@kernel.org> In-Reply-To: From: Ian Rogers Date: Sat, 25 May 2024 16:34:14 -0700 Message-ID: Subject: Re: [GIT PULL] perf tools changes for v6.10 To: Linus Torvalds Cc: Namhyung Kim , Arnaldo Carvalho de Melo , Leo Yan , Mark Rutland , Ingo Molnar , Thomas Gleixner , Jiri Olsa , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Anne Macedo , Bhaskar Chowdhury , Ethan Adams , James Clark , Kan Liang , Thomas Richter , Tycho Andersen , Yang Jihong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, May 25, 2024 at 10:22=E2=80=AFAM Linus Torvalds wrote: > > On Sat, 25 May 2024 at 00:38, Namhyung Kim wrote: > > > > Yep, so I'm curious what makes it fail. IIUC the commit in question > > would convert "cycles" event to "${whatever_pmu}/cycles/" if the pmu > > has "events/cycles" alias in sysfs or in JSON. But it should work afte= r > > that too. :( > > Well, having looked at it some more, I have the main CPU PMU: > > /sys/bus/event_source/devices/armv8_pmuv3_0/ > > which has a 'cpu_cycles' event, and the cpumask covers all the 128 > cores in this thing. > > That's the thing the regular profiling *should* use: > > $ ls events/ > br_mis_pred l1d_cache_wb l3d_cache_allocate > br_mis_pred_retired l1d_tlb l3d_cache_refill > br_pred l1d_tlb_refill l3d_cache_wb > br_retired l1i_cache mem_access > bus_access l1i_cache_refill memory_error > bus_cycles l1i_tlb sample_collision > cid_write_retired l1i_tlb_refill sample_feed > cpu_cycles l2d_cache sample_filtrate > exc_return l2d_cache_allocate sample_pop > exc_taken l2d_cache_refill stall_backend > inst_retired l2d_cache_wb stall_frontend > inst_spec l2d_tlb ttbr_write_retired > l1d_cache l2d_tlb_refill > l1d_cache_refill l3d_cache > > But the thing that seems to have confused the new parsing is that this > machine _also_ has > > /sys/bus/event_source/devices/arm_dsu_{0..63}/ > > which all have a 'cycles' event: > > $ ls events/ > bus_access cycles l3d_cache_allocate l3d_cache_wb > bus_cycles l3d_cache l3d_cache_refill memory_error > > but these things are basically some "each pair of cpus has some bridge > to the L3", which is why this 128-core machine has 64 of them. So each > of those have something like this: > > $ cat cpumask > 40 > $ cat associated_cpus > 40-41 > > I did not look any closer at what the 'cycles' there can actually > count, but clearly they can't be used for recording. And even if they > can, they shouldn't for the default "cycles". So this is now the behavior with the patch I sent. > > It seems my system doesn't have the alias (both in x86_64 and arm64) > > at least in sysfs. I think that's why I don't see the failure and mayb= e > > there's a specific hardware issue - like a M1 macbook issue? IIRC it > > required the exclude_guest bit to be set, but I think we handled it alr= eady > > so this must be a different issue. > > This is my new Ampere system, which has basically replaced the M2 > Macbook Air as my arm64 test platform, since it builds the kernel a > whole lot faster. That's what 128 cores will do... > > Ian's patch at > > https://lore.kernel.org/lkml/20240525152927.665498-1-irogers@google.c= om/ > > makes things work for me again, but I get the feeling that the JSON > parsing is too fragile. It should have noticed that the 'cycles' event > it found wasn't useful for profiling, and gone on to the next one, > instead of just giving an incomprehensible error message. > > I think the real problem was that the JSON parsing code blindly just > looked for "cycles". I don't think JSON really means anything here. We use JSON as a way to import tables of events. We want to map an event name to a config value, we could do it in lots of different ways. There is a difference between: - legacy events: hard coded event numbers for certain typically CPU events, although there are L3 cache events in there, - sysfs: events advertised by the PMU driver in sysfs, - events built into the tool, imported from json files. The first problem that happened was BIG.little. ARM did nothing to fix the perf APIs for BIG.little and Intel fixed things up when they did hybrid. What does it mean to open a legacy event on a process in a BIG.little CPU when the process may be scheduled onto either BIG or little cores? ARM's non-solution was that you'd profile based on which PMU driver registered first and not profile on the other - you would be profiling on some fraction of your CPUs but not all. While Intel added proper hybrid/BIG.little support they did so by essentially forking every aspect of the perf tool to have a "hybrid" version. I put a stop to this in the metrics code and by doing so ended up taking on responsibility for cleaning up the mess Intel had been creating. This led to the event parser being able to parse "//" for example in "cpu_core/cycles/" and "cpu_atom/cycles/" and encode the legacy event. This caused issues on ARM, especially Apple ones - maybe Apple should be asked to support their PMU? Previously their PMU would advertise events like cycles and the sysfs encoding would be used as there was no notion of using the legacy encoding. Now the legacy encoding was used and for some reason we don't maintain legacy mappings of events for PMUs on Apple CPUs. After being politely shouted at, and to my surprise Intel agreeing, we made it so sysfs or events built into the tool take priority over legacy events if the PMU is specified. This wasn't a small change as every test expectation needed updating for this. We still have some broken test expectations. So we had a case where legacy events weren't the priority if the PMU was specified but when no PMU was specified they had priority. This was frankly weird and so the patch you bisected to fixed this and was also a behavior RISC-V had asked for. There was even some discussion on this subject at LPC 2023. Is everything fixed? Nope. It is still the case on ARM that we don't profile on all CPUs for perf stat. This is because when no event is specified hand crafted perf_event_attr are passed to perf_event_open and these perf_event_attr need to open multiple for a BIG.little/hybrid system: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/too= ls/perf/builtin-stat.c#n1942 I wrote a fix for this: https://lore.kernel.org/lkml/20240510053705.2462258-4-irogers@google.com/ Unreviewed/unmerged and frankly I think ARM should be in the driving seat for reviewing it as it is trying to fix their CPUs. > The only thing that seems to make Ian's new > evlist__add_default_events() special is that it uses > "perf_pmus__scan_core()" for that cycles finding, which in turn then > uses only the *core* PMU's. > > It feels to me like the "parse the JSON info" is just too fragile, > picks the wrong events, and Ian's "add defaults" just works around the > weakness. So I think the parsing is now robust/consistent but that doesn't mean the behavior matches your expectations. I say robust as when any event, regardless of whether it happens to alias the few hundred legacy names, will parse. Previous parsing meant events advertised by AMD's PMU, like branch-brs, would return parse errors as "branch" and "brs" looked like components of a legacy event name. Consistent in that, regardless of event name, we will try the same process to find the event. I don't understand why you think JSON comes into this. Is it because I've sent patches with JSON encoding events and metrics in? In the case of AMD's "branch-brs" and the "cycles" event, the event has been advertised via sysfs and not from data in JSON tables. > But whatever. With his patch, at least it works for me. You followed up in: https://lore.kernel.org/lkml/CAHk-=3Dwi5Ri=3DyR2jBVk-4HzTzpoAWOgstr1LEvg_-O= XtJvXXJOA@mail.gmail.com/ with: > So no. That still needs to be fixed, or the whole "prefer sysfs/JSON > by default" needs to be reverted. So I think we still need to figure out what: $ perf -e ... where doesn't specify a PMU means. I'll try to enumerate the option= s: 1) the 6.9 behavior where will be searched for on every PMU and each PMU that has that event will have it opened. This can lead to failures depending on what is going to do. If is a legacy event name then it will be opened only on core PMUs. 2) the current perf-tools branch behavior where is searched for on every PMU regardless of it being a legacy or non-legacy event name. 3) (2) but we change drivers to not advertise events where the name conflicts with a legacy event name. 4) if the PMU isn't specified with then we only search core PMUs (e.g. armv8_pmuv3_0, cpu, cpu_core, cpu_atom) 5) we parse all events as with (2) but depending on can choose to ignore perf_event_open failing. I'll try to rustle up a patch for (5), I have no way to test it. I expect it will make somebody somewhere unhappy, apologies in advance. Thanks, Ian > Linus