Kernel code interrupted by Timer

Peter Teoh htmldeveloper at gmail.com
Sat Feb 9 03:34:50 EST 2013


On Sat, Feb 9, 2013 at 4:20 PM, Peter Teoh <htmldeveloper at gmail.com> wrote:

>
>
> On Sat, Feb 9, 2013 at 3:51 PM, anish kumar <anish198519851985 at gmail.com>wrote:
>
>> On Sat, 2013-02-09 at 14:57 +0800, Peter Teoh wrote:
>> >
>> >
>> > On Sat, Feb 9, 2013 at 1:47 PM, anish kumar
>> > .
>> >         Timer interrupts is supposed to cause scheduling and scheduler
>> >         may or
>> >         may not pick up your last process(we always use the term
>> >         "task" in
>> >         kernel space) after handling timer interrupt.
>> >         >
>> >
>> >
>> >
>> > Sorry if I may disagree, correct me if wrong.   Timer interrupt and
>> > scheduler is two different thing.   I just counted in the "drivers"
>> > subdirectory, there are at least more than 200 places where
>> > "setup_timer()" is called, and these have nothing to do with
>> > scheduling.   For eg, heartbeat operation etc.  Not sure I
>> > misunderstood something?
>> Have a look at kernel/timer.c and kernel/hrtimer.c.
>> There are many sched() calls in these files.This will invoke scheduler.
>> >
>>
>
> kernel/timer.c and kernel/hrtimer.c are implementing the logic outside of
> timer interrupt context, ie, it is NOT executed in timer interrupt context,
> but in bottom half context.   the real timer interrupt context is done in
> arch-specific branch:  arch/x86/kernel/tsc.c, for example, and the entire
> tsc.c has no scheduling concept in it.   the entire file tsc.c in fact is
> handling all the hardware-specific stuff - in the top-half context.
>

one mistake here:  kernel/timer.c is running in bottom half interrupt
context, which is still in interrupt context/mode.    but as I glanced
through the entire kernel/timer.c, there is no task scheduling called
anywhere in this file.   it is doing timer scheduling in fact.   whereas
the context switching we were discussing, that necessitate consistent state
maintenance, is done in task scheduling (inside kernel/sched.c).   of
course sometimes timer interrupt will trigger task scheduling logic
sometime, but it is not always......not sure if my statement is correct?
(no time to search the source, please pardon me).


>
> in linux kernel scheduling is done in two ways:  voluntary and involuntary
> scheduling.   involuntary scheduling means it is triggered by timer
> interrupt.   but voluntary scheduling (which is only recently introduced
> into kernel for performance reasons) drastically improve the latency
> numbers.    voluntary scheduling is NOT triggered by timer, but ANYONE who
> want to give up the CPU can call sched_cpu() to do a rescheduling.
>
> hope i am not wrong.....
>
>
>> >
>> > --
>> > Regards,
>> > Peter Teoh
>>
>>
>>
>
>
> --
> Regards,
> Peter Teoh




-- 
Regards,
Peter Teoh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130209/f2752690/attachment.html 


More information about the Kernelnewbies mailing list