Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1291649rwb; Thu, 22 Sep 2022 12:53:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5JPYo9TwlC1TwE2w641sgo22v4TVomKiz+MHHSteFAKgohg8bSvz3MUZpSr8nE4iAjshbg X-Received: by 2002:a17:907:2c41:b0:77d:8aed:cf7c with SMTP id hf1-20020a1709072c4100b0077d8aedcf7cmr4219523ejc.447.1663876403545; Thu, 22 Sep 2022 12:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663876403; cv=none; d=google.com; s=arc-20160816; b=n1AAadnsXm/WyoeJCt+BXxW2GqnewFazp41CySxzJuwYgcIPm4uJeti9ic9f7KBlMT fv8wGwHexbiGxdKVm9vhuyy5kJtJlNrCwqKSm8QywWmsc4qu73+ByBOKUCz0y/bfsSK0 mWuiJEce1Rtf5cRQHDKpjbSHkLpJELTRnW4avZnskpMuJXakESrzfco1YugaldZOwC4y mb2mxCUQrMHg0JM6NN91X3DDSn3tSLQmSC0oVmr6kRuDcsiBVTLBhhkXfBMmf+QBOF13 E24YvA7XIYMSC2y+F5bwV3AhTafqdtpHuG1Zh5NyLHNlY7XSxARfcHgDiVIrE+6H3DXk b9TQ== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PDb0+/WZqbRjgi4osfgV+grcbqLRB2P+3mQsbyE1Wl4=; b=0+1PdUX4/9SEWmlY0c1BAizPrrbYUcAqUJZ7nKQvn2bUcaDSUspxXreBGyICFThvRu wJA9yj1UR5orqvZf1wLrx0NY+7EgIfgAg8tTtsafEyFVxVzzKxIuyIs//kAtNuv1gnGF 7Ty5RICjelXxM3oK9FhrWw1D2oJ5Dl8K2ntvDEotnx7mDzTxhQb9/0l2dbf57DA4LFrp hmfmJD6g+WT4yIiRRqLfTrLXMy8ihKqKVbZAgTkvvpu2q9zqZe6d4y47F/Ed7qLiH7tJ UYvljAWbuZZOoHGPZa945J1z3gMVZo1MZ92EdRHgVjde60jtp1g61n6nqU8g3K3toSKz GMrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r4c2Z+6T; 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 a3-20020a170906468300b00780f607444asi5728980ejr.868.2022.09.22.12.52.57; Thu, 22 Sep 2022 12:53:23 -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=@kernel.org header.s=k20201202 header.b=r4c2Z+6T; 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 S230005AbiIVTXO (ORCPT + 99 others); Thu, 22 Sep 2022 15:23:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbiIVTXM (ORCPT ); Thu, 22 Sep 2022 15:23:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 894F2286D6; Thu, 22 Sep 2022 12:23:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1EE9C61175; Thu, 22 Sep 2022 19:23:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52694C433D7; Thu, 22 Sep 2022 19:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663874590; bh=2DZjj8mS7EZ9M/LXHnntgYzTasGSbm7dQDwq3kbKrRU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r4c2Z+6Trx3SV1wFpJqn4BFOBW6BC8w7thIgfQWX74LAcI+V+O0N/WRFFUtd+Ihvi iLZ1wEggUF41RDsoday1TMULHLMRXkXw9122nsBxKAtPkt1RQLOzEWmmn8BRasg1CR E0NPWAYW29BrVPmUsJtdRzUG9B+8EtGqvT4xUet+SYLv+z/kONZ4iBxQQlbJbGDCWD Ws9HurS6Saaf/MjkBzf7ndLtNbfylsFF3wRgcLTWUrDoWhrZzhz9u2K4C4QOpIWak2 YM7WsbMA0GjeUfgiIoUO0ZSSA58qUTDN/xok/YmcH1MQhk2VLMN9/S/CAzxX/Hk93v vLTOG1egpTOtA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 0B3A6403B0; Thu, 22 Sep 2022 20:23:08 +0100 (IST) Date: Thu, 22 Sep 2022 20:23:08 +0100 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Jiri Olsa , Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , bpf@vger.kernel.org Subject: Re: [PATCH v2] perf tools: Get a perf cgroup more portably in BPF Message-ID: References: <20220922044023.718774-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220922044023.718774-1-namhyung@kernel.org> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Em Wed, Sep 21, 2022 at 09:40:23PM -0700, Namhyung Kim escreveu: > The perf_event_cgrp_id can be different on other configurations. > To be more portable as CO-RE, it needs to get the cgroup subsys id > using the bpf_core_enum_value() helper. > > Suggested-by: Ian Rogers > Signed-off-by: Namhyung Kim Applying, Ian, can I have your Reviewed-by? - Arnaldo > --- > v2 changes) > * fix off_cpu.bpf.c too > * get perf_subsys_id only once > > tools/perf/util/bpf_skel/bperf_cgroup.bpf.c | 6 +++++- > tools/perf/util/bpf_skel/off_cpu.bpf.c | 12 ++++++++---- > 2 files changed, 13 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > index 292c430768b5..9223e4b87fe9 100644 > --- a/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > +++ b/tools/perf/util/bpf_skel/bperf_cgroup.bpf.c > @@ -48,6 +48,7 @@ const volatile __u32 num_cpus = 1; > > int enabled = 0; > int use_cgroup_v2 = 0; > +int perf_subsys_id = -1; > > static inline int get_cgroup_v1_idx(__u32 *cgrps, int size) > { > @@ -58,7 +59,10 @@ static inline int get_cgroup_v1_idx(__u32 *cgrps, int size) > int level; > int cnt; > > - cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_event_cgrp_id], cgroup); > + if (perf_subsys_id == -1) > + perf_subsys_id = bpf_core_enum_value(enum cgroup_subsys_id, perf_event_cgrp_id); > + > + cgrp = BPF_CORE_READ(p, cgroups, subsys[perf_subsys_id], cgroup); > level = BPF_CORE_READ(cgrp, level); > > for (cnt = 0; i < MAX_LEVELS; i++) { > diff --git a/tools/perf/util/bpf_skel/off_cpu.bpf.c b/tools/perf/util/bpf_skel/off_cpu.bpf.c > index c4ba2bcf179f..e917ef7b8875 100644 > --- a/tools/perf/util/bpf_skel/off_cpu.bpf.c > +++ b/tools/perf/util/bpf_skel/off_cpu.bpf.c > @@ -94,6 +94,8 @@ const volatile bool has_prev_state = false; > const volatile bool needs_cgroup = false; > const volatile bool uses_cgroup_v1 = false; > > +int perf_subsys_id = -1; > + > /* > * Old kernel used to call it task_struct->state and now it's '__state'. > * Use BPF CO-RE "ignored suffix rule" to deal with it like below: > @@ -119,11 +121,13 @@ static inline __u64 get_cgroup_id(struct task_struct *t) > { > struct cgroup *cgrp; > > - if (uses_cgroup_v1) > - cgrp = BPF_CORE_READ(t, cgroups, subsys[perf_event_cgrp_id], cgroup); > - else > - cgrp = BPF_CORE_READ(t, cgroups, dfl_cgrp); > + if (!uses_cgroup_v1) > + return BPF_CORE_READ(t, cgroups, dfl_cgrp, kn, id); > + > + if (perf_subsys_id == -1) > + perf_subsys_id = bpf_core_enum_value(enum cgroup_subsys_id, perf_event_cgrp_id); > > + cgrp = BPF_CORE_READ(t, cgroups, subsys[perf_subsys_id], cgroup); > return BPF_CORE_READ(cgrp, kn, id); > } > > -- > 2.37.3.968.ga6b4b080e4-goog -- - Arnaldo