1/*
2 * Copyright (c) 2012, 2016 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
53typedef 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
62typedef unsigned short cid_t;   /* workload partition identifier */
63
64typedef 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
93typedef 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
172typedef 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
256typedef 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
344typedef struct { /* global cpu information AIX 7.2  / 6.1 TL6 (see oslevel -r) */
345  int ncpus;                /* number of active logical processors */
346  int ncpus_cfg;             /* number of configured processors */
347  char description[IDENTIFIER_LENGTH]; /* processor description (type/official name) */
348  u_longlong_t processorHZ; /* processor speed in Hz */
349  u_longlong_t user;        /*  raw total number of clock ticks spent in user mode */
350  u_longlong_t sys;         /* raw total number of clock ticks spent in system mode */
351  u_longlong_t idle;        /* raw total number of clock ticks spent idle */
352  u_longlong_t wait;        /* raw total number of clock ticks spent waiting for I/O */
353  u_longlong_t pswitch;     /* number of process switches (change in currently running process) */
354  u_longlong_t syscall;     /* number of system calls executed */
355  u_longlong_t sysread;     /* number of read system calls executed */
356  u_longlong_t syswrite;    /* number of write system calls executed */
357  u_longlong_t sysfork;     /* number of forks system calls executed */
358  u_longlong_t sysexec;     /* number of execs system calls executed */
359  u_longlong_t readch;      /* number of characters tranferred with read system call */
360  u_longlong_t writech;     /* number of characters tranferred with write system call */
361  u_longlong_t devintrs;    /* number of device interrupts */
362  u_longlong_t softintrs;   /* number of software interrupts */
363  time_t lbolt;             /* number of ticks since last reboot */
364  u_longlong_t loadavg[3];  /* (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes.    */
365                            /* To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>. */
366  u_longlong_t runque;      /* length of the run queue (processes ready) */
367  u_longlong_t swpque;      /* ength of the swap queue (processes waiting to be paged in) */
368  u_longlong_t bread;       /* number of blocks read */
369  u_longlong_t bwrite;      /* number of blocks written */
370  u_longlong_t lread;       /* number of logical read requests */
371  u_longlong_t lwrite;      /* number of logical write requests */
372  u_longlong_t phread;      /* number of physical reads (reads on raw devices) */
373  u_longlong_t phwrite;     /* number of physical writes (writes on raw devices) */
374  u_longlong_t runocc;      /* updated whenever runque is updated, i.e. the runqueue is occupied.
375                             * This can be used to compute the simple average of ready processes  */
376  u_longlong_t swpocc;      /* updated whenever swpque is updated. i.e. the swpqueue is occupied.
377                             * This can be used to compute the simple average processes waiting to be paged in */
378  u_longlong_t iget;        /* number of inode lookups */
379  u_longlong_t namei;       /* number of vnode lookup from a path name */
380  u_longlong_t dirblk;      /* number of 512-byte block reads by the directory search routine to locate an entry for a file */
381  u_longlong_t msg;         /* number of IPC message operations */
382  u_longlong_t sema;        /* number of IPC semaphore operations */
383  u_longlong_t rcvint;      /* number of tty receive interrupts */
384  u_longlong_t xmtint;      /* number of tyy transmit interrupts */
385  u_longlong_t mdmint;      /* number of modem interrupts */
386  u_longlong_t tty_rawinch; /* number of raw input characters  */
387  u_longlong_t tty_caninch; /* number of canonical input characters (always zero) */
388  u_longlong_t tty_rawoutch;/* number of raw output characters */
389  u_longlong_t ksched;      /* number of kernel processes created */
390  u_longlong_t koverf;      /* kernel process creation attempts where:
391                             * -the user has forked to their maximum limit
392                             * -the configuration limit of processes has been reached */
393  u_longlong_t kexit;       /* number of kernel processes that became zombies */
394  u_longlong_t rbread;      /* number of remote read requests */
395  u_longlong_t rcread;      /* number of cached remote reads */
396  u_longlong_t rbwrt;       /* number of remote writes */
397  u_longlong_t rcwrt;       /* number of cached remote writes */
398  u_longlong_t traps;       /* number of traps */
399  int ncpus_high;           /* index of highest processor online */
400  u_longlong_t puser;       /* raw number of physical processor tics in user mode */
401  u_longlong_t psys;        /* raw number of physical processor tics in system mode */
402  u_longlong_t pidle;       /* raw number of physical processor tics idle */
403  u_longlong_t pwait;       /* raw number of physical processor tics waiting for I/O */
404  u_longlong_t decrintrs;   /* number of decrementer tics interrupts */
405  u_longlong_t mpcrintrs;   /* number of mpc's received interrupts */
406  u_longlong_t mpcsintrs;   /* number of mpc's sent interrupts */
407  u_longlong_t phantintrs;  /* number of phantom interrupts */
408  u_longlong_t idle_donated_purr; /* number of idle cycles donated by a dedicated partition enabled for donation */
409  u_longlong_t idle_donated_spurr;/* number of idle spurr cycles donated by a dedicated partition enabled for donation */
410  u_longlong_t busy_donated_purr; /* number of busy cycles donated by a dedicated partition enabled for donation */
411  u_longlong_t busy_donated_spurr;/* number of busy spurr cycles donated by a dedicated partition enabled for donation */
412  u_longlong_t idle_stolen_purr;  /* number of idle cycles stolen by the hypervisor from a dedicated partition */
413  u_longlong_t idle_stolen_spurr; /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
414  u_longlong_t busy_stolen_purr;  /* number of busy cycles stolen by the hypervisor from a dedicated partition */
415  u_longlong_t busy_stolen_spurr; /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
416  short iowait;             /* number of processes that are asleep waiting for buffered I/O */
417  short physio;             /* number of processes waiting for raw I/O */
418  longlong_t twait;         /* number of threads that are waiting for filesystem direct(cio) */
419  u_longlong_t hpi;         /* number of hypervisor page-ins */
420  u_longlong_t hpit;        /* Time spent in hypervisor page-ins (in nanoseconds) */
421  u_longlong_t puser_spurr; /* number of spurr cycles spent in user mode */
422  u_longlong_t psys_spurr;  /* number of spurr cycles spent in kernel mode */
423  u_longlong_t pidle_spurr; /* number of spurr cycles spent in idle mode */
424  u_longlong_t pwait_spurr; /* number of spurr cycles spent in wait mode */
425  int spurrflag;            /* set if running in spurr mode */
426  u_longlong_t  version;    /* version number (1, 2, etc.,) */
427  u_longlong_t tb_last;     /*time base counter */
428  u_longlong_t purr_coalescing;   /* If the calling partition is
429                                   * authorized to see pool wide statistics then
430                                   * PURR cycles consumed to coalesce data
431                                   * else set to zero.*/
432  u_longlong_t spurr_coalescing;  /* If the calling partition is
433                                   * authorized to see pool wide statistics then
434                                   * SPURR cycles consumed to coalesce data
435                                   * else set to zero.*/
436
437/*      >>>>> END OF STRUCTURE DEFINITION <<<<<         */
438#define CURR_VERSION_CPU_TOTAL 2 /* Incremented by one for every new release *
439                                  * of perfstat_cpu_total_t data structure   */
440} perfstat_cpu_total_t_72;
441
442
443typedef union {
444  uint    w;
445  struct {
446          unsigned smt_capable :1;          /* OS supports SMT mode */
447          unsigned smt_enabled :1;          /* SMT mode is on */
448          unsigned lpar_capable :1;         /* OS supports logical partitioning */
449          unsigned lpar_enabled :1;         /* logical partitioning is on */
450          unsigned shared_capable :1;       /* OS supports shared processor LPAR */
451          unsigned shared_enabled :1;       /* partition runs in shared mode */
452          unsigned dlpar_capable :1;        /* OS supports dynamic LPAR */
453          unsigned capped :1;               /* partition is capped */
454          unsigned kernel_is_64 :1;         /* kernel is 64 bit */
455          unsigned pool_util_authority :1;  /* pool utilization available */
456          unsigned donate_capable :1;       /* capable of donating cycles */
457          unsigned donate_enabled :1;       /* enabled for donating cycles */
458          unsigned ams_capable:1;           /* 1 = AMS(Active Memory Sharing) capable, 0 = Not AMS capable */
459          unsigned ams_enabled:1;           /* 1 = AMS(Active Memory Sharing) enabled, 0 = Not AMS enabled */
460          unsigned power_save:1;            /* 1 = Power saving mode is enabled */
461          unsigned ame_enabled:1;           /* Active Memory Expansion is enabled */
462          unsigned shared_extended :1;
463          unsigned spare :15;               /* reserved for future usage */
464  } b;
465} perfstat_partition_type_t;
466
467typedef struct { /* partition total information AIX 5.3 < TL6 */
468  char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
469  perfstat_partition_type_t type;       /* set of bits describing the partition */
470  int lpar_id;                          /* logical partition identifier */
471  int group_id;                         /* identifier of the LPAR group this partition is a member of */
472  int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
473  int online_cpus;                      /* number of virtual CPUs currently online on the partition */
474  int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
475  int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
476  u_longlong_t online_memory;           /* amount of memory currently online */
477  u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
478  u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
479  int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
480  int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
481  int min_proc_capacity;                /* minimum number of processor units this partition must have */
482  int proc_capacity_increment;          /* increment value to the entitled capacity */
483  int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
484  int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
485  int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
486  int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
487  int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
488  int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
489  u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
490  u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
491  u_longlong_t pidle;                   /* raw number of physical processor tics idle */
492  u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
493  u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
494  u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
495  u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
496  u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
497  u_longlong_t timebase_last;           /* most recently cpu time base */
498  u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
499  u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
500} perfstat_partition_total_t_53_5;
501
502typedef struct { /* partition total information AIX 5.3 < TL10 */
503  char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
504  perfstat_partition_type_t type;       /* set of bits describing the partition */
505  int lpar_id;                          /* logical partition identifier */
506  int group_id;                         /* identifier of the LPAR group this partition is a member of */
507  int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
508  int online_cpus;                      /* number of virtual CPUs currently online on the partition */
509  int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
510  int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
511  u_longlong_t online_memory;           /* amount of memory currently online */
512  u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
513  u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
514  int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
515  int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
516  int min_proc_capacity;                /* minimum number of processor units this partition must have */
517  int proc_capacity_increment;          /* increment value to the entitled capacity */
518  int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
519  int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
520  int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
521  int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
522  int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
523  int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
524  u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
525  u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
526  u_longlong_t pidle;                   /* raw number of physical processor tics idle */
527  u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
528  u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
529  u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
530  u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
531  u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
532  u_longlong_t timebase_last;           /* most recently cpu time base */
533  u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
534  u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
535  u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
536  u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
537  u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
538  u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
539  u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
540  u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
541  u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
542  u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
543  u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
544  u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
545  u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
546  u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
547  u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
548  u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
549  u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
550  u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
551  u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
552  int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
553  int var_mem_weight;                   /* variable memory capacity weight */
554  u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
555  u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
556  u_longlong_t hpi;                     /* number of hypervisor page-ins */
557  u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
558  u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
559} perfstat_partition_total_t_53;
560
561typedef struct { /* partition total information AIX 6.1|5.3 > TL09 */
562  char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
563  perfstat_partition_type_t type;       /* set of bits describing the partition */
564  int lpar_id;                          /* logical partition identifier */
565  int group_id;                         /* identifier of the LPAR group this partition is a member of */
566  int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
567  int online_cpus;                      /* number of virtual CPUs currently online on the partition */
568  int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
569  int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
570  u_longlong_t online_memory;           /* amount of memory currently online */
571  u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
572  u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
573  int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
574  int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
575  int min_proc_capacity;                /* minimum number of processor units this partition must have */
576  int proc_capacity_increment;          /* increment value to the entitled capacity */
577  int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
578  int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
579  int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
580  int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
581  int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
582  int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
583  u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
584  u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
585  u_longlong_t pidle;                   /* raw number of physical processor tics idle */
586  u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
587  u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
588  u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
589  u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
590  u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
591  u_longlong_t timebase_last;           /* most recently cpu time base */
592  u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
593  u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
594  u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
595  u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
596  u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
597  u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
598  u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
599  u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
600  u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
601  u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
602  u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
603  u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
604  u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
605  u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
606  u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
607  u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
608  u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
609  u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
610  u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
611  int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
612  int var_mem_weight;                   /* variable memory capacity weight */
613  u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
614  u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
615  u_longlong_t hpi;                     /* number of hypervisor page-ins */
616  u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
617  u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
618  uint online_lcpus;                    /* number of online logical cpus */
619  uint smt_thrds;                       /* number of hardware threads that are running */
620  u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
621  u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
622  u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
623  u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
624  int spurrflag;                        /* set if running in spurr mode */
625} perfstat_partition_total_t_61;
626
627typedef struct { /* partition total information AIX 7.1 */
628  char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
629  perfstat_partition_type_t type;       /* set of bits describing the partition */
630  int lpar_id;                          /* logical partition identifier */
631  int group_id;                         /* identifier of the LPAR group this partition is a member of */
632  int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
633  int online_cpus;                      /* number of virtual CPUs currently online on the partition */
634  int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
635  int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
636  u_longlong_t online_memory;           /* amount of memory currently online */
637  u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
638  u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
639  int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
640  int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
641  int min_proc_capacity;                /* minimum number of processor units this partition must have */
642  int proc_capacity_increment;          /* increment value to the entitled capacity */
643  int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
644  int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
645  int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
646  int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
647  int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
648  int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
649  u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
650  u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
651  u_longlong_t pidle;                   /* raw number of physical processor tics idle */
652  u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
653  u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
654  u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
655  u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
656  u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
657  u_longlong_t timebase_last;           /* most recently cpu time base */
658  u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
659  u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
660  u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
661  u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
662  u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
663  u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
664  u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
665  u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
666  u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
667  u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
668  u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
669  u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
670  u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
671  u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
672  u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
673  u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
674  u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
675  u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
676  u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
677  int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
678  int var_mem_weight;                   /* variable memory capacity weight */
679  u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
680  u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
681  u_longlong_t hpi;                     /* number of hypervisor page-ins */
682  u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
683  u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
684  uint online_lcpus;                    /* number of online logical cpus */
685  uint smt_thrds;                       /* number of hardware threads that are running */
686  u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
687  u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
688  u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
689  u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
690  int spurrflag;                        /* set if running in spurr mode */
691  char hardwareid[CEC_ID_LEN];          /* CEC Identifier */
692        uint power_save_mode;                 /* Power save mode for the LPAR. Introduced through LI 53K PRF : Feature 728 292*/
693        ushort ame_version;                   /* AME Version */
694        u_longlong_t true_memory;             /* True Memory Size in 4KB pages */
695        u_longlong_t expanded_memory;         /* Expanded Memory Size in 4KB pages */
696        u_longlong_t target_memexp_factr;     /* Target Memory Expansion Factor scaled by 100 */
697        u_longlong_t current_memexp_factr;    /* Current Memory Expansion Factor scaled by 100 */
698        u_longlong_t target_cpool_size;       /* Target Compressed Pool Size in bytes */
699        u_longlong_t max_cpool_size;          /* Max Size of Compressed Pool in bytes */
700        u_longlong_t min_ucpool_size;         /* Min Size of Uncompressed Pool in bytes */
701        u_longlong_t ame_deficit_size;        /*Deficit memory size in bytes */
702        u_longlong_t version;                 /* version number (1, 2, etc.,) */
703        u_longlong_t cmcs_total_time;         /* Total CPU time spent due to active memory expansion */
704} perfstat_partition_total_t_71;
705
706typedef struct { /* partition total information AIX 7.1 >= TL1*/
707        char name[IDENTIFIER_LENGTH];         /* name of the logical partition */
708        perfstat_partition_type_t type;       /* set of bits describing the partition */
709        int lpar_id;                          /* logical partition identifier */
710        int group_id;                         /* identifier of the LPAR group this partition is a member of */
711        int pool_id;                          /* identifier of the shared pool of physical processors this partition is a member of */
712        int online_cpus;                      /* number of virtual CPUs currently online on the partition */
713        int max_cpus;                         /* maximum number of virtual CPUs this parition can ever have */
714        int min_cpus;                         /* minimum number of virtual CPUs this partition must have */
715        u_longlong_t online_memory;           /* amount of memory currently online */
716        u_longlong_t max_memory;              /* maximum amount of memory this partition can ever have */
717        u_longlong_t min_memory;              /* minimum amount of memory this partition must have */
718        int entitled_proc_capacity;           /* number of processor units this partition is entitled to receive */
719        int max_proc_capacity;                /* maximum number of processor units this partition can ever have */
720        int min_proc_capacity;                /* minimum number of processor units this partition must have */
721        int proc_capacity_increment;          /* increment value to the entitled capacity */
722        int unalloc_proc_capacity;            /* number of processor units currently unallocated in the shared processor pool this partition belongs to */
723        int var_proc_capacity_weight;         /* partition priority weight to receive extra capacity */
724        int unalloc_var_proc_capacity_weight; /* number of variable processor capacity weight units currently unallocated  in the shared processor pool this partition belongs to */
725        int online_phys_cpus_sys;             /* number of physical CPUs currently active in the system containing this partition */
726        int max_phys_cpus_sys;                /* maximum possible number of physical CPUs in the system containing this partition */
727        int phys_cpus_pool;                   /* number of the physical CPUs currently in the shared processor pool this partition belong to */
728        u_longlong_t puser;                   /* raw number of physical processor tics in user mode */
729        u_longlong_t psys;                    /* raw number of physical processor tics in system mode */
730        u_longlong_t pidle;                   /* raw number of physical processor tics idle */
731        u_longlong_t pwait;                   /* raw number of physical processor tics waiting for I/O */
732        u_longlong_t pool_idle_time;          /* number of clock tics a processor in the shared pool was idle */
733        u_longlong_t phantintrs;              /* number of phantom interrupts received by the partition */
734        u_longlong_t invol_virt_cswitch;      /* number involuntary virtual CPU context switches */
735        u_longlong_t vol_virt_cswitch;        /* number voluntary virtual CPU context switches */
736        u_longlong_t timebase_last;           /* most recently cpu time base */
737        u_longlong_t reserved_pages;          /* Currenlty number of 16GB pages. Cannot participate in DR operations */
738        u_longlong_t reserved_pagesize;       /* Currently 16GB pagesize Cannot participate in DR operations */
739        u_longlong_t idle_donated_purr;       /* number of idle cycles donated by a dedicated partition enabled for donation */
740        u_longlong_t idle_donated_spurr;      /* number of idle spurr cycles donated by a dedicated partition enabled for donation */
741        u_longlong_t busy_donated_purr;       /* number of busy cycles donated by a dedicated partition enabled for donation */
742        u_longlong_t busy_donated_spurr;      /* number of busy spurr cycles donated by a dedicated partition enabled for donation */
743        u_longlong_t idle_stolen_purr;        /* number of idle cycles stolen by the hypervisor from a dedicated partition */
744        u_longlong_t idle_stolen_spurr;       /* number of idle spurr cycles stolen by the hypervisor from a dedicated partition */
745        u_longlong_t busy_stolen_purr;        /* number of busy cycles stolen by the hypervisor from a dedicated partition */
746        u_longlong_t busy_stolen_spurr;       /* number of busy spurr cycles stolen by the hypervisor from a dedicated partition */
747        u_longlong_t shcpus_in_sys;           /* Number of physical processors allocated for shared processor use */
748        u_longlong_t max_pool_capacity;       /* Maximum processor capacity of partitions pool */
749        u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
750        u_longlong_t pool_max_time;           /* Summation of maximum time that could be consumed by the pool (nano seconds) */
751        u_longlong_t pool_busy_time;          /* Summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
752        u_longlong_t pool_scaled_busy_time;   /* Scaled summation of busy (non-idle) time accumulated across all partitions in the pool (nano seconds) */
753        u_longlong_t shcpu_tot_time;          /* Summation of total time across all physical processors allocated for shared processor use (nano seconds) */
754        u_longlong_t shcpu_busy_time;         /* Summation of busy (non-idle) time accumulated across all shared processor partitions (nano seconds) */
755        u_longlong_t shcpu_scaled_busy_time;  /* Scaled summation of busy time accumulated across all shared processor partitions (nano seconds) */
756        int ams_pool_id;                      /* AMS pool id of the pool the LPAR belongs to */
757        int var_mem_weight;                   /* variable memory capacity weight */
758        u_longlong_t iome;                    /* I/O memory entitlement of the partition in bytes*/
759        u_longlong_t pmem;                    /* Physical memory currently backing the partition's logical memory in bytes*/
760        u_longlong_t hpi;                     /* number of hypervisor page-ins */
761        u_longlong_t hpit;                    /* Time spent in hypervisor page-ins (in nanoseconds)*/
762        u_longlong_t hypv_pagesize;           /* Hypervisor page size in KB*/
763        uint online_lcpus;                    /* number of online logical cpus */
764        uint smt_thrds;                       /* number of hardware threads that are running */
765        u_longlong_t puser_spurr;             /* number of spurr cycles spent in user mode */
766        u_longlong_t psys_spurr;              /* number of spurr cycles spent in kernel mode */
767        u_longlong_t pidle_spurr;             /* number of spurr cycles spent in idle mode */
768        u_longlong_t pwait_spurr;             /* number of spurr cycles spent in wait mode */
769        int spurrflag;                        /* set if running in spurr mode */
770        char hardwareid[CEC_ID_LEN];          /* CEC Identifier */
771        uint power_save_mode;                 /* Power save mode for the LPAR. Introduced through LI 53K PRF : Feature 728 292*/
772        ushort ame_version;                   /* AME Version */
773        u_longlong_t true_memory;             /* True Memory Size in 4KB pages */
774        u_longlong_t expanded_memory;         /* Expanded Memory Size in 4KB pages */
775        u_longlong_t target_memexp_factr;     /* Target Memory Expansion Factor scaled by 100 */
776        u_longlong_t current_memexp_factr;    /* Current Memory Expansion Factor scaled by 100 */
777        u_longlong_t target_cpool_size;       /* Target Compressed Pool Size in bytes */
778        u_longlong_t max_cpool_size;          /* Max Size of Compressed Pool in bytes */
779        u_longlong_t min_ucpool_size;         /* Min Size of Uncompressed Pool in bytes */
780        u_longlong_t ame_deficit_size;        /*Deficit memory size in bytes */
781        u_longlong_t version;                 /* version number (1, 2, etc.,) */
782        u_longlong_t cmcs_total_time;         /* Total CPU time spent due to active memory expansion */
783        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.*/
784        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.*/
785        u_longlong_t MemPoolSize;             /* Indicates the memory pool size of the pool that the partition belongs to (in bytes)., mpsz */
786        u_longlong_t IOMemEntInUse;           /* I/O memory entitlement of the LPAR in use in bytes. iomu */
787        u_longlong_t IOMemEntFree;            /* free I/O memory entitlement in bytes.  iomf */
788        u_longlong_t IOHighWaterMark;         /* high water mark of I/O memory entitlement usage in bytes. iohwn */
789        u_longlong_t purr_counter;            /* number of purr cycles spent in user + kernel mode */
790        u_longlong_t spurr_counter;           /* number of spurr cycles spent in user + kernel mode */
791
792        /* Marketing Requirement(MR): MR1124083744  */
793        u_longlong_t real_free;               /* free real memory (in 4KB pages) */
794        u_longlong_t real_avail;              /* number of pages available for user application (memfree + numperm - minperm - minfree) */
795        /*      >>>>> END OF STRUCTURE DEFINITION <<<<<         */
796#define CURR_VERSION_PARTITION_TOTAL 5        /* Incremented by one for every new release     *
797                                               * of perfstat_partition_total_t data structure */
798} perfstat_partition_total_t_71_1;
799
800typedef union { /* WPAR Type & Flags */
801        uint    w;
802        struct {
803                unsigned app_wpar :1;        /* Application WPAR */
804                unsigned cpu_rset :1;        /* WPAR restricted to CPU resource set */
805                unsigned cpu_xrset:1;        /* WPAR restricted to CPU Exclusive resource set */
806                unsigned cpu_limits :1;      /* CPU resource limits enforced */
807                unsigned mem_limits :1;      /* Memory resource limits enforced */
808                unsigned spare :27;          /* reserved for future usage */
809        } b;
810} perfstat_wpar_type_t;
811
812typedef struct { /* Workload partition Information AIX 5.3 & 6.1*/
813       char name[MAXCORRALNAMELEN+1]; /* name of the Workload Partition */
814       perfstat_wpar_type_t type;     /* set of bits describing the wpar */
815       cid_t wpar_id;                 /* workload partition identifier */
816       uint  online_cpus;             /* Number of Virtual CPUs in partition rset or  number of virtual CPUs currently online on the Global partition*/
817       int   cpu_limit;               /* CPU limit in 100ths of % - 1..10000 */
818       int   mem_limit;               /* Memory limit in 100ths of % - 1..10000 */
819       u_longlong_t online_memory;    /* amount of memory currently online in Global Partition */
820       int entitled_proc_capacity;    /* number of processor units this partition is entitled to receive */
821} perfstat_wpar_total_t_61;
822
823typedef struct { /* Workload partition Information AIX 7.1*/
824       char name[MAXCORRALNAMELEN+1]; /* name of the Workload Partition */
825       perfstat_wpar_type_t type;     /* set of bits describing the wpar */
826       cid_t wpar_id;                 /* workload partition identifier */
827       uint  online_cpus;             /* Number of Virtual CPUs in partition rset or  number of virtual CPUs currently online on the Global partition*/
828       int   cpu_limit;               /* CPU limit in 100ths of % - 1..10000 */
829       int   mem_limit;               /* Memory limit in 100ths of % - 1..10000 */
830       u_longlong_t online_memory;    /* amount of memory currently online in Global Partition */
831       int entitled_proc_capacity;    /* number of processor units this partition is entitled to receive */
832       u_longlong_t version;          /* version number (1, 2, etc.,)                  */
833/*      >>>>> END OF STRUCTURE DEFINITION <<<<<         */
834#define CURR_VERSION_WPAR_TOTAL 1     /* Incremented by one for every new release      *
835                                       * of perfstat_wpar_total_t data structure       */
836} perfstat_wpar_total_t_71;
837
838typedef void * rsethandle_t;  /* Type to identify a resource set handle: rsethandle_t */
839
840typedef enum { WPARNAME, WPARID, RSETHANDLE } wparid_specifier; /* Type of wparid_specifier */
841
842typedef struct { /* WPAR identifier */
843        wparid_specifier spec;  /* Specifier to choose wpar id or name */
844        union  {
845                cid_t wpar_id;                      /* WPAR ID */
846                rsethandle_t rset;                  /* Rset Handle */
847                char wparname[MAXCORRALNAMELEN+1];  /* WPAR NAME */
848        } u;
849        char name[IDENTIFIER_LENGTH]; /* name of the structure element identifier */
850} perfstat_id_wpar_t;
851
852
853
854// end: libperfstat.h (AIX 5.2, 5.3, 6.1, 7.1)
855//////////////////////////////////////////////////////////////////////////////////////////////////////////////
856
857#define PERFSTAT_PARTITON_TOTAL_T_LATEST perfstat_partition_total_t_71_1/* latest perfstat_partition_total_t structure */
858#define PERFSTAT_CPU_TOTAL_T_LATEST perfstat_cpu_total_t_72             /* latest perfstat_cpu_total_t structure */
859#define PERFSTAT_WPAR_TOTAL_T_LATEST perfstat_wpar_total_t_71           /* latest perfstat_wpar_total_t structure */
860
861class libperfstat {
862
863public:
864
865  // Load the libperfstat library (must be in LIBPATH).
866  // Returns true if succeeded, false if error.
867  static bool init();
868  static void cleanup();
869
870  // Direct wrappers for the libperfstat functionality. All they do is
871  // to call the functions with the same name via function pointers.
872  // Get all available data also on newer AIX versions (PERFSTAT_CPU_TOTAL_T_LATEST).
873  static int perfstat_cpu_total(perfstat_id_t *name, PERFSTAT_CPU_TOTAL_T_LATEST* userbuff,
874                                int sizeof_userbuff, int desired_number);
875
876  static int perfstat_memory_total(perfstat_id_t *name, perfstat_memory_total_t* userbuff,
877                                   int sizeof_userbuff, int desired_number);
878
879  static int perfstat_partition_total(perfstat_id_t *name, PERFSTAT_PARTITON_TOTAL_T_LATEST* userbuff,
880                                      int sizeof_userbuff, int desired_number);
881
882  static void perfstat_reset();
883
884  static int perfstat_wpar_total(perfstat_id_wpar_t *name, PERFSTAT_WPAR_TOTAL_T_LATEST* userbuff,
885                                 int sizeof_userbuff, int desired_number);
886
887  static cid_t wpar_getcid();
888
889
890  ////////////////////////////////////////////////////////////////
891  // The convenience functions get_partitioninfo(), get_cpuinfo(), get_wparinfo() return
892  // information about partition, cpu and wpars, respectivly. They can be used without
893  // regard for which OS release we are on. On older AIX release, some output structure
894  // members will be 0.
895
896  // Result struct for get_partitioninfo().
897  struct partitioninfo_t {
898    // partition type info
899    unsigned smt_capable :1;          /* OS supports SMT mode */
900    unsigned smt_enabled :1;          /* SMT mode is on */
901    unsigned lpar_capable :1;         /* OS supports logical partitioning */
902    unsigned lpar_enabled :1;         /* logical partitioning is on */
903    unsigned shared_capable :1;       /* OS supports shared processor LPAR */
904    unsigned shared_enabled :1;       /* partition runs in shared mode */
905    unsigned dlpar_capable :1;        /* OS supports dynamic LPAR */
906    unsigned capped :1;               /* partition is capped */
907    unsigned kernel_is_64 :1;         /* kernel is 64 bit */
908    unsigned pool_util_authority :1;  /* pool utilization available */
909    unsigned donate_capable :1;       /* capable of donating cycles */
910    unsigned donate_enabled :1;       /* enabled for donating cycles */
911    unsigned ams_capable:1;           /* 1 = AMS(Active Memory Sharing) capable, 0 = Not AMS capable */
912    unsigned ams_enabled:1;           /* 1 = AMS(Active Memory Sharing) enabled, 0 = Not AMS enabled */
913    unsigned power_save:1;            /* 1 = Power saving mode is enabled */
914    unsigned ame_enabled:1;           /* Active Memory Expansion is enabled */
915    // partition total info
916    int online_cpus;                  /* number of virtual CPUs currently online on the partition */
917    int entitled_proc_capacity;       /* number of processor units this partition is entitled to receive */
918    int var_proc_capacity_weight;     /* partition priority weight to receive extra capacity */
919    int phys_cpus_pool;               /* number of the physical CPUs currently in the shared processor pool this partition belong to */
920    int pool_id;                      /* identifier of the shared pool of physical processors this partition is a member of */
921    u_longlong_t entitled_pool_capacity;  /* Entitled processor capacity of partitions pool */
922    char name[IDENTIFIER_LENGTH];     /* name of the logical partition */
923
924    u_longlong_t timebase_last;       /* most recently cpu time base (an incremented long int on PowerPC) */
925    u_longlong_t pool_idle_time;      /* pool idle time = number of clock tics a processor in the shared pool was idle */
926    u_longlong_t pcpu_tics_user;      /* raw number of physical processor tics in user mode */
927    u_longlong_t pcpu_tics_sys;       /* raw number of physical processor tics in system mode */
928    u_longlong_t pcpu_tics_idle;      /* raw number of physical processor tics idle */
929    u_longlong_t pcpu_tics_wait;      /* raw number of physical processor tics waiting for I/O */
930
931    u_longlong_t true_memory;          /* True Memory Size in 4KB pages */
932    u_longlong_t expanded_memory;      /* Expanded Memory Size in 4KB pages */
933    u_longlong_t target_memexp_factr;  /* Target Memory Expansion Factor scaled by 100 */
934    u_longlong_t current_memexp_factr; /* Current Memory Expansion Factor scaled by 100 */
935    u_longlong_t cmcs_total_time;      /* Total CPU time spent due to active memory expansion */
936  };
937
938  // Result struct for get_cpuinfo().
939  struct cpuinfo_t {
940    char description[IDENTIFIER_LENGTH];  // processor description (type/official name)
941    u_longlong_t processorHZ;             // processor speed in Hz
942    int ncpus;                            // number of active logical processors
943    double loadavg[3];                    // (1<<SBITS) times the average number of runnables processes during the last 1, 5 and 15 minutes.
944                                          // To calculate the load average, divide the numbers by (1<<SBITS). SBITS is defined in <sys/proc.h>.
945    char version[20];                     // processor version from _system_configuration (sys/systemcfg.h)
946    unsigned long long user_clock_ticks;  // raw total number of clock ticks spent in user mode
947    unsigned long long sys_clock_ticks;   // raw total number of clock ticks spent in system mode
948    unsigned long long idle_clock_ticks;  // raw total number of clock ticks spent idle
949    unsigned long long wait_clock_ticks;  // raw total number of clock ticks spent waiting for I/O
950  };
951
952  // Result struct for get_wparinfo().
953  struct wparinfo_t {
954    char name[MAXCORRALNAMELEN+1];  /* name of the Workload Partition */
955    unsigned short wpar_id;         /* workload partition identifier */
956    unsigned app_wpar :1;           /* Application WPAR */
957    unsigned cpu_rset :1;           /* WPAR restricted to CPU resource set */
958    unsigned cpu_xrset:1;           /* WPAR restricted to CPU Exclusive resource set */
959    unsigned cpu_limits :1;         /* CPU resource limits enforced */
960    unsigned mem_limits :1;         /* Memory resource limits enforced */
961    int cpu_limit;                  /* CPU limit in 100ths of % - 1..10000 */
962    int mem_limit;                  /* Memory limit in 100ths of % - 1..10000 */
963  };
964
965  static bool get_partitioninfo(partitioninfo_t* ppi);
966  static bool get_cpuinfo(cpuinfo_t* pci);
967  static bool get_wparinfo(wparinfo_t* pwi);
968
969};
970
971#endif // OS_AIX_VM_LIBPERFSTAT_AIX_HPP
972