Package: powertop Version: 1.9-2 Severity: wishlist Tags: patch Hi,
please, include the attatched patches to support PowerPC power managment. Bye, Jörg. -- System Information: Debian Release: unstable/experimental APT prefers unstable APT policy: (900, 'unstable'), (700, 'experimental') Architecture: powerpc (ppc) Kernel: Linux 2.6.24-rc6 Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages powertop depends on: ii libc6 2.7-6 GNU C Library: Shared libraries ii libncursesw5 5.6+20080105-1 Shared libraries for terminal hand powertop recommends no packages. -- no debconf information
From 2d89bd652413ecbfdf577d5e2bdaa1a5c38b84ad Mon Sep 17 00:00:00 2001 From: =?utf-8?q?J=C3=B6rg=20Sommer?= <[EMAIL PROTECTED]> Date: Sun, 27 Jan 2008 00:58:46 +0100 Subject: [PATCH] Ignore ACPI on PowerPC The PowerPC architecture doesn't provide support for ACPI. It's meaningless to suggest the user to enable ACPI or check for /proc/acpi. It will never exist. --- Makefile | 3 +++ display.c | 8 ++++++++ powertop.c | 6 ++++++ 3 files changed, 17 insertions(+), 0 deletions(-) diff --git a/Makefile b/Makefile index 62f133e..c3bb650 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ WARNFLAGS=-Wall -W -Wshadow CFLAGS?=-Os -g ${WARNFLAGS} CC?=gcc +ifeq (, $(findstring $(shell uname -m),ppc ppc64)) + CFLAGS += -DWITH_ACPI +endif # # The w in -lncursesw is not a typo; it is the wide-character version diff --git a/display.c b/display.c index 6271da9..a753eae 100644 --- a/display.c +++ b/display.c @@ -38,7 +38,9 @@ static WINDOW *title_bar_window; static WINDOW *cstate_window; static WINDOW *wakeup_window; +#ifdef WITH_ACPI static WINDOW *acpi_power_window; +#endif static WINDOW *timerstat_window; static WINDOW *suggestion_window; static WINDOW *status_bar_window; @@ -65,10 +67,12 @@ static void zap_windows(void) delwin(wakeup_window); wakeup_window = NULL; } +#ifdef WITH_ACPI if (acpi_power_window) { delwin(acpi_power_window); acpi_power_window = NULL; } +#endif if (timerstat_window) { delwin(timerstat_window); timerstat_window = NULL; @@ -98,7 +102,9 @@ void setup_windows(void) title_bar_window = subwin(stdscr, 1, maxx, 0, 0); cstate_window = subwin(stdscr, 7, maxx, 2, 0); wakeup_window = subwin(stdscr, 1, maxx, 9, 0); +#ifdef WITH_ACPI acpi_power_window = subwin(stdscr, 2, maxx, 10, 0); +#endif timerstat_window = subwin(stdscr, maxy-16, maxx, 12, 0); maxtimerstats = maxy-16 -2; maxwidth = maxx - 18; @@ -186,6 +192,7 @@ void show_cstates(void) } +#ifdef WITH_ACPI void show_acpi_power_line(double rate, double cap, double capdelta, time_t ti) { char buffer[1024]; @@ -207,6 +214,7 @@ void show_acpi_power_line(double rate, double cap, double capdelta, time_t ti) print(acpi_power_window, 0, 0, "%s\n", buffer); wrefresh(acpi_power_window); } +#endif void show_wakeups(double d, double interval, double C0time) { diff --git a/powertop.c b/powertop.c index abf32cd..54b709f 100644 --- a/powertop.c +++ b/powertop.c @@ -238,6 +238,7 @@ static void do_proc_irq(void) static void read_data(uint64_t * usage, uint64_t * duration) { +#ifdef WITH_ACPI DIR *dir; struct dirent *entry; FILE *file = NULL; @@ -284,6 +285,7 @@ static void read_data(uint64_t * usage, uint64_t * duration) fclose(file); } closedir(dir); +#endif } void stop_timerstats(void) @@ -322,6 +324,7 @@ void sort_lines(void) void print_battery(void) { +#ifdef WITH_ACPI DIR *dir; struct dirent *dirent; FILE *file; @@ -404,6 +407,7 @@ void print_battery(void) } show_acpi_power_line(rate, cap, prev_bat_cap - cap, time(NULL) - prev_bat_time); +#endif } char cstate_lines[6][200]; @@ -693,8 +697,10 @@ int main(int argc, char **argv) _("Suggestion: Enable the CONFIG_CPU_FREQ_GOV_ONDEMAND kernel configuration option.\n" "The 'ondemand' CPU speed governor will minimize the CPU power usage while\n" "giving you performance when it is needed."), 5); suggest_kernel_config("CONFIG_NO_HZ", 1, _("Suggestion: Enable the CONFIG_NO_HZ kernel configuration option.\nThis option is required to get any kind of longer sleep times in the CPU."), 50); +#ifdef WITH_ACPI suggest_kernel_config("CONFIG_ACPI_BATTERY", 1, _("Suggestion: Enable the CONFIG_ACPI_BATTERY kernel configuration option.\n " "This option is required to get power estimages from PowerTOP"), 5); +#endif suggest_kernel_config("CONFIG_HPET_TIMER", 1, _("Suggestion: Enable the CONFIG_HPET_TIMER kernel configuration option.\n" "Without HPET support the kernel needs to wake up every 20 milliseconds for \n" "some housekeeping tasks."), 10); -- 1.5.4.rc4
From 38e4746f26e5e4374f88be12166fd3cf5e6ee6a6 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?J=C3=B6rg=20Sommer?= <[EMAIL PROTECTED]> Date: Sun, 27 Jan 2008 02:18:41 +0100 Subject: [PATCH] Rename acpi_power_window to power_window For other types of power managment systems a more common name is better. --- display.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/display.c b/display.c index a753eae..0e92bbc 100644 --- a/display.c +++ b/display.c @@ -39,7 +39,7 @@ static WINDOW *title_bar_window; static WINDOW *cstate_window; static WINDOW *wakeup_window; #ifdef WITH_ACPI -static WINDOW *acpi_power_window; +static WINDOW *power_window; #endif static WINDOW *timerstat_window; static WINDOW *suggestion_window; @@ -68,9 +68,9 @@ static void zap_windows(void) wakeup_window = NULL; } #ifdef WITH_ACPI - if (acpi_power_window) { - delwin(acpi_power_window); - acpi_power_window = NULL; + if (power_window) { + delwin(power_window); + power_window = NULL; } #endif if (timerstat_window) { @@ -103,7 +103,7 @@ void setup_windows(void) cstate_window = subwin(stdscr, 7, maxx, 2, 0); wakeup_window = subwin(stdscr, 1, maxx, 9, 0); #ifdef WITH_ACPI - acpi_power_window = subwin(stdscr, 2, maxx, 10, 0); + power_window = subwin(stdscr, 2, maxx, 10, 0); #endif timerstat_window = subwin(stdscr, maxy-16, maxx, 12, 0); maxtimerstats = maxy-16 -2; @@ -199,7 +199,7 @@ void show_acpi_power_line(double rate, double cap, double capdelta, time_t ti) sprintf(buffer, _("no ACPI power usage estimate available") ); - werase(acpi_power_window); + werase(power_window); if (rate > 0.001) { char *c; sprintf(buffer, _("Power usage (ACPI estimate): %3.1fW (%3.1f hours)"), rate, cap/rate); @@ -211,8 +211,8 @@ void show_acpi_power_line(double rate, double cap, double capdelta, time_t ti) else if (ti>120 && capdelta > 0.001) sprintf(buffer, _("Power usage (5 minute ACPI estimate) : %5.1f W (%3.1f hours left)"), 3600*capdelta / ti, cap / (3600*capdelta/ti+0.01)); - print(acpi_power_window, 0, 0, "%s\n", buffer); - wrefresh(acpi_power_window); + print(power_window, 0, 0, "%s\n", buffer); + wrefresh(power_window); } #endif -- 1.5.4.rc4
From c3e3a92373bb0e8c44a58c53112b6f5d567ed1db Mon Sep 17 00:00:00 2001 From: =?utf-8?q?J=C3=B6rg=20Sommer?= <[EMAIL PROTECTED]> Date: Sun, 27 Jan 2008 02:39:10 +0100 Subject: [PATCH] Support for PMU The PowerPC architecture uses the Power Managment Unit instead of ACPI to access the power state. --- Makefile | 3 ++ display.c | 45 ++++++++++++++++++++++++++++++++++++-- powertop.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c3bb650..e0c6e61 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ CC?=gcc ifeq (, $(findstring $(shell uname -m),ppc ppc64)) CFLAGS += -DWITH_ACPI endif +ifneq (, $(findstring $(shell uname -m),ppc ppc64)) + CFLAGS += -DWITH_PMU +endif # # The w in -lncursesw is not a typo; it is the wide-character version diff --git a/display.c b/display.c index 0e92bbc..3783a42 100644 --- a/display.c +++ b/display.c @@ -38,7 +38,7 @@ static WINDOW *title_bar_window; static WINDOW *cstate_window; static WINDOW *wakeup_window; -#ifdef WITH_ACPI +#if defined(WITH_ACPI) || defined(WITH_PMU) static WINDOW *power_window; #endif static WINDOW *timerstat_window; @@ -67,7 +67,7 @@ static void zap_windows(void) delwin(wakeup_window); wakeup_window = NULL; } -#ifdef WITH_ACPI +#if defined(WITH_ACPI) || defined(WITH_PMU) if (power_window) { delwin(power_window); power_window = NULL; @@ -102,7 +102,7 @@ void setup_windows(void) title_bar_window = subwin(stdscr, 1, maxx, 0, 0); cstate_window = subwin(stdscr, 7, maxx, 2, 0); wakeup_window = subwin(stdscr, 1, maxx, 9, 0); -#ifdef WITH_ACPI +#if defined(WITH_ACPI) || defined(WITH_PMU) power_window = subwin(stdscr, 2, maxx, 10, 0); #endif timerstat_window = subwin(stdscr, maxy-16, maxx, 12, 0); @@ -216,6 +216,45 @@ void show_acpi_power_line(double rate, double cap, double capdelta, time_t ti) } #endif +#ifdef WITH_PMU +void show_pmu_power_line(unsigned num_batteries, unsigned sum_voltage_mV, + unsigned sum_charge_mAh, unsigned sum_max_charge_mAh, + int sum_discharge_mA) +{ + char buffer[1024]; + + if (sum_discharge_mA != 0) + { + unsigned remaining_charge_mAh; + + if (sum_discharge_mA < 0) + { + /* we are currently discharging */ + sum_discharge_mA = -sum_discharge_mA; + remaining_charge_mAh = sum_charge_mAh; + } + else + { + /* we are currently charging */ + remaining_charge_mAh = (sum_max_charge_mAh + - sum_charge_mAh); + } + + snprintf(buffer, sizeof(buffer), + _("Power usage: %3.1fW (%3.1f hours)"), + sum_voltage_mV * sum_discharge_mA / 1e6, + (double)remaining_charge_mAh / sum_discharge_mA); + } + else + snprintf(buffer, sizeof(buffer), + _("no power usage estimate available") ); + + werase(power_window); + print(power_window, 0, 0, "%s\n", buffer); + wrefresh(power_window); +} +#endif + void show_wakeups(double d, double interval, double C0time) { werase(wakeup_window); diff --git a/powertop.c b/powertop.c index 54b709f..f7c2897 100644 --- a/powertop.c +++ b/powertop.c @@ -407,6 +407,75 @@ void print_battery(void) } show_acpi_power_line(rate, cap, prev_bat_cap - cap, time(NULL) - prev_bat_time); +#elif WITH_PMU + char line[80]; + int i; + int power_present = 0; + int num_batteries = 0; + /* unsigned rem_time_sec = 0; */ + unsigned charge_mAh = 0, max_charge_mAh = 0, voltage_mV = 0; + int discharge_mA = 0; + FILE *fd; + + fd = fopen("/proc/pmu/info", "r"); + if (fd == NULL) + return; + + while ( fgets(line, sizeof(line), fd) != NULL ) + { + if (strncmp("AC Power", line, strlen("AC Power")) == 0) + sscanf(strchr(line, ':')+2, "%d", &power_present); + else if (strncmp("Battery count", line, strlen("Battery count")) == 0) + sscanf(strchr(line, ':')+2, "%d", &num_batteries); + } + fclose(fd); + + for (i = 0; i < num_batteries; ++i) + { + char file_name[20]; + int flags = 0; + /* int battery_charging, battery_full; */ + /* unsigned this_rem_time_sec = 0; */ + unsigned this_charge_mAh = 0, this_max_charge_mAh = 0; + unsigned this_voltage_mV = 0, this_discharge_mA = 0; + + snprintf(file_name, sizeof(file_name), "/proc/pmu/battery_%d", i); + fd = fopen(file_name, "r"); + if (fd == NULL) + continue; + + while (fgets(line, sizeof(line), fd) != NULL) + { + if (strncmp("flags", line, strlen("flags")) == 0) + sscanf(strchr(line, ':')+2, "%x", &flags); + else if (strncmp("charge", line, strlen("charge")) == 0) + sscanf(strchr(line, ':')+2, "%d", &this_charge_mAh); + else if (strncmp("max_charge", line, strlen("max_charge")) == 0) + sscanf(strchr(line, ':')+2, "%d", &this_max_charge_mAh); + else if (strncmp("voltage", line, strlen("voltage")) == 0) + sscanf(strchr(line, ':')+2, "%d", &this_voltage_mV); + else if (strncmp("current", line, strlen("current")) == 0) + sscanf(strchr(line, ':')+2, "%d", &this_discharge_mA); + /* else if (strncmp("time rem.", line, strlen("time rem.")) == 0) */ + /* sscanf(strchr(line, ':')+2, "%d", &this_rem_time_sec); */ + } + fclose(fd); + + if ( !(flags & 0x1) ) + /* battery isn't present */ + continue; + + /* battery_charging = flags & 0x2; */ + /* battery_full = !battery_charging && power_present; */ + + charge_mAh += this_charge_mAh; + max_charge_mAh += this_max_charge_mAh; + voltage_mV += this_voltage_mV; + discharge_mA += this_discharge_mA; + /* rem_time_sec += this_rem_time_sec; */ + } + show_pmu_power_line(num_batteries, voltage_mV, charge_mAh, max_charge_mAh, + discharge_mA); #endif } -- 1.5.4.rc4
signature.asc
Description: Digital signature