Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title CPU Speed and features from osinfo.h
Ref. No. QNX.000008031
Category(ies) Development
Issue We would like to get a rough estimate of the processor clock speed of our host processor.  In the qnx_osinfo structure there are two fields may be useful for this purpose, cpu_speed and cpu_features.

cpu_speed reports numbers that we do not know the basis of.  On our 200MHz Pentium it reports 24438.  What are the units of this number?

cpu_features is not mentioned in the QNX documentation. For the 200Mhz Pentium it reports 199.  For our 166MHz Pentium
it reports 166.  If the units on this number is MHz, then this looks like the field for us to use.  What is the intended use of the cpu_features field?


Solution The bottom 12 bits out of the 16 in the osinfo.cpu_features flag variable represent CPU speed in MHZ.  Note that a speed of 200 actually is 199.  The number is accurate for Intel 386,486,586,686 CPUs. osinfo.cpu_features is calculated by executing 'aam' instructions in a loop until a certain timer quantum expires.  This is then scaled by the execution time of aam on each class of processor.  We have no scale values for non-intel processors for QNX4.

The cpu_speed variable in the osinfo structure is the result of running a AAD instruction for a predetermined length of time and then adjusting the "speed" reading based on the

Cpu_speed is a historical calculation based upon the execution of:
l1:
        push eax
        push edx
        mov eax,0
        mov edx,0
        mov eax,ecx
        mov edx,ebx
        add eax,ebx
        pop edx
        pop eax
        sub eax,1
        jnz l1

The timer is set for 50ms then 'synchronize with timer interrupt'
qtime.nsec = 0;
for (i=0; qtime.nsec != 50000000; i++)
        loop(6);
osinfo.cpu_speed = i/8;

So cpu_speed is 3/80ths of the number of iterations of the assembly code shown above in one second.  Not quite arbitrary, but it tracks relative cpu performance.

Download 'os_info.tgz' from the Contributed Software section of our website, in the directory qnx4/os/utils/misc.  It's a system monitoring program that makes use of most of the os_info structure variables.