运行队列和优先级数组

  • The runqueue Data Structure

    The runqueue lists link the process descriptors of all runnable processes--that is, of those in a TASK_RUNNING state--except the swapper process (idle process).
    The runqueue data structure is the most important data structure of the Linux 2.6 scheduler. Each CPU in the system has its own runqueue; all runqueue structures are stored in the runqueues per-CPU variable.
    The this_rq( ) macro yields the address of the runqueue of the local CPU, while the cpu_rq(n) macro yields the address of the runqueue of the CPU having index n.
    宏this_rq()用来返回当前处理器的可执行队列的地址,宏cpu_rq(n)用来返回给定处理器可执行队列的指针。



The runqueue structure and the two sets of runnable processes

       runqueue
     |----------|
     |          |
     |          |
     |          |
     |----------|
+----| *active  |
|    |----------|
| +--| *expired |
| |  |----------|
| +->|          |<--> P                 priority 0
|    |          |        .
|    | array[0] |        .
|    |          |        .
|    |          |<--> P <--> P          priority 139
|    |----------|
+--->|          |<--> P <--> P <--> P   priority 0
     |          |        .
     | array[1] |        .
     |          |        .
     |          |<--> P <--> P          priority 139
     |----------|
     |          |
     |          |
     |          |
     |----------|
 

runqueue各个域的解释:

runqueue.timestamp_last_tick (unsigned long long)
    Timestamp value of the last timer interrupt
    最近一次定时器中断的时间戳的值

runqueue.active  (prio_array_t *)
runqueue.expired (prio_array_t *)
    The active field of the runqueue structure points to one of the two prio_array_t data structures in arrays: the corresponding set of runnable processes includes the active processes. Conversely, the expired field points to the other prio_array_t data structure in arrays: the corresponding set of runnable processes includes the expired processes.
    Periodically, the role of the two data structures in arrays changes: the active processes suddenly become the expired processes, and the expired processes become the active ones. To achieve this change, the scheduler simply exchanges the contents of the active and expired fields of the runqueue.

runqueue.nr_uninterruptible (unsigned long)
    Number of processes that were previously in the runqueue lists and are now sleeping in TASK_UNINTERRUPTIBLE state (only the sum of these fields across all runqueues is meaningful)
    先前在运行队列链表中而现在TASK_UNINTERRUPTIBLE状态下睡眠的进程的数量(所有运行队列的nr_uninterruptible域的总和才是有意义的)

runqueue.nr_running
    Number of runnable processes in the runqueue lists
    可运行队列中(runqueue)所有可运行进程的总和(包括活跃进程和过期进程)

runqueue.curr
    Process descriptor pointer of the currently running process (same as current for the local CPU)
  • The Priority Arrays
runqueue.arrays[0]

prio_array_t(prio_array) arrays[0]
|------------------------|
|unsigned int nr_active  |a counter of the processes included in the set
|------------------------|
|unsigned long bitmap[0] |a priority bitmap
|unsigned long bitmap[1] |
|unsigned long bitmap[2] |
|unsigned long bitmap[3] |
|unsigned long bitmap[4] |
|------------------------|
|list_head queue[0]      |<--> P            priority 0
|        .               |     .
|        .               |     .
|        .               |     .
|list_head queue[139]    |<--> P <--> P     priority 139
|------------------------|

priority bitmap

runqueue.array[0].bitmap[0]:
    The priority arrays also contain a priority bitmap used to efficiently discover the highest-priority runnable task in the system.
    Finding the highest priority task on the system is therefore only a matter of finding the first set bit in the bitmap. Because the number of priorities is static, the time to complete this search is constant and unaffected by the number of running processes on the system.
    查找系统中最高的优先级就变成了查找位图中被设置的第一位。因为优先级的个数是个定值,所以查找时间恒定,并不受系统到底有多少可执行进程的影响。
    Furthermore, each supported architecture in Linux implements a fast find first set algorithm to quickly search the bitmap. This method is called sched_find_first_bit(). Many architectures provide a find-first-set instruction that operates on a given word[4]. On these systems, finding the first set bit is as trivial as executing this instruction at most a couple of times.
    此外,Linux对它支持的每一种体系结构都提供了对应的快速查找算法,以保证对位图的快速查找,提供该功能的函数是sched_find_first_bit()。很多体系结构提供了find_first_set指令,这条指令对指定的字操作。在这些系统上,找到第一个设置位的时间顶多是执行这条指令(find-first-set)的两倍,可以说是微不足道。

[4] On the x86 architecture, this instruction is called bsfl. On PPC, cntlzw is used for this purpose.







 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值