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。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM