lpar plugin: Introduce a "NS_TO_TICKS" macro.
[collectd.git] / src / lpar.c
index 4f7f444..562d2d4 100644 (file)
@@ -34,6 +34,8 @@
                    (double)(_system_configuration.Xfrac))
 #endif
 
+#define NS_TO_TICKS(ns) ((ns) / XINTFRAC)
+
 static const char *config_keys[] =
 {
   "CpuPoolStats",
@@ -201,14 +203,6 @@ static int lpar_read (void)
                return (-1);
        }
 
-       /*
-        * On a shared partition, we're "entitled" to a certain amount of
-        * processing power, for example 250/100 of a physical CPU. Processing
-        * capacity not used by the partition may be assigned to a different
-        * partition by the hypervisor, so "idle" is hopefully a very small
-        * number.
-        */
-
        /* Number of ticks since we last run. */
        ticks = lparstats.timebase_last - time_old;
        if (ticks == 0)
@@ -217,6 +211,14 @@ static int lpar_read (void)
                return (0);
        }
 
+       /*
+        * On a shared partition, we're "entitled" to a certain amount of
+        * processing power, for example 250/100 of a physical CPU. Processing
+        * capacity not used by the partition may be assigned to a different
+        * partition by the hypervisor, so "idle" is hopefully a very small
+        * number.
+        */
+
        /* entitled_proc_capacity is in 1/100th of a CPU */
        entitled_proc_capacity = 0.01 * ((double) lparstats.entitled_proc_capacity);
        lpar_submit ("entitled", entitled_proc_capacity);
@@ -245,6 +247,8 @@ static int lpar_read (void)
 
                /* FYI:  PURR == Processor Utilization of Resources Register
                 *      SPURR == Scaled PURR */
+               /* donated => ticks given to another partition
+                * stolen  => ticks received from another partition */
                lpar_submit ("idle_donated", (double) idle_donated_ticks / (double) ticks);
                lpar_submit ("busy_donated", (double) busy_donated_ticks / (double) ticks);
                lpar_submit ("idle_stolen",  (double) idle_stolen_ticks  / (double) ticks);
@@ -266,10 +270,10 @@ static int lpar_read (void)
 
                /* Pool stats are in CPU x ns */
                ssnprintf (typinst, sizeof (typinst), "pool-%X-busy", lparstats.pool_id);
-               lpar_submit (typinst, (double) pool_busy_ns / XINTFRAC / (double) ticks);
+               lpar_submit (typinst, NS_TO_TICKS ((double) pool_busy_ns) / (double) ticks);
 
                ssnprintf (typinst, sizeof (typinst), "pool-%X-total", lparstats.pool_id);
-               lpar_submit (typinst, (double) pool_max_ns / XINTFRAC / (double) ticks);
+               lpar_submit (typinst, NS_TO_TICKS ((double) pool_max_ns) / (double) ticks);
        }
 
        save_last_values (&lparstats);