diff options
author | arjan <arjan@arjan-desktop.localdomain> | 2010-09-10 10:11:39 -0700 |
---|---|---|
committer | arjan <arjan@arjan-desktop.localdomain> | 2010-09-10 10:11:39 -0700 |
commit | fad77e4a04efe8bfaa60d5a098cea3036e619ed6 (patch) | |
tree | baaafaab5240634a2e310510e88d27b1b0c92a48 | |
parent | c03e70096428bd3de6077acf1cbf1152f95c4011 (diff) | |
download | powertop-fad77e4a04efe8bfaa60d5a098cea3036e619ed6.tar.gz |
add thinkpad fan speed as input
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | calibrate/calibrate.cpp | 25 | ||||
-rw-r--r-- | devices/device.cpp | 3 | ||||
-rw-r--r-- | devices/thinkpad-fan.cpp | 77 | ||||
-rw-r--r-- | devices/thinkpad-fan.h | 27 | ||||
-rw-r--r-- | lib.cpp | 27 | ||||
-rw-r--r-- | lib.h | 14 |
7 files changed, 142 insertions, 33 deletions
@@ -7,7 +7,7 @@ OBJS := lib.o main.o OBJS += cpu/cpu.o cpu/abstract_cpu.o cpu/cpu_linux.o cpu/cpu_core.o cpu/cpu_package.o cpu/intel_cpus.o cpu/cpudevice.cpp OBJS += perf/perf.o perf/perf_bundle.o OBJS += process/process.o process/do_process.o process/interrupt.o process/timer.o process/work.o process/powerconsumer.o process/device.o -OBJS += devices/device.o devices/backlight.o devices/usb.o devices/ahci.o devices/alsa.o devices/rfkill.o devices/i915-gpu.o +OBJS += devices/device.o devices/backlight.o devices/usb.o devices/ahci.o devices/alsa.o devices/rfkill.o devices/i915-gpu.o devices/thinkpad-fan.o OBJS += measurement/measurement.o measurement/acpi.o OBJS += parameters/parameters.o parameters/learn.o parameters/persistent.o OBJS += calibrate/calibrate.o diff --git a/calibrate/calibrate.cpp b/calibrate/calibrate.cpp index ac9c88f..c83093f 100644 --- a/calibrate/calibrate.cpp +++ b/calibrate/calibrate.cpp @@ -46,30 +46,6 @@ static void save_sysfs(char *filename) saved_sysfs[filename] = line; } -static void write_sysfs(string filename, string value) -{ - ofstream file; - - file.open(filename.c_str(), ios::out); - if (!file) - return; - file << value; - file.close(); -} - -static int read_sysfs(string filename) -{ - ifstream file; - int i; - - file.open(filename.c_str(), ios::in); - if (!file) - return 0; - file >> i; - file.close(); - return i; -} - static void restore_all_sysfs(void) { map<string, string>::iterator it; @@ -458,6 +434,7 @@ static void disk_calibration(void) /* work around a bug in the ahci driver where medium->min transitions don't work */ set_scsi_link("max_performance"); + sleep(1); set_scsi_link("min_power"); } diff --git a/devices/device.cpp b/devices/device.cpp index f87323a..ba82a47 100644 --- a/devices/device.cpp +++ b/devices/device.cpp @@ -10,6 +10,7 @@ using namespace std; #include "alsa.h" #include "rfkill.h" #include "i915-gpu.h" +#include "thinkpad-fan.h" #include "../parameters/parameters.h" @@ -69,5 +70,5 @@ void create_all_devices(void) create_all_alsa(); create_all_rfkills(); create_i915_gpu(); - + create_thinkpad_fan(); } diff --git a/devices/thinkpad-fan.cpp b/devices/thinkpad-fan.cpp new file mode 100644 index 0000000..a9fe46c --- /dev/null +++ b/devices/thinkpad-fan.cpp @@ -0,0 +1,77 @@ +#include <iostream> +#include <fstream> + +#include <stdio.h> +#include <sys/types.h> +#include <dirent.h> + +#include "../lib.h" + + +#include "device.h" +#include "thinkpad-fan.h" +#include "../parameters/parameters.h" +#include "../process/powerconsumer.h" + +#include <string.h> + + +thinkpad_fan::thinkpad_fan() +{ + start_rate = 0; + end_rate = 0; +} + +void thinkpad_fan::start_measurement(void) +{ + start_rate = read_sysfs("/sys/devices/platform/thinkpad_hwmon/fan1_input"); +} + +void thinkpad_fan::end_measurement(void) +{ + end_rate = read_sysfs("/sys/devices/platform/thinkpad_hwmon/fan1_input"); + + report_utilization("thinkpad-fan", utilization()); +} + + +double thinkpad_fan::utilization(void) +{ + return (start_rate+end_rate) / 100.0; +} + +void create_thinkpad_fan(void) +{ + char filename[4096]; + class thinkpad_fan *fan; + + strcpy(filename, "/sys/devices/platform/thinkpad_hwmon/fan1_input"); + + if (access(filename, R_OK) !=0) + return; + + register_parameter("thinkpad-fan"); + + fan = new class thinkpad_fan(); + all_devices.push_back(fan); +} + + + +double thinkpad_fan::power_usage(struct result_bundle *result, struct parameter_bundle *bundle) +{ + double power; + double factor; + double utilization; + + power = 0; + factor = get_parameter_value("thinkpad-fan", bundle); + utilization = get_result_value("thinkpad-fan", result); + + utilization = utilization - 60; + if (utilization < 0) + utilization = 0; + + power += utilization * factor / 100.0; + return power; +} diff --git a/devices/thinkpad-fan.h b/devices/thinkpad-fan.h new file mode 100644 index 0000000..53e8ae6 --- /dev/null +++ b/devices/thinkpad-fan.h @@ -0,0 +1,27 @@ +#ifndef _INCLUDE_GUARD_THINKPAD_FAN_H +#define _INCLUDE_GUARD_THINKPAD_FAN_H + + +#include "device.h" + +class thinkpad_fan: public device { + double start_rate, end_rate; +public: + + thinkpad_fan(); + + virtual void start_measurement(void); + virtual void end_measurement(void); + + virtual double utilization(void); /* percentage */ + + virtual const char * class_name(void) { return "fan";}; + + virtual const char * device_name(void) { return "Fan-1";}; + virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); +}; + +extern void create_thinkpad_fan(void); + + +#endif
\ No newline at end of file @@ -7,6 +7,8 @@ #include <string> +#include "lib.h" + #include <stdio.h> #include <stdint.h> #include <stdlib.h> @@ -20,7 +22,6 @@ #include <libintl.h> -#include "lib.h" static int kallsyms_read = 0; @@ -129,3 +130,27 @@ bool stringless::operator()(const char * const & lhs, const char * const & rhs) return true; return false; } + +void write_sysfs(string filename, string value) +{ + ofstream file; + + file.open(filename.c_str(), ios::out); + if (!file) + return; + file << value; + file.close(); +} + +int read_sysfs(string filename) +{ + ifstream file; + int i; + + file.open(filename.c_str(), ios::in); + if (!file) + return 0; + file >> i; + file.close(); + return i; +} @@ -4,15 +4,9 @@ #include <libintl.h> #include <stdint.h> -#ifdef __cplusplus -extern "C" { -#endif #define _(STRING) gettext(STRING) -#ifdef __cplusplus -} -#endif extern int get_max_cpu(void); extern void set_max_cpu(int cpu); @@ -31,4 +25,12 @@ public: + +#include <string> +using namespace std; + +extern void write_sysfs(string filename, string value); +extern int read_sysfs(string filename); + + #endif
\ No newline at end of file |