Re: pstat_getdynamic/pstat_getprocessor-Can these system calls be used for getting CPU usage on HP-U (524 Views)
Reply
Contributor
PrasannaKumari
Posts: 22
Registered: ‎09-09-2008
Message 1 of 4 (684 Views)

pstat_getdynamic/pstat_getprocessor-Can these system calls be used for getting CPU usage on HP-UX

Hi,

  We are using the following piece of code for getting the processor utilization details on HP-UX systems.

 

<code>

 

 struct pst_processor pstat_buffer[MAX_PROCESSORS];
        struct pst_dynamic pstat_dyn;
        int nproc,id;
        printf("In main class\n");

        if(pstat_getdynamic(&pstat_dyn, sizeof(struct pst_dynamic),1,0) == -1)
        {
            printf("pstat_getdynamic failed");
        }


        nproc = pstat_dyn.psd_proc_cnt;
        printf("nproc = %d\n", nproc);
        if (nproc > MAX_PROCESSORS)
        {
              nproc = MAX_PROCESSORS;
        }

         if(pstat_getprocessor(pstat_buffer,sizeof(struct pst_processor), nproc, 0) == -1)
         {
              printf("pstat_getprocessor failed");
         }

        for (id=0; nproc>0; ++id)
         {

                printf("id = %d \n",id);

 

                printf("CP_USER %d\n",pstat_buffer[id].psp_cpu_time[CP_USER]);

 

                printf("CP_SYS %d \n",pstat_buffer[id].psp_cpu_time[CP_SYS]);


                printf("CP_WAIT %d \n ",pstat_buffer[id].psp_cpu_time[CP_WAIT]);


                printf("CP_IDLE %d\n",pstat_buffer[id].psp_cpu_time[CP_IDLE] );

                nproc--;
        }
        printf("Returning 0");

        return 0;

 

</code>

 

We are seeing that the above code returns zero values for some of the processors while the top command shows non zero values for processor utilization for the same set of processors. There is one more observation that the above peice of code returns usage values for all processors on a system if they are numbered with IDs that are consecutive similar to 0,1, 2 , 3..... . However, the same piece of code returns zero values for some of the processors when their IDs are numbered in the following manner - 0, 2, 4, 6 etc.

 

 

Can some one please let me know if this is a known issue? Also, I would like to know if processor utlization can be collected using other system calls?

 

Acclaimed Contributor
Dennis Handly
Posts: 25,277
Registered: ‎03-06-2006
Message 2 of 4 (675 Views)

Re: pstat_getdynamic/pstat_getprocessor-Can these calls be used for getting CPU usage on HP-UX

What HP-UX version?

Do you have the correct number of processors from your code?  What does machinfo(1) show?

Is it confusing hyperthreads?

Occasional Visitor
pfhwjd0
Posts: 1
Registered: ‎03-19-2014
Message 3 of 4 (533 Views)

Re: pstat_getdynamic/pstat_getprocessor-Can these system calls be used for getting CPU usage on HP-U

Was there any solution to this reqeust for even numbered processors when using the function pstat_getprocessor()?

 

Is there a os patch that resolved the issue?

Acclaimed Contributor
Dennis Handly
Posts: 25,277
Registered: ‎03-06-2006
Message 4 of 4 (524 Views)

Re: pstat_getdynamic/pstat_getprocessor-Can these system calls be used for getting CPU usage on HP-U

[ Edited ]

Why do you think there is a problem?  Rewriting the program correctly, I get this info:

getprocessor returned: 4
id     = 0 lid    = 0 sockid = 0, coreid = 0, thrdid = 0
...
id     = 1 lid    = 1 sockid = 0, coreid = 0, thrdid = 1
id     = 2 lid    = 2 sockid = 0, coreid = 2, thrdid = 0
id     = 3 lid    = 3 sockid = 0, coreid = 2, thrdid = 1
Last idx: 4
getprocessor returned: 4
id     = 4 lid    = 4 sockid = 3, coreid = 4, thrdid = 0
id     = 5 lid    = 5 sockid = 3, coreid = 4, thrdid = 1
id     = 6 lid    = 6 sockid = 3, coreid = 6, thrdid = 0
id     = 7 lid    = 7 sockid = 3, coreid = 6, thrdid = 1
Last idx: 8

So the reason the odd logical _id times are 0, is that hyperthreading is turned off.

So Example 2 in pstat(2) is wrong.

(I'm not sure why the socket ID jumps from 0 to 3 but perhaps more sockets could be added to this rx2660?)

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.