我试图了解Linux内核的调度程序是如何工作的
正如此链接所示
http://books.google.co.in/books?id=NXVkcCjPblcC&lpg=PP1&pg=PA47#v=onepage&q&f=false以下链接http://www.informit.com/articles/article.aspx?p=101760&seqNum=2
struct runque是调度程序运行的基本数据结构
它是
struct runqueue {
spinlock_t lock; /* spin lock which protects this
runqueue */
unsigned long nr_running; /* number of runnable tasks */
unsigned long nr_switches; /* number of contextswitches */
unsigned long expired_timestamp; /* time of last array swap */
unsigned long nr_uninterruptible; /* number of tasks in
uinterruptible sleep */
struct task_struct *curr; /* this processor's currently
running task */
struct task_struct *idle; /* this processor's idle task */
struct mm_struct *prev_mm; /* mm_struct of last running task
*/
struct prio_array *active; /* pointer to the active priority
array */
struct prio_array *expired; /* pointer to the expired
priority array */
struct prio_array arrays[2]; /* the actual priority arrays */
int prev_cpu_load[NR_CPUS];/* load on each processor */
struct task_struct *migration_thread; /* the migration thread on this
processor */
struct list_head migration_queue; /* the migration queue for this
processor */
atomic_t nr_iowait; /* number of tasks waiting on I/O
*/
}
上面有两个成员
struct prio_array *active; /* pointer to the active priority
array */
struct prio_array *expired; /* pointer to the expired priority array */
和struct prio_array定义为
struct prio_array {
int nr_active; /* number of tasks */
unsigned long bitmap[BITMAP_SIZE]; /* priority bitmap */
struct list_head queue[MAX_PRIO]; /* priority queues */
};
我不清楚以下句子
Question 1)Each priority array contains one queue of runnable processors per priority level.
struct prio_array
where is the que of runnable processors 的上述定义中
然后它说
优先级数组还包含用于的优先级位图
有效地发现系统中优先级最高的可运行任务 .
然后它说“有140个优先级和32位字,这是五个 . ”
如何得出结论这是五个什么是它背后的数学计算?
以上是本书第4章的摘录,发表于第2个链接,均包含相同的文字 . 为了清楚起见,此处张贴在此处 .
- UPDATE1 *基于评论我只是想澄清一下我要求作者说的话
BITMAP_SIZE是无符号长类型变量数组必须为每个有效优先级提供一位的大小 . 有140个优先级和32位字,这是五个 .
Question 2)
我不清楚的是给出了每个优先级的一位,并且有140个优先级,那么数组大小如何变为5我没有得到BITMAP_SIZE计算的逻辑而不是140/32 = 5
它与以下段落有一些关系
When a task of a given priority becomes runnable (that is,
its state becomes TASK_RUNNING), the corresponding bit in the
bitmap is set to one. For example, if a task with priority seven is
runnable, then bit seven is set
在链接上哪个是数组
unsigned long bitmap[BITMAP_SIZE]; /* priority bitmap */
设置基本上我不清楚这个数组是如何设置的,如果我能够正确解释也可以看问题1 .
UPDATE 2 and explanation of answer below
下面的答案我只是添加一个小解释,如果他们基本上来到这里可能会对将来有所帮助
调度程序维护一个runque和runnable进程列表,每个runnable进程只有一个runqueue,我给它的链接的文章考虑了多处理器系统有很多运行问题,回到我们的情况,一个处理器和一个带有进程的runque各种优先级
每个优先级有140个优先级,在TASK_RUNNING状态下有不同的进程说例如可以有多个优先级为8的进程等等(我把8作为例子)struct runque指向优先级数组告诉
btimap[BITMAP] /* this is the priority level
struct list_head /* points to the start of list of processes of that run level
因此,runque指向优先级数组,并且从优先级数组中,您可以轻松获得需要在O(1)时间内执行的进程 .
1 回答
你在问如何在阵列中找到合适的位吗?
像这样的东西: