2010-10-25 07:14:34 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* A mini 'powertop' utility:
|
|
|
|
* Analyze power consumption on Intel-based laptops.
|
|
|
|
* Based on powertop 1.11.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Marek Polacek <mmpolacek@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
|
|
|
*/
|
|
|
|
|
Move several applets to different install dir:
Moved to [/usr]/sbin:
addgroup, adduser, delgroup, deluser,
arping, chat, ether-wake, fdformat, ifplugd,
ip, ipaddr, iplink, iproute, iprule, iptunnel,
killall5, readahead, rtcwake, tftpd, add-shell, remove-shell, powertop.
Moved to /bin for /usr/bin: kbd_mode.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-06-20 23:54:57 +05:30
|
|
|
//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
|
|
|
|
|
|
|
|
//config:config POWERTOP
|
|
|
|
//config: bool "powertop"
|
|
|
|
//config: default y
|
|
|
|
//config: help
|
|
|
|
//config: Analyze power consumption on Intel-based laptops
|
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
// XXX This should be configurable
|
2010-10-26 06:24:13 +05:30
|
|
|
#define ENABLE_FEATURE_POWERTOP_PROCIRQ 1
|
|
|
|
|
2010-10-25 07:14:34 +05:30
|
|
|
#include "libbb.h"
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
|
2010-10-25 07:14:34 +05:30
|
|
|
//#define debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
|
|
|
|
#define debug(fmt, ...) ((void)0)
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
|
|
|
|
#define BLOATY_HPET_IRQ_NUM_DETECTION 0
|
|
|
|
#define MAX_CSTATE_COUNT 8
|
|
|
|
#define IRQCOUNT 40
|
|
|
|
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
#define DEFAULT_SLEEP 10
|
|
|
|
#define DEFAULT_SLEEP_STR "10"
|
|
|
|
|
|
|
|
/* Frequency of the ACPI timer */
|
|
|
|
#define FREQ_ACPI 3579.545
|
2010-10-28 22:27:19 +05:30
|
|
|
#define FREQ_ACPI_1000 3579545
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Max filename length of entry in /sys/devices subsystem */
|
|
|
|
#define BIG_SYSNAME_LEN 16
|
|
|
|
|
|
|
|
typedef unsigned long long ullong;
|
|
|
|
|
|
|
|
struct line {
|
|
|
|
char *string;
|
|
|
|
int count;
|
2010-10-26 06:24:13 +05:30
|
|
|
/*int disk_count;*/
|
2010-10-25 07:14:34 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_POWERTOP_PROCIRQ
|
|
|
|
struct irqdata {
|
2010-10-26 06:24:13 +05:30
|
|
|
smallint active;
|
2010-10-25 07:14:34 +05:30
|
|
|
int number;
|
|
|
|
ullong count;
|
|
|
|
char irq_desc[32];
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct globals {
|
2010-10-26 16:09:36 +05:30
|
|
|
struct line *lines; /* the most often used member */
|
2010-10-26 06:24:13 +05:30
|
|
|
int lines_cnt;
|
|
|
|
int lines_cumulative_count;
|
2010-10-25 07:14:34 +05:30
|
|
|
int maxcstate;
|
2010-10-26 06:24:13 +05:30
|
|
|
unsigned total_cpus;
|
|
|
|
smallint cant_enable_timer_stats;
|
2010-10-25 07:14:34 +05:30
|
|
|
#if ENABLE_FEATURE_POWERTOP_PROCIRQ
|
2010-10-26 06:24:13 +05:30
|
|
|
# if BLOATY_HPET_IRQ_NUM_DETECTION
|
|
|
|
smallint scanned_timer_list;
|
2010-10-25 07:14:34 +05:30
|
|
|
int percpu_hpet_start;
|
|
|
|
int percpu_hpet_end;
|
2010-10-26 06:24:13 +05:30
|
|
|
# endif
|
|
|
|
int interrupt_0;
|
|
|
|
int total_interrupt;
|
2010-10-25 07:14:34 +05:30
|
|
|
struct irqdata interrupts[IRQCOUNT];
|
|
|
|
#endif
|
2010-10-26 06:24:13 +05:30
|
|
|
ullong start_usage[MAX_CSTATE_COUNT];
|
|
|
|
ullong last_usage[MAX_CSTATE_COUNT];
|
|
|
|
ullong start_duration[MAX_CSTATE_COUNT];
|
|
|
|
ullong last_duration[MAX_CSTATE_COUNT];
|
2010-10-25 07:14:34 +05:30
|
|
|
#if ENABLE_FEATURE_USE_TERMIOS
|
|
|
|
struct termios init_settings;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#define G (*ptr_to_globals)
|
|
|
|
#define INIT_G() do { \
|
|
|
|
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_USE_TERMIOS
|
|
|
|
static void reset_term(void)
|
|
|
|
{
|
|
|
|
tcsetattr_stdin_TCSANOW(&G.init_settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_handler(int signo UNUSED_PARAM)
|
|
|
|
{
|
|
|
|
reset_term();
|
2010-10-26 06:24:13 +05:30
|
|
|
_exit(EXIT_FAILURE);
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int write_str_to_file(const char *fname, const char *str)
|
|
|
|
{
|
|
|
|
FILE *fp = fopen_for_write(fname);
|
|
|
|
if (!fp)
|
|
|
|
return 1;
|
|
|
|
fputs(str, fp);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make it more readable */
|
2010-10-28 22:27:19 +05:30
|
|
|
#define start_timer() write_str_to_file("/proc/timer_stats", "1\n")
|
|
|
|
#define stop_timer() write_str_to_file("/proc/timer_stats", "0\n")
|
2010-10-25 07:14:34 +05:30
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
static NOINLINE void clear_lines(void)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
int i;
|
2010-10-26 16:09:36 +05:30
|
|
|
if (G.lines) {
|
|
|
|
for (i = 0; i < G.lines_cnt; i++)
|
|
|
|
free(G.lines[i].string);
|
|
|
|
free(G.lines);
|
|
|
|
G.lines_cnt = 0;
|
|
|
|
G.lines = NULL;
|
|
|
|
}
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
static void update_lines_cumulative_count(void)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
int i;
|
2010-10-26 06:24:13 +05:30
|
|
|
for (i = 0; i < G.lines_cnt; i++)
|
|
|
|
G.lines_cumulative_count += G.lines[i].count;
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int line_compare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const struct line *a = p1;
|
|
|
|
const struct line *b = p2;
|
2010-10-26 06:24:13 +05:30
|
|
|
return (b->count /*+ 50 * b->disk_count*/) - (a->count /*+ 50 * a->disk_count*/);
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
static void sort_lines(void)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
2010-10-26 06:24:13 +05:30
|
|
|
qsort(G.lines, G.lines_cnt, sizeof(G.lines[0]), line_compare);
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
/* Save C-state usage and duration. Also update maxcstate. */
|
|
|
|
static void read_cstate_counts(ullong *usage, ullong *duration)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *d;
|
|
|
|
|
|
|
|
dir = opendir("/proc/acpi/processor");
|
|
|
|
if (!dir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((d = readdir(dir)) != NULL) {
|
|
|
|
FILE *fp;
|
|
|
|
char buf[192];
|
2010-10-26 06:24:13 +05:30
|
|
|
int level;
|
2010-10-25 07:14:34 +05:30
|
|
|
int len;
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
len = strlen(d->d_name); /* "CPUnn" */
|
2010-10-25 07:14:34 +05:30
|
|
|
if (len < 3 || len > BIG_SYSNAME_LEN)
|
|
|
|
continue;
|
|
|
|
|
2010-11-04 13:11:57 +05:30
|
|
|
sprintf(buf, "%s/%s/power", "/proc/acpi/processor", d->d_name);
|
2010-10-25 07:14:34 +05:30
|
|
|
fp = fopen_for_read(buf);
|
|
|
|
if (!fp)
|
|
|
|
continue;
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
// Example file contents:
|
|
|
|
// active state: C0
|
|
|
|
// max_cstate: C8
|
|
|
|
// maximum allowed latency: 2000000000 usec
|
|
|
|
// states:
|
|
|
|
// C1: type[C1] promotion[--] demotion[--] latency[001] usage[00006173] duration[00000000000000000000]
|
|
|
|
// C2: type[C2] promotion[--] demotion[--] latency[001] usage[00085191] duration[00000000000083024907]
|
|
|
|
// C3: type[C3] promotion[--] demotion[--] latency[017] usage[01017622] duration[00000000017921327182]
|
|
|
|
level = 0;
|
2010-10-25 07:14:34 +05:30
|
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
2010-10-26 06:24:13 +05:30
|
|
|
char *p = strstr(buf, "age[");
|
2010-10-25 07:14:34 +05:30
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
p += 4;
|
|
|
|
usage[level] += bb_strtoull(p, NULL, 10) + 1;
|
|
|
|
p = strstr(buf, "ation[");
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
p += 6;
|
|
|
|
duration[level] += bb_strtoull(p, NULL, 10);
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
if (level >= MAX_CSTATE_COUNT-1)
|
|
|
|
break;
|
2010-10-25 07:14:34 +05:30
|
|
|
level++;
|
2010-10-26 06:24:13 +05:30
|
|
|
if (level > G.maxcstate) /* update maxcstate */
|
2010-10-25 07:14:34 +05:30
|
|
|
G.maxcstate = level;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add line and/or update count */
|
2010-10-26 06:24:13 +05:30
|
|
|
static void save_line(const char *string, int count)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
int i;
|
2010-10-26 06:24:13 +05:30
|
|
|
for (i = 0; i < G.lines_cnt; i++) {
|
2010-10-25 07:14:34 +05:30
|
|
|
if (strcmp(string, G.lines[i].string) == 0) {
|
|
|
|
/* It's already there, only update count */
|
|
|
|
G.lines[i].count += count;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
/* Add new line */
|
2010-10-26 16:09:36 +05:30
|
|
|
G.lines = xrealloc_vector(G.lines, 4, G.lines_cnt);
|
2010-10-26 06:24:13 +05:30
|
|
|
G.lines[G.lines_cnt].string = xstrdup(string);
|
|
|
|
G.lines[G.lines_cnt].count = count;
|
|
|
|
/*G.lines[G.lines_cnt].disk_count = 0;*/
|
|
|
|
G.lines_cnt++;
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_POWERTOP_PROCIRQ
|
2010-10-26 06:24:13 +05:30
|
|
|
static int is_hpet_irq(const char *name)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
char *p;
|
2010-10-26 06:24:13 +05:30
|
|
|
# if BLOATY_HPET_IRQ_NUM_DETECTION
|
2010-10-25 07:14:34 +05:30
|
|
|
long hpet_chan;
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
/* Learn the range of existing hpet timers. This is done once */
|
|
|
|
if (!G.scanned_timer_list) {
|
2010-10-25 07:14:34 +05:30
|
|
|
FILE *fp;
|
|
|
|
char buf[80];
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
G.scanned_timer_list = true;
|
2010-10-25 07:14:34 +05:30
|
|
|
fp = fopen_for_read("/proc/timer_list");
|
|
|
|
if (!fp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
|
|
|
p = strstr(buf, "Clock Event Device: hpet");
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
p += sizeof("Clock Event Device: hpet")-1;
|
2010-10-26 06:24:13 +05:30
|
|
|
if (!isdigit(*p))
|
2010-10-25 07:14:34 +05:30
|
|
|
continue;
|
|
|
|
hpet_chan = xatoi_positive(p);
|
|
|
|
if (hpet_chan < G.percpu_hpet_start)
|
|
|
|
G.percpu_hpet_start = hpet_chan;
|
|
|
|
if (hpet_chan > G.percpu_hpet_end)
|
|
|
|
G.percpu_hpet_end = hpet_chan;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2010-10-26 06:24:13 +05:30
|
|
|
# endif
|
|
|
|
//TODO: optimize
|
2010-10-25 07:14:34 +05:30
|
|
|
p = strstr(name, "hpet");
|
|
|
|
if (!p)
|
|
|
|
return 0;
|
|
|
|
p += 4;
|
2010-10-26 06:24:13 +05:30
|
|
|
if (!isdigit(*p))
|
2010-10-25 07:14:34 +05:30
|
|
|
return 0;
|
2010-10-26 06:24:13 +05:30
|
|
|
# if BLOATY_HPET_IRQ_NUM_DETECTION
|
2010-10-25 07:14:34 +05:30
|
|
|
hpet_chan = xatoi_positive(p);
|
2010-10-26 06:24:13 +05:30
|
|
|
if (hpet_chan < G.percpu_hpet_start || hpet_chan > G.percpu_hpet_end)
|
|
|
|
return 0;
|
|
|
|
# endif
|
|
|
|
return 1;
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
/* Save new IRQ count, return delta from old one */
|
|
|
|
static int save_irq_count(int irq, ullong count)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
int unused = IRQCOUNT;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < IRQCOUNT; i++) {
|
|
|
|
if (G.interrupts[i].active && G.interrupts[i].number == irq) {
|
2010-10-26 06:24:13 +05:30
|
|
|
ullong old = G.interrupts[i].count;
|
2010-10-25 07:14:34 +05:30
|
|
|
G.interrupts[i].count = count;
|
|
|
|
return count - old;
|
|
|
|
}
|
|
|
|
if (!G.interrupts[i].active && unused > i)
|
|
|
|
unused = i;
|
|
|
|
}
|
2010-10-26 06:24:13 +05:30
|
|
|
if (unused < IRQCOUNT) {
|
|
|
|
G.interrupts[unused].active = 1;
|
|
|
|
G.interrupts[unused].count = count;
|
|
|
|
G.interrupts[unused].number = irq;
|
|
|
|
}
|
2010-10-25 07:14:34 +05:30
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
/* Read /proc/interrupts, save IRQ counts and IRQ description */
|
2010-10-26 16:09:36 +05:30
|
|
|
static void process_irq_counts(void)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
/* Reset values */
|
|
|
|
G.interrupt_0 = 0;
|
|
|
|
G.total_interrupt = 0;
|
|
|
|
|
|
|
|
fp = xfopen_for_read("/proc/interrupts");
|
|
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
|
|
|
char irq_desc[sizeof(" <kernel IPI> : ") + sizeof(buf)];
|
|
|
|
char *p;
|
|
|
|
const char *name;
|
2010-10-26 06:24:13 +05:30
|
|
|
int nr;
|
2010-10-25 07:14:34 +05:30
|
|
|
ullong count;
|
|
|
|
ullong delta;
|
|
|
|
|
|
|
|
p = strchr(buf, ':');
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
/* 0: 143646045 153901007 IO-APIC-edge timer
|
|
|
|
* ^
|
|
|
|
*/
|
2010-11-04 13:11:57 +05:30
|
|
|
*p = '\0';
|
2010-10-25 07:14:34 +05:30
|
|
|
/* Deal with non-maskable interrupts -- make up fake numbers */
|
2010-11-05 03:52:40 +05:30
|
|
|
nr = index_in_strings("NMI\0RES\0CAL\0TLB\0TRM\0THR\0SPU\0", buf);
|
|
|
|
if (nr >= 0) {
|
2010-11-04 13:11:57 +05:30
|
|
|
nr += 20000;
|
2010-10-25 07:14:34 +05:30
|
|
|
} else {
|
2010-10-26 06:24:13 +05:30
|
|
|
/* bb_strtou doesn't eat leading spaces, using strtoul */
|
2010-11-05 03:52:40 +05:30
|
|
|
errno = 0;
|
2010-10-26 06:24:13 +05:30
|
|
|
nr = strtoul(buf, NULL, 10);
|
2010-11-05 03:52:40 +05:30
|
|
|
if (errno)
|
|
|
|
continue;
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
p++;
|
|
|
|
/* 0: 143646045 153901007 IO-APIC-edge timer
|
|
|
|
* ^
|
|
|
|
*/
|
2010-10-26 06:24:13 +05:30
|
|
|
/* Sum counts for this IRQ */
|
2010-10-25 07:14:34 +05:30
|
|
|
count = 0;
|
|
|
|
while (1) {
|
|
|
|
char *tmp;
|
|
|
|
p = skip_whitespace(p);
|
|
|
|
if (!isdigit(*p))
|
|
|
|
break;
|
|
|
|
count += bb_strtoull(p, &tmp, 10);
|
|
|
|
p = tmp;
|
|
|
|
}
|
|
|
|
/* 0: 143646045 153901007 IO-APIC-edge timer
|
|
|
|
* NMI: 1 2 Non-maskable interrupts
|
2010-10-28 22:27:19 +05:30
|
|
|
* ^
|
2010-10-25 07:14:34 +05:30
|
|
|
*/
|
2010-10-26 06:24:13 +05:30
|
|
|
if (nr < 20000) {
|
2010-10-25 07:14:34 +05:30
|
|
|
/* Skip to the interrupt name, e.g. 'timer' */
|
|
|
|
p = strchr(p, ' ');
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
p = skip_whitespace(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
name = p;
|
|
|
|
strchrnul(name, '\n')[0] = '\0';
|
|
|
|
/* Save description of the interrupt */
|
2010-10-26 16:12:53 +05:30
|
|
|
if (nr >= 20000)
|
2010-10-25 07:14:34 +05:30
|
|
|
sprintf(irq_desc, " <kernel IPI> : %s", name);
|
|
|
|
else
|
|
|
|
sprintf(irq_desc, " <interrupt> : %s", name);
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
delta = save_irq_count(nr, count);
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Skip per CPU timer interrupts */
|
2010-10-26 06:24:13 +05:30
|
|
|
if (is_hpet_irq(name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nr != 0 && delta != 0)
|
|
|
|
save_line(irq_desc, delta);
|
|
|
|
|
|
|
|
if (nr == 0)
|
2010-10-25 07:14:34 +05:30
|
|
|
G.interrupt_0 = delta;
|
|
|
|
else
|
|
|
|
G.total_interrupt += delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2010-10-26 06:24:13 +05:30
|
|
|
#else /* !ENABLE_FEATURE_POWERTOP_PROCIRQ */
|
2010-10-26 16:09:36 +05:30
|
|
|
# define process_irq_counts() ((void)0)
|
2010-10-26 06:24:13 +05:30
|
|
|
#endif
|
2010-10-25 07:14:34 +05:30
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
static NOINLINE int process_timer_stats(void)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
char line[15 + 3 + 128];
|
|
|
|
int n;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
2010-11-06 06:26:19 +05:30
|
|
|
n = 0;
|
2010-10-26 16:09:36 +05:30
|
|
|
fp = NULL;
|
|
|
|
if (!G.cant_enable_timer_stats)
|
|
|
|
fp = fopen_for_read("/proc/timer_stats");
|
|
|
|
if (fp) {
|
|
|
|
// Example file contents:
|
|
|
|
// Timer Stats Version: v0.2
|
|
|
|
// Sample period: 1.329 s
|
|
|
|
// 76, 0 swapper hrtimer_start_range_ns (tick_sched_timer)
|
|
|
|
// 88, 0 swapper hrtimer_start_range_ns (tick_sched_timer)
|
|
|
|
// 24, 3787 firefox hrtimer_start_range_ns (hrtimer_wakeup)
|
|
|
|
// 46D, 1136 kondemand/1 do_dbs_timer (delayed_work_timer_fn)
|
|
|
|
// ...
|
|
|
|
// 1, 1656 Xorg hrtimer_start_range_ns (hrtimer_wakeup)
|
|
|
|
// 1, 2159 udisks-daemon hrtimer_start_range_ns (hrtimer_wakeup)
|
|
|
|
// 331 total events, 249.059 events/sec
|
|
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
|
|
|
const char *count, *process, *func;
|
|
|
|
char *p;
|
2010-11-04 13:11:57 +05:30
|
|
|
int idx;
|
2010-11-06 06:26:19 +05:30
|
|
|
unsigned cnt;
|
2010-10-26 16:09:36 +05:30
|
|
|
|
|
|
|
count = skip_whitespace(buf);
|
|
|
|
p = strchr(count, ',');
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
*p++ = '\0';
|
2010-11-06 06:26:19 +05:30
|
|
|
cnt = bb_strtou(count, NULL, 10);
|
|
|
|
if (strcmp(skip_non_whitespace(count), " total events") == 0) {
|
|
|
|
#if ENABLE_FEATURE_POWERTOP_PROCIRQ
|
|
|
|
n = cnt / G.total_cpus;
|
|
|
|
if (n > 0 && n < G.interrupt_0) {
|
|
|
|
sprintf(line, " <interrupt> : %s", "extra timer interrupt");
|
|
|
|
save_line(line, G.interrupt_0 - n);
|
|
|
|
}
|
|
|
|
#endif
|
2010-11-05 04:00:11 +05:30
|
|
|
break;
|
2010-11-06 06:26:19 +05:30
|
|
|
}
|
2010-11-04 13:11:57 +05:30
|
|
|
if (strchr(count, 'D'))
|
|
|
|
continue; /* deferred */
|
|
|
|
p = skip_whitespace(p); /* points to pid now */
|
|
|
|
process = NULL;
|
|
|
|
get_func_name:
|
|
|
|
p = strchr(p, ' ');
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
*p++ = '\0';
|
|
|
|
p = skip_whitespace(p);
|
|
|
|
if (process == NULL) {
|
|
|
|
process = p;
|
|
|
|
goto get_func_name;
|
|
|
|
}
|
2010-10-26 16:09:36 +05:30
|
|
|
func = p;
|
2010-11-04 13:11:57 +05:30
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
//if (strcmp(process, "swapper") == 0
|
|
|
|
// && strcmp(func, "hrtimer_start_range_ns (tick_sched_timer)\n") == 0
|
|
|
|
//) {
|
|
|
|
// process = "[kernel scheduler]";
|
|
|
|
// func = "Load balancing tick";
|
|
|
|
//}
|
|
|
|
|
|
|
|
if (strncmp(func, "tick_nohz_", 10) == 0)
|
|
|
|
continue;
|
|
|
|
if (strncmp(func, "tick_setup_sched_timer", 20) == 0)
|
|
|
|
continue;
|
|
|
|
//if (strcmp(process, "powertop") == 0)
|
|
|
|
// continue;
|
|
|
|
|
2010-11-04 13:11:57 +05:30
|
|
|
idx = index_in_strings("insmod\0modprobe\0swapper\0", process);
|
|
|
|
if (idx != -1) {
|
|
|
|
process = idx < 2 ? "[kernel module]" : "<kernel core>";
|
|
|
|
}
|
2010-10-26 16:09:36 +05:30
|
|
|
|
|
|
|
strchrnul(p, '\n')[0] = '\0';
|
|
|
|
|
2010-11-04 13:11:57 +05:30
|
|
|
// 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn)
|
|
|
|
// ^ ^ ^
|
|
|
|
// count process func
|
2010-10-26 16:09:36 +05:30
|
|
|
|
|
|
|
//if (strchr(process, '['))
|
|
|
|
sprintf(line, "%15.15s : %s", process, func);
|
|
|
|
//else
|
|
|
|
// sprintf(line, "%s", process);
|
2010-11-06 06:26:19 +05:30
|
|
|
save_line(line, cnt);
|
2010-10-26 16:09:36 +05:30
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-10-25 07:14:34 +05:30
|
|
|
#ifdef __i386__
|
|
|
|
/*
|
|
|
|
* Get information about CPU using CPUID opcode.
|
|
|
|
*/
|
|
|
|
static void cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
|
2013-01-14 06:04:48 +05:30
|
|
|
unsigned int *edx)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
/* EAX value specifies what information to return */
|
|
|
|
__asm__(
|
|
|
|
" pushl %%ebx\n" /* Save EBX */
|
|
|
|
" cpuid\n"
|
|
|
|
" movl %%ebx, %1\n" /* Save content of EBX */
|
|
|
|
" popl %%ebx\n" /* Restore EBX */
|
|
|
|
: "=a"(*eax), /* Output */
|
|
|
|
"=r"(*ebx),
|
|
|
|
"=c"(*ecx),
|
|
|
|
"=d"(*edx)
|
|
|
|
: "0"(*eax), /* Input */
|
|
|
|
"1"(*ebx),
|
|
|
|
"2"(*ecx),
|
|
|
|
"3"(*edx)
|
|
|
|
/* No clobbered registers */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-28 22:27:19 +05:30
|
|
|
#ifdef __i386__
|
2010-10-26 16:09:36 +05:30
|
|
|
static NOINLINE void print_intel_cstates(void)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
int bios_table[8] = { 0 };
|
|
|
|
int nbios = 0;
|
|
|
|
DIR *cpudir;
|
|
|
|
struct dirent *d;
|
|
|
|
int i;
|
|
|
|
unsigned eax, ebx, ecx, edx;
|
|
|
|
|
|
|
|
cpudir = opendir("/sys/devices/system/cpu");
|
|
|
|
if (!cpudir)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Loop over cpuN entries */
|
|
|
|
while ((d = readdir(cpudir)) != NULL) {
|
|
|
|
DIR *dir;
|
|
|
|
int len;
|
|
|
|
char fname[sizeof("/sys/devices/system/cpu//cpuidle//desc") + 2*BIG_SYSNAME_LEN];
|
|
|
|
|
|
|
|
len = strlen(d->d_name);
|
|
|
|
if (len < 3 || len > BIG_SYSNAME_LEN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!isdigit(d->d_name[3]))
|
|
|
|
continue;
|
|
|
|
|
2010-11-04 13:11:57 +05:30
|
|
|
len = sprintf(fname, "%s/%s/cpuidle", "/sys/devices/system/cpu", d->d_name);
|
2010-10-25 07:14:34 +05:30
|
|
|
dir = opendir(fname);
|
|
|
|
if (!dir)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Every C-state has its own stateN directory, that
|
2010-10-26 16:09:36 +05:30
|
|
|
* contains a 'time' and a 'usage' file.
|
2010-10-25 07:14:34 +05:30
|
|
|
*/
|
|
|
|
while ((d = readdir(dir)) != NULL) {
|
|
|
|
FILE *fp;
|
|
|
|
char buf[64];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = strlen(d->d_name);
|
|
|
|
if (n < 3 || n > BIG_SYSNAME_LEN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sprintf(fname + len, "/%s/desc", d->d_name);
|
|
|
|
fp = fopen_for_read(fname);
|
|
|
|
if (fp) {
|
|
|
|
char *p = fgets(buf, sizeof(buf), fp);
|
|
|
|
fclose(fp);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p = strstr(p, "MWAIT ");
|
|
|
|
if (p) {
|
|
|
|
int pos;
|
|
|
|
p += sizeof("MWAIT ") - 1;
|
|
|
|
pos = (bb_strtoull(p, NULL, 16) >> 4) + 1;
|
|
|
|
if (pos >= ARRAY_SIZE(bios_table))
|
|
|
|
continue;
|
|
|
|
bios_table[pos]++;
|
|
|
|
nbios++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
closedir(cpudir);
|
|
|
|
|
|
|
|
if (!nbios)
|
|
|
|
return;
|
|
|
|
|
|
|
|
eax = 5;
|
|
|
|
ebx = ecx = edx = 0;
|
|
|
|
cpuid(&eax, &ebx, &ecx, &edx);
|
|
|
|
if (!edx || !(ecx & 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
printf("Your CPU supports the following C-states: ");
|
|
|
|
i = 0;
|
|
|
|
while (edx) {
|
|
|
|
if (edx & 7)
|
|
|
|
printf("C%u ", i);
|
|
|
|
edx >>= 4;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
bb_putchar('\n');
|
|
|
|
|
|
|
|
/* Print BIOS C-States */
|
|
|
|
printf("Your BIOS reports the following C-states: ");
|
2010-10-28 22:27:19 +05:30
|
|
|
for (i = 0; i < ARRAY_SIZE(bios_table); i++)
|
2010-10-25 07:14:34 +05:30
|
|
|
if (bios_table[i])
|
|
|
|
printf("C%u ", i);
|
|
|
|
|
|
|
|
bb_putchar('\n');
|
|
|
|
}
|
2010-10-28 22:27:19 +05:30
|
|
|
#else
|
2010-10-29 19:55:18 +05:30
|
|
|
# define print_intel_cstates() ((void)0)
|
2010-10-28 22:27:19 +05:30
|
|
|
#endif
|
2010-10-25 07:14:34 +05:30
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
static void show_timerstats(void)
|
2010-10-25 07:14:34 +05:30
|
|
|
{
|
|
|
|
unsigned lines;
|
|
|
|
|
|
|
|
/* Get terminal height */
|
|
|
|
get_terminal_width_height(STDOUT_FILENO, NULL, &lines);
|
|
|
|
|
|
|
|
/* We don't have whole terminal just for timerstats */
|
|
|
|
lines -= 12;
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
if (!G.cant_enable_timer_stats) {
|
2010-10-25 07:14:34 +05:30
|
|
|
int i, n = 0;
|
2010-10-26 16:09:36 +05:30
|
|
|
char strbuf6[6];
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
puts("\nTop causes for wakeups:");
|
2010-10-26 06:24:13 +05:30
|
|
|
for (i = 0; i < G.lines_cnt; i++) {
|
|
|
|
if ((G.lines[i].count > 0 /*|| G.lines[i].disk_count > 0*/)
|
2010-10-25 07:14:34 +05:30
|
|
|
&& n++ < lines
|
|
|
|
) {
|
2010-10-26 16:09:36 +05:30
|
|
|
/* NB: upstream powertop prints "(wakeups/sec)",
|
|
|
|
* we print just "(wakeup counts)".
|
|
|
|
*/
|
|
|
|
/*char c = ' ';
|
|
|
|
if (G.lines[i].disk_count)
|
2010-10-26 06:24:13 +05:30
|
|
|
c = 'D';*/
|
2013-09-06 16:23:14 +05:30
|
|
|
smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY")[0] = '\0';
|
2010-10-26 16:09:36 +05:30
|
|
|
printf(/*" %5.1f%% (%s)%c %s\n"*/
|
|
|
|
" %5.1f%% (%s) %s\n",
|
|
|
|
G.lines[i].count * 100.0 / G.lines_cumulative_count,
|
|
|
|
strbuf6, /*c,*/
|
|
|
|
G.lines[i].string);
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bb_putchar('\n');
|
|
|
|
bb_error_msg("no stats available; run as root or"
|
2013-01-04 14:21:57 +05:30
|
|
|
" enable the timer_stats module");
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
// Example display from powertop version 1.11
|
|
|
|
// Cn Avg residency P-states (frequencies)
|
|
|
|
// C0 (cpu running) ( 0.5%) 2.00 Ghz 0.0%
|
|
|
|
// polling 0.0ms ( 0.0%) 1.67 Ghz 0.0%
|
|
|
|
// C1 mwait 0.0ms ( 0.0%) 1333 Mhz 0.1%
|
|
|
|
// C2 mwait 0.1ms ( 0.1%) 1000 Mhz 99.9%
|
|
|
|
// C3 mwait 12.1ms (99.4%)
|
|
|
|
//
|
|
|
|
// Wakeups-from-idle per second : 93.6 interval: 15.0s
|
|
|
|
// no ACPI power usage estimate available
|
|
|
|
//
|
|
|
|
// Top causes for wakeups:
|
2010-10-27 03:34:50 +05:30
|
|
|
// 32.4% ( 26.7) <interrupt> : extra timer interrupt
|
|
|
|
// 29.0% ( 23.9) <kernel core> : hrtimer_start_range_ns (tick_sched_timer)
|
2010-10-26 06:24:13 +05:30
|
|
|
// 9.0% ( 7.5) <kernel core> : hrtimer_start (tick_sched_timer)
|
|
|
|
// 6.5% ( 5.3) <interrupt> : ata_piix
|
|
|
|
// 5.0% ( 4.1) inetd : hrtimer_start_range_ns (hrtimer_wakeup)
|
|
|
|
|
2010-10-25 07:14:34 +05:30
|
|
|
//usage:#define powertop_trivial_usage
|
|
|
|
//usage: ""
|
|
|
|
//usage:#define powertop_full_usage "\n\n"
|
2015-01-25 00:16:45 +05:30
|
|
|
//usage: "Analyze power consumption on Intel-based laptops"
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
int powertop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
|
|
|
|
{
|
2010-10-26 06:24:13 +05:30
|
|
|
ullong cur_usage[MAX_CSTATE_COUNT];
|
|
|
|
ullong cur_duration[MAX_CSTATE_COUNT];
|
2010-10-26 16:09:36 +05:30
|
|
|
char cstate_lines[MAX_CSTATE_COUNT + 2][64];
|
2010-10-25 07:14:34 +05:30
|
|
|
#if ENABLE_FEATURE_USE_TERMIOS
|
|
|
|
struct termios new_settings;
|
|
|
|
struct pollfd pfd[1];
|
|
|
|
|
|
|
|
pfd[0].fd = 0;
|
|
|
|
pfd[0].events = POLLIN;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
INIT_G();
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
#if ENABLE_FEATURE_POWERTOP_PROCIRQ && BLOATY_HPET_IRQ_NUM_DETECTION
|
2010-10-25 07:14:34 +05:30
|
|
|
G.percpu_hpet_start = INT_MAX;
|
|
|
|
G.percpu_hpet_end = INT_MIN;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Print warning when we don't have superuser privileges */
|
|
|
|
if (geteuid() != 0)
|
|
|
|
bb_error_msg("run as root to collect enough information");
|
|
|
|
|
|
|
|
/* Get number of CPUs */
|
|
|
|
G.total_cpus = get_cpu_count();
|
|
|
|
|
|
|
|
printf("Collecting data for "DEFAULT_SLEEP_STR" seconds\n");
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_USE_TERMIOS
|
|
|
|
tcgetattr(0, (void *)&G.init_settings);
|
|
|
|
memcpy(&new_settings, &G.init_settings, sizeof(new_settings));
|
|
|
|
/* Turn on unbuffered input, turn off echoing */
|
|
|
|
new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
|
2010-10-26 06:24:13 +05:30
|
|
|
/* So we don't forget to reset term settings */
|
|
|
|
atexit(reset_term);
|
2010-10-25 07:14:34 +05:30
|
|
|
bb_signals(BB_FATAL_SIGS, sig_handler);
|
|
|
|
tcsetattr_stdin_TCSANOW(&new_settings);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Collect initial data */
|
2010-10-26 16:09:36 +05:30
|
|
|
process_irq_counts();
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Read initial usage and duration */
|
2010-10-26 06:24:13 +05:30
|
|
|
read_cstate_counts(G.start_usage, G.start_duration);
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Copy them to "last" */
|
|
|
|
memcpy(G.last_usage, G.start_usage, sizeof(G.last_usage));
|
|
|
|
memcpy(G.last_duration, G.start_duration, sizeof(G.last_duration));
|
|
|
|
|
|
|
|
/* Display C-states */
|
|
|
|
print_intel_cstates();
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
G.cant_enable_timer_stats |= stop_timer(); /* 1 on error */
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* The main loop */
|
|
|
|
for (;;) {
|
2010-10-26 16:09:36 +05:30
|
|
|
//double maxsleep = 0.0;
|
2010-10-25 07:14:34 +05:30
|
|
|
ullong totalticks, totalevents;
|
|
|
|
int i;
|
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
G.cant_enable_timer_stats |= start_timer(); /* 1 on error */
|
2010-10-25 07:14:34 +05:30
|
|
|
#if !ENABLE_FEATURE_USE_TERMIOS
|
|
|
|
sleep(DEFAULT_SLEEP);
|
|
|
|
#else
|
|
|
|
if (safe_poll(pfd, 1, DEFAULT_SLEEP * 1000) > 0) {
|
|
|
|
unsigned char c;
|
|
|
|
if (safe_read(STDIN_FILENO, &c, 1) != 1)
|
|
|
|
break; /* EOF/error */
|
|
|
|
if (c == G.init_settings.c_cc[VINTR])
|
|
|
|
break; /* ^C */
|
|
|
|
if ((c | 0x20) == 'q')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2010-10-26 06:24:13 +05:30
|
|
|
G.cant_enable_timer_stats |= stop_timer(); /* 1 on error */
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
clear_lines();
|
2010-10-26 16:09:36 +05:30
|
|
|
process_irq_counts();
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Clear the stats */
|
|
|
|
memset(cur_duration, 0, sizeof(cur_duration));
|
|
|
|
memset(cur_usage, 0, sizeof(cur_usage));
|
|
|
|
|
|
|
|
/* Read them */
|
2010-10-26 06:24:13 +05:30
|
|
|
read_cstate_counts(cur_usage, cur_duration);
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Count totalticks and totalevents */
|
2010-10-26 06:24:13 +05:30
|
|
|
totalticks = totalevents = 0;
|
|
|
|
for (i = 0; i < MAX_CSTATE_COUNT; i++) {
|
|
|
|
if (cur_usage[i] != 0) {
|
2010-10-25 07:14:34 +05:30
|
|
|
totalticks += cur_duration[i] - G.last_duration[i];
|
|
|
|
totalevents += cur_usage[i] - G.last_usage[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
/* Clear the screen */
|
|
|
|
printf("\033[H\033[J");
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Clear C-state lines */
|
|
|
|
memset(&cstate_lines, 0, sizeof(cstate_lines));
|
|
|
|
|
|
|
|
if (totalevents == 0 && G.maxcstate <= 1) {
|
|
|
|
/* This should not happen */
|
2010-10-26 16:33:31 +05:30
|
|
|
strcpy(cstate_lines[0], "C-state information is not available\n");
|
2010-10-25 07:14:34 +05:30
|
|
|
} else {
|
|
|
|
double percentage;
|
2010-10-26 16:33:31 +05:30
|
|
|
unsigned newticks;
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
newticks = G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000 - totalticks;
|
|
|
|
/* Handle rounding errors: do not display negative values */
|
2010-10-26 16:33:31 +05:30
|
|
|
if ((int)newticks < 0)
|
2010-10-25 07:14:34 +05:30
|
|
|
newticks = 0;
|
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
sprintf(cstate_lines[0], "Cn\t\t Avg residency\n");
|
2010-10-25 07:14:34 +05:30
|
|
|
percentage = newticks * 100.0 / (G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000);
|
2010-10-28 22:27:19 +05:30
|
|
|
sprintf(cstate_lines[1], "C0 (cpu running) (%4.1f%%)\n", percentage);
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Compute values for individual C-states */
|
2010-10-26 06:24:13 +05:30
|
|
|
for (i = 0; i < MAX_CSTATE_COUNT; i++) {
|
|
|
|
if (cur_usage[i] != 0) {
|
2010-10-26 16:09:36 +05:30
|
|
|
double slept;
|
2010-10-25 07:14:34 +05:30
|
|
|
slept = (cur_duration[i] - G.last_duration[i])
|
|
|
|
/ (cur_usage[i] - G.last_usage[i] + 0.1) / FREQ_ACPI;
|
|
|
|
percentage = (cur_duration[i] - G.last_duration[i]) * 100
|
|
|
|
/ (G.total_cpus * DEFAULT_SLEEP * FREQ_ACPI_1000);
|
2010-10-26 16:33:31 +05:30
|
|
|
sprintf(cstate_lines[i + 2], "C%u\t\t%5.1fms (%4.1f%%)\n",
|
|
|
|
i + 1, slept, percentage);
|
2010-10-26 16:09:36 +05:30
|
|
|
//if (maxsleep < slept)
|
|
|
|
// maxsleep = slept;
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
for (i = 0; i < MAX_CSTATE_COUNT + 2; i++)
|
|
|
|
if (cstate_lines[i][0])
|
2010-10-26 16:33:31 +05:30
|
|
|
fputs(cstate_lines[i], stdout);
|
2010-10-25 07:14:34 +05:30
|
|
|
|
2010-10-26 16:09:36 +05:30
|
|
|
i = process_timer_stats();
|
2010-10-25 07:14:34 +05:30
|
|
|
#if ENABLE_FEATURE_POWERTOP_PROCIRQ
|
2010-10-26 16:09:36 +05:30
|
|
|
if (totalevents == 0) {
|
|
|
|
/* No C-state info available, use timerstats */
|
|
|
|
totalevents = i * G.total_cpus + G.total_interrupt;
|
|
|
|
if (i < 0)
|
|
|
|
totalevents += G.interrupt_0 - i;
|
2010-10-25 07:14:34 +05:30
|
|
|
}
|
|
|
|
#endif
|
2010-10-26 16:09:36 +05:30
|
|
|
/* Upstream powertop prints wakeups per sec per CPU,
|
|
|
|
* we print just raw wakeup counts.
|
|
|
|
*/
|
|
|
|
//TODO: show real seconds (think about manual refresh)
|
|
|
|
printf("\nWakeups-from-idle in %u seconds: %llu\n",
|
|
|
|
DEFAULT_SLEEP,
|
|
|
|
totalevents
|
|
|
|
);
|
2010-10-25 07:14:34 +05:30
|
|
|
|
2010-10-26 06:24:13 +05:30
|
|
|
update_lines_cumulative_count();
|
|
|
|
sort_lines();
|
|
|
|
show_timerstats();
|
2010-10-25 07:14:34 +05:30
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
/* Clear the stats */
|
|
|
|
memset(cur_duration, 0, sizeof(cur_duration));
|
|
|
|
memset(cur_usage, 0, sizeof(cur_usage));
|
|
|
|
|
|
|
|
/* Get new values */
|
2010-10-26 06:24:13 +05:30
|
|
|
read_cstate_counts(cur_usage, cur_duration);
|
2010-10-25 07:14:34 +05:30
|
|
|
|
|
|
|
/* Save them */
|
|
|
|
memcpy(G.last_usage, cur_usage, sizeof(G.last_usage));
|
|
|
|
memcpy(G.last_duration, cur_duration, sizeof(G.last_duration));
|
|
|
|
} /* for (;;) */
|
|
|
|
|
|
|
|
bb_putchar('\n');
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|