Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎯 Sync smart & scheduler codes #8537

Merged
merged 7 commits into from
Feb 23, 2024

Conversation

polarvid
Copy link
Contributor

@polarvid polarvid commented Feb 18, 2024

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

[

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

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

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

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 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 polarvid force-pushed the shell/sched-dev branch 5 times, most recently from 67fdcbb to 00bb5b9 Compare February 18, 2024 10:28
include/rtdef.h Outdated Show resolved Hide resolved
include/rtdef.h Outdated Show resolved Hide resolved
@Guozhanxin
Copy link
Member

改动这么大,是不是有些测试结果给出来,是不是确实优化了,性能提高了多少😂

@BernardXiong BernardXiong changed the title Sync smart & scheduler codes 🎯 Sync smart & scheduler codes Feb 19, 2024
@polarvid polarvid force-pushed the shell/sched-dev branch 3 times, most recently from bbac067 to 8519468 Compare February 19, 2024 09:18
src/ipc.c Outdated Show resolved Hide resolved
src/kservice.c Show resolved Hide resolved
components/drivers/ipc/dataqueue.c Outdated Show resolved Hide resolved
include/rtdef.h Show resolved Hide resolved
@mysterywolf mysterywolf linked an issue Feb 20, 2024 that may be closed by this pull request
Copy link
Member

@mysterywolf mysterywolf left a comment

Choose a reason for hiding this comment

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

我阻塞一下合入按钮,这个准备好了麻烦让我review一下

@polarvid
Copy link
Contributor Author

polarvid commented Feb 20, 2024

新增 UTEST 集

测试项目 配置 状态 (patch 后) 状态 (patch 前)
scheduler.mtx qemu aa64, RT_USING_SMP, RT_CPUS_NR=4 PASSED 内核崩溃
scheduler.mtx qemu a9, RT_USING_SMP, RT_CPUS_NR=2 PASSED 内核死锁
scheduler.mtx qemu a9, RT_USING_SMP, RT_CPUS_NR=1 PASSED
scheduler.mtx qemu rv64, RT_CPUS_NR=1 PASSED
scheduler.mtx rt-spark PASSED
scheduler.mtx rpi4b 64 PASSED
scheduler.sem qemu aa64, RT_USING_SMP, RT_CPUS_NR=4 PASSED
scheduler.sem qemu a9, RT_USING_SMP, RT_CPUS_NR=2 PASSED
scheduler.sem qemu a9, RT_USING_SMP, RT_CPUS_NR=1 PASSED
scheduler.sem qemu a9, RT_CPUS_NR=1 PASSED
scheduler.sem qemu rv64, RT_CPUS_NR=1 PASSED
scheduler.sem rt-spark PASSED
scheduler.sem rpi4b 64 PASSED
scheduler.timed_mtx qemu aa64, RT_USING_SMP, RT_CPUS_NR=4 PASSED 内核崩溃
scheduler.timed_mtx qemu a9, RT_USING_SMP, RT_CPUS_NR=2 PASSED 内核死锁
scheduler.timed_mtx qemu a9, RT_USING_SMP, RT_CPUS_NR=1 PASSED
scheduler.timed_mtx qemu rv64, RT_CPUS_NR=1 PASSED
scheduler.timed_mtx rt-spark PASSED
scheduler.timed_mtx rpi4b 64 PASSED
scheduler.timed_sem qemu aa64, RT_USING_SMP, RT_CPUS_NR=4 PASSED
scheduler.timed_sem qemu a9, RT_USING_SMP, RT_CPUS_NR=2 PASSED
scheduler.timed_sem qemu a9, RT_USING_SMP, RT_CPUS_NR=1 PASSED
scheduler.timed_sem qemu rv64, RT_CPUS_NR=1 PASSED
scheduler.timed_sem rt-spark PASSED
scheduler.timed_sem rpi4b 64 PASSED
scheduler.thread qemu aa64, RT_USING_SMP, RT_CPUS_NR=4 PASSED
scheduler.thread qemu a9, RT_USING_SMP, RT_CPUS_NR=2 PASSED
scheduler.thread qemu a9, RT_USING_SMP, RT_CPUS_NR=1 PASSED
scheduler.thread qemu rv64, RT_CPUS_NR=1 PASSED
scheduler.thread rt-spark PASSED
scheduler.thread rpi4b 64 PASSED

@mysterywolf
Copy link
Member

麻烦基于最新基线重新rebase一下 并通过CI

src/kservice.c Outdated Show resolved Hide resolved
src/scheduler_comm.c Outdated Show resolved Hide resolved
components/libc/compilers/common/include/sys/time.h Outdated Show resolved Hide resolved
src/cpu.c Show resolved Hide resolved
polarvid and others added 2 commits February 22, 2024 14:24
Add Support for ~FUTEX_PRIVATE, and futex requeue and futex pi feature.

Co-authored-by: xqyjlj <[email protected]>
Signed-off-by: Shell <[email protected]>
In the previous implementation, each call will create a new timer object
for the process. But according to the manual, the itimer is a singleton
object per-process.

This un-compatible semantic will corrupt the API by a call to cancel
previous setup timer.

Signed-off-by: Shell <[email protected]>
This patch adds an abstraction layer of scheduler(rt_sched). Following
features are added:

- The scheduler class (rt_sched) is added for rtthread source and ipc
  primitives. Critical region of scheduler is also redesigned to
  simplify the synchronization and acquire better performance.
- Support nested lock/unlock detection for scheduler
- Suspended thread and completed status tracking of rt_completion is
  modified for smaller footprint and easier locking.
- Add suspend list - A basic building block for IPC primitives which
  interacts with scheduler directly. Its API is similar to a FIFO list.
  This new object simplify the synchronization between IPC primitives
  and asynchronization event like timeout, signals. And it fixed the
  data racing commonly found on IPC objects currently.
- add RT_TIMER_FLAG_THREAD_TIMER as new type of rt_timer for rt_thread,
  so the timer is notified to do the necessary co-op with scheduler, as
  the legacy semantics required.

Besides, following bugs are fixed:

- _scheduler_get_highest_priority_thread() may access an empty list, and
  cause the codes to corrupt.
- rt_thread_control(RT_THREAD_CTRL_CHANGE_PRIORITY) has data racing with
  scheduler codes, by the leaving of the critical region for a while
  which corrupts the data coherency of ready queue.
- data racing on rt_completion.
- in rt_timer_check(): rt_hw_cpu_id() should be called with IRQ masked.
- fixup of mutex_delete(). While mutex owner did not release the mutex
  but delete it after taken, the prio inheritance algorithm may cause
  the owner thread to lose its original priority. This patch fix this
  issue by adding a thread priority restore on rt_mutex_delete()/
  rt_mutex_detach() API.
- For qemu-vexpress-a9, fixup boot-up failure while RT_CPUS_NR is config
  as 1.

Signed-off-by: Shell <[email protected]>
@polarvid polarvid marked this pull request as ready for review February 23, 2024 01:32
Copy link
Member

@mysterywolf mysterywolf left a comment

Choose a reason for hiding this comment

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

我关心的问题已经都解决。


int main(void)
{
printf("Hello RT-Thread!\n");
rt_kprintf("Hello RT-Thread!\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

现在内核里用printf和rt_kprintf的讲究是啥?

Copy link
Member

Choose a reason for hiding this comment

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

尽量用rt_kprintf吧 这个只是编程习惯~ printf里边乱七八糟一堆东西不可控

Copy link
Contributor Author

@polarvid polarvid Feb 23, 2024

Choose a reason for hiding this comment

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

musl 工具链会串到 stdio 那个地方,然后跑飞了。总之内核态还是不要用用户态的 print 为好,两边实现思路都不一样。

Copy link
Member

Choose a reason for hiding this comment

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

如果是我 我也不用printf,这玩意完全依赖第三方libc。

Copy link
Member

Choose a reason for hiding this comment

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

后面mlibc需要提上日程了,smart最终还得依赖于mlibc的

Copy link
Contributor Author

Choose a reason for hiding this comment

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

现在还有个头文件的问题。仓库里面不同的 BSP 用的工具链自带的头文件,因为跨架构,有些甚至是直接拿的 x86 Linux ,存在很多不兼容的定义。比如 time.h 里面的 struct timeval

RT_ASSERT(_dfs_page_insert(aspace, page) == 0);
if (_dfs_page_insert(aspace, page))
{
RT_ASSERT(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

不如将RT_ASSERT在不开debug的选项的时候让他求表达式,例如:

#define RT_ASSERT(EX)                                                         \
do { \
     rt_base_t val; \
     val = (exp); \
} while (0)

因为ASSERT是对值进行断言,如果调用者使用了复合表达式,那应该要执行他的符合表达式。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个变量不使用的话,编译器还是可以优化掉的吧

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
Member

Choose a reason for hiding this comment

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

还是建议不要在ASSERT内写太复杂的计算,而更多是判断。所以,最好也用不ASSERT的方式编译过代码,运行过代码。

未来也可以加入,RT_ASSERT_RET(condition, ret)的方式来处理condition不满足时应该返回,跳出函数的处理。

Copy link
Member

@mysterywolf mysterywolf Feb 23, 2024

Choose a reason for hiding this comment

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

RT_ASSERT_RET(condition, ret) 好建议~ 我创建了一个issue 后续可以处理 #8553

include/rtsched.h Outdated Show resolved Hide resolved
src/SConscript Outdated Show resolved Hide resolved
@polarvid
Copy link
Contributor Author

polarvid commented Feb 23, 2024

改动这么大,是不是有些测试结果给出来,是不是确实优化了,性能提高了多少😂

这个 PR 主要是功能修复和 smart 的 IPC 研发分支同步。功能在 qemu aa64, a9, rv64 以及星火一号,rpi4b 64 平台上面测试过所有的内核 UTEST。新加入的 UTEST 结果参考 #8537 (comment)

性能方面,在 arm64 多核平台下测试,PR 前后 cyclictest 的 MIN/AVG 指标分别有 42.31%/41.94% 的优化,MAX 降低了 50.77%。iperf 带宽抖动明显减小,多核性能和单核性能基本一致。

@BernardXiong BernardXiong merged commit 71560ba into RT-Thread:master Feb 23, 2024
41 checks passed
@polarvid polarvid deleted the shell/sched-dev branch February 23, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SMP下中断与互斥锁同时使用存在死锁的场景
5 participants