Linux不遵守SCHED_FIFO优先级? (正常或GDB执行) [英] Linux not respecting SCHED_FIFO priority ? ( normal or GDB execution )

查看:183
本文介绍了Linux不遵守SCHED_FIFO优先级? (正常或GDB执行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR

似乎在多处理器/多核引擎上,可能会调度多个RT SCHED_FIFO线程一个以上的执行单元。因此,优先级为60的线程和优先级为40的线程可以同时在2个不同的内核上运行。

It seems that on multiprocessors/multicores engines, more than one RT SCHED_FIFO threads may be scheduled on more than one execution unit. So thread with priority 60 and thread with priority 40 may run simultaneously on 2 different cores.

这可能是违反直觉的,尤其是在模拟运行在依赖于单核处理器的嵌入式系统上时严格优先级执行。

This may be counter-intuitive, especially when simulating embedded systems that runs on single core processor that rely on strict priority execution.

对于仿真,您不能修改原始代码,但可以将仿真代码的执行限制在单个内核上(例如,任务集外壳cmd或sched_setaffinity(... ))

For simulation you can not modify the original code, but you can restrict the execution of the simulated code on a single core ( e.g. taskset shell cmd or sched_setaffinity(...))

原始问题描述

即使使用非常简单的代码,我仍然遇到困难通过调度策略SCHED_FIFO使Linux尊重我的线程的优先级。

I have difficulties even with very simple code to make Linux respect the priority of my threads with scheduling policy SCHED_FIFO.


  • 请参阅问题末尾的MCVE。

  • 请参见修改后的MCVE

这种情况是由于需要在Linux PC上模拟嵌入式代码以执行集成测试

This situation comes from the need to simulate an embedded code under a Linux PC in order to perform integration tests

具有fifo优先级 10 线程将启动线程除数比率

The main thread with fifo priority 10 will launch the thread divisor and ratio.

除数线程应该获得 priority 2 ,这样 ratio 线程和优先级1 不会在b得到一个合适的值之前对a / b进行求值(这仅是针对MCVE的完全假设的情况,而不是带有信号量或条件变量的实际情况)。

divisor thread should get priority 2 so that the ratio thread with priority 1 will not evaluate a/b before b gets a decent value ( this is a completely hypothetical scenario only for the MCVE, not a real life case with semaphores or condition variables ).

潜在的先决条件您需要是root 或更好地 setcap 该程序,以便可以更改计划策略并优先级

Potential Prerequiste: You need to be root or BETTER to setcap the program so that to can change the scheduling policy and priority

sudo setcap cap_sys_nice + ep main

johndoe@VirtualBox:~/Code/gdb_sched_fifo$ getcap main
main = cap_sys_nice+ep


查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆