
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICA1GK -------------------------------- Restore cgroup_rstat_flush_atomic() that was removed by commit 0a2dc6ac3329 ("cgroup: remove cgroup_rstat_flush_atomic()") and expose it to bpf. This function is basically the same with cgroup_rstat_flush(), and the later one is sleepable only in PREEMPT_RT case, which is not a supported scenario of this feature. Signed-off-by: GONG Ruiqi <gongruiqi1@huawei.com> --- include/linux/cgroup.h | 3 +++ kernel/cgroup/rstat.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 29fb4556d123..48f0e9dcd3a1 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -693,6 +693,9 @@ static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) void cgroup_rstat_updated(struct cgroup *cgrp, int cpu); void cgroup_rstat_flush(struct cgroup *cgrp); void cgroup_rstat_flush_hold(struct cgroup *cgrp); +#if defined(CONFIG_BPF_RVI) && !defined(CONFIG_PREEMPT_RT) +void cgroup_rstat_flush_atomic(struct cgroup *cgrp); +#endif void cgroup_rstat_flush_release(void); /* diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index c32439b855f5..329c10c084a2 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -239,6 +239,21 @@ __bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp) spin_unlock_irq(&cgroup_rstat_lock); } +#if defined(CONFIG_BPF_RVI) && !defined(CONFIG_PREEMPT_RT) +/** + * cgroup_rstat_flush_atomic- atomic version of cgroup_rstat_flush() + * @cgrp: target cgroup + * + * This function can be called from any context. + */ +__bpf_kfunc void cgroup_rstat_flush_atomic(struct cgroup *cgrp) +{ + spin_lock_irq(&cgroup_rstat_lock); + cgroup_rstat_flush_locked(cgrp); + spin_unlock_irq(&cgroup_rstat_lock); +} +#endif + /** * cgroup_rstat_flush_hold - flush stats in @cgrp's subtree and hold * @cgrp: target cgroup @@ -525,6 +540,9 @@ void cgroup_base_stat_cputime_show(struct seq_file *seq) BTF_SET8_START(bpf_rstat_kfunc_ids) BTF_ID_FLAGS(func, cgroup_rstat_updated) BTF_ID_FLAGS(func, cgroup_rstat_flush, KF_SLEEPABLE) +#if defined(CONFIG_BPF_RVI) && !defined(CONFIG_PREEMPT_RT) +BTF_ID_FLAGS(func, cgroup_rstat_flush_atomic) +#endif BTF_SET8_END(bpf_rstat_kfunc_ids) static const struct btf_kfunc_id_set bpf_rstat_kfunc_set = { -- 2.25.1