Linux struct sched_param 结构参数

原文出处:https://blog.csdn.net/weixin_38239856/article/details/82117600

----------------------

作用:

  • 描述调度参数的结构
#include <sched.h>

struct sched_param 
{ 
    int32_t  sched_priority; 
    int32_t  sched_curpriority; 
    union 
    { 
        int32_t  reserved[8]; 
        struct 
        {    
            int32_t  __ss_low_priority;  
            int32_t  __ss_max_repl;  
            struct timespec     __ss_repl_period;   
            struct timespec     __ss_init_budget;   
        }           __ss;   
    }           __ss_un;    
}

#define sched_ss_low_priority   __ss_un.__ss.__ss_low_priority
#define sched_ss_max_repl       __ss_un.__ss.__ss_max_repl
#define sched_ss_repl_period    __ss_un.__ss.__ss_repl_period
#define sched_ss_init_budget    __ss_un.__ss.__ss_init_budget

当获得或设置线程/进程的调度参数时,会使用sched_param结构;

使用下列函数获取调度参数
  • pthread_attr_getschedparam()
  • pthread_getschedparam()
  • sched_getparam()
  • SchedGet()
使用下列参数设置调度参数
  • pthread_attr_setschedparam()
  • pthread_setschedparam()
  • sched_setparam()
  • sched_setscheduler()
  • SchedSet()
  • ThreadCreate()
sched_param的成员包括
  • sched_priority
    • 当获得调度参数时,该成员反映出分配给线程或进程的优先级。它不反映任何由于优先级继承而造成的临时调整。
    • 当您设置调度参数时,请将此成员设置为您想要使用的优先级。优先级必须介于sched_get_priority_min()和sched_get_priority_max()为调度策略返回的最小值和最大值之间。
  • sched_curpriority
    • 当您获得调度参数时,该成员被设置为线程或进程当前运行的优先级。这是内核在做出调度决策时使用的值。
    • 当您设置调度参数时,该成员将被忽略。
  • sched_ss_low_priority
    • 正在执行的后台或低优先级线程
  • sched_ss_max_repl
    • 补给计划的最大次数,通常是由于阻塞操作。在一个线程多次阻塞之后,它会自动将其执行的剩余部分降至低优先级,直到其执行预算得到补充。
  • sched_ss_repl_period
    • The time that should be used for scheduling the replenishment of an execution budget after being blocked or having overrun the maximum number of replenishments. This time is used as an offset against the time that a thread is made READY.
  • sched_ss_init_budget
    • 应该用于线程执行预算的时间。当线程运行在其高优先级级别时,它的执行时间就从这个预算中划分出来了。一旦预算完全耗尽,线程就会降到低优先级,如果可能的话,由于优先级安排,线程可以继续运行,直到执行预算得到补充。
注意
    • sched_priority必须总是高于sched_ss_low_priority。
    • sched_ss_max_repl必须小于SS_REPL_MAX。
    • sched_ss_init_budget必须大于sched_ss_repl_period。
原文地址:https://www.cnblogs.com/debug-the-heart/p/13894765.html