Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp759088rwr; Fri, 5 May 2023 04:48:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5EGEhFqPkfNDjG+jA4VIYjPbt0VTbaRdQ3dqgGOT1Vj4ctXUGcqT2DWpLFJXjc1VWUXv3A X-Received: by 2002:a17:902:d4cb:b0:1a6:d763:3736 with SMTP id o11-20020a170902d4cb00b001a6d7633736mr1278789plg.58.1683287299479; Fri, 05 May 2023 04:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683287299; cv=none; d=google.com; s=arc-20160816; b=wf/kAefouwbK6nY3aMda8lZ94jxBpTksT1coCCTCf6owPmGtCtHyEU3yaAWP7W3FXi x+MRYTxuDiLqFif9BJ+SiPLK8Xqr7yMZ7QmI4jS64uWmFrVukafW3fecIJog6MIa2rj8 8xRgyr7rB+2yNdSeiBMInhpS2L7QevKAkfnDc9SW4+yYWhH87K/FrtkNem71H2ggc9fA NRjBmyWDadGKk7JgL6KO41JvXWejXGJD4M72PxbUm+FGt0KF0cq7J8ypw/tBEzzunM/F imgjWEOD6m1pkchycRAateH29IvolbPhCIBIFoLcLx1MhZmOTzG1b0O+vAA8VFDV38NV RvHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=jwA4RNzHLoe51BKJcNUYfJNJRyNu9DKsCjgDMwmTA7A=; b=SuCnuWBxuP3fMj+iDFratsx2+jl+zYuhjFN+AiwjbIl5RowDyIJ1BdNb4Wkac09LXx fCEmiJ3aWFuYP8OvwfaMtjtWqXie4q8MQAkOVgO1Z9IwGcP90zgljvdlZ5EWV1IDlGBr +Ry+HHM/Rb6KdT/VL4/VgjUoe004b47/vqPogCNPJtGsjXSHhY4xi/hTNU/ooSCWhnf9 fd8yc1cccLvF9m4q7CQ4xCkHhyg7oeVKKekKZGPuuu7g6cJlc9CPBTkfnWXa+Tb1MU2m NPy7GKtGuXW7yV1FM5JnBCNEdi4Rye2IxjLz0ag2Tm1No9fWeBzWSO7lOl/qQess7mg2 RS0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="WF62c/j6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020a170902848800b001ab03c66823si1402680plo.141.2023.05.05.04.48.03; Fri, 05 May 2023 04:48:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="WF62c/j6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231796AbjEELmT (ORCPT + 99 others); Fri, 5 May 2023 07:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbjEELmR (ORCPT ); Fri, 5 May 2023 07:42:17 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3DB411607; Fri, 5 May 2023 04:42:15 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f178da21b5so11393215e9.3; Fri, 05 May 2023 04:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683286934; x=1685878934; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=jwA4RNzHLoe51BKJcNUYfJNJRyNu9DKsCjgDMwmTA7A=; b=WF62c/j6RiITYW667aRT9w0LZy3zB+wgpx/WJ54+TRNLcLn4nTSikrpYai6OPrVGkz IhgIvNnPGGl2SqlqbS+XLVcmzlBBB3OIewdGD/Mc7jw1zvkSCZS0gO6g4I18UKjJpoj1 FO9voODgeBvwtJghqcm99OfSx20ZYAYuzHd2L/pDpWIFnzEdDA3BDtg027bp6yGvd9Dy qmFj4Wp7HLufi3CpLf5X1VBmgRP2xFU6Kl41WtHiVSFzxiRuFE36kp27VfhPHPstuWxI 64+hwtMFhwaAojMK5K/YmDlC2xrKZsqTNtkbqts5wT+hjaUtZQ2H9I3Ym5HgEfVBlr30 j7CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683286934; x=1685878934; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jwA4RNzHLoe51BKJcNUYfJNJRyNu9DKsCjgDMwmTA7A=; b=e/mr5PElj8n0EMnDDEUQ19+O3x5Zdr3t8VmUh93yvsoaMFdsMogYYy15fPAxd1T3PW yU4qDoIOoD2TIJktpgZzzvH6rMrGak1VW2snljc+09rvjNY64xlRx0XVDo/V+pDC039y VbfULTcewhhBnp9yCtoHNjj5bqvT28oB2tRVN3i9J/4EZqfm9JTvWsdBRuyqxhQsFBpe Y1g1iJWACcBPP/iTWOxSh1uSMWbCmTDXpy2g7QoTMPv7tZfPZ1YFS4AacUAI0RUmJMxI geMOioyVM3+9fGX06c3YjAYHO7YQIzvtQwt3iYuaF3QgBDLizmOVwSdP5rUfi+3pkO60 iZng== X-Gm-Message-State: AC+VfDxcU7eFgZrlqZH+5Ri0VIHSVXYNdA+y78uxgbALkzaBy2uJemDW HR9wKLnYWYfucxF/GroU85+2U0hCPI6OCg== X-Received: by 2002:a7b:c8d9:0:b0:3f1:78a7:6bd2 with SMTP id f25-20020a7bc8d9000000b003f178a76bd2mr930562wml.27.1683286934055; Fri, 05 May 2023 04:42:14 -0700 (PDT) Received: from krava (2001-1ae9-1c2-4c00-726e-c10f-8833-ff22.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:726e:c10f:8833:ff22]) by smtp.gmail.com with ESMTPSA id 20-20020a05600c029400b003f16932fe7dsm7803364wmk.38.2023.05.05.04.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 04:42:13 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Fri, 5 May 2023 13:42:10 +0200 To: Ian Rogers Cc: Jiri Olsa , Arnaldo Carvalho de Melo , Andrii Nakryiko , Namhyung Kim , Linus Torvalds , Song Liu , Andrii Nakryiko , Ingo Molnar , Thomas Gleixner , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Adrian Hunter , Changbin Du , Hao Luo , James Clark , Kan Liang , Roman Lozko , Stephane Eranian , Thomas Richter , Arnaldo Carvalho de Melo , bpf Subject: Re: BPF skels in perf .Re: [GIT PULL] perf tools changes for v6.4 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 05, 2023 at 11:39:19AM +0200, Jiri Olsa wrote: > On Thu, May 04, 2023 at 04:19:47PM -0700, Ian Rogers wrote: > > On Thu, May 4, 2023 at 4:03 PM Jiri Olsa wrote: > > > > > > On Thu, May 04, 2023 at 03:03:42PM -0700, Ian Rogers wrote: > > > > On Thu, May 4, 2023 at 2:48 PM Arnaldo Carvalho de Melo wrote: > > > > > > > > > > Em Thu, May 04, 2023 at 04:07:29PM -0300, Arnaldo Carvalho de Melo escreveu: > > > > > > Em Thu, May 04, 2023 at 11:50:07AM -0700, Andrii Nakryiko escreveu: > > > > > > > On Thu, May 4, 2023 at 10:52 AM Arnaldo Carvalho de Melo wrote: > > > > > > > > Andrii, can you add some more information about the usage of vmlinux.h > > > > > > > > instead of using kernel headers? > > > > > > > > > > > > > I'll just say that vmlinux.h is not a hard requirement to build BPF > > > > > > > programs, it's more a convenience allowing easy access to definitions > > > > > > > of both UAPI and kernel-internal structures for tracing needs and > > > > > > > marking them relocatable using BPF CO-RE machinery. Lots of real-world > > > > > > > applications just check-in pregenerated vmlinux.h to avoid build-time > > > > > > > dependency on up-to-date host kernel and such. > > > > > > > > > > > > > If vmlinux.h generation and usage is causing issues, though, given > > > > > > > that perf's BPF programs don't seem to be using many different kernel > > > > > > > types, it might be a better option to just use UAPI headers for public > > > > > > > kernel type definitions, and just define CO-RE-relocatable minimal > > > > > > > definitions locally in perf's BPF code for the other types necessary. > > > > > > > E.g., if perf needs only pid and tgid from task_struct, this would > > > > > > > suffice: > > > > > > > > > > > > > struct task_struct { > > > > > > > int pid; > > > > > > > int tgid; > > > > > > > } __attribute__((preserve_access_index)); > > > > > > > > > > > > Yeah, that seems like a way better approach, no vmlinux involved, libbpf > > > > > > CO-RE notices that task_struct changed from this two integers version > > > > > > (of course) and does the relocation to where it is in the running kernel > > > > > > by using /sys/kernel/btf/vmlinux. > > > > > > > > > > Doing it for one of the skels, build tested, runtime untested, but not > > > > > using any vmlinux, BTF to help, not that bad, more verbose, but at least > > > > > we state what are the fields we actually use, have those attribute > > > > > documenting that those offsets will be recorded for future use, etc. > > > > > > > > > > Namhyung, can you please check that this works? > > > > > > > > > > Thanks, > > > > > > > > > > - Arnaldo > > > > > > > > > > diff --git a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > > > > > index 6a438e0102c5a2cb..f376d162549ebd74 100644 > > > > > --- a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > > > > > +++ b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > > > > > @@ -1,11 +1,40 @@ > > > > > // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) > > > > > // Copyright (c) 2021 Facebook > > > > > // Copyright (c) 2021 Google > > > > > -#include "vmlinux.h" > > > > > +#include > > > > > +#include > > > > > > > > Compared to vmlinux.h here be dragons. It is easy to start dragging in > > > > all of libc and that may not work due to missing #ifdefs, etc.. Could > > > > we check in a vmlinux.h like libbpf-tools does? > > > > https://github.com/iovisor/bcc/tree/master/libbpf-tools#vmlinuxh-generation > > > > https://github.com/iovisor/bcc/tree/master/libbpf-tools/arm64 > > > > > > > > This would also remove some of the errors that could be introduced by > > > > copy+pasting enums, etc. and also highlight issues with things being > > > > renamed as build time rather than runtime failures. > > > > > > we already have to deal with that, right? doing checks on fields in > > > structs like mm_struct___old > > > > We do, but the way I detected the problems in the first place was by > > building against older kernels. Now the build will always succeed but > > fail at runtime. > > > > > > Could this be some shared resource for the different linux tools > > > > projects using a vmlinux.h? e.g. tools/lib/vmlinuxh with an > > > > install_headers target that builds a vmlinux.h. > > > > > > I tried to do the minimal header and it's not too big, > > > I pushed it in here: > > > https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git/log/?h=perf/vmlinux_h > > > > > > compile tested so far > > > > > > jirka > > > > Cool, could we just call it vmlinux.h rather than perf-defs.h? > > right, it also makes the change smaller > > > > > I notice cgroup_subsys_id is in there which is called out in Andrii's > > CO-RE guide/blog: > > https://nakryiko.com/posts/bpf-core-reference-guide/#relocatable-enums > > perhaps we can do something with names/types to make sure a helper is > > being used for these enum values. both bperf_cgroup and off_cpu programs use bpf_core_enum_value, so we should be fine jirka