proc/stat.c // 整个CPU所有的进程占用率分析
proc/array.c // CPU进程占用率
Jiffies = Ns / (10^9 / HZ)
int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task, int whole)
{
thread_group_times(task, &utime, &stime);
=>void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
{
thread_group_cputime(p, &cputime);
total = cputime_add(cputime.utime, cputime.stime);
rtime = nsecs_to_cputime(cputime.sum_exec_runtime);
=># define nsecs_to_cputime(__nsecs) nsecs_to_jiffies(__nsecs)
unsigned long nsecs_to_jiffies(u64 n)
{
return (unsigned long)nsecs_to_jiffies64(n);
=>u64 nsecs_to_jiffies64(u64 n)
{
#if (NSEC_PER_SEC % HZ) == 0
/* Common case, HZ = 100, 128, 200, 250, 256, 500, 512, 1000 etc. */
return div_u64(n, NSEC_PER_SEC / HZ);
#else
#endif
}
}
}
Linux下如何查看高CPU占用率线程 LINUX CPU利用率计算
https://www.cnblogs.com/lidabo/p/4738113.html
linux内核中的HZ介绍
https://blog.youkuaiyun.com/hzrandd/article/details/10850043
博客围绕Linux系统展开,涉及proc/stat.c和proc/array.c文件对CPU进程占用率的分析,介绍了Jiffies的计算公式,还提及如何查看高CPU占用率线程、CPU利用率计算,同时给出了linux内核中HZ介绍的相关链接。
490





