Skip to content

Conversation

Dyyt587
Copy link
Contributor

@Dyyt587 Dyyt587 commented Apr 2, 2024

拉取/合并请求描述:(PR description)

为什么提交这份PR (why to submit this PR)

让rtthread支持线程cpu占用率统计

你的解决方案是什么 (what is your solution)

使用全局tick或者perfcounter组件获取全局时间,然后记录线程运行总时间,最后得到占用率

请提供验证的bsp和config (provide the config and bsp)

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@polarvid
Copy link
Contributor

polarvid commented Apr 2, 2024

@Dyyt587
Copy link
Contributor Author

Dyyt587 commented Apr 2, 2024

这个在软件包里也有一个实现呢 https://github.com/RT-Thread/packages/blob/2848549066ddf0c87e2c364d383618b6d2ff20b2/tools/cpu_usage/package.json

这个软件包只有总的cpu使用率,并且占用钩子函数

@polarvid
Copy link
Contributor

polarvid commented Apr 2, 2024

这个在软件包里也有一个实现呢 https://github.com/RT-Thread/packages/blob/2848549066ddf0c87e2c364d383618b6d2ff20b2/tools/cpu_usage/package.json

这个软件包只有总的cpu使用率,并且占用钩子函数

#8091 建议是有套独立的框架,兼顾到 SMP/UMP 的场景。用静态 HOOK 插入,而不是这样直接在调度器插入一大堆条件编译代码。否则维护者阅读代码会很累的。

HOOK 可以用 HOOKLIST 实现,无限制 hook 数量的。

rt_weak rt_uint64_t rt_thread_usage_get_now_time(void)
{
#ifdef PKG_USING_PERF_COUNTER
// #include <perf_counter.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请不要在提交中加入注释掉的代码。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是考虑软件包出处的结果,我会马上修改

@Dyyt587
Copy link
Contributor Author

Dyyt587 commented Apr 2, 2024

这个在软件包里也有一个实现呢 https://github.com/RT-Thread/packages/blob/2848549066ddf0c87e2c364d383618b6d2ff20b2/tools/cpu_usage/package.json

这个软件包只有总的cpu使用率,并且占用钩子函数

#8091 建议是有套独立的框架,兼顾到 SMP/UMP 的场景。用静态 HOOK 插入,而不是这样直接在调度器插入一大堆条件编译代码。否则维护者阅读代码会很累的。

HOOK 可以用 HOOKLIST 实现,无限制 hook 数量的。

目前代码考虑到调度器的时间占用排除,独立框架要实现可以通过添加hook接入点解决(预计多添加一个接入点),这样是否可行,同时对于兼顾到 SMP/UMP 的场景能否给与一些指点,对于多核场景,我不是太熟悉

@mysterywolf mysterywolf closed this Apr 2, 2024
@mysterywolf mysterywolf reopened this Apr 2, 2024
@BernardXiong
Copy link
Member

需要支持到多核的,否则没办法合入。或者也可以把软件包的合并到内核中来。

@BernardXiong BernardXiong added the discussion This PR/issue needs to be discussed later label Apr 3, 2024
@Dyyt587
Copy link
Contributor Author

Dyyt587 commented Apr 3, 2024

需要支持到多核的,否则没办法合入。或者也可以把软件包的合并到内核中来。

我正在学习多核兼容相关内容,预计很快会有更新

@mysterywolf mysterywolf marked this pull request as draft April 3, 2024 00:56
@Rbb666
Copy link
Member

Rbb666 commented Aug 30, 2025

#10644

@Rbb666 Rbb666 closed this Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion This PR/issue needs to be discussed later
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants