forked from TencentOS/TencentOS-kernel
tqos/mbuf: write a help function to get cgroup struct from task_struct.
In order to support cgroup V1 with mbuf and sli, we need a special cgroup structure, cpuacct subsys cgroup is nice. We only prepare mbuf and sli for cpuacct cgroup in V1. so first find cpuacct cgroup and if return NULl or root, just find df1_cgrp. Signed-off-by: Bauerchen <bauerchen@tencent.com> Reviewed-by: mungerjiang<mungerjiang@tencent.com> Reviewed-by: mungerjiang<mungerjiang@tencent.com>
This commit is contained in:
parent
7600f2ca44
commit
7795ccbf82
|
|
@ -960,4 +960,5 @@ static inline void cgroup_bpf_put(struct cgroup *cgrp) {}
|
|||
#endif /* CONFIG_CGROUP_BPF */
|
||||
|
||||
ssize_t mbuf_print(struct cgroup *cgrp, const char *fmt, ...);
|
||||
struct cgroup *get_cgroup_from_task(struct task_struct *task);
|
||||
#endif /* _LINUX_CGROUP_H */
|
||||
|
|
|
|||
|
|
@ -3763,6 +3763,33 @@ static int mbuf_show(struct seq_file *s, void *v)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get cgroup struct from task_struct for mbuf and sli.
|
||||
*
|
||||
* In cgroup V1, return cpuacct cgroup, and if cpuacct cgroup is root, df1_cgrp
|
||||
* is returned, but is harmless.
|
||||
*
|
||||
* In cgroup V2, just return task_struct.cgroups.dfl_cgrp.
|
||||
*/
|
||||
struct cgroup *get_cgroup_from_task(struct task_struct *task)
|
||||
{
|
||||
struct cgroup *cgrp;
|
||||
|
||||
/* First, try to get cpuacct cgroup for V1*/
|
||||
cgrp = task_cgroup(task, cpuacct_cgrp_id);
|
||||
if (cgrp && cgrp->level)
|
||||
return cgrp;
|
||||
|
||||
/*
|
||||
* If can not find cpuacct cgroup or cpuacct cgroup is root, just return
|
||||
* dfl_cgrp.
|
||||
*/
|
||||
cgrp = task_dfl_cgroup(task);
|
||||
|
||||
return cgrp;
|
||||
}
|
||||
|
||||
|
||||
ssize_t mbuf_print(struct cgroup *cgrp, const char *fmt, ...)
|
||||
{
|
||||
struct mbuf_slot *mb;
|
||||
|
|
|
|||
Loading…
Reference in New Issue