Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp174340rwb; Fri, 30 Sep 2022 20:06:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rh7LCeu/kBN8ai6tle46+AF3WaLmUw68oNJv5O2/vBg8uxp0CLVAhU1E8tScyO07PxcP6 X-Received: by 2002:a17:906:591:b0:73d:c3ef:84ae with SMTP id 17-20020a170906059100b0073dc3ef84aemr8528675ejn.155.1664593607614; Fri, 30 Sep 2022 20:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664593607; cv=none; d=google.com; s=arc-20160816; b=jPECgN/t5hx8Exgc1w3o8kYik4NuaSvvkBDtlQBudlDJInY1QrAVHtvKqUAN8PDMUV RfaHGf1YojdB32CQ28abBupqU+5qDk0EZQfSMK2qJR7yBXOiMpNxWB7dFQ4GgWAt3uq3 XIR6MGnxlsFP/5mkEoLDqWrHBZpYilm1GuXnqj3QoqOBrB0LJh+/hheGW2Z4SwKIE3Pu RHiJZ3x5Pe1LMaz1leQG5C+JbJA+09/Z9IxyC4dxyyP/kcVG4Qyg6By4mvWoE8xDOkHg oQcQDbqGVu0v5UMeUFCoYSjpt1uUnougbBR7GGdgyMOFY6uJlaKtuF158Im6fEVNvSym Dcrw== 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; bh=TsSNtaxjzzrx0UGRlq15EZuhaugUhUgclS9Wef+tMjA=; b=VnUA+XJ/ScTP4DwzOKZvsYtrLNte2b/+zb8OKo8GKjpx4M3znP5rdIXNohTsb74Zs2 2bZCgEsivYzFbFoy9fI30PoWm//ka+FnUtZvq2S39itu6xUrMktgnuqE90Yi4R+ZVqrq H7Qdr9mhIN5WQ0t81+rGCYdhT2rQFif/9ATYOyJEL549ykJ9JXqOqoonDWK1S0hyoMb0 tuiaDOBE72Td8RvFhNeEKQYxbHH4QlHDUeDR56pmPhxy7Jup8pav5UQswDEMshmIBQm8 Q5soD+BwEqYU1QlRVyh7xt8xK22vH6GMA+gs1IMHZXDhlP+WKqVsK8XTZHsL4UxANjcW F8ZA== ARC-Authentication-Results: i=1; mx.google.com; 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 ec39-20020a0564020d6700b00458b9b7bbc5si411455edb.401.2022.09.30.20.06.21; Fri, 30 Sep 2022 20:06:47 -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; 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 S232257AbiJACbk (ORCPT + 99 others); Fri, 30 Sep 2022 22:31:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232302AbiJACba (ORCPT ); Fri, 30 Sep 2022 22:31:30 -0400 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21826125D96; Fri, 30 Sep 2022 19:31:29 -0700 (PDT) Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-127dca21a7dso7399296fac.12; Fri, 30 Sep 2022 19:31:29 -0700 (PDT) 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; bh=TsSNtaxjzzrx0UGRlq15EZuhaugUhUgclS9Wef+tMjA=; b=kaUDziaMuKIsPXEo1NARHh6a8YfZ7PCTfT9/4dAjqpR1bf7i+xcJ+KXsWgHIhBDvkI JyQ+EdlsDdcxuF9aOGcUepMhWYcm9C1g3lnYzHHVa5b7EYKeLATDa0zLEuPUNEU9P3YO Nt8O77O95l+WMszY3azrrXe69g8wnGfeWyLTGRbcrMAQ5JPL/mMHnSsGRd32WHYpbg+c C4GykgbpKh5wT/NxS/elCsl2I4DS8lErGfc2QUF26gOP0OVEA3e76U98pSbE4zzxkzp8 S7/oa9rLAl0zV6WcfCd+tEn1sr33bh/6g9m4Kpc44ghgOeHlaiP7hrx2LB3amS4AfAzJ PzCw== X-Gm-Message-State: ACrzQf1tvtUwA/re8/D1Axjh/vL0NekT2nqHFRDTVHZ9ZsQvlH2rNIZQ 9XUME8csjIwd9HY4eiO4szaPyCJjLpRStqInWT8= X-Received: by 2002:a05:6871:14f:b0:131:a644:7c58 with SMTP id z15-20020a056871014f00b00131a6447c58mr469446oab.209.1664591488387; Fri, 30 Sep 2022 19:31:28 -0700 (PDT) MIME-Version: 1.0 References: <20220922041435.709119-1-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Fri, 30 Sep 2022 19:31:17 -0700 Message-ID: Subject: Re: [PATCH] perf stat: Support old kernels for bperf cgroup counting To: Andrii Nakryiko 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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS 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 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? Thanks, Namhyung