慢慢欣赏linux CPU占用率学习

博客围绕Linux系统展开,涉及proc/stat.c和proc/array.c文件对CPU进程占用率的分析,介绍了Jiffies的计算公式,还提及如何查看高CPU占用率线程、CPU利用率计算,同时给出了linux内核中HZ介绍的相关链接。

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

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值