Run queue of FreeBsd

Data structure:
/*
 * Head of run queues.
 */
TAILQ_HEAD(rqhead, thread);

/*
 * Bit array which maintains the status of a run queue.  When a queue is
 * non-empty the bit corresponding to the queue number will be set.
 */
struct rqbits {
        rqb_word_t rqb_bits[RQB_LEN];
};

/*
 * Run queue structure.  Contains an array of run queues on which processes
 * are placed, and a structure to maintain the status of each queue.
 */
struct runq {
        struct  rqbits rq_status;
        struct  rqhead rq_queues[RQ_NQS];
};

Data macros and variables:
#define RQ_NQS          (64)            /* Number of run queues. */
#define RQ_PPQ          (4)             /* Priorities per queue. */

          for amd6:
#define RQB_LEN         (1)             /* Number of priority status words. */
#define RQB_L2BPW       (6)             /* Log2(sizeof(rqb_word_t) * NBBY)). */
#define RQB_BPW         (1<<RQB_L2BPW)  /* Bits in an rqb_word_t. */

#define RQB_BIT(pri)    (1ul << ((pri) & (RQB_BPW - 1)))
#define RQB_WORD(pri)   ((pri) >> RQB_L2BPW)

#define RQB_FFS(word)   (bsfq(word))

/*
 * Type of run queue status word.
 */
typedef u_int64_t       rqb_word_t;
        
          for arm:
#define RQB_LEN         (2)             /* Number of priority status words. */
#define RQB_L2BPW       (5)             /* Log2(sizeof(rqb_word_t) * NBBY)). */
#define RQB_BPW         (1<<RQB_L2BPW)  /* Bits in an rqb_word_t. */

#define RQB_BIT(pri)    (1 << ((pri) & (RQB_BPW - 1)))
#define RQB_WORD(pri)   ((pri) >> RQB_L2BPW)

#define RQB_FFS(word)   (ffs(word) - 1)

/*
 * Type of run queue status word.
 */
typedef u_int32_t       rqb_word_t;

for other arches ….


API functions:
void    runq_add(struct runq *, struct thread *, int);
void    runq_add_pri(struct runq *, struct thread *, u_char, int);
int     runq_check(struct runq *);
struct  thread *runq_choose(struct runq *);
struct  thread *runq_choose_from(struct runq *, u_char);
struct  thread *runq_choose_fuzz(struct runq *, int);
void    runq_init(struct runq *);
void    runq_remove(struct runq *, struct thread *);
void    runq_remove_idx(struct runq *, struct thread *, u_char *);


Summary:
Thread’s priority level is from 0 to 255. And there are only 64 queues. Then thread which priority level 0 to 3 are put into first queue and 4-7 are put into second queue and so on.

There are 64 status bits in rqb_bits to flag whether queue is empty.  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值