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

[bug][kernel][ipc][mutex]只有在PRIO策略下进行优先级继承 #4771

Closed
wants to merge 2 commits into from
Closed

[bug][kernel][ipc][mutex]只有在PRIO策略下进行优先级继承 #4771

wants to merge 2 commits into from

Conversation

mysterywolf
Copy link
Member

@mysterywolf mysterywolf commented Jun 7, 2021

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

[
FIFO策略即FCFS调度为非实时调度算法,因此无需考虑实时调度法中考虑的无界优先级反转问题。
]

以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.

当前拉取/合并请求的状态 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
  • 本拉取/合并符合RT-Thread代码规范 This PR complies with RT-Thread code specification

@mysterywolf mysterywolf requested a review from KyleChenjh June 7, 2021 09:12
@mysterywolf mysterywolf changed the title [kernel][ipc][mutex]只有在PRIO策略下进行优先级继承 [bug][kernel][ipc][mutex]只有在PRIO策略下进行优先级继承 Jun 7, 2021
if (thread->current_priority < mutex->owner->current_priority)
/* priority inheritance */
if (thread->current_priority < mutex->owner->current_priority
&& mutex->parent.parent.flag == RT_IPC_FLAG_PRIO)
Copy link
Member

Choose a reason for hiding this comment

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

如果改了这个,如果软件包或者客户代码里用fifo的方式做了互斥,也就退化成了信号量了,没有了防止优先级反转的特效,下次release版本需要强调这个API的改动了。

Copy link
Member

@Guozhanxin Guozhanxin Jun 13, 2021

Choose a reason for hiding this comment

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

优先级反转,之前指的好像不是获取同一个资源排队的问题,指的是一个线程1在获取的资源A之后再去获取资源B,其中A是以互斥量的形式获取的。因此如果此时有更高优先级的线程2来获取A,那么此时就要提高线程1的优先级,保证它不会被低优先级的打断,可以及时释放资源A。

所以我又有了疑惑,因为我们之前的文档说明“mutex具有防止优先级反转的作用”,指的应该就是这个优先级继承的机制,和其内部的排队机制应该是无关的。但是,FIFO的排队机制本身就会导致优先级被反转……

而且revert掉之前的一个pr之后,FIFO下的优先级继承本来就是假的了,没有起到防止优先级反转的作用。所以以后,mutex只有以Pro的形式创建才具有防止优先级反转的功能。。。所以FIFO在mutex里存在的意义是什么?

Copy link
Member Author

Choose a reason for hiding this comment

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

刚才我计算了一下,在FIFO处理所谓“优先级反转”的问题,根本无法防止优先级反转,因为防止优先级反转的先决条件就是等待列表按照PRIO排序才可以。

@Guozhanxin Guozhanxin added the discussion This PR/issue needs to be discussed later label Jun 18, 2021
@mysterywolf mysterywolf marked this pull request as draft July 1, 2021 13:28
@mysterywolf mysterywolf marked this pull request as ready for review July 2, 2021 05:15
@mysterywolf mysterywolf closed this Jul 6, 2021
@mysterywolf mysterywolf deleted the mutexinvert branch July 6, 2021 04:17
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.

2 participants