X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Flpar.c;h=69a56e1cdea3e9508c0b3bc14ab5aace5a622deb;hb=db8b1cda4841f45af22d149c6bfc575e79289f75;hp=ec39d5c0e8cac9fdc19f2f326a070ae91375dec3;hpb=ddeeba4c8179448e3045403823f327254c781257;p=collectd.git diff --git a/src/lpar.c b/src/lpar.c index ec39d5c0..69a56e1c 100644 --- a/src/lpar.c +++ b/src/lpar.c @@ -20,6 +20,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -34,7 +35,7 @@ (double)(_system_configuration.Xfrac)) #endif -#define NS_TO_TICKS(ns) ((ns) / XINTFRAC) +#define CLOCKTICKS_TO_TICKS(cticks) ((cticks) / XINTFRAC) static const char *config_keys[] = { @@ -45,7 +46,9 @@ static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static _Bool pool_stats = 0; static _Bool report_by_serial = 0; +#if PERFSTAT_SUPPORTS_DONATION static _Bool donate_flag = 0; +#endif static char serial[SYS_NMLN]; static perfstat_partition_total_t lparstats_old; @@ -91,11 +94,13 @@ static int lpar_init (void) return (-1); } +#if PERFSTAT_SUPPORTS_DONATION if (!lparstats_old.type.b.shared_enabled && lparstats_old.type.b.donate_enabled) { donate_flag = 1; } +#endif if (pool_stats && !lparstats_old.type.b.pool_util_authority) { @@ -109,22 +114,15 @@ static int lpar_init (void) static void lpar_submit (const char *type_instance, double value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = (gauge_t)value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; if (report_by_serial) { sstrncpy (vl.host, serial, sizeof (vl.host)); sstrncpy (vl.plugin_instance, hostname_g, sizeof (vl.plugin)); } - else - { - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); - } sstrncpy (vl.plugin, "lpar", sizeof (vl.plugin)); sstrncpy (vl.type, "vcpu", sizeof (vl.type)); sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); @@ -202,6 +200,7 @@ static int lpar_read (void) lpar_submit ("wait", (double) wait_ticks / (double) ticks); lpar_submit ("idle", (double) idle_ticks / (double) ticks); +#if PERFSTAT_SUPPORTS_DONATION if (donate_flag) { /* donated => ticks given to another partition @@ -224,27 +223,31 @@ static int lpar_read (void) /* Donated ticks will be accounted for as stolen ticks in other LPARs */ consumed_ticks += idle_stolen_ticks + busy_stolen_ticks; } +#endif lpar_submit ("consumed", (double) consumed_ticks / (double) ticks); if (pool_stats) { char typinst[DATA_MAX_NAME_LEN]; - u_longlong_t pool_busy_ns; - u_longlong_t pool_max_ns; - u_longlong_t pool_idle_ns = 0; - - pool_busy_ns = lparstats.pool_busy_time - lparstats_old.pool_busy_time; - pool_max_ns = lparstats.pool_max_time - lparstats_old.pool_max_time; - if (pool_max_ns > pool_busy_ns) - pool_idle_ns = pool_max_ns - pool_busy_ns; + u_longlong_t pool_idle_cticks; + double pool_idle_cpus; + double pool_busy_cpus; + + /* We're calculating "busy" from "idle" and the total number of + * CPUs, because the "busy" member didn't exist in early versions + * of libperfstat. It was added somewhere between AIX 5.3 ML5 and ML9. */ + pool_idle_cticks = lparstats.pool_idle_time - lparstats_old.pool_idle_time; + pool_idle_cpus = CLOCKTICKS_TO_TICKS ((double) pool_idle_cticks) / (double) ticks; + pool_busy_cpus = ((double) lparstats.phys_cpus_pool) - pool_idle_cpus; + if (pool_busy_cpus < 0.0) + pool_busy_cpus = 0.0; - /* Pool stats are in CPU x ns */ ssnprintf (typinst, sizeof (typinst), "pool-%X-busy", lparstats.pool_id); - lpar_submit (typinst, NS_TO_TICKS ((double) pool_busy_ns) / (double) ticks); + lpar_submit (typinst, pool_busy_cpus); ssnprintf (typinst, sizeof (typinst), "pool-%X-idle", lparstats.pool_id); - lpar_submit (typinst, NS_TO_TICKS ((double) pool_idle_ns) / (double) ticks); + lpar_submit (typinst, pool_idle_cpus); } memcpy (&lparstats_old, &lparstats, sizeof (lparstats_old));