Updating branch refs/heads/master
         to d04d9b15a97df645286cfb6be2a2d8987b0167f7 (commit)
       from eb6a0246c9c8f23f5f3a6144b0ddc13d2b68894f (commit)

commit d04d9b15a97df645286cfb6be2a2d8987b0167f7
Author: Landry Breuil <[email protected]>
Date:   Wed Apr 18 23:27:54 2012 +0200

    Add support for multicore on FreeBSD (bug #6531)

 panel-plugin/os.c |   50 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/panel-plugin/os.c b/panel-plugin/os.c
index 83967c4..87e0322 100644
--- a/panel-plugin/os.c
+++ b/panel-plugin/os.c
@@ -134,28 +134,54 @@ gboolean read_cpu_data( CpuData *data, guint nb_cpu )
 #elif defined (__FreeBSD__)
 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)
 {
        glong used, total;
-       glong cp_time[CPUSTATES];
-       gsize len = sizeof( cp_time );
+       glong *cp_time;
+       glong *cp_time1;
+       gint i;
+       unsigned int max_cpu;
+       gsize len = sizeof(max_cpu);
 
-       if( sysctlbyname( "kern.cp_time", &cp_time, &len, NULL, 0 ) < 0 )
+       data[0].load = 0;
+       if (sysctlbyname("kern.smp.maxid", &max_cpu, &len, NULL, 0) < 0)
                return FALSE;
 
-       used = cp_time[CP_USER] + cp_time[CP_NICE] + cp_time[CP_SYS] + 
cp_time[CP_INTR];
-       total = used + cp_time[CP_IDLE];
-       if( (total - data[0].previous_total) != 0 )
-               data[0].load = (CPU_SCALE * (used - 
data[0].previous_used))/(total - data[0].previous_total);
-       else
-               data[0].load = 0;
+       max_cpu++; /* max_cpu is 0-based */
+       if (max_cpu < nb_cpu)
+               return FALSE; /* should not happen */
+       len = sizeof(glong) * max_cpu * CPUSTATES;
+       cp_time = (glong *) g_malloc(len);
 
-       data[0].previous_used = used;
-       data[0].previous_total = total;
+       if (sysctlbyname( "kern.cp_times", cp_time, &len, NULL, 0 ) < 0) {
+               g_free(cp_time);
+               return FALSE;
+       }
+       for (i = 1; i <= nb_cpu; i++ )
+       {
+               cp_time1 = &cp_time[CPUSTATES * (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;
+       g_free(cp_time);
        return TRUE;
 }
 
_______________________________________________
Xfce4-commits mailing list
[email protected]
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to