Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp183112rwr; Thu, 4 May 2023 17:07:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Hgm47uO1K0XQ0x9+zt0z/akxUk6juJ0v592I6AfsgnAVUidlkRrlFodfly3p8Z4srSXhF X-Received: by 2002:a17:90a:7064:b0:24b:fd8d:536b with SMTP id f91-20020a17090a706400b0024bfd8d536bmr3726055pjk.29.1683245232518; Thu, 04 May 2023 17:07:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683245232; cv=none; d=google.com; s=arc-20160816; b=dZdo3O+URprUG29M0Fv0DWpmpoVHnV3t51oDD9IHq1fApFOQ6IN4duE+Dup4CDeG+e OhbPRimMiVOziAkRopn19eKFfQ936MByVRSb+a5Oumu8Z+7vnpsHsJLumir8YpwM/SDG Z9ld87hlPIu63VxP3Co3c9JOC/Pz8bGTwLNPwMEsOrWvsl3Gc1x3MjlSRymGu1j11w9Q VfrjR3tJq/AO5yizRm8Q2U/cQeFA9xcn48k0NlzFjwPZlu37k1kE5Z1bs4FDQ7isTSKw dRWT7E6ht1Yumfqg8nqH+/oFXwuhqNSuGIJlpRWxauD8rpeEetuTcwOPS8vG9fVv1zKO opOg== 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:from:date:sender:dkim-signature; bh=BjP0EmNlXO6ALrWkFxsQZrdnE8TeyGcuWOdh12wVBRc=; b=f38Pm080UxQVWE12iyy4mDZ724VXffrdRZ3icrYRHHgOq2qL5n8sas+O5FEEnLzlll 3/DoAb7EQVDm2ACHRTbNYGLsUnHzjgUdbAe4CeJ5BWBKAd/9/ufYZQBfvezJALfrR+ab 8EtzLblCAK/yOdFwHUOF7argrVD4iCgZnqkHz5pJFc4DkV+7kFUgpQ5/+C9iZnMjqsyk 24wy7VKfEh+o2jtz5nfjrREXB4zJAX20GRqJppLM23IAR1xuzhojNJPCGI5diTpC0ZA/ KN9nGOD++8PmJh6aU/JQRtx9cgpMydIH9sMOwiM+TfjA2QAclfxYJlEVZaRuC98Cdc9I P0qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=KG0gxaVl; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo2-20020a17090b1c8200b0024b27e48a27si5639050pjb.74.2023.05.04.17.06.45; Thu, 04 May 2023 17:07:12 -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=KG0gxaVl; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbjEDXPP (ORCPT + 99 others); Thu, 4 May 2023 19:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbjEDXPN (ORCPT ); Thu, 4 May 2023 19:15:13 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21783124B0; Thu, 4 May 2023 16:15:12 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-64395e2a715so986313b3a.3; Thu, 04 May 2023 16:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683242111; x=1685834111; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :from:to:cc:subject:date:message-id:reply-to; bh=BjP0EmNlXO6ALrWkFxsQZrdnE8TeyGcuWOdh12wVBRc=; b=KG0gxaVldcn1eGhfOHLP4fc8ptS5aAPZ7MH/i+5QDbkNoS8KOPwwuYzvNCUgXJPxRH wv+V6LmYR4UjlKOoJf1441qe4ijpUiO6Mtwnhiv4FprGSinRTW7paIyNxxTeRGqWHpWZ ppvxkGuy3qWRLyc+wjkG4rW/609cax53AFuwAvqIuktNl+B8CWomfioykN3B8oDaLIXW lYdXyWn1KAzSijHTpPZC2ZFR0mz1p29fqQREVEH8MFkyLz27yYB2vrJtRUutLB+u998A zJvH0TFhB9T8f8qDmuDvVqcSXqjgQKiT5e22m4CeELQK0mWEDNp+83q3kynAZiIhhR+g Cz6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683242111; x=1685834111; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BjP0EmNlXO6ALrWkFxsQZrdnE8TeyGcuWOdh12wVBRc=; b=d8FNGWNNUa8j+CT8sJl+f7HYP0g6h53V06VqMgpITGEahkEb+2K5R5/uJ6Mc1o3KQT L/S5c1XnP/Q4Um+u3Lq8IofLpbmm090qLBfqwEFmWqZRkcvZsbheNZMNsvKYslR0fcwn EewmcPSIiUw8neErQGY1cikF9l7yqlCorH6RTGmc/cT5fsrBz1QX2ocQ3c0ilkLxC38a D97Yj+8OtJsLPQgoHYmmTZG7rGRytZw5dYL3BqgR/LtaQAA/9vwf0BOHydZmDHz+0Ehw OTe0msntHwxmSra9x+gutLbxY4qzYrrGQdzqORXUxcKyEFnT8l28VfukrmHZw9BzFbWP YjAA== X-Gm-Message-State: AC+VfDwP5nrekW04vkKq+MLAF8jqpypwaPxUJMj5ieYifwiyy6Cj9Iuz Gu+H++GyB2BEj3+1JS5N6UI= X-Received: by 2002:a05:6a00:2443:b0:643:aa2:4dcd with SMTP id d3-20020a056a00244300b006430aa24dcdmr4691186pfj.16.1683242111305; Thu, 04 May 2023 16:15:11 -0700 (PDT) Received: from google.com ([2620:15c:2d4:203:cf29:c3f3:b6aa:dcb5]) by smtp.gmail.com with ESMTPSA id s1-20020aa78281000000b0063f9de332f8sm184642pfm.167.2023.05.04.16.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:15:10 -0700 (PDT) Sender: Namhyung Kim Date: Thu, 4 May 2023 16:15:08 -0700 From: Namhyung Kim To: Jiri Olsa Cc: Ian Rogers , Arnaldo Carvalho de Melo , Andrii Nakryiko , 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=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Jiri, On Fri, May 05, 2023 at 01:03:14AM +0200, 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 > > > 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 Cool. But I think you missed this. diff --git a/tools/perf/util/bpf_skel/perf-defs.h b/tools/perf/util/bpf_skel/perf-defs.h index 1320e1be03b8..4cfa8a9fce39 100644 --- a/tools/perf/util/bpf_skel/perf-defs.h +++ b/tools/perf/util/bpf_skel/perf-defs.h @@ -253,6 +253,7 @@ typedef struct { } atomic64_t; struct rw_semaphore { + atomic_long_t owner; } __attribute__((preserve_access_index)); typedef atomic64_t atomic_long_t; Thanks, Namhyung