-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
fix priority inversion bug of mutex. #3647
Conversation
fix priority inversion bug of mutex. |
其它OS是否有类似处理机制? |
以下描述基于最新版UCOSIII和LiteOS:
UCOSIII参考下面3个接口实现:
LiteOS参考下面2个接口实现:
|
此时才需要对要唤醒的任务进行优先级调整,也就是说只有同时满足下面4个条件时,才会进行优先级调整:
|
@tmmdh 学习了,ID是我微信,希望能够和你交流。 |
@BernardXiong 这个问题还有人跟进吗? |
在看,这里涉及到内核的PR会慢些。另外,不知道是否可以提供测试用的测试用例? |
提交的文件中有一个\examples\kernel\mutex_priority.c用例,可以用该用例进行测试,可以在qemu-vexpress-a9中模拟测试的,具体步骤如下:
|
@BernardXiong 两个月了,还有进展吗? |
引入了新的问题,建议删除第 2 条与第 3 条。本身 mutex 的优先级与当前线程 ready 优先级没有关系,只需要保持 mutex suspend 的最高优先级即可。以下两种情形,按照以上修改均会出现优先级翻转: 1.如果当前系统线程 ready 最高优先级为 idle 线程 ,那么一个线程 take 到 mutex 之后,创建了一个比当前线程更高优先级的线程,但比 mutex suspend 线程中的最高优先级要低,导致这个线程依然无法有效运行,一样是优先级翻转,没有做好保护。 2.优先级为 0 的控制线程 take 到了该 mutex,而 mutex 中还 suspend 测试线程优先级为254,253,252,.....,系统中 ready 比较线程优先级分别为0, 1, 0x7f。
|
我这边没什么问题 |
Please fix the conflicting file. |
|
@Guozhanxin Could you please test it? |
@BernardXiong, @KyleChenjh, @Guozhanxin |
围观大佬 |
这个PR看起来确实没什么问题了,之前在忙4.x和3.x的新版本发布,把这份PR给漏了,抱歉了😥 我们的小伙伴也是今天刚处理完新版本的事情:https://github.com/RT-Thread/rt-thread/pull/4248。 明天就帮你测试下,没问题的话,应该就可以合并了。 |
非常抱歉,这个pr很重要,前段时间给忙忘了,现在就帮你测试并给出结果。😥😥 |
@tmmdh 你好,该pr已经测试过,没有问题,只是使用上有个建议,就是在使用 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmmdh 非常抱歉,该pr还需要再解决冲突。
@KyleChenjh 冲突文件已处理,请关注! |
拉取/合并请求描述:(PR description)
[
当存在多个不同优先级的任务同时在申请互斥锁的时候,低优先级的任务在释放了互斥锁后,从该互斥锁的suspend链表上取出一个进程并唤醒执行,此时被唤醒的进程没有进行优先级调整,如果此时系统中存在一个不需要使用该互斥锁的中间优先级的任务,这将造成这个中间优先级的任务比该互斥锁的suspend链表上的高优先级的任务先执行,也就是优先级翻转错误,影响操作系统的实时性;
为了解决该问题,我们在唤醒该互斥锁的suspend链表上的每一个任务时,都应该对被唤醒的任务的优先级进行调整,使之始终与该互斥锁的suspend链表上的所有任务的优先级的最高的优先级保持一致;
该修改项已在qemu-vexpress-a9上完成测试;
]
以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use web browser to visit PR, and check items one by one, and ticked them if no problem.
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0
代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up