简体   繁体   English

我不明白优先级反转如何发生

[英]I cannot understand how priority inversion can occur

HPT -> Highest Priority Task. HPT->最高优先级任务。
MPT -> Medium Priority Task MPT->中优先级任务
LPT -> Low Priority Task LPT->低优先级任务

Hello Friend, I read priority inversion from many websites (eg http://www.embeddedheaven.com/priority-inversion-2.htm ). 朋友你好,我从许多网站(例如http://www.embeddedheaven.com/priority-inversion-2.htm )上阅读了优先级倒置。 But I would like to know, why HPT can not preempt LPT? 但是我想知道,为什么HPT不能抢占LPT? If you will read the section 3.3 Unbounded Inversion, It says if LPT has acquired the resource, same time if HPT is ready but blocked because of LPT. 如果您将阅读第3.3节“无界倒置”,则说明LPT是否已获取资源,如果HPT已准备好但由于LPT而被阻塞,则同时显示。 But if MPT is ready then it preempts the LPT and executes itself. 但是,如果MPT准备就绪,则它将抢占LPT并自行执行。 Then LPT has to wait till MPT finishes. 然后LPT必须等到MPT完成。 Once MPT finishes then LPT resumes. 一旦MPT完成,则LPT恢复。 And once LPT finishes then HPT starts. 一旦LPT完成,则HPT开始。 So my question is why can't HPT preempt LPT or MPT? 所以我的问题是,为什么HPT不能抢占LPT或MPT?

The wikipedia explanation is perhaps a bit easier to understand than the link you provided: https://en.wikipedia.org/wiki/Priority_inversion Wikipedia的解释也许比您提供的链接更容易理解: https : //en.wikipedia.org/wiki/Priority_inversion

To answer your question in slightly different words, what happens roughly chronologically is 要用稍微不同的词回答您的问题,大致按时间顺序是

  1. LPT acquires R LPT收购R
  2. MPT becomes runnable, thus preempting LPT MPT变为可运行,因此抢占了LPT
  3. HPT becomes runnable, thus preempting MPT HPT可运行,因此抢占了MPT
  4. HPT tries to acquire R and blocks HPT尝试获取R和块
  5. Scheduler chooses the highest priority task which is runnable, that is MPT. 调度程序选择可运行的最高优先级任务,即MPT。
  6. MPT runs unbounded (potentially "forever"), thus preventing LPT from running and releasing R, and thus prevents HPT from running. MPT不受限制地运行(可能“永远”运行),从而阻止LPT运行并释放R,从而阻止HPT运行。

Pre-empting (so that the task gets CPU time) is not enough, if the lower-priority task also holds some exclusive resource. 如果优先级较低的任务拥有一些独占资源,则抢占(以便任务获得CPU时间)是不够的。 Then the higher-priority task will just try to acquire the resource (by locking a mutex, for instance) which will block it until the lower-priority task is done with the resource. 然后,较高优先级的任务将仅尝试获取资源(例如,通过锁定互斥锁),该资源将阻塞该资源,直到对资源进行较低优先级的任务为止。

Thus, the higher-prio task ends up blocked (not running) while the lower-prio task gets to run. 因此,较高优先级的任务最终被阻塞(未运行),而较低优先级的任务开始运行。

Priority inversion is a form of indefinite postponement of preemptive executives with shared resources. 优先级倒置是指拥有共享资源的先发高管无限期推迟的一种形式。

Priority inversion occurs when a high priority tasks requests access to shared resource which is currently allocated to low priority task. 当高优先级任务请求访问当前分配给低优先级任务的共享资源时,就会发生优先级倒置。 The high priority task must be blocked until the low priority task releases the resource. 必须阻止高优先级任务,直到低优先级任务释放资源。

This problem becomes complex when the low priority task is prevented from executing by one or more medium priority tasks. 当低优先级任务被一个或多个中优先级任务阻止执行时,此问题变得复杂。 Because the low priority task is not executing, it cannot complete its interaction with the resource and release that resource. 因为低优先级任务没有执行,所以它无法完成与资源的交互并释放该资源。 Hence, the high priority task is effectively prevented from executing by lower priority tasks. 因此,通过低优先级任务有效地防止了高优先级任务执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM