1 /*
   2  * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 // Encapsulates the libperfstat library.
  26 //
  27 // The purpose of this code is to dynamically load the libperfstat library
  28 // instead of statically linking against it. The libperfstat library is an
  29 // AIX-specific library which only exists on AIX, not on PASE. If I want to
  30 // share binaries between AIX and PASE, I cannot directly link against libperfstat.so.
  31 
  32 #ifndef OS_AIX_VM_LIBPERFSTAT_AIX_HPP
  33 #define OS_AIX_VM_LIBPERFSTAT_AIX_HPP
  34 
  35 #include <sys/types.h>
  36 #include <stdlib.h>
  37 
  38 ///////////////////////////////////////////////////////////////////////////////////////////////
  39 // These are excerpts from the AIX 5.3, 6.1, 7.1 libperfstat.h -
  40 // this is all we need from libperfstat.h and I want to avoid having to include <libperfstat.h>
  41 //
  42 // Note: I define all structures as if I were to include libperfstat.h on an AIX 5.2
  43 // build machine.
  44 //
  45 // The ratio behind that is that if I would build on an AIX 5.2 build machine,
  46 // include libperfstat.h and hard-link against libperfstat.a, the program should
  47 // work without recompilation on all newer AIX versions.
  48 //
  49 
  50 #define IDENTIFIER_LENGTH 64    /* length of strings included in the structures */
  51 
  52 
  53 typedef struct { /* structure element identifier */
  54   char name[IDENTIFIER_LENGTH]; /* name of the identifier */
  55 } perfstat_id_t;
  56 
  57 #define CEC_ID_LEN 40           /* CEC identifier length */
  58 #define MAXCORRALNAMELEN 25     /* length of the wpar name */
  59 #define FIRST_WPARNAME ""       /* pseudo-name for the first WPAR */
  60 #define FIRST_WPARID -1         /* pseudo-id for the first WPAR */
  61 
  62 typedef unsigned short cid_t;   /* workload partition identifier */
  63 
  64 typedef struct { /* Virtual memory utilization */
  65   u_longlong_t virt_total;    /* total virtual memory (in 4KB pages) */
  66   u_longlong_t real_total;    /* total real memory (in 4KB pages) */
  67   u_longlong_t real_free;     /* free real memory (in 4KB pages) */
  68   u_longlong_t real_pinned;   /* real memory which is pinned (in 4KB pages) */
  69   u_longlong_t real_inuse;    /* real memory which is in use (in 4KB pages) */
  70   u_longlong_t pgbad;         /* number of bad pages */
  71   u_longlong_t pgexct;        /* number of page faults */
  72   u_longlong_t pgins;         /* number of pages paged in */
  73   u_longlong_t pgouts;        /* number of pages paged out */
  74   u_longlong_t pgspins;       /* number of page ins from paging space */
  75   u_longlong_t pgspouts;      /* number of page outs from paging space */
  76   u_longlong_t scans;         /* number of page scans by clock */
  77   u_longlong_t cycles;        /* number of page replacement cycles */
  78   u_longlong_t pgsteals;      /* number of page steals */
  79   u_longlong_t numperm;       /* number of frames used for files (in 4KB pages) */
  80   u_longlong_t pgsp_total;    /* total paging space (in 4KB pages) */
  81   u_longlong_t pgsp_free;     /* free paging space (in 4KB pages) */
  82   u_longlong_t pgsp_rsvd;     /* reserved paging space (in 4KB pages) */
  83   u_longlong_t real_system;   /* real memory used by system segments (in 4KB pages). This is the sum of all the used pages in segment marked for system usage.
  84                                * Since segment classifications are not always guaranteed to be accurate, this number is only an approximation. */
  85   u_longlong_t real_user;     /* real memory used by non-system segments (in 4KB pages). This is the sum of all pages used in segments not marked for system usage.
  86                                * Since segment classifications are not always guaranteed to be accurate, this number is only an approximation. */
  87   u_longlong_t real_process;  /* real memory used by process segments (in 4KB pages). This is real_total-real_free-numperm-real_system. Since real_system is an
  88                                * approximation, this number is too. */
  89   u_longlong_t virt_active;   /* Active virtual pages. Virtual pages are considered active if they have been accessed */
  90 
  91 } perfstat_memory_total_t;
  92 
  93 typedef struct { /* global cpu information AIX 5.3 < TL10 */
  94   int ncpus;                            /* number of active logical processors */
  95   int ncpus_cfg;                        /* number of configured processors */
  96   char description[IDENTIFIER_LENGTH];  /* processor description (type/official name) */
  97   u_longlong_t processorHZ;             /* processor speed in Hz */
  98   u_longlong_t user;                    /* raw total number of clock ticks spent in user mode */
  99   u_longlong_t sys;                     /* raw total number of clock ticks spent in system mode */
 100   u_longlong_t idle;                    /* raw total number of clock ticks spent idle */
 101   u_longlong_t wait;                    /* raw total number of clock ticks spent waiting for I/O */
 102   u_longlong_t pswitch;                 /* number of process switches (change in currently running process) */
 103   u_longlong_t syscall;                 /* number of system calls executed */
 104   u_longlong_t sysread;                 /* number of read system calls executed */
 105   u_longlong_t syswrite;                /* number of write system calls executed */
 106   u_longlong_t sysfork;                 /* number of forks system calls executed */
 107   u_longlong_t sysexec;                 /* number of execs system calls executed */
 108   u_longlong_t readch;                  /* number of characters tranferred with read system call */
 109   u_longlong_t writech;                 /* number of characters tranferred with write system call */
 110   u_longlong_t devintrs;                /* number of device interrupts */
 111   u_longlong_t softintrs;               /* number of software interrupts */
 112   time_t lbolt;                         /* number of ticks since last reboot */
 113   u_longlong_t loadavg[3];              /* (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes.
 114                                                * To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>. */
 115   u_longlong_t runque;                  /* length of the run queue (processes ready) */
 116   u_longlong_t swpque;                  /* ength of the swap queue (processes waiting to be paged in) */
 117   u_longlong_t bread;                   /* number of blocks read */
 118   u_longlong_t bwrite;                  /* number of blocks written */
 119   u_longlong_t lread;                   /* number of logical read requests */
 120   u_longlong_t lwrite;                  /* number of logical write requests */
 121   u_longlong_t phread;                  /* number of physical reads (reads on raw devices) */
 122   u_longlong_t phwrite;                 /* number of physical writes (writes on raw devices) */
 123   u_longlong_t runocc;                  /* updated whenever runque is updated, i.e. the runqueue is occupied.
 124                                                * This can be used to compute the simple average of ready processes  */
 125   u_longlong_t swpocc;                  /* updated whenever swpque is updated. i.e. the swpqueue is occupied.
 126                                                * This can be used to compute the simple average processes waiting to be paged in */
 127   u_longlong_t iget;                    /* number of inode lookups */
 128   u_longlong_t namei;                   /* number of vnode lookup from a path name */
 129   u_longlong_t dirblk;                  /* number of 512-byte block reads by the directory search routine to locate an entry for a file */
 130   u_longlong_t msg;                     /* number of IPC message operations */
 131   u_longlong_t sema;                    /* number of IPC semaphore operations */
 132   u_longlong_t rcvint;                  /* number of tty receive interrupts */
 133   u_longlong_t xmtint;                  /* number of tyy transmit interrupts */
 134   u_longlong_t mdmint;                  /* number of modem interrupts */
 135   u_longlong_t tty_rawinch;             /* number of raw input characters  */
 136   u_longlong_t tty_caninch;             /* number of canonical input characters (always zero) */
 137   u_longlong_t tty_rawoutch;            /* number of raw output characters */
 138   u_longlong_t ksched;                  /* number of kernel processes created */
 139   u_longlong_t koverf;                  /* kernel process creation attempts where:
 140                                                * -the user has forked to their maximum limit
 141                                                * -the configuration limit of processes has been reached */
 142   u_longlong_t kexit;                   /* number of kernel processes that became zombies */
 143   u_longlong_t rbread;                  /* number of remote read requests */
 144   u_longlong_t rcread;                  /* number of cached remote reads */
 145   u_longlong_t rbwrt;                   /* number of remote writes */
 146   u_longlong_t rcwrt;                   /* number of cached remote writes */
 147   u_longlong_t traps;                   /* number of traps */
 148   int ncpus_high;                       /* index of highest processor online */
 149   u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 150   u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 151   u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 152   u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 153   u_longlong_t decrintrs;               /* number of decrementer tics interrupts */
 154   u_longlong_t mpcrintrs;               /* number of mpc's received interrupts */
 155   u_longlong_t mpcsintrs;               /* number of mpc's sent interrupts */
 156   u_longlong_t phantintrs;              /* number of phantom interrupts */
 157   u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
 158   u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
 159   u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
 160   u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
 161   u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
 162   u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
 163   u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
 164   u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
 165   short iowait;                         /* number of processes that are asleep waiting for buffered I/O */
 166   short physio;                         /* number of processes waiting for raw I/O */
 167   longlong_t twait;                     /* number of threads that are waiting for filesystem direct(cio) */
 168   u_longlong_t hpi;                     /* number of hypervisor page-ins */
 169   u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds) */
 170 } perfstat_cpu_total_t_53;
 171 
 172 typedef struct { /* global cpu information AIX 6.1|5.3 > TL09 */
 173   int ncpus;                            /* number of active logical processors */
 174   int ncpus_cfg;                        /* number of configured processors */
 175   char description[IDENTIFIER_LENGTH];  /* processor description (type/official name) */
 176   u_longlong_t processorHZ;             /* processor speed in Hz */
 177   u_longlong_t user;                    /* raw total number of clock ticks spent in user mode */
 178   u_longlong_t sys;                     /* raw total number of clock ticks spent in system mode */
 179   u_longlong_t idle;                    /* raw total number of clock ticks spent idle */
 180   u_longlong_t wait;                    /* raw total number of clock ticks spent waiting for I/O */
 181   u_longlong_t pswitch;                 /* number of process switches (change in currently running process) */
 182   u_longlong_t syscall;                 /* number of system calls executed */
 183   u_longlong_t sysread;                 /* number of read system calls executed */
 184   u_longlong_t syswrite;                /* number of write system calls executed */
 185   u_longlong_t sysfork;                 /* number of forks system calls executed */
 186   u_longlong_t sysexec;                 /* number of execs system calls executed */
 187   u_longlong_t readch;                  /* number of characters tranferred with read system call */
 188   u_longlong_t writech;                 /* number of characters tranferred with write system call */
 189   u_longlong_t devintrs;                /* number of device interrupts */
 190   u_longlong_t softintrs;               /* number of software interrupts */
 191   time_t lbolt;                         /* number of ticks since last reboot */
 192   u_longlong_t loadavg[3];              /* (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes.
 193                                                * To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>. */
 194   u_longlong_t runque;                  /* length of the run queue (processes ready) */
 195   u_longlong_t swpque;                  /* length of the swap queue (processes waiting to be paged in) */
 196   u_longlong_t bread;                   /* number of blocks read */
 197   u_longlong_t bwrite;                  /* number of blocks written */
 198   u_longlong_t lread;                   /* number of logical read requests */
 199   u_longlong_t lwrite;                  /* number of logical write requests */
 200   u_longlong_t phread;                  /* number of physical reads (reads on raw devices) */
 201   u_longlong_t phwrite;                 /* number of physical writes (writes on raw devices) */
 202   u_longlong_t runocc;                  /* updated whenever runque is updated, i.e. the runqueue is occupied.
 203                                                * This can be used to compute the simple average of ready processes  */
 204   u_longlong_t swpocc;                  /* updated whenever swpque is updated. i.e. the swpqueue is occupied.
 205                                                * This can be used to compute the simple average processes waiting to be paged in */
 206   u_longlong_t iget;                    /* number of inode lookups */
 207   u_longlong_t namei;                   /* number of vnode lookup from a path name */
 208   u_longlong_t dirblk;                  /* number of 512-byte block reads by the directory search routine to locate an entry for a file */
 209   u_longlong_t msg;                     /* number of IPC message operations */
 210   u_longlong_t sema;                    /* number of IPC semaphore operations */
 211   u_longlong_t rcvint;                  /* number of tty receive interrupts */
 212   u_longlong_t xmtint;                  /* number of tyy transmit interrupts */
 213   u_longlong_t mdmint;                  /* number of modem interrupts */
 214   u_longlong_t tty_rawinch;             /* number of raw input characters  */
 215   u_longlong_t tty_caninch;             /* number of canonical input characters (always zero) */
 216   u_longlong_t tty_rawoutch;            /* number of raw output characters */
 217   u_longlong_t ksched;                  /* number of kernel processes created */
 218   u_longlong_t koverf;                  /* kernel process creation attempts where:
 219                                                * -the user has forked to their maximum limit
 220                                                * -the configuration limit of processes has been reached */
 221   u_longlong_t kexit;                   /* number of kernel processes that became zombies */
 222   u_longlong_t rbread;                  /* number of remote read requests */
 223   u_longlong_t rcread;                  /* number of cached remote reads */
 224   u_longlong_t rbwrt;                   /* number of remote writes */
 225   u_longlong_t rcwrt;                   /* number of cached remote writes */
 226   u_longlong_t traps;                   /* number of traps */
 227   int ncpus_high;                       /* index of highest processor online */
 228   u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 229   u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 230   u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 231   u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 232   u_longlong_t decrintrs;               /* number of decrementer tics interrupts */
 233   u_longlong_t mpcrintrs;               /* number of mpc's received interrupts */
 234   u_longlong_t mpcsintrs;               /* number of mpc's sent interrupts */
 235   u_longlong_t phantintrs;              /* number of phantom interrupts */
 236   u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
 237   u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
 238   u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
 239   u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
 240   u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
 241   u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
 242   u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
 243   u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
 244   short iowait;                         /* number of processes that are asleep waiting for buffered I/O */
 245   short physio;                         /* number of processes waiting for raw I/O */
 246   longlong_t twait;                     /* number of threads that are waiting for filesystem direct(cio) */
 247   u_longlong_t hpi;                     /* number of hypervisor page-ins */
 248   u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds) */
 249   u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
 250   u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
 251   u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
 252   u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
 253   int spurrflag;                        /* set if running in spurr mode */
 254 } perfstat_cpu_total_t_61;
 255 
 256 typedef struct { /* global cpu information AIX 7.1 */
 257   int ncpus;                            /* number of active logical processors */
 258   int ncpus_cfg;                        /* number of configured processors */
 259   char description[IDENTIFIER_LENGTH];  /* processor description (type/official name) */
 260   u_longlong_t processorHZ;             /* processor speed in Hz */
 261   u_longlong_t user;                    /* raw total number of clock ticks spent in user mode */
 262   u_longlong_t sys;                     /* raw total number of clock ticks spent in system mode */
 263   u_longlong_t idle;                    /* raw total number of clock ticks spent idle */
 264   u_longlong_t wait;                    /* raw total number of clock ticks spent waiting for I/O */
 265   u_longlong_t pswitch;                 /* number of process switches (change in currently running process) */
 266   u_longlong_t syscall;                 /* number of system calls executed */
 267   u_longlong_t sysread;                 /* number of read system calls executed */
 268   u_longlong_t syswrite;                /* number of write system calls executed */
 269   u_longlong_t sysfork;                 /* number of forks system calls executed */
 270   u_longlong_t sysexec;                 /* number of execs system calls executed */
 271   u_longlong_t readch;                  /* number of characters tranferred with read system call */
 272   u_longlong_t writech;                 /* number of characters tranferred with write system call */
 273   u_longlong_t devintrs;                /* number of device interrupts */
 274   u_longlong_t softintrs;               /* number of software interrupts */
 275   time_t lbolt;                         /* number of ticks since last reboot */
 276   u_longlong_t loadavg[3];              /* (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes.
 277                                                * To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>. */
 278   u_longlong_t runque;                  /* length of the run queue (processes ready) */
 279   u_longlong_t swpque;                  /* ength of the swap queue (processes waiting to be paged in) */
 280   u_longlong_t bread;                   /* number of blocks read */
 281   u_longlong_t bwrite;                  /* number of blocks written */
 282   u_longlong_t lread;                   /* number of logical read requests */
 283   u_longlong_t lwrite;                  /* number of logical write requests */
 284   u_longlong_t phread;                  /* number of physical reads (reads on raw devices) */
 285   u_longlong_t phwrite;                 /* number of physical writes (writes on raw devices) */
 286   u_longlong_t runocc;                  /* updated whenever runque is updated, i.e. the runqueue is occupied.
 287                                                * This can be used to compute the simple average of ready processes  */
 288   u_longlong_t swpocc;                  /* updated whenever swpque is updated. i.e. the swpqueue is occupied.
 289                                                * This can be used to compute the simple average processes waiting to be paged in */
 290   u_longlong_t iget;                    /* number of inode lookups */
 291   u_longlong_t namei;                   /* number of vnode lookup from a path name */
 292   u_longlong_t dirblk;                  /* number of 512-byte block reads by the directory search routine to locate an entry for a file */
 293   u_longlong_t msg;                     /* number of IPC message operations */
 294   u_longlong_t sema;                    /* number of IPC semaphore operations */
 295   u_longlong_t rcvint;                  /* number of tty receive interrupts */
 296   u_longlong_t xmtint;                  /* number of tyy transmit interrupts */
 297   u_longlong_t mdmint;                  /* number of modem interrupts */
 298   u_longlong_t tty_rawinch;             /* number of raw input characters  */
 299   u_longlong_t tty_caninch;             /* number of canonical input characters (always zero) */
 300   u_longlong_t tty_rawoutch;            /* number of raw output characters */
 301   u_longlong_t ksched;                  /* number of kernel processes created */
 302   u_longlong_t koverf;                  /* kernel process creation attempts where:
 303                                                * -the user has forked to their maximum limit
 304                                                * -the configuration limit of processes has been reached */
 305   u_longlong_t kexit;                   /* number of kernel processes that became zombies */
 306   u_longlong_t rbread;                  /* number of remote read requests */
 307   u_longlong_t rcread;                  /* number of cached remote reads */
 308   u_longlong_t rbwrt;                   /* number of remote writes */
 309   u_longlong_t rcwrt;                   /* number of cached remote writes */
 310   u_longlong_t traps;                   /* number of traps */
 311   int ncpus_high;                       /* index of highest processor online */
 312   u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 313   u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 314   u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 315   u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 316   u_longlong_t decrintrs;               /* number of decrementer tics interrupts */
 317   u_longlong_t mpcrintrs;               /* number of mpc's received interrupts */
 318   u_longlong_t mpcsintrs;               /* number of mpc's sent interrupts */
 319   u_longlong_t phantintrs;              /* number of phantom interrupts */
 320   u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
 321   u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
 322   u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
 323   u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
 324   u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
 325   u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
 326   u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
 327   u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
 328   short iowait;                         /* number of processes that are asleep waiting for buffered I/O */
 329   short physio;                         /* number of processes waiting for raw I/O */
 330   longlong_t twait;                     /* number of threads that are waiting for filesystem direct(cio) */
 331   u_longlong_t hpi;                     /* number of hypervisor page-ins */
 332   u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds) */
 333   u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
 334   u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
 335   u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
 336   u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
 337   int spurrflag;                        /* set if running in spurr mode */
 338   u_longlong_t  version;                /* version number (1, 2, etc.,) */
 339 /*      >>>>> END OF STRUCTURE DEFINITION <<<<<         */
 340 #define CURR_VERSION_CPU_TOTAL 1              /* Incremented by one for every new release *
 341                                                * of perfstat_cpu_total_t data structure   */
 342 } perfstat_cpu_total_t_71;
 343 
 344 typedef union {
 345   uint    w;
 346   struct {
 347           unsigned smt_capable :1;          /* OS supports SMT mode */
 348           unsigned smt_enabled :1;          /* SMT mode is on */
 349           unsigned lpar_capable :1;         /* OS supports logical partitioning */
 350           unsigned lpar_enabled :1;         /* logical partitioning is on */
 351           unsigned shared_capable :1;       /* OS supports shared processor LPAR */
 352           unsigned shared_enabled :1;       /* partition runs in shared mode */
 353           unsigned dlpar_capable :1;        /* OS supports dynamic LPAR */
 354           unsigned capped :1;               /* partition is capped */
 355           unsigned kernel_is_64 :1;         /* kernel is 64 bit */
 356           unsigned pool_util_authority :1;  /* pool utilization available */
 357           unsigned donate_capable :1;       /* capable of donating cycles */
 358           unsigned donate_enabled :1;       /* enabled for donating cycles */
 359           unsigned ams_capable:1;           /* 1 = AMS(Active Memory Sharing) capable, 0 = Not AMS capable */
 360           unsigned ams_enabled:1;           /* 1 = AMS(Active Memory Sharing) enabled, 0 = Not AMS enabled */
 361           unsigned power_save:1;            /* 1 = Power saving mode is enabled */
 362           unsigned ame_enabled:1;           /* Active Memory Expansion is enabled */
 363           unsigned shared_extended :1;
 364           unsigned spare :15;               /* reserved for future usage */
 365   } b;
 366 } perfstat_partition_type_t;
 367 
 368 typedef struct { /* partition total information AIX 5.3 < TL6 */
 369   char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
 370   perfstat_partition_type_t type;       /* set of bits describing the partition */
 371   int lpar_id;                          /* logical partition identifier */
 372   int group_id;                         /* identifier of the LPAR group this partition is a member of */
 373   int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
 374   int online_cpus;                      /* number of virtual CPUs currently online on the partition */
 375   int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
 376   int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
 377   u_longlong_t online_memory;           /* amount of memory currently online */
 378   u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
 379   u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
 380   int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
 381   int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
 382   int min_proc_capacity;                /* minimum number of processor units this partition must have */
 383   int proc_capacity_increment;          /* increment value to the entitled capacity */
 384   int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
 385   int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
 386   int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
 387   int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
 388   int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
 389   int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
 390   u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 391   u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 392   u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 393   u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 394   u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
 395   u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
 396   u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
 397   u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
 398   u_longlong_t timebase_last;           /* most recently cpu time base */
 399   u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
 400   u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
 401 } perfstat_partition_total_t_53_5;
 402 
 403 typedef struct { /* partition total information AIX 5.3 < TL10 */
 404   char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
 405   perfstat_partition_type_t type;       /* set of bits describing the partition */
 406   int lpar_id;                          /* logical partition identifier */
 407   int group_id;                         /* identifier of the LPAR group this partition is a member of */
 408   int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
 409   int online_cpus;                      /* number of virtual CPUs currently online on the partition */
 410   int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
 411   int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
 412   u_longlong_t online_memory;           /* amount of memory currently online */
 413   u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
 414   u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
 415   int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
 416   int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
 417   int min_proc_capacity;                /* minimum number of processor units this partition must have */
 418   int proc_capacity_increment;          /* increment value to the entitled capacity */
 419   int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
 420   int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
 421   int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
 422   int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
 423   int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
 424   int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
 425   u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 426   u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 427   u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 428   u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 429   u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
 430   u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
 431   u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
 432   u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
 433   u_longlong_t timebase_last;           /* most recently cpu time base */
 434   u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
 435   u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
 436   u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
 437   u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
 438   u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
 439   u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
 440   u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
 441   u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
 442   u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
 443   u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
 444   u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
 445   u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
 446   u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
 447   u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
 448   u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 449   u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 450   u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
 451   u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
 452   u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
 453   int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
 454   int var_mem_weight;                   /* variable memory capacity weight */
 455   u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
 456   u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
 457   u_longlong_t hpi;                     /* number of hypervisor page-ins */
 458   u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
 459   u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
 460 } perfstat_partition_total_t_53;
 461 
 462 typedef struct { /* partition total information AIX 6.1|5.3 > TL09 */
 463   char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
 464   perfstat_partition_type_t type;       /* set of bits describing the partition */
 465   int lpar_id;                          /* logical partition identifier */
 466   int group_id;                         /* identifier of the LPAR group this partition is a member of */
 467   int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
 468   int online_cpus;                      /* number of virtual CPUs currently online on the partition */
 469   int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
 470   int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
 471   u_longlong_t online_memory;           /* amount of memory currently online */
 472   u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
 473   u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
 474   int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
 475   int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
 476   int min_proc_capacity;                /* minimum number of processor units this partition must have */
 477   int proc_capacity_increment;          /* increment value to the entitled capacity */
 478   int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
 479   int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
 480   int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
 481   int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
 482   int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
 483   int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
 484   u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 485   u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 486   u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 487   u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 488   u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
 489   u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
 490   u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
 491   u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
 492   u_longlong_t timebase_last;           /* most recently cpu time base */
 493   u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
 494   u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
 495   u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
 496   u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
 497   u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
 498   u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
 499   u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
 500   u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
 501   u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
 502   u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
 503   u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
 504   u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
 505   u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
 506   u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
 507   u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 508   u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 509   u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
 510   u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
 511   u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
 512   int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
 513   int var_mem_weight;                   /* variable memory capacity weight */
 514   u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
 515   u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
 516   u_longlong_t hpi;                     /* number of hypervisor page-ins */
 517   u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
 518   u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
 519   uint online_lcpus;                    /* number of online logical cpus */
 520   uint smt_thrds;                       /* number of hardware threads that are running */
 521   u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
 522   u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
 523   u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
 524   u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
 525   int spurrflag;                        /* set if running in spurr mode */
 526 } perfstat_partition_total_t_61;
 527 
 528 typedef struct { /* partition total information AIX 7.1 */
 529   char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
 530   perfstat_partition_type_t type;       /* set of bits describing the partition */
 531   int lpar_id;                          /* logical partition identifier */
 532   int group_id;                         /* identifier of the LPAR group this partition is a member of */
 533   int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
 534   int online_cpus;                      /* number of virtual CPUs currently online on the partition */
 535   int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
 536   int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
 537   u_longlong_t online_memory;           /* amount of memory currently online */
 538   u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
 539   u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
 540   int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
 541   int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
 542   int min_proc_capacity;                /* minimum number of processor units this partition must have */
 543   int proc_capacity_increment;          /* increment value to the entitled capacity */
 544   int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
 545   int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
 546   int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
 547   int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
 548   int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
 549   int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
 550   u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 551   u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 552   u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 553   u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 554   u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
 555   u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
 556   u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
 557   u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
 558   u_longlong_t timebase_last;           /* most recently cpu time base */
 559   u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
 560   u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
 561   u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
 562   u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
 563   u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
 564   u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
 565   u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
 566   u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
 567   u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
 568   u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
 569   u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
 570   u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
 571   u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
 572   u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
 573   u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 574   u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 575   u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
 576   u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
 577   u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
 578   int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
 579   int var_mem_weight;                   /* variable memory capacity weight */
 580   u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
 581   u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
 582   u_longlong_t hpi;                     /* number of hypervisor page-ins */
 583   u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
 584   u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
 585   uint online_lcpus;                    /* number of online logical cpus */
 586   uint smt_thrds;                       /* number of hardware threads that are running */
 587   u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
 588   u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
 589   u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
 590   u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
 591   int spurrflag;                        /* set if running in spurr mode */
 592   char hardwareid[CEC_ID_LEN];          /* CEC Identifier */
 593         uint power_save_mode;                 /* Power save mode for the LPAR. Introduced through LI 53K PRF : Feature 728 292*/
 594         ushort ame_version;                   /* AME Version */
 595         u_longlong_t true_memory;             /* True Memory Size in 4KB pages */
 596         u_longlong_t expanded_memory;         /* Expanded Memory Size in 4KB pages */
 597         u_longlong_t target_memexp_factr;     /* Target Memory Expansion Factor scaled by 100 */
 598         u_longlong_t current_memexp_factr;    /* Current Memory Expansion Factor scaled by 100 */
 599         u_longlong_t target_cpool_size;       /* Target Compressed Pool Size in bytes */
 600         u_longlong_t max_cpool_size;          /* Max Size of Compressed Pool in bytes */
 601         u_longlong_t min_ucpool_size;         /* Min Size of Uncompressed Pool in bytes */
 602         u_longlong_t ame_deficit_size;        /*Deficit memory size in bytes */
 603         u_longlong_t version;                 /* version number (1, 2, etc.,) */
 604         u_longlong_t cmcs_total_time;         /* Total CPU time spent due to active memory expansion */
 605 } perfstat_partition_total_t_71;
 606 
 607 typedef struct { /* partition total information AIX 7.1 >= TL1*/
 608         char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
 609         perfstat_partition_type_t type;       /* set of bits describing the partition */
 610         int lpar_id;                          /* logical partition identifier */
 611         int group_id;                         /* identifier of the LPAR group this partition is a member of */
 612         int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
 613         int online_cpus;                      /* number of virtual CPUs currently online on the partition */
 614         int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
 615         int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
 616         u_longlong_t online_memory;           /* amount of memory currently online */
 617         u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
 618         u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
 619         int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
 620         int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
 621         int min_proc_capacity;                /* minimum number of processor units this partition must have */
 622         int proc_capacity_increment;          /* increment value to the entitled capacity */
 623         int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
 624         int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
 625         int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
 626         int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
 627         int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
 628         int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
 629         u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
 630         u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
 631         u_longlong_t pidle;                   /* raw number of physical processor tics idle */
 632         u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
 633         u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
 634         u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
 635         u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
 636         u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
 637         u_longlong_t timebase_last;           /* most recently cpu time base */
 638         u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
 639         u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
 640         u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
 641         u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
 642         u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
 643         u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
 644         u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
 645         u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
 646         u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
 647         u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
 648         u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
 649         u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
 650         u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
 651         u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
 652         u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 653         u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
 654         u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
 655         u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
 656         u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
 657         int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
 658         int var_mem_weight;                   /* variable memory capacity weight */
 659         u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
 660         u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
 661         u_longlong_t hpi;                     /* number of hypervisor page-ins */
 662         u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
 663         u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
 664         uint online_lcpus;                    /* number of online logical cpus */
 665         uint smt_thrds;                       /* number of hardware threads that are running */
 666         u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
 667         u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
 668         u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
 669         u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
 670         int spurrflag;                        /* set if running in spurr mode */
 671         char hardwareid[CEC_ID_LEN];          /* CEC Identifier */
 672         uint power_save_mode;                 /* Power save mode for the LPAR. Introduced through LI 53K PRF : Feature 728 292*/
 673         ushort ame_version;                   /* AME Version */
 674         u_longlong_t true_memory;             /* True Memory Size in 4KB pages */
 675         u_longlong_t expanded_memory;         /* Expanded Memory Size in 4KB pages */
 676         u_longlong_t target_memexp_factr;     /* Target Memory Expansion Factor scaled by 100 */
 677         u_longlong_t current_memexp_factr;    /* Current Memory Expansion Factor scaled by 100 */
 678         u_longlong_t target_cpool_size;       /* Target Compressed Pool Size in bytes */
 679         u_longlong_t max_cpool_size;          /* Max Size of Compressed Pool in bytes */
 680         u_longlong_t min_ucpool_size;         /* Min Size of Uncompressed Pool in bytes */
 681         u_longlong_t ame_deficit_size;        /*Deficit memory size in bytes */
 682         u_longlong_t version;                 /* version number (1, 2, etc.,) */
 683         u_longlong_t cmcs_total_time;         /* Total CPU time spent due to active memory expansion */
 684         u_longlong_t purr_coalescing;         /* If the calling partition is authorized to see pool wide statistics then PURR cycles consumed to coalesce data else set to zero.*/
 685         u_longlong_t spurr_coalescing;        /* If the calling partition is authorized to see pool wide statistics then SPURR cycles consumed to coalesce data else set to zero.*/
 686         u_longlong_t MemPoolSize;             /* Indicates the memory pool size of the pool that the partition belongs to (in bytes)., mpsz */
 687         u_longlong_t IOMemEntInUse;           /* I/O memory entitlement of the LPAR in use in bytes. iomu */
 688         u_longlong_t IOMemEntFree;            /* free I/O memory entitlement in bytes.  iomf */
 689         u_longlong_t IOHighWaterMark;         /* high water mark of I/O memory entitlement usage in bytes. iohwn */
 690         u_longlong_t purr_counter;            /* number of purr cycles spent in user + kernel mode */
 691         u_longlong_t spurr_counter;           /* number of spurr cycles spent in user + kernel mode */
 692 
 693         /* Marketing Requirement(MR): MR1124083744  */
 694         u_longlong_t real_free;               /* free real memory (in 4KB pages) */
 695         u_longlong_t real_avail;              /* number of pages available for user application (memfree + numperm - minperm - minfree) */
 696         /*      >>>>> END OF STRUCTURE DEFINITION <<<<<         */
 697 #define CURR_VERSION_PARTITION_TOTAL 5        /* Incremented by one for every new release     *
 698                                                * of perfstat_partition_total_t data structure */
 699 } perfstat_partition_total_t_71_1;
 700 
 701 typedef union { /* WPAR Type & Flags */
 702         uint    w;
 703         struct {
 704                 unsigned app_wpar :1;        /* Application WPAR */
 705                 unsigned cpu_rset :1;        /* WPAR restricted to CPU resource set */
 706                 unsigned cpu_xrset:1;        /* WPAR restricted to CPU Exclusive resource set */
 707                 unsigned cpu_limits :1;      /* CPU resource limits enforced */
 708                 unsigned mem_limits :1;      /* Memory resource limits enforced */
 709                 unsigned spare :27;          /* reserved for future usage */
 710         } b;
 711 } perfstat_wpar_type_t;
 712 
 713 typedef struct { /* Workload partition Information AIX 5.3 & 6.1*/
 714        char name[MAXCORRALNAMELEN+1]; /* name of the Workload Partition */
 715        perfstat_wpar_type_t type;     /* set of bits describing the wpar */
 716        cid_t wpar_id;                 /* workload partition identifier */
 717        uint  online_cpus;             /* Number of Virtual CPUs in partition rset or  number of virtual CPUs currently online on the Global partition*/
 718        int   cpu_limit;               /* CPU limit in 100ths of % - 1..10000 */
 719        int   mem_limit;               /* Memory limit in 100ths of % - 1..10000 */
 720        u_longlong_t online_memory;    /* amount of memory currently online in Global Partition */
 721        int entitled_proc_capacity;    /* number of processor units this partition is entitled to receive */
 722 } perfstat_wpar_total_t_61;
 723 
 724 typedef struct { /* Workload partition Information AIX 7.1*/
 725        char name[MAXCORRALNAMELEN+1]; /* name of the Workload Partition */
 726        perfstat_wpar_type_t type;     /* set of bits describing the wpar */
 727        cid_t wpar_id;                 /* workload partition identifier */
 728        uint  online_cpus;             /* Number of Virtual CPUs in partition rset or  number of virtual CPUs currently online on the Global partition*/
 729        int   cpu_limit;               /* CPU limit in 100ths of % - 1..10000 */
 730        int   mem_limit;               /* Memory limit in 100ths of % - 1..10000 */
 731        u_longlong_t online_memory;    /* amount of memory currently online in Global Partition */
 732        int entitled_proc_capacity;    /* number of processor units this partition is entitled to receive */
 733        u_longlong_t version;          /* version number (1, 2, etc.,)                  */
 734 /*      >>>>> END OF STRUCTURE DEFINITION <<<<<         */
 735 #define CURR_VERSION_WPAR_TOTAL 1     /* Incremented by one for every new release      *
 736                                        * of perfstat_wpar_total_t data structure       */
 737 } perfstat_wpar_total_t_71;
 738 
 739 typedef void * rsethandle_t;  /* Type to identify a resource set handle: rsethandle_t */
 740 
 741 typedef enum { WPARNAME, WPARID, RSETHANDLE } wparid_specifier; /* Type of wparid_specifier */
 742 
 743 typedef struct { /* WPAR identifier */
 744         wparid_specifier spec;  /* Specifier to choose wpar id or name */
 745         union  {
 746                 cid_t wpar_id;                      /* WPAR ID */
 747                 rsethandle_t rset;                  /* Rset Handle */
 748                 char wparname[MAXCORRALNAMELEN+1];  /* WPAR NAME */
 749         } u;
 750         char name[IDENTIFIER_LENGTH]; /* name of the structure element identifier */
 751 } perfstat_id_wpar_t;
 752 
 753 
 754 
 755 // end: libperfstat.h (AIX 5.2, 5.3, 6.1, 7.1)
 756 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 757 
 758 #define PERFSTAT_PARTITON_TOTAL_T_LATEST perfstat_partition_total_t_71_1/* latest perfstat_partition_total_t structure */
 759 #define PERFSTAT_CPU_TOTAL_T_LATEST perfstat_cpu_total_t_71             /* latest perfstat_cpu_total_t structure */
 760 #define PERFSTAT_WPAR_TOTAL_T_LATEST perfstat_wpar_total_t_71           /* latest perfstat_wpar_total_t structure */
 761 
 762 class libperfstat {
 763 
 764 public:
 765 
 766   // Load the libperfstat library (must be in LIBPATH).
 767   // Returns true if succeeded, false if error.
 768   static bool init();
 769   static void cleanup();
 770 
 771   // Direct wrappers for the libperfstat functionality. All they do is
 772   // to call the functions with the same name via function pointers.
 773   // Get all available data also on newer AIX versions (PERFSTAT_CPU_TOTAL_T_LATEST).
 774   static int perfstat_cpu_total(perfstat_id_t *name, PERFSTAT_CPU_TOTAL_T_LATEST* userbuff,
 775                                 int sizeof_userbuff, int desired_number);
 776 
 777   static int perfstat_memory_total(perfstat_id_t *name, perfstat_memory_total_t* userbuff,
 778                                    int sizeof_userbuff, int desired_number);
 779 
 780   static int perfstat_partition_total(perfstat_id_t *name, PERFSTAT_PARTITON_TOTAL_T_LATEST* userbuff,
 781                                       int sizeof_userbuff, int desired_number);
 782 
 783   static void perfstat_reset();
 784 
 785   static int perfstat_wpar_total(perfstat_id_wpar_t *name, PERFSTAT_WPAR_TOTAL_T_LATEST* userbuff,
 786                                  int sizeof_userbuff, int desired_number);
 787 
 788   static cid_t wpar_getcid();
 789 
 790 
 791   ////////////////////////////////////////////////////////////////
 792   // The convenience functions get_partitioninfo(), get_cpuinfo(), get_wparinfo() return
 793   // information about partition, cpu and wpars, respectivly. They can be used without
 794   // regard for which OS release we are on. On older AIX release, some output structure
 795   // members will be 0.
 796 
 797   // Result struct for get_partitioninfo().
 798   struct partitioninfo_t {
 799     // partition type info
 800     unsigned smt_capable :1;          /* OS supports SMT mode */
 801     unsigned smt_enabled :1;          /* SMT mode is on */
 802     unsigned lpar_capable :1;         /* OS supports logical partitioning */
 803     unsigned lpar_enabled :1;         /* logical partitioning is on */
 804     unsigned shared_capable :1;       /* OS supports shared processor LPAR */
 805     unsigned shared_enabled :1;       /* partition runs in shared mode */
 806     unsigned dlpar_capable :1;        /* OS supports dynamic LPAR */
 807     unsigned capped :1;               /* partition is capped */
 808     unsigned kernel_is_64 :1;         /* kernel is 64 bit */
 809     unsigned pool_util_authority :1;  /* pool utilization available */
 810     unsigned donate_capable :1;       /* capable of donating cycles */
 811     unsigned donate_enabled :1;       /* enabled for donating cycles */
 812     unsigned ams_capable:1;           /* 1 = AMS(Active Memory Sharing) capable, 0 = Not AMS capable */
 813     unsigned ams_enabled:1;           /* 1 = AMS(Active Memory Sharing) enabled, 0 = Not AMS enabled */
 814     unsigned power_save:1;            /* 1 = Power saving mode is enabled */
 815     unsigned ame_enabled:1;           /* Active Memory Expansion is enabled */
 816     // partition total info
 817     int online_cpus;                  /* number of virtual CPUs currently online on the partition */
 818     int entitled_proc_capacity;       /* number of processor units this partition is entitled to receive */
 819     int var_proc_capacity_weight;     /* partition priority weight to receive extra capacity */
 820     int phys_cpus_pool;               /* number of the physical CPUs currently in the shared processor pool this partition belong to */
 821     int pool_id;                      /* identifier of the shared pool of physical processors this partition is a member of */
 822     u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
 823     char name[IDENTIFIER_LENGTH];     /* name of the logical partition */
 824 
 825     u_longlong_t timebase_last;       /* most recently cpu time base (an incremented long int on PowerPC) */
 826     u_longlong_t pool_idle_time;      /* pool idle time = number of clock tics a processor in the shared pool was idle */
 827     u_longlong_t pcpu_tics_user;      /* raw number of physical processor tics in user mode */
 828     u_longlong_t pcpu_tics_sys;       /* raw number of physical processor tics in system mode */
 829     u_longlong_t pcpu_tics_idle;      /* raw number of physical processor tics idle */
 830     u_longlong_t pcpu_tics_wait;      /* raw number of physical processor tics waiting for I/O */
 831 
 832     u_longlong_t true_memory;          /* True Memory Size in 4KB pages */
 833     u_longlong_t expanded_memory;      /* Expanded Memory Size in 4KB pages */
 834     u_longlong_t target_memexp_factr;  /* Target Memory Expansion Factor scaled by 100 */
 835     u_longlong_t current_memexp_factr; /* Current Memory Expansion Factor scaled by 100 */
 836     u_longlong_t cmcs_total_time;      /* Total CPU time spent due to active memory expansion */
 837   };
 838 
 839   // Result struct for get_cpuinfo().
 840   struct cpuinfo_t {
 841     char description[IDENTIFIER_LENGTH];  // processor description (type/official name)
 842     u_longlong_t processorHZ;             // processor speed in Hz
 843     int ncpus;                            // number of active logical processors
 844     double loadavg[3];                    // (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes.
 845                                           // To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>.
 846     char version[20];                     // processor version from _system_configuration (sys/systemcfg.h)
 847     unsigned long long user_clock_ticks;  // raw total number of clock ticks spent in user mode
 848     unsigned long long sys_clock_ticks;   // raw total number of clock ticks spent in system mode
 849     unsigned long long idle_clock_ticks;  // raw total number of clock ticks spent idle
 850     unsigned long long wait_clock_ticks;  // raw total number of clock ticks spent waiting for I/O
 851   };
 852 
 853   // Result struct for get_wparinfo().
 854   struct wparinfo_t {
 855     char name[MAXCORRALNAMELEN+1];  /* name of the Workload Partition */
 856     unsigned short wpar_id;         /* workload partition identifier */
 857     unsigned app_wpar :1;           /* Application WPAR */
 858     unsigned cpu_rset :1;           /* WPAR restricted to CPU resource set */
 859     unsigned cpu_xrset:1;           /* WPAR restricted to CPU Exclusive resource set */
 860     unsigned cpu_limits :1;         /* CPU resource limits enforced */
 861     unsigned mem_limits :1;         /* Memory resource limits enforced */
 862     int cpu_limit;                  /* CPU limit in 100ths of % - 1..10000 */
 863     int mem_limit;                  /* Memory limit in 100ths of % - 1..10000 */
 864   };
 865 
 866   static bool get_partitioninfo(partitioninfo_t* ppi);
 867   static bool get_cpuinfo(cpuinfo_t* pci);
 868   static bool get_wparinfo(wparinfo_t* pwi);
 869 
 870 };
 871 
 872 #endif // OS_AIX_VM_LIBPERFSTAT_AIX_HPP