火星探路者号当年到底发生了什么?优先级反转经典案例复盘Mars Pathfinder: What Really Happened?


AI free token/AI免费积分
火星探路者号当年到底发生了什么?优先级反转经典案例复盘

你可能听说过火星探路者号(Mars Pathfinder),这艘 NASA 着陆器与它的旅居者号(Sojourner)探测车在 1997 年登陆火星。起初一切正常,但几天后,着陆器开始出现一系列完全系统重置。一个看门狗定时器检测到问题并强制重启。[Vivek Bhageria] 最近的一篇文章深入研究了当时发生了什么以及最终的解决方案。

根本原因是优先级反转(priority inversion)。当低优先级任务持有高优先级任务所需的资源,从而阻止高优先级任务执行时,就会发生这种情况。本例中的操作系统是 VxWorks,但这在任何类型的优先级调度系统上都可能发生。

简化后的情形是:有两个任务各自使用同一个互斥锁,以避免相互踩踏。优先级最高的是一个数据分发任务,优先级最低的任务负责气象数据处理,还有一个中等优先级任务负责总线维护。

当低优先级任务拿到互斥锁、却在释放之前用完了自己的时间片时,故障就会发生。此时高优先级任务会发现自己拿不到互斥锁。而由于有中优先级任务在等待运行,低优先级任务又无法再次获得控制权。

实际上,高优先级任务正在等待一个只有在最低优先级任务得以运行后才可能变为可用的资源。这就是优先级反转。

遗憾的是,工程师在测试期间确实偶尔注意到这一现象,但就像我们常做的那样,他们把它归结为偶发故障。正如笔者一位老上司常说的:「如果你不知道它为什么发生,你就不知道它不会再次发生。」

当然,VxWorks 明白这种情况可能发生,幸运的是,航天器上有足够的能力为该互斥锁开启优先级继承。这让低优先级任务因为有更高优先级任务在等待它而获得临时提升。

更多细节可以阅读原文。我们在十年前也做过自己的分析。

本文来源:https://hackaday.com/2026/10/11/mars-pathfinder-what-really-happened/
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

The root cause was priority inversion. This happens when a lower-priority task holds a resource needed by a higher-priority task and prevents the higher-priority task from executing. In this case, the operating system was VxWorks, but this can happen on any kind of priority scheduling system.

The simplified version is that there were two tasks that each used the same mutex to avoid stepping on each other. The highest priority was a data distribution task. The lowest priority task dealt with meteorology data processing. There was also a medium-priority task that handled bus maintenance.

The failure would occur when the low-priority task had the mutex and lost its time slot before releasing it. The high-priority task would then find it couldn’t take the mutex. However, the low-priority task didn’t get control again because of the medium-priority tasks waiting to run.

In effect, the high-priority task was now waiting on something that couldn’t become available until the lowest-priority task was able to run. That’s priority inversion.

Mars Pathfinder: What Really Happened?

Sadly, engineers noticed this happening occasionally during testing but, as we are often prone to do, they chalked it up to glitches. As one of our old bosses used to say: “If you don’t know why it happened, then you don’t know that it won’t happen again.”

VxWorks, of course, understands that this might happen and, luckily, there was enough capability on the spacecraft to turn priority inheritance on for the mutex in question. This allows the low-priority task to get a boost because a higher-priority task is waiting on it.

You can read more about the details in the post. We also covered this a decade ago with our own analysis.

暂无评论,快来发表第一条评论吧!No comments yet. Be the first!

📮 需求咨询📮 Inquiry