This patch is based on http://processors.wiki.ti.com/index.php/Running_PowerTOP_on_OMAP35x_platform...
Its a simple port from above location.
Signed-off-by: Amit Arora amit.arora@linaro.org --- Makefile | 2 +- cpufreqstats.c | 2 +- display.c | 18 ++++++++------- omapcstates.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ powertop.c | 12 +++++++--- powertop.h | 18 ++++++++++++++- 6 files changed, 100 insertions(+), 16 deletions(-) create mode 100644 omapcstates.c
diff --git a/Makefile b/Makefile index 15b1e29..0b41dc4 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ CC?=gcc
OBJS = powertop.o config.o process.o misctips.o bluetooth.o display.o suggestions.o wireless.o cpufreq.o \ sata.o xrandr.o ethernet.o cpufreqstats.o usb.o urbnum.o intelcstates.o wifi-new.o perf.o \ - alsa-power.o ahci-alpm.o dmesg.o devicepm.o + alsa-power.o ahci-alpm.o dmesg.o devicepm.o omapcstates.o
powertop: $(OBJS) Makefile powertop.h diff --git a/cpufreqstats.c b/cpufreqstats.c index d10b047..b250407 100644 --- a/cpufreqstats.c +++ b/cpufreqstats.c @@ -42,7 +42,7 @@ struct cpufreqdata oldfreqs[16];
struct cpufreqdata delta[16];
-char cpufreqstrings[6][80]; +char cpufreqstrings[MAX_NUM_PSTATES+1][80]; int topfreq = -1;
static void zap(void) diff --git a/display.c b/display.c index 79732ab..cc81efe 100644 --- a/display.c +++ b/display.c @@ -91,15 +91,17 @@ int maxwidth = 200;
void setup_windows(void) { + int yline = MAX_NUM_CSTATES; + getmaxyx(stdscr, maxy, maxx);
zap_windows();
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); - battery_power_window = subwin(stdscr, 2, maxx, 10, 0); - timerstat_window = subwin(stdscr, maxy-16, maxx, 12, 0); + cstate_window = subwin(stdscr, (yline + 2), maxx, 2, 0); + wakeup_window = subwin(stdscr, 1, maxx, (yline + 5), 0); + battery_power_window = subwin(stdscr, 2, maxx, (yline + 6), 0); + timerstat_window = subwin(stdscr, maxy-16, maxx, (yline + 8), 0); maxtimerstats = maxy-16 -2; maxwidth = maxx - 18; suggestion_window = subwin(stdscr, 3, maxx, maxy-4, 0); @@ -150,7 +152,7 @@ void show_title_bar(void) werase(status_bar_window);
x = 0; - for (i=0; i<10; i++) { + for (i=0; i < MAX_CSTATE_LINES; i++) { if (strlen(status_bar_slots[i])==0) continue; wattron(status_bar_window, A_REVERSE); @@ -166,18 +168,18 @@ void show_cstates(void) int i, count = 0; werase(cstate_window);
- for (i=0; i < 10; i++) { + for (i=0; i < MAX_CSTATE_LINES; i++) { if (i == topcstate+1) wattron(cstate_window, A_BOLD); else wattroff(cstate_window, A_BOLD); - if (strlen(cstate_lines[i]) && count <= 6) { + if (strlen(cstate_lines[i]) && count <= MAX_CSTATE_LINES) { print(cstate_window, count, 0, "%s", cstate_lines[i]); count++; } }
- for (i=0; i<6; i++) { + for (i=0; i <= MAX_NUM_PSTATES; i++) { if (i == topfreq+1) wattron(cstate_window, A_BOLD); else diff --git a/omapcstates.c b/omapcstates.c new file mode 100644 index 0000000..9d1da4f --- /dev/null +++ b/omapcstates.c @@ -0,0 +1,64 @@ +/* + * Copyright 2008, Texas Instruments Incorporated. + * + * This file prints the C states supported by the OMAP processor. + * (Based on intelcstates.c) + * + * 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 + */ + +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <sys/types.h> +#include <dirent.h> +#include <ctype.h> + +#include "powertop.h" + + +#if defined(OMAP3) +/** + * print_omap3_cstates() - Prints the list of supported C-states. + * + * This functions uses standard sysfs interface of the cpuidle framework + * to extract the information of the C-states supported by the Linux + * kernel. + **/ +void print_omap3_cstates(void) +{ + DIR *dir; + struct dirent *entry; + + dir = opendir("/sys/devices/system/cpu/cpu0/cpuidle"); + + if (dir) { + printf(_("Supported C-states : ")); + + while ((entry = readdir(dir))) { + if (strlen(entry->d_name) < 3) + continue; + + printf("C%s ", entry->d_name); + } + printf("\n"); + + closedir(dir); + } +} +#endif diff --git a/powertop.c b/powertop.c index 74eb328..7a32623 100644 --- a/powertop.c +++ b/powertop.c @@ -824,7 +824,7 @@ void print_battery_sysfs(void) show_acpi_power_line(rate, cap, prev_bat_cap - cap, time(NULL) - prev_bat_time); }
-char cstate_lines[12][200]; +char cstate_lines[MAX_CSTATE_LINES][200];
void usage() { @@ -922,7 +922,11 @@ int main(int argc, char **argv) printf(_("PowerTOP needs to be run as root to collect enough information\n")); printf(_("Collecting data for %i seconds \n"), (int)ticktime); printf("\n\n"); +#if defined (__I386__) print_intel_cstates(); +#elif defined (OMAP3) + print_omap3_cstates(); +#endif stop_timerstats();
while (1) { @@ -959,7 +963,7 @@ int main(int argc, char **argv)
totalticks = 0; totalevents = 0; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_NUM_CSTATES; i++) if (cur_usage[i]) { totalticks += cur_duration[i] - last_duration[i]; totalevents += cur_usage[i] - last_usage[i]; @@ -975,7 +979,7 @@ int main(int argc, char **argv) }
memset(&cstate_lines, 0, sizeof(cstate_lines)); - topcstate = -4; + topcstate = -(MAX_NUM_CSTATES); if (totalevents == 0 && maxcstate <= 1) { sprintf(cstate_lines[5],_("< Detailed C-state information is not available.>\n")); } else { @@ -989,7 +993,7 @@ int main(int argc, char **argv) sprintf(cstate_lines[1], _("C0 (cpu running) (%4.1f%%)\n"), percentage); if (percentage > 50) topcstate = 0; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_NUM_CSTATES; i++) if (cur_usage[i]) { sleept = (cur_duration[i] - last_duration[i]) / (cur_usage[i] - last_usage[i] + 0.1) / FREQ; diff --git a/powertop.h b/powertop.h index e0f7c68..21f5538 100644 --- a/powertop.h +++ b/powertop.h @@ -30,6 +30,20 @@
#define VERSION "1.12"
+#if defined(__i386__) +#define MAX_NUM_CSTATES 4 +#define MAX_NUM_PSTATES 5 + +#elif defined(OMAP3) +#define MAX_NUM_CSTATES 7 +#define MAX_NUM_PSTATES 5 + +#else +#error "No valid architecture is defined." +#endif + +#define MAX_CSTATE_LINES (MAX_NUM_CSTATES + 3) + struct line { char *string; int count; @@ -72,8 +86,8 @@ void devicepm_activity_hint(void);
-extern char cstate_lines[12][200]; -extern char cpufreqstrings[6][80]; +extern char cstate_lines[MAX_CSTATE_LINES][200]; +extern char cpufreqstrings[MAX_NUM_PSTATES+1][80];
extern int topcstate; extern int topfreq;