File gkrellm-cpufreq-cpupower.patch of Package gkrellm-cpufreq

Index: cpufreqnextgovernor
===================================================================
--- cpufreqnextgovernor.orig	2012-02-10 07:37:06.000000000 +0100
+++ cpufreqnextgovernor	2013-11-07 14:21:56.652153887 +0100
@@ -3,15 +3,15 @@
 cpu="$1"
 
 # determine actual governor
-actual_gov=`cpufreq-info -c $cpu -p | sed 's/.*\ //'`
+actual_gov=`cpupower -c $cpu frequency-info -p | tail -n 1 | sed 's/.*\ //'`
 
 # determine available governors
-avail_gov=`cpufreq-info -c $cpu -g`
+avail_gov=`cpupower -c $cpu frequency-info -g | tail -n 1`
 
 avail_gov1=`echo $avail_gov | sed "s/.*$actual_gov//"`
 avail_gov2=`echo $avail_gov | sed "s/$actual_gov.*//"`
 avail_gov=`echo "$avail_gov1 $avail_gov2" | sed "s/^\ //"`
-
 next_gov=`echo $avail_gov | sed "s/\ .*//"`
 
-cpufreq-set -c $cpu -g $next_gov
+cpupower -c $cpu frequency-set -g $next_gov
+
Index: cpufreq.c
===================================================================
--- cpufreq.c.orig	2012-02-10 07:37:06.000000000 +0100
+++ cpufreq.c	2013-11-07 14:51:10.395895054 +0100
@@ -48,6 +48,7 @@
  */
 
 #include <gkrellm2/gkrellm.h>
+#include <sys/stat.h>
 #include <cpufreq.h>
 
 /* version number */
@@ -63,6 +64,8 @@
 
 #define NCPU_MAX 8
 
+#define MAX_LINE_LEN 1024
+
 static unsigned int ncpu;
 static unsigned long khz_max;
 static unsigned long khz[NCPU_MAX];
@@ -83,6 +86,7 @@
 static GkrellmKrell* slider_in_motion[NCPU_MAX];
 static double slider_value[NCPU_MAX];
 
+static gint intel_pstate;
 static gint gov_enable = 1;
 static gint gov_enable_current;
 static gint slider_enable = 1;
@@ -96,6 +100,60 @@
 static gint one_freq_coupled_current;
 static gint style_id;
 
+static void is_intel_pstate_active() {
+  struct stat statbuf;
+  if (stat("/sys/devices/system/cpu/intel_pstate", &statbuf) == 0)
+  {
+    intel_pstate = 1;
+    fprintf(stderr, "gkrellm-cpufreq: WARNING: intel_pstate driver active.\n");
+    fprintf(stderr, "                 Setting frequencies will not be possible.\n");
+    fprintf(stderr, "                 Consider adding intel_pstate=disable to kernel command line\n");
+  }
+  else
+    intel_pstate = 0;
+}
+
+/* taken from cpufrequtils lib and modified */
+unsigned long proc_get_freq_kernel(unsigned int cpu) {
+        FILE *fp;
+        char line[MAX_LINE_LEN];
+        char file[MAX_LINE_LEN];
+        unsigned long value2;
+        unsigned int reading_cpu;
+        unsigned int mhz = 0, khz = 0, ret;
+
+        snprintf(file, MAX_LINE_LEN, "/proc/cpuinfo");
+
+        fp = fopen(file,"r");
+        if (!fp)
+                return 0;
+
+        while(!feof(fp)) {
+                if (!fgets(line, MAX_LINE_LEN, fp)) {
+                        break;
+                }
+
+                if (strlen(line) > (MAX_LINE_LEN - 10)) {
+                        break;
+                }
+
+                ret = sscanf(line, "processor       : %u",
+                             &reading_cpu);
+                if (ret != 1 && reading_cpu == cpu) {
+                        ret = sscanf(line, "cpu MHz         : %u.%u",
+                                     &mhz, &khz);
+                        if (ret == 2)
+                        {
+                          break;
+                        }
+                }
+
+        }
+
+        fclose(fp);
+        return mhz*1000 + khz;
+}
+
 static void read_governors() {
   unsigned int cpu;
   for ( cpu=0; cpu<ncpu; ++cpu ) {
@@ -119,7 +177,10 @@
   /* current freqs */
   unsigned int cpu;
   for ( cpu=0; cpu<ncpu; ++cpu ) {
-    khz[cpu] = cpufreq_get_freq_kernel(cpu);
+    if (! intel_pstate)
+      khz[cpu] = cpufreq_get_freq_kernel(cpu);
+    else
+      khz[cpu] =  proc_get_freq_kernel(cpu);
 
     /* max freq */
     khz_max = khz[cpu] > khz_max ? khz[cpu] : khz_max;
@@ -135,13 +196,13 @@
 
 static void governor_userspace(unsigned int cpu) {
   char cmd[length];
-  sprintf(cmd, "sudo cpufreq-set -c %u -g userspace", cpu);
+  sprintf(cmd, "sudo cpupower -c %u frequency-set -g userspace", cpu);
   system(cmd);
 }
 
 static void set_frequency(unsigned int cpu, unsigned long freq) {
   char cmd[length];
-  sprintf(cmd, "sudo cpufreq-set -c %u -f %lu", cpu, freq );
+  sprintf(cmd, "sudo cpupower -c %u frequency-set -f %lu", cpu, freq );
   system(cmd);
 }
 
@@ -347,6 +408,7 @@
   if (first_create)
   	panel = gkrellm_panel_new0();
 
+  is_intel_pstate_active();
   read_khz();
 
   for ( cpu=0; cpu<ncpu; ++cpu ) {
openSUSE Build Service is sponsored by