Page 1 of 1
Disable just timer interrupt
Posted: Thu May 11, 2017 5:33 am
by maco
Hey there,
is there any chance to disable the timer interrupt only? I want to idle my cpus, until there is work for them. If I halt them (sure with enabled interrupts for wakeup), they will wake up on every timer interrupt.
Thank you
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 6:14 am
by iansjack
You can mask the interrupt in the PIC. But an OS that doesn't make use of timer interrupts seems like a bad idea.
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 6:17 am
by maco
Thanks! It's just while "sleeping". Are there other realizations for that?
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 7:01 am
by dozniak
maco wrote:Thanks! It's just while "sleeping". Are there other realizations for that?
You reprogram PIC to fire the timer exactly at the moment when you want to wake up.
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 7:12 am
by iansjack
If your timer routine does nothing, why worry? An occasional wakeup, followed by a long period of sleep, is hardly a problem. The proportion of time spent processing the interrupt will be minimal compared to the halt period.
I take it you are not doing any form of pre-emtive multitasking or maintaining a time-since-boot function (otherwise you certainly wouldn't want to disable timer interrupts).
I would have thought that at some point, as your OS becomes more functional, you will want to make use of the timer interrupt. Why not plan for it now rather than having to rewrite things in the future?
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 8:40 am
by maco
An occasional wakeup, followed by a long period of sleep, is hardly a problem
In what way?
I take it you are not doing any form of pre-emtive multitasking
I do, but sometimes, some processors have no work, so they could sleep, until they have. I want to save power with halting the cpus.
I would have thought that at some point, as your OS becomes more functional, you will want to make use of the timer interrupt.
You're right, I need the timer interrupt, but not on every cpu every time.
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 8:59 am
by iansjack
The question is not in what way is it not a problem, but in what way is it a problem.
For an interrupt routine to check whether there is work for a particular core to do takes just a few instructions. The time between timer ticks is enough for hundreds of thousands of instructions. The overhead of waking the core to check at each timer tick is negligible - probably far less of an impact than incorporating logic to disable the interrupt for the core and re-enable it.
But, if you still want to do this, doesn't the APIC allows you to route interrupts to a particular core?
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 9:33 am
by Boris
Your scheduler have to know when to be wake up.
It may be a quantum (ex 1ms) but if every task is sleeping on timer, you can program your pic to sleep not a quantum , but a whole sleep timer
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 3:06 pm
by onlyonemac
Boris wrote:if every task is sleeping on timer, you can program your pic to sleep not a quantum , but a whole sleep timer
...which is probably more trouble than it's worth, especially considering that this situation will only ever happen occasionally (if ever) and this is likely to introduce bugs into the scheduler.
Re: Disable just timer interrupt
Posted: Thu May 11, 2017 5:03 pm
by Muf
onlyonemac wrote:Boris wrote:if every task is sleeping on timer, you can program your pic to sleep not a quantum , but a whole sleep timer
...which is probably more trouble than it's worth, especially considering that this situation will only ever happen occasionally (if ever) and this is likely to introduce bugs into the scheduler.
This is called timer coalescing and all major OSes including Linux and Windows do it because of the gains in battery saving on mobile platforms. You program a one-shot timer for the shortest timer duration requested by all tasks combined and on wake-up you re-evaluate what the next shortest period should be and program another one-shot timer, etc.