cgroup学习(七)——cpu子系统

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(
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值