bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getloadavg on aix5


From: Jim Meyering
Subject: Re: getloadavg on aix5
Date: Mon, 04 Feb 2008 15:25:53 +0100

"Peter O'Gorman" <address@hidden> wrote:
> I seem to have lost Jim's reply, but here is a patch. Works on
> aix-4.3.3 and aix-5.3.
>
> The SBITS thing is the way the libperstat.h header recommends
> calculating the loadavg:
>
> /* To calculate the load average, divide the numbers by (1<<SBITS). SBITS is 
> defined in <sys/proc.h>. */
>
> Of course, it is not defined on aix4.3.3 ...

Hi Peter,

Here's an incremental diff.
Most changes are syntactic, but I did eliminate an #if block
by moving the static declaration of cpu_stats into the
block that uses that variable.  I also removed some casts.

FYI, I realize you were just retaining the existing style,
but I'd rather begin the process of moving toward less
syntax (removing parentheses around cpp symbols), at least
on most of the lines touched by this change.

If you can confirm that this works, I'll write
the ChangeLog and check in the combined change set.


diff --git a/lib/getloadavg.c b/lib/getloadavg.c
index ec09919..5faa8fa 100644
--- a/lib/getloadavg.c
+++ b/lib/getloadavg.c
@@ -256,7 +256,7 @@
 #   define LOAD_AVE_TYPE long
 #  endif

-#  if defined (_AIX) && ! defined(HAVE_LIBPERFSTAT)
+#  if defined _AIX && ! defined HAVE_LIBPERFSTAT
 #   define LOAD_AVE_TYPE long
 #  endif

@@ -311,7 +311,7 @@
 #   define FSCALE 100.0
 #  endif

-#  if defined (_AIX) && !defined(HAVE_LIBPERFSTAT)
+#  if defined _AIX && !defined HAVE_LIBPERFSTAT
 #   define FSCALE 65536.0
 #  endif

@@ -406,7 +406,7 @@

 # endif /* LOAD_AVE_TYPE */

-# if defined (HAVE_LIBPERFSTAT)
+# if defined HAVE_LIBPERFSTAT
 #  include <libperfstat.h>
 #  include <sys/proc.h>
 #  ifndef SBITS
@@ -495,10 +495,6 @@ static kvm_t *kd;
 #  endif /* SUNOS_5 */

 # endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */
-
-# if defined(HAVE_LIBPERFSTAT)
-static perfstat_cpu_total_t cpu_stats;
-# endif
 
 /* Put the 1 minute, 5 minute and 15 minute load averages
    into the first NELEM elements of LOADAVG.
@@ -582,16 +578,20 @@ getloadavg (double loadavg[], int nelem)

 # endif /* hpux && HAVE_PSTAT_GETDYNAMIC */

-# if ! defined (LDAV_DONE) && defined(HAVE_LIBPERFSTAT)
+# if ! defined LDAV_DONE && defined HAVE_LIBPERFSTAT
 #  define LDAV_DONE
 #  undef LOAD_AVE_TYPE
 /* Use perfstat_cpu_total because we don't have to be root. */
-  int result = perfstat_cpu_total( NULL, &cpu_stats, sizeof(cpu_stats), 1);
-  if (result == -1) return result;
-  loadavg[0] = (double) cpu_stats.loadavg[0] / (double)(1 << SBITS);
-  loadavg[1] = (double) cpu_stats.loadavg[1] / (double)(1 << SBITS);
-  loadavg[2] = (double) cpu_stats.loadavg[2] / (double)(1 << SBITS);
-  elem = 3;
+  {
+    perfstat_cpu_total_t cpu_stats;
+    int result = perfstat_cpu_total (NULL, &cpu_stats, sizeof cpu_stats, 1);
+    if (result == -1)
+      return result;
+    loadavg[0] = cpu_stats.loadavg[0] / (double)(1 << SBITS);
+    loadavg[1] = cpu_stats.loadavg[1] / (double)(1 << SBITS);
+    loadavg[2] = cpu_stats.loadavg[2] / (double)(1 << SBITS);
+    elem = 3;
+  }
 # endif

 # if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]