In article <bjitbk$i36$1@nntp.qnx.com>, dagibbs@qnx.com says…
ed1k <> ed1k@humber.bay> > wrote:
In article <bhu4ir$79q$> 1@nntp.qnx.com> >, > dagibbs@qnx.com > says…
Hi David,
Could you share with us the algorithm of calculating that cycles_per_sec
entry during startup?
Its shipped with (at least) Momentics PE.
On a self-hosted system, take a look at:
/usr/src/bsp-6.2.1/libs/src/hardware/startup/lib/x86/set_cycles.c
If not self-hosted, prefix the above with $(QNX_TARGET), I think.
Thank you.
In fact, if you have a better algorithm for your system(s)…
No, I don’t. My algorithm isn’t better and definitely it isn’t for start-up. And my goal was just
check out what’s wrong with standard one (which is used now in QNX). Start-up time is better for
such a task as CPU speed measurement than the same measurement in working multi-task system, so your
algorithm should be better. But in fact, my algorithm gives me result much closer to result of other
benchmark tools…
Algorithm which I used has some advantages: it takes long time in order to get 100 (it could be
extended) measurements and make some statistical processing of result. Also it has a lot of
disanvatnages:
- it takes long time;
- it uses float point arithmetic;
- it has precission limitation of method. I use periodical interrupts to get state of CPU free-
running counter. That means, after RTC chip rise up an interrupt request, there is some time before
rdtsc instruction executed in ISR - interrupt latency. RTC interrupt isn’t high priority interrupt,
and generally speaking, interrupt latency could vary from time to time. That fact that I have so
small dispersion of results, indirectly says that interrupt latency in QNX doesn’t vary much (it’s
also good to know, though it doesn’t say this latency is small or big
)
you could
just build yourself a new startup, using your version of set_cycles.c
rather than the standard one, and all your machines will now have a
better value for cycles_per_sec.
Yes, I could. Why QSSL doesn’t want it too? Then all our machines (x86 at least) will have a better
value for cycles_per_sec. In file init_qtime.c, there is defined period of 8254 clock:
#define PC_CLOCK_RATE 838095345UL
And this is used to calculated another PC related constant, in set_cycles.c, when we need to know
how many ticks of 8254 are in 0.01s period. The problem is it’s calculated by integer arithmetic,
and result is 11933. I don’t understand why you need to calculate it rather than just
#define PC_TICKS_IN_10MS 11932
It looks like not a big error, big deal 11933 instead of 11932, but
11933 * 0.838095345 us = 10000.992 us, i.e. error is almost 1 us.
My slow CPU makes extra 347 cycles in that extra 0.992 us, and because we have to multiply result by
100 (we took 0.01s period but need cycles_per_sec) it is 34700 Hz difference. This is exactly what I
saw as offset error in my experiments.
For now,
systematic error (Hz) = Fcpu (MHz) * 99.2
so, the faster CPU the bigger error.
And it isn’t error because of hardware limitation.
Cheers,
Eduard