perfstat_cpu Subroutine

Purpose

Retrieves individual logical processor usage statistics.

Library

perfstat library (libperfstat.a)

Syntax

#include <libperfstat.h>
int perfstat_cpu (name, userbuff, sizeof_struct, desired_number)
perfstat_id_t * name;
perfstat_cpu_t * userbuff;
size_t sizeof_struct;
int desired_number;

Description

The perfstat_cpu subroutine retrieves one or more individual processor usage statistics. The same function can be used to retrieve the number of available sets of logical processor statistics.

To get one or more sets of processor usage metrics, set the name parameter to the name of the first processor for which statistics are desired, and set the desired_number parameter. To start from the first processor, set the name parameter to "". The userbuff parameter must always point to a memory area big enough to contain the desired number of perfstat_cpu_t structures that will be copied by this function. Upon return, the name parameter will be set to either the name of the next processor, or to "" after all structures have been copied.

To retrieve the number of available sets of processor usage metrics, set the name and userbuff parameters to NULL, and the desired_number parameter to 0. The returned value will be the number of available sets.

This number represents the number of logical processors for which statistics are available. In a dynamic logical partitioning (DLPAR) environment, this number is the highest logical index of an online processor since the last reboot. See the Perfstat API article in Performance Tools and APIs Technical Reference for more information on the perfstat_cpu subroutine and DLPAR.

The SPLPAR environments virtualize physical processors. To help accurately measure the resource use in a virtualized environment, the POWER5 family of processors implements a register PURR (Processor Utilization Resource Register) for each core. The PURR is a 64-bit counter with the same units as the timebase register and tracks the real physical processor resource used on a per-thread or per-partition level. The PURR registers are not compatible with previous global counters (user, system, idle and wait fields) returned by the perfstat_cpu and the perfstat_cpu_total subroutines. All data consumers requiring processor utilization must be modified to support PURR-based computations as shown in the example for the perfstat_partition_total interface under Perfstat API programming.

This subroutine returns only global processor statistics inside a workload partition (WPAR).

Parameters

Item Description
name Contains either "", FIRST_CPU, or a name identifying the first logical processor for which statistics are desired. Logical processor names are:
cpu0, cpu1,...
To provide binary compatibility with previous versions of the library, names like proc0, proc1, ... will still be accepted. These names will be treated as if their corresponding cpuN name was used, but the names returned in the structures will always be names starting with cpu.
userbuff Points to the memory area that is to be filled with one or more perfstat_cpu_t structures.
sizeof_struct Specifies the size of the perfstat_cpu_t structure: sizeof(perfstat_cpu_t).
desired_number Specifies the number of perfstat_cpu_t structures to copy to userbuff.

Return Values

Unless the perfstat_cpu subroutine is used to retrieve the number of available structures, the number of structures filled is returned upon successful completion. If unsuccessful, a value of -1 is returned and the errno global variable is set.

Error Codes

The perfstat_cpu subroutine is unsuccessful if the following is true:

Item Description
EINVAL One of the parameters is not valid.

Files

The libperfstat.h file defines standard macros, data types, and subroutines.