Belinda <yye@is2.dal.ca> wrote in article <afja4c$74p$1@inn.qnx.com>…
i cann’t make sense what it is said in the below. How does the system know
to choose 357 or 357 as integer divisor.
The kernel knows the frequency of oscillator in your system. It’s 1.1931816 MHz on all x86
platforms. You have to don’t care about frequencies and divisors. By kernel’s call (ClockPeriod)
you tell to the kernel “I want 300 us timeslice” (by appropriate field in _clockperiod structure
newtime). The kernel calculates that divisor and sees the divisor 357 is good, because when divisor
is 358 you’ll have the timeslice worse than 300 us. Then kernel sets hardware (puts divisor into
8254 hwrd timer) to have interrupt every 299.200456 us. You can read this value by call
ClockPeriod once more with NULL as newtime and empty structure oldtime, see actual timeslice in
nanosec in this oldtime structure.
And I want to make sure whether the
smallest value of ticksize in QNX 6.01 is 500us.
If you will try to setup 300 us or 499 us by ClockPeriod it will not take effect. The smallest
value in QNX 6.0 - 6.1A is 500 us, just try to setup smallest value to be sure.
Additionally, if I set a timer, and the interval time doens’t equal to
ticksize, such as a bigger value than ticksize, how does it impose upon the
system?
The timer and timeslice are different. The timeslice is the time precission of system. This is a
time unit for timers. It’s a smallest quantity of time for kernel. For instanse, the timeslice is
300 us and you set the timer for 1.3 sec. The kernel will creat internal variable for your timer
with the value
1300000 / 299.200456 = 4345. You see, the kernel knows and uses the actual timeslice. Kernel will
decrement this value every timer interrupt, and when the variable reaches 0, the kernel will
generate the event for your timer. So, you’ll get the timer’s event not early than the time of
timer (1.3 sec in example). It’s important, you can’t get time precission of timers better than
timeslice, and timer gets you the time more or equal to the required time in accordance with the
POSIX (read as “always more because there is timeslice in a system”).
If you will try to setup the timer for 300 us and in ideal system (there are not threads with
bigest priorities) you’ll get timer’s event during next 300-600 us. Setting the timer and hardware
time interrupts are asyncronously processes, so if you set the timer exactly after timer interrupt
you will get the worse precission: the time which you setted plus the mainly all time of timeslice
(it’s “dead” time for the kernel, kernel will wait for the next timer interrupt and from this first
timemark will calculate time for your timer). Don’t think “kernel will wait” - in reality it just
rounds the timer variable to biggest value ) (300 / 299.200456 = 2) Or, may be, just add 1, I
guess kernel guys should know.
I highly suggest you to buy Robert’s book. You’ll find many answers for your questions. Also there
are few good developers articles about time at qnx web site.
Cheers,
Eduard.
ed1k at ukr dot net
Thanks,
Belinda