CPU子系统
对于CPU子系统最常见的参数就是cpu.shares,我们来通过《cgroup学习(三)——伪文件》的表格来跟踪一下对该参数的读写操作。
通过systemtap我们可以看到读的bt:(cat cpu.shares)
2327 (cat) cpu_shares_read_u64 call trace:
0xffffffff8104d0a0 : cpu_shares_read_u64+0x0/0x20[kernel]
0xffffffff810be3aa :cgroup_file_read+0xaa/0x100 [kernel]
0xffffffff811786a5 : vfs_read+0xb5/0x1a0[kernel]
0xffffffff811787e1 : sys_read+0x51/0x90[kernel]
0xffffffff8100b0f2 :system_call_fastpath+0x16/0x1b [kernel]
在上面我们已经说过,在创建cgroup的时候将对文件的操作cftype保存到file->f_dentry->d_fsdata,同时cgroup信息保存在目录的dentry->d_fsdata,所以当通过vfs进入cgroup文件系统里时,通过cgroup_file_read获得这些信息后,直接调用该文件的cpu_shares_read_u64:
static u64 cpu_shares_read_u64(struct cgroup *cgrp, struct cftype *cft)
{
struct task_group *tg = cgroup_tg(cgrp);
return (u64) tg->shares;
}
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
/* return corresponding task_group object of a cgroup */
static inline struct task_group *cgroup_tg(struct cgroup *cgrp)
{
return container_of(cgroup_subsys_state(cgrp, cpu_cgroup_subsys_id),
struct task_group, css);
}
static inline struct cgroup_subsys_state *cgroup_subsys_state(