Re: fixed time slices?
- From: "m" <m@xxx>
- Date: Tue, 26 Jun 2007 10:13:56 -0400
See Inline:
"Jan Bruns" <testzugang_janbruns@xxxxxxxx> wrote in message
news:467ff475$0$6392$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"m" <m@xxx>:
"Jan Bruns":
What I meant with reliability was, if I can count on that the minimum
time a sleep(n) might take is really (n+m+k) ms, where m is the least
valid value passed to timeBeginPeriod(m) and k is some oberhead
value less than m.
No; assuming no clock skew, the minimum duration of Sleep(n) is (n + (n %
m)
+ k)
By (n % m) yu mean the remainder of n/m?
yes - modulus of n and m
That's clear. But it also says:
| If a higher-priority thread becomes available to run, the system
| ceases to execute the lower-priority thread (without allowing it
| to finish using its time slice), and assigns a full time slice
| to the higher-priority thread.
The key here is that a thread becomes ready to run. A thread can only
become ready to run, and be scheduled on a CPU, when the scheduler is
running and decides that it is ready to run. The scheduler only runs in
response to a timer interrupt or a call to a wait function (maybe other
kernel entry points also), so the precision of pre-emption timing is
always
bounded by the system timer frequency (by the case, on a UP machine,
where
the running thread executes all user mode code for its entire time
slice).
But the scheduler would also have the chance to let the hardware generate
a timer-IRQ within wahtevr delay is desired. So it could put the CPU on
a ready low-priority thread for as long as a higher priority thread is
known to be unrunnable.
In old MS-DOS days, the precision of the programmable intervall timer
(an extra chip for this purpose?) AFAIR was better then 1/10MHz. At
least it was possible to sync it to a screen's scanline
(60Hz*480scanlines)=28800Hz -> timer resolution better than 35e-6 s.
AFAIK the scheduler does not behave this way but if the scheduler planed a
timer interrupt for a specific delay for the purpose of changing tasks
pre-emptivly, then that is just the end of the low-priority thread's time
slice. In this case, the scheduler would not detect that a higher priority
thread was ready to run, but would _know_ that said thread would be ready to
run and adjusted the time slices of other threads accordingly.
This example only makes sense in the case of simple Sleep(n) calls because
the scheduler can only _know_ when a thread will become ready to run if
there is a fixed or known delay. Since even the relatively simple call
SleepEx(n, true) does not have a fixed or known delay, the scheduler cannot
make any assumptions about how best to optimize the timer interrupts.
Combine this complexity with thousands of threads using tens of thousands of
wait objects in much more complex ways than sleep (like WFMO and Semaphores,
GQCS & IOCP, or Timer Queues) and it is easy to see why a fixed timer
interrupt interval would be the implementation of choice.
Maybe I should have said a noticeable performance cost to increasing
the timer frequency.
Not on my computer. I've tried this using a CPU-intensive working
process, and another high priority process, that effectively does
nothing but sleep(2) (measured).
The working process slowed down about 2%. 500 sleep instructions,
each resulting in about 4 CPU-task switches -> 2000 Task-swithes
per second might really eat 2% of CPU, when the intermediate
sheduler-task also takes some overhead. That's fully in the
range I expected.
A 2% decrease in throughput can be considered significant.
PROCEDURE bute_force_sleep(ms : dword);
This depends on how frequently you would need to use bute_force_sleep.
It's near to always*somwhat_lesser.
Given that you are planning a standalone application, I doubt you will
have
a problem either way. As long as you know that you don't play nice in
the
sandbox, you can do whatever you like ;)
#(o;
Gruss
Jan Bruns
.
- Follow-Ups:
- Re: fixed time slices?
- From: Alexander Grigoriev
- Re: fixed time slices?
- From: Jan Bruns
- Re: fixed time slices?
- References:
- fixed time slices?
- From: Jan Bruns
- Re: fixed time slices?
- From: Don Burn
- Re: fixed time slices?
- From: m
- Re: fixed time slices?
- From: Jan Bruns
- Re: fixed time slices?
- From: Jan Bruns
- Re: fixed time slices?
- From: m
- Re: fixed time slices?
- From: Jan Bruns
- Re: fixed time slices?
- From: m
- Re: fixed time slices?
- From: Jan Bruns
- fixed time slices?
- Prev by Date: Re: Non-blocking version of ReadConsole?
- Next by Date: Re: fixed time slices?
- Previous by thread: Re: fixed time slices?
- Next by thread: Re: fixed time slices?
- Index(es):
Relevant Pages
|