2011-03-30 22:30:11 +08:00
|
|
|
/*
|
|
|
|
* (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
|
|
|
|
* (C) 2010 Thomas Renninger <trenn@suse.de>
|
|
|
|
*
|
|
|
|
* Licensed under the terms of the GNU GPL License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2016-04-28 21:24:40 +08:00
|
|
|
#include <cpuidle.h>
|
|
|
|
|
2011-03-30 22:30:11 +08:00
|
|
|
#include "helpers/sysfs.h"
|
2016-04-28 21:24:40 +08:00
|
|
|
#include "helpers/helpers.h"
|
2011-03-30 22:30:11 +08:00
|
|
|
#include "helpers/bitmask.h"
|
|
|
|
|
|
|
|
#define LINE_LEN 10
|
|
|
|
|
|
|
|
static void cpuidle_cpu_output(unsigned int cpu, int verbose)
|
|
|
|
{
|
2013-06-28 21:34:29 +08:00
|
|
|
unsigned int idlestates, idlestate;
|
2011-03-30 22:30:11 +08:00
|
|
|
char *tmp;
|
|
|
|
|
2016-04-28 21:24:40 +08:00
|
|
|
idlestates = cpuidle_state_count(cpu);
|
2011-03-30 22:30:11 +08:00
|
|
|
if (idlestates == 0) {
|
|
|
|
printf(_("CPU %u: No idle states\n"), cpu);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-28 21:34:29 +08:00
|
|
|
|
2011-03-30 22:30:11 +08:00
|
|
|
printf(_("Number of idle states: %d\n"), idlestates);
|
|
|
|
printf(_("Available idle states:"));
|
2011-12-16 22:35:53 +08:00
|
|
|
for (idlestate = 0; idlestate < idlestates; idlestate++) {
|
2016-04-28 21:24:40 +08:00
|
|
|
tmp = cpuidle_state_name(cpu, idlestate);
|
2011-03-30 22:30:11 +08:00
|
|
|
if (!tmp)
|
|
|
|
continue;
|
|
|
|
printf(" %s", tmp);
|
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (!verbose)
|
|
|
|
return;
|
|
|
|
|
2011-12-16 22:35:53 +08:00
|
|
|
for (idlestate = 0; idlestate < idlestates; idlestate++) {
|
2016-04-28 21:24:40 +08:00
|
|
|
int disabled = cpuidle_is_state_disabled(cpu, idlestate);
|
2013-06-28 21:34:31 +08:00
|
|
|
/* Disabled interface not supported on older kernels */
|
|
|
|
if (disabled < 0)
|
|
|
|
disabled = 0;
|
2016-04-28 21:24:40 +08:00
|
|
|
tmp = cpuidle_state_name(cpu, idlestate);
|
2011-03-30 22:30:11 +08:00
|
|
|
if (!tmp)
|
|
|
|
continue;
|
2013-06-28 21:34:31 +08:00
|
|
|
printf("%s%s:\n", tmp, (disabled) ? " (DISABLED) " : "");
|
2011-03-30 22:30:11 +08:00
|
|
|
free(tmp);
|
|
|
|
|
2016-04-28 21:24:40 +08:00
|
|
|
tmp = cpuidle_state_desc(cpu, idlestate);
|
2011-03-30 22:30:11 +08:00
|
|
|
if (!tmp)
|
|
|
|
continue;
|
|
|
|
printf(_("Flags/Description: %s\n"), tmp);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
printf(_("Latency: %lu\n"),
|
2016-04-28 21:24:40 +08:00
|
|
|
cpuidle_state_latency(cpu, idlestate));
|
2011-03-30 22:30:11 +08:00
|
|
|
printf(_("Usage: %lu\n"),
|
2016-04-28 21:24:40 +08:00
|
|
|
cpuidle_state_usage(cpu, idlestate));
|
2011-03-30 22:30:11 +08:00
|
|
|
printf(_("Duration: %llu\n"),
|
2016-04-28 21:24:40 +08:00
|
|
|
cpuidle_state_time(cpu, idlestate));
|
2011-03-30 22:30:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpuidle_general_output(void)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
2016-04-28 21:24:40 +08:00
|
|
|
tmp = cpuidle_get_driver();
|
2011-03-30 22:30:11 +08:00
|
|
|
if (!tmp) {
|
|
|
|
printf(_("Could not determine cpuidle driver\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(_("CPUidle driver: %s\n"), tmp);
|
2011-04-20 02:33:50 +08:00
|
|
|
free(tmp);
|
2011-03-30 22:30:11 +08:00
|
|
|
|
2016-04-28 21:24:40 +08:00
|
|
|
tmp = cpuidle_get_governor();
|
2011-03-30 22:30:11 +08:00
|
|
|
if (!tmp) {
|
|
|
|
printf(_("Could not determine cpuidle governor\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(_("CPUidle governor: %s\n"), tmp);
|
2011-04-20 02:33:50 +08:00
|
|
|
free(tmp);
|
2011-03-30 22:30:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void proc_cpuidle_cpu_output(unsigned int cpu)
|
|
|
|
{
|
|
|
|
long max_allowed_cstate = 2000000000;
|
2013-06-28 21:34:29 +08:00
|
|
|
unsigned int cstate, cstates;
|
2011-03-30 22:30:11 +08:00
|
|
|
|
2016-04-28 21:24:40 +08:00
|
|
|
cstates = cpuidle_state_count(cpu);
|
2011-03-30 22:30:11 +08:00
|
|
|
if (cstates == 0) {
|
2013-06-28 21:34:29 +08:00
|
|
|
printf(_("CPU %u: No C-states info\n"), cpu);
|
2011-03-30 22:30:11 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(_("active state: C0\n"));
|
|
|
|
printf(_("max_cstate: C%u\n"), cstates-1);
|
|
|
|
printf(_("maximum allowed latency: %lu usec\n"), max_allowed_cstate);
|
|
|
|
printf(_("states:\t\n"));
|
|
|
|
for (cstate = 1; cstate < cstates; cstate++) {
|
|
|
|
printf(_(" C%d: "
|
|
|
|
"type[C%d] "), cstate, cstate);
|
|
|
|
printf(_("promotion[--] demotion[--] "));
|
|
|
|
printf(_("latency[%03lu] "),
|
2016-04-28 21:24:40 +08:00
|
|
|
cpuidle_state_latency(cpu, cstate));
|
2011-03-30 22:30:11 +08:00
|
|
|
printf(_("usage[%08lu] "),
|
2016-04-28 21:24:40 +08:00
|
|
|
cpuidle_state_usage(cpu, cstate));
|
2011-03-30 22:30:11 +08:00
|
|
|
printf(_("duration[%020Lu] \n"),
|
2016-04-28 21:24:40 +08:00
|
|
|
cpuidle_state_time(cpu, cstate));
|
2011-03-30 22:30:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct option info_opts[] = {
|
2015-10-23 15:52:45 +08:00
|
|
|
{"silent", no_argument, NULL, 's'},
|
|
|
|
{"proc", no_argument, NULL, 'o'},
|
2011-03-30 22:30:11 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void cpuidle_exit(int fail)
|
|
|
|
{
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_idle_info(int argc, char **argv)
|
|
|
|
{
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind, opterr, optopt;
|
|
|
|
int ret = 0, cont = 1, output_param = 0, verbose = 1;
|
|
|
|
unsigned int cpu = 0;
|
|
|
|
|
|
|
|
do {
|
2011-08-07 00:11:43 +08:00
|
|
|
ret = getopt_long(argc, argv, "os", info_opts, NULL);
|
2011-03-30 22:30:11 +08:00
|
|
|
if (ret == -1)
|
|
|
|
break;
|
|
|
|
switch (ret) {
|
|
|
|
case '?':
|
|
|
|
output_param = '?';
|
|
|
|
cont = 0;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
verbose = 0;
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
cont = 0;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (output_param) {
|
|
|
|
output_param = -1;
|
|
|
|
cont = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
output_param = ret;
|
|
|
|
break;
|
|
|
|
}
|
2011-04-20 02:33:50 +08:00
|
|
|
} while (cont);
|
2011-03-30 22:30:11 +08:00
|
|
|
|
|
|
|
switch (output_param) {
|
|
|
|
case -1:
|
|
|
|
printf(_("You can't specify more than one "
|
|
|
|
"output-specific argument\n"));
|
|
|
|
cpuidle_exit(EXIT_FAILURE);
|
|
|
|
case '?':
|
|
|
|
printf(_("invalid or unknown argument\n"));
|
|
|
|
cpuidle_exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default is: show output of CPU 0 only */
|
|
|
|
if (bitmask_isallclear(cpus_chosen))
|
|
|
|
bitmask_setbit(cpus_chosen, 0);
|
2011-04-20 02:33:50 +08:00
|
|
|
|
2011-03-30 22:30:11 +08:00
|
|
|
if (output_param == 0)
|
|
|
|
cpuidle_general_output();
|
2011-04-20 02:33:50 +08:00
|
|
|
|
2011-03-30 22:30:11 +08:00
|
|
|
for (cpu = bitmask_first(cpus_chosen);
|
|
|
|
cpu <= bitmask_last(cpus_chosen); cpu++) {
|
|
|
|
|
2015-12-02 00:14:15 +08:00
|
|
|
if (!bitmask_isbitset(cpus_chosen, cpu))
|
2011-03-30 22:30:11 +08:00
|
|
|
continue;
|
|
|
|
|
2015-12-02 00:14:15 +08:00
|
|
|
printf(_("analyzing CPU %d:\n"), cpu);
|
|
|
|
|
|
|
|
if (sysfs_is_cpu_online(cpu) != 1) {
|
|
|
|
printf(_(" *is offline\n"));
|
|
|
|
printf("\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-03-30 22:30:11 +08:00
|
|
|
switch (output_param) {
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
proc_cpuidle_cpu_output(cpu);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
printf("\n");
|
|
|
|
cpuidle_cpu_output(cpu, verbose);
|
|
|
|
break;
|
|
|
|
}
|
2015-12-02 00:14:15 +08:00
|
|
|
printf("\n");
|
2011-03-30 22:30:11 +08:00
|
|
|
}
|
2011-04-20 02:33:50 +08:00
|
|
|
return EXIT_SUCCESS;
|
2011-03-30 22:30:11 +08:00
|
|
|
}
|