Reading CPU clock speed

I am writing an application where I need the CPU clock speed, I tried the qnx_osinfo() but the this doesen’t give a valid speed with modern processors.

Can anyone help me with getting the clock speed from elsewhere, the BIOS or … ???

Thanks.

Have you looked at the source code for SPIN (you can find it under “WebLinks” section? Maybe it can give you some ideas.
By the way, are you on qnx4 or qnx6?

We are running QNX 4.25.

What is SPIN ? I am VERY green in the QNX area… There are tons of utilities under dos and windows who can detect the processor type, any ideas to how that is done ?

From the docs for qnx_osinfo():

long unsigned cpu_features 
cpu_features & 0xFFF gives the CPU speed, in Mhz. 

but as you mentioned, it may not work for the modern processors. when 4.5 GHz CPUs come on the scene they will show up as 500 MHz.
don’t know if QSSL will fix it, or maybe it is time for you to upgrade to qnx6.

the other place to look is the cycles_per_sec in the timesel.

Code like:

#include <sys/osinfo.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <i86.h>

void main()
{
  struct _osinfo osinfo;
  struct _timesel far *ts;
  long unsigned cycles_per_sec;

  qnx_osinfo( 0, &osinfo );

  ts = MK_FP( osinfo.timesel, 0 );

  cycles_per_sec = ts->cycles_per_sec;

  printf("speed is %d Mhz\n", osinfo.cpu_features & 0xFFF );
  printf("cycles is %d\n", cycles_per_sec );
}

But, that is an unsigned long, so it will also wrap around 4G speed.
So, it doesn't help much either.

First, I must get a new view of what a modern processor is… the fastest we are running are K6’s at 500MHz. :unamused:

the other place to look is the cycles_per_sec in the timesel.

WOW That was just what i was looking for… I actually got a reading of 501 MHz, thanks alot…

But, that is an unsigned long, so it will also wrap around 4G speed.
So, it doesn’t help much either.

I don’t think we will be using processors above 4GHz in near future, the next base system will be based on a PIII @ 750 MHz… the current system has just been upgraded from PI @ 133 to this K6 @ 500 after 6-7 years of service.

BTW… osinfo.cpu gave me 12759 and osinfo.cpu_features gave me 1104 on that K6 processor. These values seemed a little off, even when AND’ed with 0xFFF.