powertop: simplified C-state display code

function                                             old     new   delta
.rodata                                           145530  145514     -16
powertop_main                                       1510    1403    -107

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko 2010-10-26 13:03:31 +02:00
parent d8b687f992
commit a43e969574

View File

@ -82,7 +82,6 @@ struct globals {
ullong last_usage[MAX_CSTATE_COUNT]; ullong last_usage[MAX_CSTATE_COUNT];
ullong start_duration[MAX_CSTATE_COUNT]; ullong start_duration[MAX_CSTATE_COUNT];
ullong last_duration[MAX_CSTATE_COUNT]; ullong last_duration[MAX_CSTATE_COUNT];
char cstate_names[MAX_CSTATE_COUNT][16];
#if ENABLE_FEATURE_USE_TERMIOS #if ENABLE_FEATURE_USE_TERMIOS
struct termios init_settings; struct termios init_settings;
#endif #endif
@ -806,22 +805,19 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
if (totalevents == 0 && G.maxcstate <= 1) { if (totalevents == 0 && G.maxcstate <= 1) {
/* This should not happen */ /* This should not happen */
sprintf(cstate_lines[5], "< Detailed C-state information is not " strcpy(cstate_lines[0], "C-state information is not available\n");
"available.>\n");
} else { } else {
double percentage; double percentage;
double newticks; unsigned newticks;
newticks = G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000 - totalticks; newticks = G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000 - totalticks;
/* Handle rounding errors: do not display negative values */ /* Handle rounding errors: do not display negative values */
if (newticks < 0) if ((int)newticks < 0)
newticks = 0; newticks = 0;
sprintf(cstate_lines[0], "Cn\t\t Avg residency\n"); sprintf(cstate_lines[0], "Cn\t\t Avg residency\n");
percentage = newticks * 100.0 / (G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000); percentage = newticks * 100.0 / (G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000);
sprintf(cstate_lines[1], "C0 (cpu running) (%4.1f%%)\n", sprintf(cstate_lines[1], "C0 (cpu running) (%4.1f%%)\n", percentage);
percentage);
/* Compute values for individual C-states */ /* Compute values for individual C-states */
for (i = 0; i < MAX_CSTATE_COUNT; i++) { for (i = 0; i < MAX_CSTATE_COUNT; i++) {
@ -831,11 +827,8 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
/ (cur_usage[i] - G.last_usage[i] + 0.1) / FREQ_ACPI; / (cur_usage[i] - G.last_usage[i] + 0.1) / FREQ_ACPI;
percentage = (cur_duration[i] - G.last_duration[i]) * 100 percentage = (cur_duration[i] - G.last_duration[i]) * 100
/ (G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000); / (G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000);
sprintf(cstate_lines[i + 2], "C%u\t\t%5.1fms (%4.1f%%)\n",
if (!G.cstate_names[i][0]) i + 1, slept, percentage);
sprintf(G.cstate_names[i], "C%u", i + 1);
sprintf(cstate_lines[i + 2], "%s\t\t%5.1fms (%4.1f%%)\n",
G.cstate_names[i], slept, percentage);
//if (maxsleep < slept) //if (maxsleep < slept)
// maxsleep = slept; // maxsleep = slept;
} }
@ -844,7 +837,7 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
for (i = 0; i < MAX_CSTATE_COUNT + 2; i++) for (i = 0; i < MAX_CSTATE_COUNT + 2; i++)
if (cstate_lines[i][0]) if (cstate_lines[i][0])
printf("%s", cstate_lines[i]); fputs(cstate_lines[i], stdout);
i = process_timer_stats(); i = process_timer_stats();
#if ENABLE_FEATURE_POWERTOP_PROCIRQ #if ENABLE_FEATURE_POWERTOP_PROCIRQ