Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp129150rwb; Wed, 5 Oct 2022 15:58:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Re9GLUGrR0GiRMtRTNW1svvkFvd+Mrh8RI+Omi+/qfrbp9efQCAEa1q/gTgSX64JLBDgp X-Received: by 2002:a17:90a:b013:b0:20a:e33d:dfa0 with SMTP id x19-20020a17090ab01300b0020ae33ddfa0mr2067349pjq.82.1665010737909; Wed, 05 Oct 2022 15:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665010737; cv=none; d=google.com; s=arc-20160816; b=ifSLIPZVOvkFh22Sq0wL8IAWUvp7uT8hnu1lEvB9Iv9Dquki+H80tXqtEReu8SF7lc 5X+WSQa/GGDwqCEel1PtOBSTsiFkEqM/EFkKbP5vRUK80uIwCDKTpdhMNzrJz9QjXCSs PJRHa77fb3+sGVxvQu4IBhazMMY1d2lY61qbE/zxkx2GkoMRiL/OKNYDWjmM8hFuUVGf jitfmXAD2in/DP0aZLqVLokvTo+BkqNlGJhv6oGQfJJDTfNWlzTH5ZRVlH5xJvdcOF9N JClMfOfmUYwN+iasA/ni+BaPJxGcWQf/GoUIdTxjQ0c6ursHqxHyvkZmr74xv0ESeVxN DUQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5IDa4zO8fjCrFtrwiC0X35h30/CNk4qiLrUvMAkxVAs=; b=Hf1dQeY0YVz2S0f9stof2CIPN6fyYOxVp2w22NmMaS4RfTrXVc5G+pYecOgQWpqq42 UkOtQDrnE7D0GY7CTHB3EMM65bS6bHku68wup6ewAOuVBAD3GBDOQsR4KB8mnuGhMeBQ q38KBxI1MsbcI4LEPe07atI9FjFqCXbEYWGKLGUOiSJukMCzpxbwbjEwelDcEP2L3HEr 32yoPR2RmTyH+ExnH2DxN9k46bYTIje6CmcegQnmSVroOWMd1MUKUxsx3g5IDsA1vZHP +uu1/35qdQ0zRnRtGbEp3v50ftF/T/qWqOBhpYH3nRkCBXyjVC4cF7CdG4ElD7zrTZrk PGsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="bm30/cAr"; 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 e9-20020a633709000000b004340446009csi17090342pga.226.2022.10.05.15.58.19; Wed, 05 Oct 2022 15:58:57 -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=20210112 header.b="bm30/cAr"; 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 S229616AbiJEWgy (ORCPT + 99 others); Wed, 5 Oct 2022 18:36:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbiJEWgw (ORCPT ); Wed, 5 Oct 2022 18:36:52 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 800036068D; Wed, 5 Oct 2022 15:36:51 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id z23so686745ejw.12; Wed, 05 Oct 2022 15:36:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5IDa4zO8fjCrFtrwiC0X35h30/CNk4qiLrUvMAkxVAs=; b=bm30/cArbm6oXF4zz1/TtHAWlji0iXVLwmqbQ8S+eX+WoOj3CAuuIz6pZTPsG/T+x8 tQuWs0gvBC5SG/yfefFxVY2DB4LqAzzAd3/kN3emfJiPT5otMXw6F8Hnsig2FHnJaswi xyU6sVIQ9t48MFF1pB5zpnyNuo7f/Wo9gQ06BgxfSzrZoPS2PIzQIvz5rH2Hj7CZltvw EE1cHiLJW3Nx55kuMDHjzlm9+iSe749VmzE7X20P54yDycBMuaOEnnipVWFVMwzetjq3 AKlp0g8DBThkQM/uQSi27PJN7F3IdQi14TUpoO/hPCY/hN+X3QmV/7eRYIMax/s3LrUe Xb2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=5IDa4zO8fjCrFtrwiC0X35h30/CNk4qiLrUvMAkxVAs=; b=qzuCWCR6ngV6dgCpqns9lefekJxeUGQIBdT9Gi/VYBo99BU26YgGP2yw4y0tSF28H/ qpEJpZTv2SibFDKOl2UuJkT6W0ZUd90EcfSIUWjq46tHRglxqxW0fUwtAtolQSZRaiTk zS0MFDpHFcZSvAv8wMPz5voM5q/cA0nFe4Aox2IxiMuqozlhClX01b4tCaGUNxl6yQgD Z7e0gYXFmE58NUkqJ+j4XG+kZtIg47i3wu9+U1BGL2I1d8qCBwZyf8FxVByjThQXBOBn DqmCusMBI1i71HVZK2+PNoNhxK12rtN+g8yaAT2RLuJdEdzIgUE+Rq1cDh95CcR1mdcP sQvg== X-Gm-Message-State: ACrzQf1cvl+XHXcTCRxZkkEOhI3oqo8yuWg5mqPOxnh20YK/cGvQGajU n+FZahYFaCa3+Ju89UpEmdcec49QPY7ud9l0HDg= X-Received: by 2002:a17:906:5a4c:b0:78c:c893:74e6 with SMTP id my12-20020a1709065a4c00b0078cc89374e6mr1475975ejc.545.1665009409931; Wed, 05 Oct 2022 15:36:49 -0700 (PDT) MIME-Version: 1.0 References: <20220922041435.709119-1-namhyung@kernel.org> In-Reply-To: From: Andrii Nakryiko Date: Wed, 5 Oct 2022 15:36:37 -0700 Message-ID: Subject: Re: [PATCH] perf stat: Support old kernels for bperf cgroup counting To: Namhyung Kim Cc: Tejun Heo , Zefan Li , Johannes Weiner , cgroups , Arnaldo Carvalho de Melo , Jiri Olsa , LKML , linux-perf-users , Song Liu , bpf Content-Type: text/plain; charset="UTF-8" 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 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, Sep 30, 2022 at 7:31 PM Namhyung Kim wrote: > > Hello, > > On Fri, Sep 30, 2022 at 3:48 PM Andrii Nakryiko > wrote: > > > > On Wed, Sep 21, 2022 at 9:21 PM Namhyung Kim wrote: > > > > > > The recent change in the cgroup will break the backward compatiblity in > > > the BPF program. It should support both old and new kernels using BPF > > > CO-RE technique. > > > > > > Like the task_struct->__state handling in the offcpu analysis, we can > > > check the field name in the cgroup struct. > > > > > > Signed-off-by: Namhyung Kim > > > --- > > > Arnaldo, I think this should go through the cgroup tree since it depends > > > on the earlier change there. I don't think it'd conflict with other > > > perf changes but please let me know if you see any trouble, thanks! > > > > > > tools/perf/util/bpf_skel/bperf_cgroup.bpf.c | 29 ++++++++++++++++++++- > > > 1 file changed, 28 insertions(+), 1 deletion(-) > > > > > > diff --git a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > > > index 488bd398f01d..4fe61043de04 100644 > > > --- a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > > > +++ b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > > > @@ -43,12 +43,39 @@ struct { > > > __uint(value_size, sizeof(struct bpf_perf_event_value)); > > > } cgrp_readings SEC(".maps"); > > > > > > +/* new kernel cgroup definition */ > > > +struct cgroup___new { > > > + int level; > > > + struct cgroup *ancestors[]; > > > +} __attribute__((preserve_access_index)); > > > + > > > +/* old kernel cgroup definition */ > > > +struct cgroup___old { > > > + int level; > > > + u64 ancestor_ids[]; > > > +} __attribute__((preserve_access_index)); > > > + > > > const volatile __u32 num_events = 1; > > > const volatile __u32 num_cpus = 1; > > > > > > int enabled = 0; > > > int use_cgroup_v2 = 0; > > > > > > +static inline __u64 get_cgroup_v1_ancestor_id(struct cgroup *cgrp, int level) > > > +{ > > > + /* recast pointer to capture new type for compiler */ > > > + struct cgroup___new *cgrp_new = (void *)cgrp; > > > + > > > + if (bpf_core_field_exists(cgrp_new->ancestors)) { > > > + return BPF_CORE_READ(cgrp_new, ancestors[level], kn, id); > > > > have you checked generated BPF code for this ancestors[level] access? > > I'd expect CO-RE relocation for finding ancestors offset and then just > > normal + level * 8 arithmetic, but would be nice to confirm. Apart > > from this, looks good to me: > > > > Acked-by: Andrii Nakryiko > > Thanks for your review! > > How can I check the generated code? Do you have something works with > skeletons or do I have to save the BPF object somehow during the build? > skeleton is generated from ELF BPF object file. You can do llvm-objdump -d to see instructions. Unfortunately you can't see BPF CO-RE relocations this way, you'd have to use something like my custom tool ([0]). But anyways, I checked locally similar code pattern and I think it's all good from BPF CO-RE perspective. I see appropriate relocations in all the necessary places. So this should work. Acked-by: Andrii Nakryiko [0] https://github.com/anakryiko/btfdump > Thanks, > Namhyung