HP Virtual Server Environment: Tips for Application Developers

traditional HP-UX scheduling. Additional cores allocated to these applications will be assigned a
portion of the work, increasing the overall throughput of the application.
How many cores, right now?
For applications that need to know the core count, the first thing to determine is the number of cores
available “right now”. An application can determine the number of available cores by using the
mpctl() call (see mpctl(2) for additional details). For backward compatibility reasons, this call uses the
term “SPU” to refer to LCPUs (Logical CPUs, ie one per hardware thread per core). If LCPUs are not
enabled, an SPU is equivalent to a core. This call can report the number of cores or LCPUs, either in
the application’s current pset or in the whole OS. Here is an example of a program that determines
the total number of active cores and LCPUs:
#include <sys/mpctl.h>
#include <stdio.h>
main() {
int lcpus_in_pset, lcpus_in_OS, cores_in_pset, cores_in_OS;
lcpus_in_pset = mpctl(MPC_GETNUMSPUS,0,0);
lcpus_in_OS = mpctl(MPC_GETNUMSPUS_SYS,0,0);
cores_in_pset = mpctl(MPC_GETNUMCORES,0,0);
cores_in_OS = mpctl(MPC_GETNUMCORES_SYS,0,0);
printf("LCPUs currently in this pset=%d\n", lcpus_in_pset);
printf("LCPUs currently in this OS=%d\n", lcpus_in_OS);
printf("Cores currently in this pset=%d\n", cores_in_pset);
printf("Cores currently in this OS=%d\n", cores_in_OS);
}
For a more complete example on how to use this call, see the Appendix.
Note that on systems without HyperThreads, and in psets with HyperThreads disabled (the default for
all psets on 11i v3), the number of LCPUs and the number of cores will be the same.
How many cores, maximum?
Sometimes it is important for an application not only to determine the number of active cores or
LCPUs, but the maximum number of cores or LCPUs that can be active. This allows the application to
initialize itself properly by pre-allocating core or LCPU data using the maximum number of cores or
LCPUs that can be made available in the partition. Here is an example of a program that determines
the maximum number of cores and LCPUs in a partition. For additional information, consult the
pstat(2) manpage:
#ifndef _PSTAT64
#define _PSTAT64
#endif
#include <sys/pstat.h>
main() {
struct pst_dynamic buf;
int max_cores, max_lcpus;
/* get lots of config data from the kernel */
pstat_getdynamic(&buf, sizeof(buf), 1, 0);
max_cores = buf.psd_max_cores;