2012-10-03 28 views
1

我想了解處理器產生內核代碼的機會並執行維護和調節工作時的中斷機制。我所知道的是定時器中斷爲操作系統提供了這個功能。scheduler_tick - 從Linux在哪裏調用?

1)我想知道什麼是相關的中斷號,以及在Linux中調用的第一個OS例程。如果我知道這個文件和函數的名字會很好。

在Linux的情況下,scheduler_tick是爲調度新任務而調用的內核函數,但未知的是誰調用了scheduler_tick及其父項?

2)是否還有其他中斷以及在Linux中調用scheduler_tick?他們有哪些,如果有的話?

/* 
    This function gets called by the timer code, with HZ frequency. 
    We call it with interrupts disabled. 
*/ 

void scheduler_tick(void) 
{ 
     int cpu = smp_processor_id(); 
     struct rq *rq = cpu_rq(cpu); 
     struct task_struct *curr = rq->curr; 
....... 
+0

也許來自定時器中斷?我不確定。 :) – Raj

+1

是的,它是從計時器中斷 - 但是,是唯一的來源?我看到它被多個函數調用,但不知道根是否只有定時器中斷。 –

回答

6

這很簡單,當你有機會獲得交叉引用(X-REF)源代碼瀏覽器來回答。

點擊這裏:http://lxr.linux.no/#linux+v3.6.3/kernel/sched/core.c#L3214獲得一個Linux Kernel在線x-ref項目。 (這一個不會x-ref彙編代碼。)

此鏈接轉到scheduler_tick函數定義。點擊函數名稱,然後在右側的新面板中選擇「函數原型或聲明」行後面的「使用...」鏈接。過了一段時間,其中提到該功能的所有代碼都會被列出:

include/linux/sched.h, line 309 << declaration 
kernel/sched/core.c, line 3214 << definition 
kernel/timer.c, line 1373  << calling 

所以,timer.c中:1373 http://lxr.linux.no/#linux+v3.6.3/kernel/timer.c#L1373update_process_times功能的一部分:

1355 /* 
1356 * Called from the timer interrupt handler to charge one tick to the current 
1357 * process. user_tick is 1 if the tick is user time, 0 for system. 
1358 */ 
1359 void update_process_times(int user_tick) 

此功能從定時器中斷處理程序只可贖回;它應該在每次打勾時被調用。

重複交叉引用搜索update_process_times拿到名單的過程:

References: 
arch/alpha/kernel/smp.c, line 520 
arch/arm/kernel/time.c, line 108 
arch/cris/arch-v10/kernel/time.c, line 171 
arch/cris/arch-v32/kernel/time.c, line 206 
arch/h8300/kernel/time.c, line 40 
arch/ia64/kernel/time.c, line 184 
arch/m68k/kernel/time.c, line 38 
arch/parisc/kernel/time.c, line 163 
include/linux/sched.h, line 308 
kernel/time/tick-sched.c, line 683 
kernel/time/tick-sched.c, line 841 

相關的中斷號

中斷號是(有時他們在啓動時即使分配依賴於平臺)。你沒有說你是什麼平臺,感興趣的

2)是否有任何其他的中斷,以及其稱之爲scheduler_tick在Linux呢?他們有哪些,如果有的話?

有幾個定時器的實現,包括hrtimers(高分辨率定時器,這可能不同於通常的系統定時器)。每個實現可能使用不同的中斷。