[Xfce4-commits] <xfce4-cpugraph-plugin:taskbranch/bug-6721> Add Solaris support

Florian Rivoal noreply at xfce.org
Wed Oct 6 17:46:02 CEST 2010


Updating branch refs/heads/taskbranch/bug-6721
         to 71a1d163c5d31f78e91fb9d2f5bdc9ffb2dd017a (commit)
       from cacc35ee18a348a45b899690257a51889d55230f (commit)

commit 71a1d163c5d31f78e91fb9d2f5bdc9ffb2dd017a
Author: Peter Tribble <peter.tribble at gmail.com>
Date:   Thu Oct 7 00:37:25 2010 +0900

    Add Solaris support
    
    Extends the platform specific code to support Solaris, with multicore
    support. Patch from Peter Tribble.

 panel-plugin/os.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/panel-plugin/os.c b/panel-plugin/os.c
index 2655448..f0719ba 100644
--- a/panel-plugin/os.c
+++ b/panel-plugin/os.c
@@ -6,6 +6,7 @@
  *  Copyright (c) 2007-2008 Angelo Arrifano <miknix at gmail.com>
  *  Copyright (c) 2007-2008 Lidiriel <lidiriel at coriolys.org>
  *  Copyright (c) 2010 Florian Rivoal <frivoal at gmail.com>
+ *  Copyright (c) 2010  Peter Tribble <peter.tribble at gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -61,6 +62,11 @@
 #include <sys/sysctl.h>
 #endif
 
+#if defined (__sun__)
+#include <kstat.h>
+static kstat_ctl_t *kc;
+#endif
+
 #if defined (__linux__) || defined (__FreeBSD_kernel__)
 guint detect_cpu_number()
 {
@@ -234,6 +240,68 @@ gboolean read_cpu_data( CpuData *data, guint nb_cpu)
 	data[0].load /= nb_cpu;
 	return TRUE;
 }
+
+#elif defined (__sun__)
+static void init_stats()
+{
+	kc = kstat_open();
+}
+
+guint detect_cpu_number()
+{
+	kstat_t *ksp;
+	kstat_named_t *knp;
+
+	if( !kc )
+		init_stats();
+
+	if( !(ksp = kstat_lookup( kc, "unix", 0, "system_misc" )) )
+		return 0;
+	else
+		kstat_read( kc, ksp, NULL );
+		knp = kstat_data_lookup( ksp, "ncpus" );
+		return knp->value.ui32;
+}
+
+gboolean read_cpu_data( CpuData *data, guint nb_cpu )
+{
+	kstat_t *ksp;
+	kstat_named_t *knp;
+	guint64 used, total;
+	gint i;
+	data[0].load = 0;
+
+	if( !kc )
+		init_stats();
+
+	i = 1;
+	for( ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next )
+	{
+		if( !g_strcmp0( ksp->ks_module, "cpu" ) && !g_strcmp0( ksp->ks_name, "sys" ) )
+		{
+			kstat_read( kc, ksp, NULL );
+			knp = kstat_data_lookup( ksp, "cpu_nsec_user" );
+			used = knp->value.ul;
+			knp = kstat_data_lookup( ksp, "cpu_nsec_intr" );
+			used += knp->value.ul;
+			knp = kstat_data_lookup( ksp, "cpu_nsec_kernel" );
+			used += knp->value.ul;
+			knp = kstat_data_lookup( ksp, "cpu_nsec_idle" );
+			total = used + knp->value.ul;
+			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;
+			i++;
+		}
+	}
+
+	data[0].load /= nb_cpu;
+	return TRUE;
+}
 #else
 #error "Your OS is not supported."
 #endif



More information about the Xfce4-commits mailing list