Updating branch refs/heads/master
         to 2da0944c5f498d8be65340af6cd0e84e63494bf0 (commit)
       from d5077564dbe61e86ef7a0504daa4a41ddb6a3a1c (commit)

commit 2da0944c5f498d8be65340af6cd0e84e63494bf0
Author: Florian Rivoal <[email protected]>
Date:   Thu Apr 29 13:52:42 2010 +0900

    Fix support for NetBSD
    
    Fix the code reading cpu state on NetBSD, and support multiple CPUs
    while I am at it.

 panel-plugin/os.c |   55 +++++++++++++++++++++++++++--------------------------
 1 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/panel-plugin/os.c b/panel-plugin/os.c
index 1459ec9..4a843e1 100644
--- a/panel-plugin/os.c
+++ b/panel-plugin/os.c
@@ -30,8 +30,6 @@
 #include <sys/param.h>
 #include <sys/sched.h>
 #include <sys/sysctl.h>
-#include <fcntl.h>
-#include <nlist.h>
 #endif
 
 #if defined (__OpenBSD__)
@@ -146,39 +144,42 @@ gboolean read_cpu_data( CpuData *data, guint nb_cpu)
 #elif defined (__NetBSD__)
 guint detect_cpu_number()
 {
-       return 1;
+       static gint mib[] = {CTL_HW, HW_NCPU};
+       gint ncpu;
+       gsize len = sizeof( gint );
+       if( sysctl( mib, 2, &ncpu, &len, NULL, 0 ) < 0 )
+               return 0;
+       else
+               return ncpu;
 }
 
 gboolean read_cpu_data( CpuData *data, guint nb_cpu)
 {
-       guint user, nice, sys, bsdidle, idle;
-       guint used, total;
-       static gint mib[] = {CTL_KERN, KERN_CP_TIME };
-       guint64 cp_time[CPUSTATES];
-       gsize len = sizeof( cp_time );
-
+       guint64 used, total;
+       guint64 cp_time[CPUSTATES * nb_cpu];
+       guint64 *cp_time1;
+       gint i;
+       gsize len = nb_cpu * CPUSTATES * sizeof( guint64 );
+       gint mib[] = {CTL_KERN, KERN_CP_TIME};
        if( sysctl( mib, 2, &cp_time, &len, NULL, 0 ) < 0 )
-       {
                return FALSE;
-       }
 
-       user = cp_time[CP_USER];
-       nice = cp_time[CP_NICE];
-       sys = cp_time[CP_SYS];
-       bsdidle = cp_time[CP_IDLE];
-       idle = cp_time[CP_IDLE];
-
-       used = user+nice+sys;
-       total = used+bsdidle;
-
-       if( total - data[0].previous_total != 0 )
-               data[0].load = (CPU_SCALE * (used - data[0].previous_total)) / 
(total - data[0].previous_total);
-       else
-               data[0].load = 0;
-
-       data[0].previous_used = used;
-       data[0].previous_total = total;
+       data[0].load = 0;
+       for( i = 1 ; i <= nb_cpu ; i++ )
+       {
+               cp_time1 = cp_time + CPUSTATE * (i - 1)
+               used = cp_time1[CP_USER] + cp_time1[CP_NICE] + cp_time1[CP_SYS] 
+ cp_time1[CP_INTR];
+               total = used + cp_time1[CP_IDLE];
 
+               if( total - data[i].previous_total != 0 )
+                       data[i].load = (CPU_SCALE * (used - 
data[i].previous_used))/(total - data[i].previous_total);
+               else
+                       data[i].load = 0;
+               data[i].previous_used = used;
+               data[i].previous_total = total;
+               data[0].load += data[i].load;
+       }
+       data[0].load /= nb_cpu;
        return TRUE;
 }
 
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to