Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp188247rwr; Thu, 4 May 2023 17:12:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7yEnJq6cY7ofGWufxJR3iBGARNQ8MHvHlwhm8PlkNastrsR58WkHEbOdvFLwEHMd2yA87Q X-Received: by 2002:a17:902:b40c:b0:1aa:f0a7:933 with SMTP id x12-20020a170902b40c00b001aaf0a70933mr5796897plr.25.1683245528078; Thu, 04 May 2023 17:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683245528; cv=none; d=google.com; s=arc-20160816; b=oXvgmqK2lQ6MqCyuloMv6LoquCScx7hMQGBG6EkYhXzkLaKZGYztm3LcG7r4U1aWuz ycGIC+jnv0zTlbU20usYvo+EJRqWuzLCKYGXN8Uj7T2T37vx4QmSc9O5g54vytfiZC07 pCyAjt9zlrjGHOBfBV/nUFHxIZJVF/IIpX7vVjUKLQK5qL0HhZZLfOUMD5qMLNEjFrq/ ziMdR1R1Se/Ba/8yMEEgtr1LK0O56+3TWPqpOTJTfregXvNkQq9LYdGCGG/nvwAVLFKa ShuceJRP3UsfxEx4KYzzxzEcdLxuMi8j5W50DAHvIZuHj6BxNuks3gWeEtiK2bvFEGkR FZmg== 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=yWOua6diagEP9w5UDlQh2ycV9iT1GzUYH6J+nVD3eqI=; b=L512MODKN9VLxs8C3V4RNy3yb04zJpcxNjPMT06LAIIlZaHcWrP5U8/VXrzwFdvI3a ajbDiKNogJ+jrAw0EUkNNga26JfFViSr5DzDcnpJGsIy/j1L4bc3i7lfiJS9+8xPjDoh m1VzX/1JCq5Yysu78p5IEEk87wSK8IgxFyUt0l5pWPOk1LedxQGjMqjHRSIm3Kc0+Mih ingQ8yZM7DRnOCzHkytq6rs0Zu5ISCIxXTxSEiBrxwjtSWZVYSZ5JGWtLdJ+xeBQ6eDW ZAkoz7gtCDRudQrugwuZjpXODIwRV8ERHHUB3adgQ72933jOd/c01u48QCEx3JzW4213 r9KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JOAqTnfq; 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 g14-20020a1709029f8e00b0019c33978781si272752plq.283.2023.05.04.17.11.47; Thu, 04 May 2023 17:12:08 -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=JOAqTnfq; 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 S229638AbjEDXDV (ORCPT + 99 others); Thu, 4 May 2023 19:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjEDXDU (ORCPT ); Thu, 4 May 2023 19:03:20 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5594111D80; Thu, 4 May 2023 16:03:18 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-50bd87539c2so1786665a12.0; Thu, 04 May 2023 16:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683241397; x=1685833397; 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=yWOua6diagEP9w5UDlQh2ycV9iT1GzUYH6J+nVD3eqI=; b=JOAqTnfq2v2NoKHBjFk5s3WofNsDwxh5HmOdKEE+W1tN6tefO9iZvJmDvJU5wgniar 2kg2d/wPux24xedU19v/X1Hl1YbFDokk0hgcMeD5lzSva0Q+Z9k2SaFNgwmf9MThF6dd wujDiEPmjdLLf3pCexeDDNamwe1iVonEqvOxx30zdLZL63BQsFnyjI9MRCgsp65N22gJ IxqSGE1/6mGHHuYGrXd31y8nMvfWg7BYE7d6LuRIMNWGuz3FMaxlUInXjI2uiamuenDs 93WlqBfO+mSluSWlC+er610/cQcfDs/U6HJSY8LAR3yhwH9PkMavKsdER1gguoO/79G3 xQnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683241397; x=1685833397; 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=yWOua6diagEP9w5UDlQh2ycV9iT1GzUYH6J+nVD3eqI=; b=CLaxHLfcS7B6W39NeFlUcg2VMsJbpaDLuOqHGNNE93+rVwt2ogqYdfaOKvk0cyQe3f x5HwUXuUjbJqV88221gnEg1y5gc9qEIuBiKT4U9dx8nrBuDBbQKv8fBejlTWGQYohVGp KdM7qSmJd/EApwFGKmdKVhECfnvX2dPzHio0UdB08ZI9XGIY7lGstCaNuDN0ch7xFlHM lh1j/R5+tcS8pz7nFZKioeWgGb0cSFQhub5tZqMcQ4vExn8MKoYAci+NpkK3uY9od6hg k0f2ND3c/JsERYuPaFnjBS20BQuD7bhiHhxU8qxO9N8ZIxqNgRc3zutW75nV7GFBqwpy YjLA== X-Gm-Message-State: AC+VfDymeCJ9hqYgMkTdZAoOVNKE6lNxXRcGBX3jMpsJLn9f8Biq2V1B GVfcMUEoCcJGxFNfuOE5LtU= X-Received: by 2002:a17:907:98a:b0:94b:d57e:9d4b with SMTP id bf10-20020a170907098a00b0094bd57e9d4bmr382506ejc.2.1683241396599; Thu, 04 May 2023 16:03:16 -0700 (PDT) Received: from krava ([83.240.61.110]) by smtp.gmail.com with ESMTPSA id bj6-20020a170906b04600b0096595cc0810sm139867ejb.72.2023.05.04.16.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:03:16 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Fri, 5 May 2023 01:03:14 +0200 To: Ian Rogers Cc: 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: <20230503211801.897735-1-acme@kernel.org> 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 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 > 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