aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@linux.intel.com>2010-12-20 13:38:22 -0800
committerArjan van de Ven <arjan@linux.intel.com>2010-12-20 13:38:22 -0800
commitfb7ce033a2b5da31936a341ecdf012c77da70266 (patch)
tree6730b2c599dd2365a0f199d2977824588101afd8
parent40172ea233661d6a77d37e461bbc31f25f9ac71e (diff)
downloadpowertop-fb7ce033a2b5da31936a341ecdf012c77da70266.tar.gz
add the powertop 1.x cpufreq tunable
-rw-r--r--Makefile1
-rw-r--r--tuning/bluetooth.cpp2
-rw-r--r--tuning/cpufreq.cpp165
-rw-r--r--tuning/cpufreq.h48
-rw-r--r--tuning/tuning.cpp3
5 files changed, 218 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index a503903..17e808b 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@ OBJS += parameters/parameters.o parameters/learn.o parameters/persistent.o
OBJS += calibrate/calibrate.o
OBJS += tuning/tuning.o tuning/tunable.o tuning/sysfs.o tuning/usb.o tuning/runtime.o tuning/bluetooth.o
+OBJS += tuning/cpufreq.o
#
# ncurses-devel and pciutils-devel
diff --git a/tuning/bluetooth.cpp b/tuning/bluetooth.cpp
index c6cf756..7abf5d5 100644
--- a/tuning/bluetooth.cpp
+++ b/tuning/bluetooth.cpp
@@ -45,7 +45,7 @@
bt_tunable::bt_tunable(void) : tunable("", 1.0, "Good", "Bad", "Unknown")
{
- sprintf(desc, "Bluetooth device active");
+ sprintf(desc, "Bluetooth device interface status");
}
diff --git a/tuning/cpufreq.cpp b/tuning/cpufreq.cpp
new file mode 100644
index 0000000..ef6f9ec
--- /dev/null
+++ b/tuning/cpufreq.cpp
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2010, Intel Corporation
+ *
+ * This file is part of PowerTOP
+ *
+ * This program file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc,
+ * 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ * or just google for it.
+ *
+ * Authors:
+ * Arjan van de Ven <arjan@linux.intel.com>
+ */
+
+#include "tuning.h"
+#include "tunable.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <utility>
+#include <iostream>
+#include <fstream>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+
+#include "../lib.h"
+#include "cpufreq.h"
+
+cpufreq_tunable::cpufreq_tunable(void) : tunable("", 0.3, "Good", "Bad", "Unknown")
+{
+ string str;
+ sprintf(desc, "Using 'ondemand' cpufreq governor");
+
+ str = read_sysfs_string("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor");
+ strcpy(original, str.c_str());
+ if (strlen(original) < 1)
+ strcpy(original, "ondemand");
+}
+
+
+int cpufreq_tunable::good_bad(void)
+{
+ DIR *dir;
+ struct dirent *dirent;
+ FILE *file;
+ char filename[PATH_MAX];
+ char line[1024];
+
+ char gov[1024];
+ int ret = TUNE_GOOD;
+
+
+ gov[0] = 0;
+
+
+ dir = opendir("/sys/devices/system/cpu");
+ if (!dir)
+ return ret;
+
+ while ((dirent = readdir(dir))) {
+ if (dirent->d_name[0]=='.')
+ continue;
+ sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name);
+ file = fopen(filename, "r");
+ if (!file)
+ continue;
+ memset(line, 0, 1024);
+ if (fgets(line, 1023,file)==NULL) {
+ fclose(file);
+ continue;
+ }
+ if (strlen(gov)==0)
+ strcpy(gov, line);
+ else
+ /* if the governors are inconsistent, warn */
+ if (strcmp(gov, line))
+ ret = TUNE_BAD;
+ fclose(file);
+ }
+
+ closedir(dir);
+
+ /* if the governor is set to userspace, also warn */
+ if (strstr(gov, "userspace"))
+ ret = TUNE_BAD;
+
+ /* if the governor is set to performance, also warn */
+ /* FIXME: check if this is fair on all cpus */
+ if (strstr(gov, "performance"))
+ ret = TUNE_BAD;
+
+ return ret;
+}
+
+void cpufreq_tunable::toggle(void)
+{
+ DIR *dir;
+ struct dirent *dirent;
+ FILE *file;
+ char filename[PATH_MAX];
+ int good;
+ good = good_bad();
+
+ system("/sbin/modprobe cpufreq_ondemand > /dev/null 2>&1");
+
+ if (good == TUNE_GOOD) {
+ dir = opendir("/sys/devices/system/cpu");
+ if (!dir)
+ return;
+
+ while ((dirent = readdir(dir))) {
+ if (dirent->d_name[0]=='.')
+ continue;
+ sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name);
+ file = fopen(filename, "w");
+ if (!file)
+ continue;
+ fprintf(file, "%s\n", original);
+ fclose(file);
+ }
+
+ closedir(dir);
+ return;
+ }
+ dir = opendir("/sys/devices/system/cpu");
+ if (!dir)
+ return;
+
+ while ((dirent = readdir(dir))) {
+ if (dirent->d_name[0]=='.')
+ continue;
+ sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name);
+ file = fopen(filename, "w");
+ if (!file)
+ continue;
+ fprintf(file, "ondemand\n");
+ fclose(file);
+ }
+
+ closedir(dir);
+}
+
+
+
+void add_cpufreq_tunable(void)
+{
+ class cpufreq_tunable *cf;
+
+ cf = new class cpufreq_tunable();
+ all_tunables.push_back(cf);
+}
+
diff --git a/tuning/cpufreq.h b/tuning/cpufreq.h
new file mode 100644
index 0000000..55af71f
--- /dev/null
+++ b/tuning/cpufreq.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2010, Intel Corporation
+ *
+ * This file is part of PowerTOP
+ *
+ * This program file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc,
+ * 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ * or just google for it.
+ *
+ * Authors:
+ * Arjan van de Ven <arjan@linux.intel.com>
+ */
+#ifndef _INCLUDE_GUARD_CPUFREQ_TUNE_H
+#define _INCLUDE_GUARD_CPUFREQ_TUNE_H
+
+#include <vector>
+
+#include "tunable.h"
+
+using namespace std;
+
+class cpufreq_tunable : public tunable {
+ char original[4096];
+public:
+ cpufreq_tunable(void);
+
+ virtual int good_bad(void);
+
+ virtual void toggle(void);
+
+};
+
+extern void add_cpufreq_tunable(void);
+
+
+#endif
diff --git a/tuning/tuning.cpp b/tuning/tuning.cpp
index 7318d65..3eb1fbe 100644
--- a/tuning/tuning.cpp
+++ b/tuning/tuning.cpp
@@ -35,6 +35,7 @@
#include "usb.h"
#include "runtime.h"
#include "bluetooth.h"
+#include "cpufreq.h"
#include "../display.h"
#include "../html.h"
@@ -60,6 +61,8 @@ void initialize_tuning(void)
add_usb_tunables();
add_runtime_tunables("pci");
add_bt_tunable();
+ add_cpufreq_tunable();
+
sort_tunables();