Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3264861lfo; Mon, 23 May 2022 00:17:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKygnHP79dcW9TD9XtO/gd0QcCBAtvJzSIa3Ewp8ecQgEsjl+zjoJ+h3/wLspMkfPg+SMI X-Received: by 2002:a17:90b:4d0c:b0:1df:c9a6:84d8 with SMTP id mw12-20020a17090b4d0c00b001dfc9a684d8mr25269713pjb.231.1653290242040; Mon, 23 May 2022 00:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653290242; cv=none; d=google.com; s=arc-20160816; b=P5eaLMgH041IBuAv5QYaLyX+HsokDktgOs2xCGsoRJ6RnfrKMt+t0R6Pz0QtuZsB4m Fuc/rbfM9HtM7TrZlrpDFoi+54/ZK+153qCFxm9L1kcesdm78wznm6Xd+DVLyEYI6V3c gYA7g3feCl11DyO/MwB+05NDCXuxOW1STpUtKTNipGzpWJ6jj58I2qG8/bPDrSWWRify JBLMHC5KYYXX068maF6JwaNwRePmMG3Os5WOLmS//KtQvGF22ubltdl1GS8rn60PDKj0 AoLgRwfvfCS4g8oTFyzj6eYdsD5ZnIC4hrCAMBMKWFP5o7WisWcDDatNWKM3Sfi9a7cw yChw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=18Er9O41CS051aXSe9usnmRbqjT27fNlHDiukFcMpPk=; b=cxLNdIx7gb02CBhBdcGG4wsYUHHllxJnbejtrjZGxaBvSDpJhPXybMOshMrI8V5rc9 7qwmXARjU6EfFnj3o/3nm24DgoAgXqp1aCM3oW6QaqqLdCmPNHTXOuO7+P1l7HRRCBHT CQLq62A0Y5PBBmdolBB6Q3IQPatpWQy5SBRcrYAVnJEZD/BjQcS4ffLhKz2OiOUh6J3q 6szA3QXFtA+7U/I8KQvofB3H7tRvu+09iiNwfdYTiMMrJI2ZbwDyuA+6KNQoUijTKDPk P04uUMF1o+gzi5ZS31ljgIQ5G7J6+/UfIir11FiKuFgJqn8LBzbZHAzeupkPCIF4rbkj wKiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=igx0wUTd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id b1-20020a170902d40100b0016168e90f2fsi7929499ple.501.2022.05.23.00.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:17:22 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=igx0wUTd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BAD363B296; Sun, 22 May 2022 23:34:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344447AbiETBVy (ORCPT + 99 others); Thu, 19 May 2022 21:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344407AbiETBVm (ORCPT ); Thu, 19 May 2022 21:21:42 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2DEF27CC6 for ; Thu, 19 May 2022 18:21:41 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id rj11-20020a17090b3e8b00b001df51eb1831so5985972pjb.3 for ; Thu, 19 May 2022 18:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=18Er9O41CS051aXSe9usnmRbqjT27fNlHDiukFcMpPk=; b=igx0wUTdQcYupX1yAJkzuiW3tixL4/rG9QHDOE1OuemDauucgS0b4WPm/qNDTqc6tj dC8noNnsek02+MHALHDloPhHjY9PuAcO8cT0fqReQQSFMoKfhUaM0O2JYTV90eF5TW1T 1ZpTQAHA+bZ5+sSSYuH0fi+CeElAYVF0uv+c3gA5rToEvxuK4V4z2uk297hwMXxNn/CK 5nHug49g8iMgqh+7Bw17Kgzdbg90jtNx7QMIWVdBW/1UttBugbiKkD/nel+18aIOmhCW DnVdrCrB08b/fwlSt9/iJh7/Z32kjo9kzvfKYcbNc635DkaxYvbgHuDNWDgJOr4EWfTq +obQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=18Er9O41CS051aXSe9usnmRbqjT27fNlHDiukFcMpPk=; b=0mJF/xV1v78oj6ZpuhbB8fBWb28PQ0vkTWKDQdWgrzOpK5aR3Chp+Mdqkb86H5QwsI RLqZlS4O7LoWrqgdCUoUGNP3Gn28Z4lh2vUypOPirv3AmZXjnhWcNY/m4VTG1eE7tWph XbIVH2FIqVkZIRciontfTtyNwge0IoEFTY9GM7dMm+EsDHgjjJu8h1YzhaHqPBgBZZ7p pB7SFrPN1GXsRCSLd0EDDuuoT4cyrffOZezwilz9d1NeifEF+U4/NFo3thM2oWwnESne 3bimfB8Wu3T9Tosdz3n1ZUYjT6Ui9IIWU/jTU2OhbzIhsUNFskT8SeuUodN13b3Ras/Z nKYA== X-Gm-Message-State: AOAM533QOnjFX2KNVg2S8G/+Gss78ayks43iFi42omdNsDTx8q189pqR b+x6LPqx+ZjXrUf5krvL/DLgIzI28UKUJZT9 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a62:e518:0:b0:4fa:9333:ddbd with SMTP id n24-20020a62e518000000b004fa9333ddbdmr7319126pff.11.1653009701453; Thu, 19 May 2022 18:21:41 -0700 (PDT) Date: Fri, 20 May 2022 01:21:30 +0000 In-Reply-To: <20220520012133.1217211-1-yosryahmed@google.com> Message-Id: <20220520012133.1217211-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220520012133.1217211-1-yosryahmed@google.com> X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog Subject: [PATCH bpf-next v1 2/5] cgroup: bpf: add cgroup_rstat_updated() and cgroup_rstat_flush() kfuncs From: Yosry Ahmed To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , Roman Gushchin , Michal Hocko Cc: Stanislav Fomichev , David Rientjes , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org, Yosry Ahmed Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 Add cgroup_rstat_updated() and cgroup_rstat_flush() kfuncs to bpf tracing programs. bpf programs that make use of rstat can use these functions to inform rstat when they update stats for a cgroup, and when they need to flush the stats. Signed-off-by: Yosry Ahmed --- kernel/cgroup/rstat.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index e7a88d2600bd..a16a851bc0a1 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -3,6 +3,11 @@ #include +#include +#include +#include + + static DEFINE_SPINLOCK(cgroup_rstat_lock); static DEFINE_PER_CPU(raw_spinlock_t, cgroup_rstat_cpu_lock); @@ -141,7 +146,12 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos, return pos; } -/* A hook for bpf stat collectors to attach to and flush their stats */ +/* + * A hook for bpf stat collectors to attach to and flush their stats. + * Together with providing bpf kfuncs for cgroup_rstat_updated() and + * cgroup_rstat_flush(), this enables a complete workflow where bpf progs that + * collect cgroup stats can integrate with rstat for efficient flushing. + */ __weak noinline void bpf_rstat_flush(struct cgroup *cgrp, struct cgroup *parent, int cpu) { @@ -476,3 +486,26 @@ void cgroup_base_stat_cputime_show(struct seq_file *seq) "system_usec %llu\n", usage, utime, stime); } + +/* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */ +BTF_SET_START(bpf_rstat_check_kfunc_ids) +BTF_ID(func, cgroup_rstat_updated) +BTF_ID(func, cgroup_rstat_flush) +BTF_SET_END(bpf_rstat_check_kfunc_ids) + +BTF_SET_START(bpf_rstat_sleepable_kfunc_ids) +BTF_ID(func, cgroup_rstat_flush) +BTF_SET_END(bpf_rstat_sleepable_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_rstat_kfunc_set = { + .owner = THIS_MODULE, + .check_set = &bpf_rstat_check_kfunc_ids, + .sleepable_set = &bpf_rstat_sleepable_kfunc_ids, +}; + +static int __init bpf_rstat_kfunc_init(void) +{ + return register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, + &bpf_rstat_kfunc_set); +} +late_initcall(bpf_rstat_kfunc_init); -- 2.36.1.124.g0e6072fb45-goog