[collectd] AIX: WPAR and cpu patchs.

Manuel Luis Sanmartín Rozada manuel.luis at gmail.com
Wed Aug 25 16:07:31 CEST 2010


Hello.

In cpu.c the variable temp is not used:

cc1: warnings being treated as errors
cpu.c: In function 'cpu_read':
cpu.c:566: warning: unused variable 'temp'

a small patch:

diff --git a/src/cpu.c b/src/cpu.c
index f89882a..306d2e2 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -563,7 +563,6 @@ static int cpu_read (void)
        u_longlong_t *cpu_total = NULL;
        perfstat_id_t id;
        perfstat_cpu_t *pcpu;
-       u_longlong_t *temp;
        int numcpu;
        int i;

The cpus switch on/off  works well.

In the wpar plugin I change some strings, and the wpar cpu code.
The cpu part was wrong, I send an old version.
I need to do some calculations to convert the physical tics to
something like cpu total from 0 to 100.

diff --git a/src/wpar.c b/src/wpar.c
index d2f548f..1e3b308 100644
--- a/src/wpar.c
+++ b/src/wpar.c
@@ -34,6 +34,16 @@
 static int pagesize;
 static int wpar_total_num;
 static perfstat_wpar_total_t *wpar_total = NULL;
+static unsigned long long timebase_saved;
+static time_t time_saved;
+
+typedef struct wpar_cpu {
+  u_longlong_t user;
+  u_longlong_t sys;
+} wpar_cpu_t;
+
+static wpar_cpu_t *prev_wcpu;
+static wpar_cpu_t *cnt_wcpu;

 static int wpar_init(void) /* {{{ */
 {
@@ -89,7 +99,7 @@ static void load_submit (const char
*plugin_instance, gauge_t snum, gauge_t mnum
   vl.values = values;
   vl.values_len = STATIC_ARRAY_SIZE (values);
   sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-  sstrncpy (vl.plugin, "load", sizeof (vl.plugin));
+  sstrncpy (vl.plugin, "wpar", sizeof (vl.plugin));
   sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
   sstrncpy (vl.type, "load", sizeof (vl.type));

@@ -101,6 +111,33 @@ static int wpar_read (void) /* {{{ */
   int i;
   int nwpar;
   perfstat_id_wpar_t id_wpar;
+  perfstat_partition_total_t part;
+  unsigned long long hardware_ticks;
+  time_t time_now;
+  time_t time_diff;
+
+  /* Read the partition information to get the cpu time base */
+  if (perfstat_partition_total(/* perfstat_id_t */ NULL,
+      /* (out) perfstat_partition_total_t */ &part,
+      /* sizeof_userbuff = */ sizeof(perfstat_partition_total_t),
+      /* desired_number = */ 1) < 0)
+  {
+    char errbuf[1024];
+    WARNING ("wpar plugin: perfstat_partition_total failed: %s",
+        sstrerror (errno, errbuf, sizeof (errbuf)));
+    return (-1);
+  }
+
+  if (timebase_saved > 0)
+    hardware_ticks = part.timebase_last - timebase_saved;
+  else
+    hardware_ticks = 0;
+
+  timebase_saved = part.timebase_last;
+
+  time_now = time(NULL);
+  time_diff = time_now - time_saved;
+  time_saved = time_now;

   /* Read the number of partitions */
   nwpar = perfstat_wpar_total (/* id = */ NULL,
@@ -133,12 +170,29 @@ static int wpar_read (void) /* {{{ */
       return (ENOMEM);
     }
     wpar_total = tmp;
+
+    sfree(prev_wcpu);
+    prev_wcpu = calloc (nwpar, sizeof (wpar_cpu_t));
+    if (prev_wcpu == NULL)
+    {
+      ERROR ("wpar plugin: calloc failed.");
+      return (ENOMEM);
+    }
+
+    sfree(cnt_wcpu);
+    cnt_wcpu = calloc (nwpar, sizeof (wpar_cpu_t));
+    if (cnt_wcpu == NULL)
+    {
+      ERROR ("wpar plugin: calloc failed.");
+      return (ENOMEM);
+    }
+    /* Skip one loop in cpu collection to fill prev_wcpu */
+    hardware_ticks = 0;
   }
   wpar_total_num = nwpar;

   memset (&id_wpar, 0, sizeof (id_wpar));
-  id_wpar.spec = WPARID;
-  id_wpar.u.wpar_id = FIRST_WPARID;
+  id_wpar.spec = WPARNAME;

   /* Now actually query the data */
   nwpar = perfstat_wpar_total (/* id = */ &id_wpar,
@@ -148,7 +202,7 @@ static int wpar_read (void) /* {{{ */
   if (nwpar < 0)
   {
     char errbuf[1024];
-    WARNING ("cpu plugin: perfstat_wpar_total failed: %s",
+    WARNING ("wpar plugin: perfstat_wpar_total failed: %s",
         sstrerror (errno, errbuf, sizeof (errbuf)));
     return (-1);
   }
@@ -182,7 +236,7 @@ static int wpar_read (void) /* {{{ */
     if (status < 0)
     {
       char errbuf[1024];
-      WARNING ("memory plugin: perfstat_memory_total_wpar(%s) failed: %s",
+      WARNING ("wpar plugin: perfstat_memory_total_wpar(%s) failed: %s",
           wname, sstrerror (errno, errbuf, sizeof (errbuf)));
       continue;
     }
@@ -200,7 +254,7 @@ static int wpar_read (void) /* {{{ */
     if (status < 0)
     {
       char errbuf[1024];
-      WARNING ("memory plugin: perfstat_cpu_total_wpar(%s) failed: %s",
+      WARNING ("wpar plugin: perfstat_cpu_total_wpar(%s) failed: %s",
           wname, sstrerror (errno, errbuf, sizeof (errbuf)));
       continue;
     }
@@ -212,10 +266,20 @@ static int wpar_read (void) /* {{{ */

     load_submit (wname, snum, mnum, lnum);

-    cpu_submit (wname, "idle",   (counter_t) wcpu.pidle);
-    cpu_submit (wname, "system", (counter_t) wcpu.psys);
-    cpu_submit (wname, "user",   (counter_t) wcpu.puser);
-    cpu_submit (wname, "wait",   (counter_t) wcpu.pwait);
+    if (hardware_ticks > 0)
+    {
+      /* Number of physical processors */
+      int pncpus = part.smt_thrds > 0 ? wcpu.ncpus / part.smt_thrds :
wcpu.ncpus;
+
+      cnt_wcpu[i].sys += (((wcpu.psys -
prev_wcpu[i].sys)*100*time_diff)/hardware_ticks)/pncpus;
+      cpu_submit (wname, "system", cnt_wcpu[i].sys);
+
+      cnt_wcpu[i].user += (((wcpu.puser -
prev_wcpu[i].user)*100*time_diff)/hardware_ticks)/pncpus;
+      cpu_submit (wname, "user", cnt_wcpu[i].user);
+    }
+
+    prev_wcpu[i].sys = wcpu.psys;
+    prev_wcpu[i].user = wcpu.puser;
   } /* for (i = 0 ... nwpar) */

   return (0);




On Wed, Aug 4, 2010 at 5:26 PM, Florian Forster <octo at verplant.org> wrote:
> Hi Manuel,
>
> On Tue, Jul 20, 2010 at 08:18:12PM +0200, Manuel Luis Sanmartín Rozada wrote:
>> The wpar patches are for a plugin to collect cpu, load and memory from
>> Workload Partitioning in AIX. It was tested with system WPAR in
>> aix 6.1.
>
> thank you very much for your patches :) I pulled them into my Git
> repository and pushed them to Github [0].
>
> I did some changes to the code, but couldn't test them because I don't
> have an AIX machine around. It'd be great if you could tell me whether
> it still works or not, so I can pull the changes into the master branch.
>
> Regards,
> —octo
>
> [0] <http://github.com/octo/collectd/commits/ms/wpar>
> --
> Florian octo Forster
> Hacker in training
> GnuPG: 0x91523C3D
> http://verplant.org/
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFMWYayHdggu3Q05IYRAhD3AJwIs2nPDd6XqzTpEiLFOZaAt6VoKwCfdrNS
> cWwHHnBo4MCMbIG7Wgj7AIQ=
> =aaKK
> -----END PGP SIGNATURE-----
>
>



More information about the collectd mailing list