Operating System - HP-UX
1834389 Members
2057 Online
110066 Solutions
New Discussion

Way to determine number of active processors programmatically

 
Gurudutt Kumar V J
Occasional Contributor

Way to determine number of active processors programmatically

I am working on implementing some statistics in my filesystem on a per-CPU basis. For this I need to know the current number of processors online. Please let me know the way to determine programmatically, in a DLKM, the current number of active processors.
9 REPLIES 9
Robert-Jan Goossens
Honored Contributor

Re: Way to determine number of active processors programmatically

Hi,

Have a look at the sysinfo tool from this page.

http://h20331.www2.hp.com/Hpsub/cache/286022-0-0-225-121.html?jumpid=reg_R1002_USEN

Regards,
Robert-Jan
Pete Randall
Outstanding Contributor

Re: Way to determine number of active processors programmatically

The simplest way of counting your processors is to use ioscan:

ioscan -k |grep -n processor |wc -l

This does not account for active/inactive processors, however. Can you explain what you mean by active processors?


Pete

Pete
Gurudutt Kumar V J
Occasional Contributor

Re: Way to determine number of active processors programmatically

I meant active processors as the number of processors/CPUs online. I implementing some per-CPU based statistics in my filesystem implemented on HP-UX. From my DLKM I need a way to find out the number of online processors, programmatically. The tools like sysinfo would not be of help to me. I found the ksysinfo structure with proc_cnt (number of active processors) in sys/sysinfo.h. Also I found the global variable processor_count in the symbol table of the kernel on HP-UX 11.31. I am not sure if this is the total number of processors on the system or the total number of online processors. Could you please let me know which is the legal way for a kernel extension to get the total number of processors online.
Don Morris_1
Honored Contributor

Re: Way to determine number of active processors programmatically

In a DLKM this will be a bit different from user space. What version(s) are you targeting? Are your per-cpu structures going to handle CPU OL* or at least iCOD/iCAP disabling?

If we're talking v3 or v2, then from the DDR you have wsio_get_processor_count(9F) and wsio_get_active_processor_count(9F). Those will give you the number of processors possible/configured (allowing for future OLA including Cell OLA on v3, so this is your high water mark) and the number currently active respectively.

Note that there's no guarantee that the active processors are _contiguous_ in cpu identifier number (and very often they aren't), so your algorithm needs to account for this. How you do that is up to you, of course -- but typically if the per-processor statistics are small you'd just allocate/initialize to the base (zero?) state for all processors and then only update statistics for processors which are doing work (and are hence active at some point in your sampling cycle). If your statistics areas are large, you will want to think of other ways [since the total number of processors on a small vPar with v3 reflects the possibility that the underlying nPar could get full OLA and all resources could be given to this vPar, and hence can be much larger than the actual number you'd typically use -- memory consumption must be considered for those cases].
Emil Velez
Honored Contributor

Re: Way to determine number of active processors programmatically


I found this code in a pthread code library

bind_threads()
{
pthread_spu_t answer, spu_nums[4], spu = (pthread_spu_t)-1;
int i, ret;

/* Get the ID of the first processor */
ret = pthread_processor_id_np(PTHREAD_GETFIRSTSPU_NP,
&answer, spu);
check_error(ret, "get_first_spu");
spu_nums[0] = answer;

/* Get the ID of the next 3 processors */
for (i = 1; i < 4; i++) {
spu = answer;
ret = pthread_processor_id_np(PTHREAD_GETNEXTSPU_NP,
&answer, spu);
if (ret == EINVAL)
break;
spu_nums[i] = answer;
}

/* Did we find four processors? Spread out the IDs if not. */
if (i == 2) { /* found two processors */
spu_nums[2] = spu_nums[0];
spu_nums[3] = spu_nums[1];
} else if (i == 3) { /* found three processors */
spu_nums[3] = spu_nums[0];
}

/* Bind each of threads if we have multiple processors. */
if (i > 1) {
for (i = 0; i < 4; i++) {
ret = pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
&answer, spu_nums[i],
threads[i]);
check_error(ret, "pthread_processor_bind_np()");
printf("Thread %d bound to processor %d\n", threads[i],
spu_nums[i]);
}
}

/* Rest of application here. */
}
Don Morris_1
Honored Contributor

Re: Way to determine number of active processors programmatically

Good for a moment, but there's nothing keeping a spu from going away right after you ask. That's why I favor the assume all spu's are potentially active and just run on / collect data from any that ran if it doesn't cause unreasonable memory bloat.
Gurudutt Kumar V J
Occasional Contributor

Re: Way to determine number of active processors programmatically

Hi,
Thank you very much for the responses. I am trying to work with the wsio interfaces that you suggested. I did not get enough documentation on the wsio interfaces. The HP-UX 11.31 development machine that I have access to does not seem to have the 9F man pages. Please let me know any other reference to the relevant documentation.
Laurent Menase
Honored Contributor

Re: Way to determine number of active processors programmatically

you have 2 kernel variables
int active_processor_count
int processor_count

be carefull in the kernel that the number of active cpus can raise dynamically upt to processor_count.
but better to use wsio functions


Don Morris_1
Honored Contributor

Re: Way to determine number of active processors programmatically

Definitely use the wsio interfaces as they're documented and hence supported. (Kernel globals can be changed).

The 9F man pages should be available in the DDK, I'd expect -- but if nothing else, go to the DSPP site (http://h21007.www2.hp.com/portal/site/dspp) join if you need to, and get the v3 Device Developer Reference (DDR) guide. That will have the man pages within the guide.