[Xfce4-commits] [panel-plugins/xfce4-cpufreq-plugin] 05/07: Check if each cpu is online (Bug #14641)

noreply at xfce.org noreply at xfce.org
Fri Sep 21 15:21:41 CEST 2018


This is an automated email from the git hooks/post-receive script.

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-cpufreq-plugin.

commit 6c34eee3c07529529900230d32476ac840be11af
Author: Andre Miranda <andreldm at xfce.org>
Date:   Wed Sep 19 21:49:34 2018 -0300

    Check if each cpu is online (Bug #14641)
---
 panel-plugin/xfce4-cpufreq-linux-procfs.c |  2 ++
 panel-plugin/xfce4-cpufreq-linux-sysfs.c  | 13 +++++++++++++
 panel-plugin/xfce4-cpufreq-overview.c     |  1 +
 panel-plugin/xfce4-cpufreq-plugin.c       | 17 +++++++++++++++--
 panel-plugin/xfce4-cpufreq-plugin.h       |  2 ++
 5 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/panel-plugin/xfce4-cpufreq-linux-procfs.c b/panel-plugin/xfce4-cpufreq-linux-procfs.c
index acff94b..d9d9e2b 100644
--- a/panel-plugin/xfce4-cpufreq-linux-procfs.c
+++ b/panel-plugin/xfce4-cpufreq-linux-procfs.c
@@ -75,6 +75,7 @@ cpufreq_procfs_read_cpuinfo (void)
           cpu->cur_governor = NULL;
           cpu->available_freqs = NULL;
           cpu->available_governors = NULL;
+          cpu->online = TRUE;
           add_cpu = TRUE;
         }
 
@@ -137,6 +138,7 @@ cpufreq_procfs_read (void)
         cpu->cur_governor = g_new (gchar, 20);
         cpu->available_freqs = NULL;
         cpu->available_governors = NULL;
+        cpu->online = TRUE;
 
         sscanf (fileContent,
                 "CPU %*d %d kHz (%*d %%) - %d kHz (%*d %%) - %20s",
diff --git a/panel-plugin/xfce4-cpufreq-linux-sysfs.c b/panel-plugin/xfce4-cpufreq-linux-sysfs.c
index c53fad9..7dc7723 100644
--- a/panel-plugin/xfce4-cpufreq-linux-sysfs.c
+++ b/panel-plugin/xfce4-cpufreq-linux-sysfs.c
@@ -65,6 +65,18 @@ cpufreq_sysfs_read_current (gint cpu_number)
   file = g_strdup_printf (SYSFS_BASE"/cpu%i/cpufreq/scaling_governor", cpu_number);
   cpufreq_sysfs_read_string (file, &cpu->cur_governor);
   g_free (file);
+
+  /* read whether the cpu is online, skip first */
+  if (cpu_number != 0)
+  {
+    guint online;
+
+    file = g_strdup_printf (SYSFS_BASE"/cpu%i/online", cpu_number);
+    cpufreq_sysfs_read_int (file, &online);
+    g_free (file);
+
+    cpu->online = online != 0;
+  }
 }
 
 
@@ -164,6 +176,7 @@ parse_sysfs_init (gint cpu_number, CpuInfo *cpu)
 
   if (cpu == NULL) {
     cpu = g_new0 (CpuInfo, 1);
+    cpu->online = TRUE;
     add_cpu = TRUE;
   }
 
diff --git a/panel-plugin/xfce4-cpufreq-overview.c b/panel-plugin/xfce4-cpufreq-overview.c
index 0cc8060..02ea006 100644
--- a/panel-plugin/xfce4-cpufreq-overview.c
+++ b/panel-plugin/xfce4-cpufreq-overview.c
@@ -46,6 +46,7 @@ cpufreq_overview_add (CpuInfo *cpu, guint cpu_number, GtkWidget *dialog_hbox)
   GList *list;
 
   dialog_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, BORDER);
+  gtk_widget_set_sensitive (dialog_vbox, cpu->online);
   gtk_box_pack_start (GTK_BOX (dialog_hbox), dialog_vbox, TRUE, TRUE, 0);
 
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER);
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index 80723d3..b67a8d4 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -99,6 +99,9 @@ cpufreq_cpus_calc_min (void)
   {
     CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
 
+    if (!cpu->online)
+      continue;
+
     if (freq > cpu->cur_freq || i == 0)
       freq = cpu->cur_freq;
   }
@@ -116,15 +119,22 @@ cpufreq_cpus_calc_min (void)
 static CpuInfo *
 cpufreq_cpus_calc_avg (void)
 {
-  guint freq = 0;
+  guint freq = 0, count = 0;
 
   for (guint i = 0; i < cpuFreq->cpus->len; i++)
   {
     CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
+
+    if (!cpu->online)
+      continue;
+
     freq += cpu->cur_freq;
+    count++;
   }
 
-  freq /= cpuFreq->cpus->len;
+  if (count > 0)
+    freq /= count;
+
   cpuinfo_free (cpuFreq->cpu_avg);
   cpuFreq->cpu_avg = g_new0 (CpuInfo, 1);
   cpuFreq->cpu_avg->cur_freq = freq;
@@ -144,6 +154,9 @@ cpufreq_cpus_calc_max (void)
   {
     CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
 
+    if (!cpu->online)
+      continue;
+
     if (freq < cpu->cur_freq)
       freq = cpu->cur_freq;
   }
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index 8e84cd6..a6895e4 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -41,6 +41,8 @@ typedef struct
 
   GList* available_freqs;
   GList* available_governors;
+
+  gboolean online;
 } CpuInfo;
 
 typedef struct

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list