Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
10
Star
26
Fork
10
summer-competition
/
Summer 2021
Code
Issues
148
Pull Requests
1
Wiki
Insights
Pipelines
Service
JavaDoc
PHPDoc
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
No 27. 优化 Linux 系统的 CPU 占用时间统计
Backlog
#I3EBT6
Task
Xie XiuQi
Opened this issue
2021-03-31 09:55
Linux 系统常用 top 来查看CPU的占用率和各Task的CPU占用率。TOP 显示的CPU占用率的数据来源是 /proc/stat 。/proc/stat 个数据字段的具体含义可以参考“Documentation/filesystems/proc.rst”中 “1.8 Miscellaneous kernel statistics in /proc/stat”。内核中该CPU占用率的统计是基于 cpu tick 来统计的,比如 1 个 tick 间隔是 4ms,当 tick 中断到来时,cpu 运行的是哪个task,就把整个 4ms 全部算到这个 task 上。这样统计简单,开销小,针对长时间运行的 task,误差也可以接受。但是如果针对频繁切换的 task,统计误差就会很大,甚至不可接受。 举个简单例子: ``` $ vim usleep.c #include <unistd.h> int main() { int i = 0; for (;;) { if (!(i++ % 10000)) usleep(1); } return 0; } $ gcc usleep.c -o usleep $ taskset -c 1 ./usleep # 使用 top 观察 CPU 1 的占有率和 usleep task 的CPU占用率。 ``` 难度:高 导师: @xiexiuqi 联系方式:xiexiuqi@huawei.com 项目技术要求: * 掌握基本的C语言编程能力,有linux内核编程基础 * 了解内核进程调度 本题目要求对内核中CPU占有率的统计进行改进,减少误差,能尽量接近真实的CPU 占用率: * 基于 [openEuler 5.10](https://gitee.com/openeuler/kernel/tree/openEuler-21.03/) 内核 * 改进 top 显示的 CPU 占用率 * 改进 top 显示的 task 的CPU占用率 参考资料: * [fs/proc/stat.c](https://elixir.bootlin.com/linux/v5.10/source/fs/proc/stat.c) * [Documentation/filesystems/proc.rst](https://elixir.bootlin.com/linux/v5.10/source/Documentation/filesystems/proc.rst)
Linux 系统常用 top 来查看CPU的占用率和各Task的CPU占用率。TOP 显示的CPU占用率的数据来源是 /proc/stat 。/proc/stat 个数据字段的具体含义可以参考“Documentation/filesystems/proc.rst”中 “1.8 Miscellaneous kernel statistics in /proc/stat”。内核中该CPU占用率的统计是基于 cpu tick 来统计的,比如 1 个 tick 间隔是 4ms,当 tick 中断到来时,cpu 运行的是哪个task,就把整个 4ms 全部算到这个 task 上。这样统计简单,开销小,针对长时间运行的 task,误差也可以接受。但是如果针对频繁切换的 task,统计误差就会很大,甚至不可接受。 举个简单例子: ``` $ vim usleep.c #include <unistd.h> int main() { int i = 0; for (;;) { if (!(i++ % 10000)) usleep(1); } return 0; } $ gcc usleep.c -o usleep $ taskset -c 1 ./usleep # 使用 top 观察 CPU 1 的占有率和 usleep task 的CPU占用率。 ``` 难度:高 导师: @xiexiuqi 联系方式:xiexiuqi@huawei.com 项目技术要求: * 掌握基本的C语言编程能力,有linux内核编程基础 * 了解内核进程调度 本题目要求对内核中CPU占有率的统计进行改进,减少误差,能尽量接近真实的CPU 占用率: * 基于 [openEuler 5.10](https://gitee.com/openeuler/kernel/tree/openEuler-21.03/) 内核 * 改进 top 显示的 CPU 占用率 * 改进 top 显示的 task 的CPU占用率 参考资料: * [fs/proc/stat.c](https://elixir.bootlin.com/linux/v5.10/source/fs/proc/stat.c) * [Documentation/filesystems/proc.rst](https://elixir.bootlin.com/linux/v5.10/source/Documentation/filesystems/proc.rst)
Comments (
0
)
Sign in
to comment
Status
Backlog
Backlog
Doing
Done
Declined
Assignees
Not set
Labels
Not set
Projects
Unprojected
Unprojected
Milestones
No related milestones
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
Duration
(hours)
参与者(1)
1
https://gitee.com/summer-competition/summer-2021.git
git@gitee.com:summer-competition/summer-2021.git
summer-competition
summer-2021
Summer 2021
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register