【问题标题】:How can a Linux shared object detect if it is being executed on a standard or real time kernel?Linux 共享对象如何检测它是在标准内核还是实时内核上执行的?
【发布时间】:2021-07-03 10:51:16
【问题描述】:

我想知道某段 C 代码是否允许共享对象“检测”它是在标准还是在实时 Linux 平台上执行(以便采取行动因此)。我不是要求进行一些微妙的实时能力测试,而是要求更像简单地检查调度程序是否被“标记”为实时(比如信任“自动声明”类型的调度程序,如果有意义的话)。

感谢您的帮助。

【问题讨论】:

  • grep 'PREEMPT ' /boot/config-$(uname -r)

标签: linux kernel real-time scheduler detect


【解决方案1】:

您的问题询问对象如何检测“它是在标准平台上还是在实时平台上执行”。我认为这与它也有点模棱两可的要求不同,即调度程序是否被“标记”为实时的。平台(第一)部分询问实时抢占补丁是否已应用于内核并在内核中启用;调度程序类(第二个)部分可以应用于任何具有 SCHED_RR 和/或 SCHED_FIFO 类可用的 Linux 系统。所以

    1. Real-time platform answer:
        Look for the existence of the node /sys/kernel/realtime, available in
the real-time preemption patch since 2011 (PATCH 293/295).  If it exists, you
are running on a CONFIG_PREEMPT_RT patched kernel.  The current Linux 5.x
patch may be found at http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.10/.
    
    2. Real-time scheduled on current thread answer:
        An explanation and working example are given on the
pthread_getschedparam(3) man page.  The C program example there allows
you to determine if a thread in your process is currently scheduled
with either the SCHED_RR or SCHED_FIFO policies.

【讨论】:

    猜你喜欢
    • 2014-04-26
    • 2014-01-28
    • 1970-01-01
    • 2022-12-11
    • 2022-11-17
    • 1970-01-01
    • 2017-08-07
    • 2012-11-30
    • 2012-08-01
    相关资源
    最近更新 更多