From: Yosry Ahmed <yosryahmed@google.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Shuah Khan <shuah@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Michal Hocko <mhocko@kernel.org>
Cc: Stanislav Fomichev <sdf@google.com>,
David Rientjes <rientjes@google.com>,
Greg Thelen <gthelen@google.com>,
Shakeel Butt <shakeelb@google.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
bpf@vger.kernel.org, cgroups@vger.kernel.org,
Yosry Ahmed <yosryahmed@google.com>
Subject: [RFC PATCH bpf-next v2 2/7] cgroup: bpf: flush bpf stats on rstat flush
Date: Sun, 15 May 2022 02:34:59 +0000 [thread overview]
Message-ID: <20220515023504.1823463-3-yosryahmed@google.com> (raw)
In-Reply-To: <20220515023504.1823463-1-yosryahmed@google.com>
When an rstat flush is ongoing for a cgroup, also flush bpf stats by
running any attached rstat flush programs.
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
include/linux/bpf-rstat.h | 6 ++++++
kernel/bpf/rstat.c | 21 +++++++++++++++++++++
kernel/cgroup/rstat.c | 2 ++
3 files changed, 29 insertions(+)
diff --git a/include/linux/bpf-rstat.h b/include/linux/bpf-rstat.h
index 23cad23b5fc2..55e000fe0f47 100644
--- a/include/linux/bpf-rstat.h
+++ b/include/linux/bpf-rstat.h
@@ -12,6 +12,8 @@
int bpf_rstat_link_attach(const union bpf_attr *attr,
struct bpf_prog *prog);
+void bpf_rstat_flush(struct cgroup *cgrp, int cpu);
+
#else /* defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_CGROUPS) */
static inline int bpf_rstat_link_attach(const union bpf_attr *attr,
@@ -20,6 +22,10 @@ static inline int bpf_rstat_link_attach(const union bpf_attr *attr,
return -ENOTSUPP;
}
+static inline void bpf_rstat_flush(struct cgroup *cgrp, int cpu)
+{
+}
+
#endif /* defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_CGROUPS) */
#endif /* _BPF_RSTAT */
diff --git a/kernel/bpf/rstat.c b/kernel/bpf/rstat.c
index 5f529002d4b9..e96bc080f4b9 100644
--- a/kernel/bpf/rstat.c
+++ b/kernel/bpf/rstat.c
@@ -164,3 +164,24 @@ int bpf_rstat_link_attach(const union bpf_attr *attr,
return bpf_link_settle(&link_primer);
}
+
+void bpf_rstat_flush(struct cgroup *cgrp, int cpu)
+{
+ struct bpf_rstat_flusher *flusher;
+ struct bpf_rstat_flush_ctx ctx = {
+ .cgrp = cgrp,
+ .parent = cgroup_parent(cgrp),
+ .cpu = cpu,
+ };
+
+ rcu_read_lock();
+ migrate_disable();
+ spin_lock(&bpf_rstat_flushers_lock);
+
+ list_for_each_entry(flusher, &bpf_rstat_flushers, list)
+ (void) bpf_prog_run(flusher->prog, &ctx);
+
+ spin_unlock(&bpf_rstat_flushers_lock);
+ migrate_enable();
+ rcu_read_unlock();
+}
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 24b5c2ab5598..0285d496e807 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -2,6 +2,7 @@
#include "cgroup-internal.h"
#include <linux/sched/cputime.h>
+#include <linux/bpf-rstat.h>
static DEFINE_SPINLOCK(cgroup_rstat_lock);
static DEFINE_PER_CPU(raw_spinlock_t, cgroup_rstat_cpu_lock);
@@ -168,6 +169,7 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp, bool may_sleep)
struct cgroup_subsys_state *css;
cgroup_base_stat_flush(pos, cpu);
+ bpf_rstat_flush(pos, cpu);
rcu_read_lock();
list_for_each_entry_rcu(css, &pos->rstat_css_list,
--
2.36.0.550.gb090851708-goog
next prev parent reply other threads:[~2022-05-15 2:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-15 2:34 [RFC PATCH bpf-next v2 0/7] bpf: rstat: cgroup hierarchical stats Yosry Ahmed
2022-05-15 2:34 ` [RFC PATCH bpf-next v2 1/7] bpf: introduce RSTAT_FLUSH program type Yosry Ahmed
2022-05-15 2:34 ` Yosry Ahmed [this message]
2022-05-17 2:08 ` [RFC PATCH bpf-next v2 2/7] cgroup: bpf: flush bpf stats on rstat flush Alexei Starovoitov
2022-05-17 21:51 ` Yosry Ahmed
2022-05-15 2:35 ` [RFC PATCH bpf-next v2 3/7] libbpf: Add support for rstat flush progs Yosry Ahmed
2022-05-15 9:07 ` Yosry Ahmed
2022-05-15 2:35 ` [RFC PATCH bpf-next v2 4/7] bpf: add bpf rstat helpers Yosry Ahmed
2022-05-15 2:35 ` [RFC PATCH bpf-next v2 5/7] bpf: Introduce cgroup iter Yosry Ahmed
2022-05-15 2:35 ` [RFC PATCH bpf-next v2 6/7] selftests/bpf: extend cgroup helpers Yosry Ahmed
2022-05-15 2:35 ` [RFC PATCH bpf-next v2 7/7] bpf: add a selftest for cgroup hierarchical stats collection Yosry Ahmed
2022-05-16 19:39 ` [RFC PATCH bpf-next v2 0/7] bpf: rstat: cgroup hierarchical stats Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220515023504.1823463-3-yosryahmed@google.com \
--to=yosryahmed@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=mhocko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=sdf@google.com \
--cc=shakeelb@google.com \
--cc=shuah@kernel.org \
--cc=songliubraving@fb.com \
--cc=tj@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox