How to find processor frequency

Hello ,

Please tell me how to find processor frequency in HP UNIX .

This bit of perl magic should do it (answer in Mhz):

#!/usr/contrib/bin/perl

    local($PSTAT, $PSTAT_PROCESSOR) = (239, 10);        # pstat_getprocessor
    local($struct_pst_processor) = ("L30");
    local($cpu_info, $cpu_ticks);

    $cpu_info = "\0" x 120;
    syscall($PSTAT, $PSTAT_PROCESSOR, $cpu_info, length($cpu_info), 1, 0);

    ($cpu_ticks) = (unpack($struct_pst_processor, $cpu_info))[26];

        print $cpu_ticks/10000 . "\n";

PxT:

When I tried that Perl script on my BSD boxes, all I got was a core file. I guess it only works on HP-UX?

FreeBSD:/home/joeuser/procspeed $ chmod +x procspeed.pl
FreeBSD:/home/joeuser/procspeed $ ./procspeed.pl
Bad system call (core dumped)
FreeBSD:/home/joeuser/procspeed $

So I went back to dmesg output and performed a case insensitive search for "MHz":

FreeBSD:/home/joeuser $ dmesg | grep -i "mhz"
CPU: AMD Duron(tm) processor (950.04-MHz 686-class CPU)

Just out of curiosity, does this work under HP-UX (I don't have access to a HP-UX box, only BSD boxes at the moment).

Yes it does. It is using HP's pstat system call which is unique to HP-UX. It won't work on other versions of unix.

As perderabo mentioned, this is hp-ux specific. HP's boot messages generally do not provide the Mhz information, so dmesg cannot be used. The provided perl code should work on any hp-ux machine.

Just another bit of information to tuck away until needed.

Thanks

Hi all,

There's a easier way to get CPU frequency on HP-UX 11 :
echo "itick_per_usec/D" | /usr/bin/adb -k /stand/vmunix /dev/mem

Cheers.

Interesting. That works on HP-UX 10.20 as well. itick_per_usec is a new one on me. I knew about itick_per_tick but you need to multiply that by hz and then divide by 1,000,000. itick_per_tick is really what the pstat system call is returning. Since hz has been 100 forever, PxT is effectively doing the same calculation.

Even though the variable you mention avoids the need for arithmetic, adb is doing a fair amount of work to extract that data (as it must to extract any data). pstat is a single system call. That is not a real big deal here, but in a program to, say, monitor free memory on a busy system, it can start to matter. Also using adb requires read permission on /dev/mem and there are security concerns in making all of /dev/mem available. pstat() can be invoked by a any user.

I have several korn scripts that use adb to extract data from the kernel. I am in the process of rewriting them in perl using pstat(). They are faster and I can run them without special privileges. The real problem I am encountering is that pstat() does not have everything. I have been able to get some more stuff with the sysinfo() call, but I still have not found everything. So some scripts may still need adb.

nm /stand/vmunix

lists all of the symbols defined in the kernel. But it doesn't tell you what they mean.

Even better:

HP-UX 11i Internals (Hewlett-Packard Professional Books)
by Chris Cooper, Chris Moore