Reputation: 2304
I want to understand the interrupt mechanism when a processor yields a chance to kernel code and to perform maintenance and regulation work. What I know is that timer interrupt provides this facility to OS.
1) What I want to know what exactly is the related interrupt number and what is the first OS routine that gets called in case of Linux. Will be good if I get to know the file and function name for this.
In case of Linux, scheduler_tick is the kernel function that is called to schedule new tasks, however what is unknown is who calls scheduler_tick and its parent(s)?
2) Are there any other interrupts as well which call scheduler_tick in Linux ? Which ones are they, if any at all?
/*
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;
.......
Upvotes: 2
Views: 7081
Reputation: 94465
This is easy to answer when you have access to cross-reference (x-ref) source browser.
Click here: http://lxr.linux.no/#linux+v3.6.3/kernel/sched/core.c#L3214 to get one online x-ref project of Linux Kernel. (This one will not x-ref assembler code.)
This link goes to scheduler_tick
function definition. Click on the function name, then in new panel at right select after the line "Function prototype or declaration" link "usage...". After some time all code which mentions this function will be listed:
include/linux/sched.h, line 309 << declaration
kernel/sched/core.c, line 3214 << definition
kernel/timer.c, line 1373 << calling
So, timer.c: 1373 http://lxr.linux.no/#linux+v3.6.3/kernel/timer.c#L1373 is part of update_process_times
function:
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)
This function is only callable from timer interrupt handler; it should be called at every tick.
Repeat cross-reference search process for update_process_times
to get list:
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
related interrupt number
Interrupt numbers are platform-dependent (and sometimes they are even assigned at boot time). You didn't say what platform you are interested in.
2) Are there any other interrupts as well which call scheduler_tick in Linux ? Which ones are they, if any at all?
There are several timer implementations, including hrtimers (high-resolution timer, this can be different from usual system timer). Each implementation may use different interrupt.
Upvotes: 8