uClinux進(jìn)程調(diào)度器的實(shí)現(xiàn)分析
(4)當(dāng)喚醒一個(gè)睡眠進(jìn)程時(shí),發(fā)現(xiàn)被喚醒的進(jìn)程比當(dāng)前進(jìn)程優(yōu)先級(jí)更高。www.51kaifa.com
(5)一個(gè)進(jìn)程通過執(zhí)行系統(tǒng)調(diào)用來改變調(diào)度策略或降低自身的優(yōu)先級(jí),從而引起調(diào)度。
4 Schedule調(diào)度程序核心部分源代碼分析[3]
該調(diào)度程序的目標(biāo)是選擇下一個(gè)要執(zhí)行的進(jìn)程:首先對(duì)所有進(jìn)程進(jìn)行檢測(cè),喚醒任何一個(gè)得到信號(hào)的進(jìn)程,即改變進(jìn)程的state屬性;然后根據(jù)時(shí)間片和優(yōu)先級(jí)調(diào)度機(jī)制來計(jì)算處于就緒隊(duì)列中每個(gè)進(jìn)程的綜合優(yōu)先級(jí),其計(jì)算方法由goodness( )函數(shù)實(shí)現(xiàn);接著選擇綜合優(yōu)先級(jí)最高的進(jìn)程作為隨后要執(zhí)行的進(jìn)程,若就緒隊(duì)列中沒有可調(diào)度的,則重新分配時(shí)間片,即改變進(jìn)程的counter屬性值,并利用switch_to( )函數(shù)進(jìn)行進(jìn)程切換。
asmlinkage void schedule(void){
struct schedule_data * sched_data;
/*描述進(jìn)程的數(shù)據(jù)結(jié)構(gòu),
包含指向所運(yùn)行CPU的屬性。*/
struct task_struct *prev, *next, *p;
struct list_head *tmp;
int this_cpu, c;
spin_lock_prefetch(runqueue_lock);
need_resched_back:
prev = current;
this_cpu = prev->processor;
if (unlikely(in_interrupt())) {
/*判斷是否在中斷服務(wù)程序中*/
printk("Scheduling in interruptn"); www.51kaifa.com
/*是的話則打印錯(cuò)誤提示,退出調(diào)度器*/
BUG();
}
release_kernel_lock(prev, this_cpu); /*釋放全局內(nèi)核鎖和全局中斷鎖*/
sched_data=aligned_data[this_cpu].schedule_data;
if (unlikely(prev->policy == SCHED_RR))
if (!prev->counter) {
prev->counter= NICE_TO_TICKS(prev->nice);
move_last_runqueue(prev);
}
switch (prev->state) {
case TASK_INTERRUPTIBLE:
/*此狀態(tài)表明進(jìn)程可以被信號(hào)中斷*/
if (signal_pending(prev)) {
/*如果該進(jìn)程有未處理的信號(hào)*/
prev->state= TASK_RUNNING; break;
}
default:
del_from_runqueue(prev);
case TASK_RUNNING:;
}
prev->need_resched = 0;
repeat_schedule: /*缺省選擇空閑進(jìn)程*/
next = idle_task(this_cpu);
c = -1000;
list_for_each(tmp, runqueue_head) {
p = list_entry(tmp, struct task_struct, run_list);
if (can_schedule(p, this_cpu)) {
/*尋找優(yōu)先級(jí)最高的那個(gè)進(jìn)程*/
int weight=
goodness(p, this_cpu, prev->active_mm);
if (weight > c)
c = weight, next = p;
}
}
評(píng)論