Skip to content

Commit

Permalink
Merge branch 'pm-tools'
Browse files Browse the repository at this point in the history
* pm-tools:
  tools/power/cpupower: allow running without cpu0
  pm-graph: package makefile and man pages
  pm-graph: AnalyzeBoot v2.1
  pm-graph: AnalyzeSuspend v4.7
  • Loading branch information
Rafael J. Wysocki committed Sep 3, 2017
2 parents 4afbce7 + d0e4a19 commit d97561f
Show file tree
Hide file tree
Showing 13 changed files with 880 additions and 413 deletions.
15 changes: 12 additions & 3 deletions tools/power/cpupower/utils/cpupower.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sched.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
Expand All @@ -31,6 +32,7 @@ static int cmd_help(int argc, const char **argv);
*/
struct cpupower_cpu_info cpupower_cpu_info;
int run_as_root;
int base_cpu;
/* Affected cpus chosen by -c/--cpu param */
struct bitmask *cpus_chosen;

Expand Down Expand Up @@ -174,6 +176,7 @@ int main(int argc, const char *argv[])
unsigned int i, ret;
struct stat statbuf;
struct utsname uts;
char pathname[32];

cpus_chosen = bitmask_alloc(sysconf(_SC_NPROCESSORS_CONF));

Expand All @@ -198,17 +201,23 @@ int main(int argc, const char *argv[])
argv[0] = cmd = "help";
}

get_cpu_info(0, &cpupower_cpu_info);
base_cpu = sched_getcpu();
if (base_cpu < 0) {
fprintf(stderr, _("No valid cpus found.\n"));
return EXIT_FAILURE;
}

get_cpu_info(&cpupower_cpu_info);
run_as_root = !geteuid();
if (run_as_root) {
ret = uname(&uts);
sprintf(pathname, "/dev/cpu/%d/msr", base_cpu);
if (!ret && !strcmp(uts.machine, "x86_64") &&
stat("/dev/cpu/0/msr", &statbuf) != 0) {
stat(pathname, &statbuf) != 0) {
if (system("modprobe msr") == -1)
fprintf(stderr, _("MSR access not available.\n"));
}
}


for (i = 0; i < ARRAY_SIZE(commands); i++) {
struct cmd_struct *p = commands + i;
Expand Down
4 changes: 2 additions & 2 deletions tools/power/cpupower/utils/helpers/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ cpuid_func(edx);
*
* TBD: Should there be a cpuid alternative for this if /proc is not mounted?
*/
int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info)
int get_cpu_info(struct cpupower_cpu_info *cpu_info)
{
FILE *fp;
char value[64];
Expand Down Expand Up @@ -70,7 +70,7 @@ int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info)
if (!strncmp(value, "processor\t: ", 12))
sscanf(value, "processor\t: %u", &proc);

if (proc != cpu)
if (proc != (unsigned int)base_cpu)
continue;

/* Get CPU vendor */
Expand Down
5 changes: 3 additions & 2 deletions tools/power/cpupower/utils/helpers/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
/* Internationalization ****************************/

extern int run_as_root;
extern int base_cpu;
extern struct bitmask *cpus_chosen;

/* Global verbose (-d) stuff *********************************/
Expand Down Expand Up @@ -87,11 +88,11 @@ struct cpupower_cpu_info {
*
* Extract CPU vendor, family, model, stepping info from /proc/cpuinfo
*
* Returns 0 on success or a negativ error code
* Returns 0 on success or a negative error code
* Only used on x86, below global's struct values are zero/unknown on
* other archs
*/
extern int get_cpu_info(unsigned int cpu, struct cpupower_cpu_info *cpu_info);
extern int get_cpu_info(struct cpupower_cpu_info *cpu_info);
extern struct cpupower_cpu_info cpupower_cpu_info;
/* cpuid and cpuinfo helpers **************************/

Expand Down
2 changes: 1 addition & 1 deletion tools/power/cpupower/utils/helpers/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active,

*support = *active = *states = 0;

ret = get_cpu_info(0, &cpu_info);
ret = get_cpu_info(&cpu_info);
if (ret)
return ret;

Expand Down
4 changes: 2 additions & 2 deletions tools/power/cpupower/utils/idle_monitor/hsw_ext_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int hsw_ext_start(void)
previous_count[num][cpu] = val;
}
}
hsw_ext_get_count(TSC, &tsc_at_measure_start, 0);
hsw_ext_get_count(TSC, &tsc_at_measure_start, base_cpu);
return 0;
}

Expand All @@ -132,7 +132,7 @@ static int hsw_ext_stop(void)
unsigned long long val;
int num, cpu;

hsw_ext_get_count(TSC, &tsc_at_measure_end, 0);
hsw_ext_get_count(TSC, &tsc_at_measure_end, base_cpu);

for (num = 0; num < HSW_EXT_CSTATE_COUNT; num++) {
for (cpu = 0; cpu < cpu_count; cpu++) {
Expand Down
3 changes: 2 additions & 1 deletion tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ static int *is_valid;
static int mperf_get_tsc(unsigned long long *tsc)
{
int ret;
ret = read_msr(0, MSR_TSC, tsc);

ret = read_msr(base_cpu, MSR_TSC, tsc);
if (ret)
dprint("Reading TSC MSR failed, returning %llu\n", *tsc);
return ret;
Expand Down
8 changes: 4 additions & 4 deletions tools/power/cpupower/utils/idle_monitor/nhm_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ static int nhm_start(void)
int num, cpu;
unsigned long long dbg, val;

nhm_get_count(TSC, &tsc_at_measure_start, 0);
nhm_get_count(TSC, &tsc_at_measure_start, base_cpu);

for (num = 0; num < NHM_CSTATE_COUNT; num++) {
for (cpu = 0; cpu < cpu_count; cpu++) {
is_valid[cpu] = !nhm_get_count(num, &val, cpu);
previous_count[num][cpu] = val;
}
}
nhm_get_count(TSC, &dbg, 0);
nhm_get_count(TSC, &dbg, base_cpu);
dprint("TSC diff: %llu\n", dbg - tsc_at_measure_start);
return 0;
}
Expand All @@ -148,15 +148,15 @@ static int nhm_stop(void)
unsigned long long dbg;
int num, cpu;

nhm_get_count(TSC, &tsc_at_measure_end, 0);
nhm_get_count(TSC, &tsc_at_measure_end, base_cpu);

for (num = 0; num < NHM_CSTATE_COUNT; num++) {
for (cpu = 0; cpu < cpu_count; cpu++) {
is_valid[cpu] = !nhm_get_count(num, &val, cpu);
current_count[num][cpu] = val;
}
}
nhm_get_count(TSC, &dbg, 0);
nhm_get_count(TSC, &dbg, base_cpu);
dprint("TSC diff: %llu\n", dbg - tsc_at_measure_end);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions tools/power/cpupower/utils/idle_monitor/snb_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static int snb_start(void)
previous_count[num][cpu] = val;
}
}
snb_get_count(TSC, &tsc_at_measure_start, 0);
snb_get_count(TSC, &tsc_at_measure_start, base_cpu);
return 0;
}

Expand All @@ -129,7 +129,7 @@ static int snb_stop(void)
unsigned long long val;
int num, cpu;

snb_get_count(TSC, &tsc_at_measure_end, 0);
snb_get_count(TSC, &tsc_at_measure_end, base_cpu);

for (num = 0; num < SNB_CSTATE_COUNT; num++) {
for (cpu = 0; cpu < cpu_count; cpu++) {
Expand Down
19 changes: 11 additions & 8 deletions tools/power/pm-graph/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DESTDIR ?=
all:
@echo "Nothing to build"

install :
install : uninstall
install -d $(DESTDIR)$(PREFIX)/lib/pm-graph
install analyze_suspend.py $(DESTDIR)$(PREFIX)/lib/pm-graph
install analyze_boot.py $(DESTDIR)$(PREFIX)/lib/pm-graph
Expand All @@ -17,12 +17,15 @@ install :
install sleepgraph.8 $(DESTDIR)$(PREFIX)/share/man/man8

uninstall :
rm $(DESTDIR)$(PREFIX)/share/man/man8/bootgraph.8
rm $(DESTDIR)$(PREFIX)/share/man/man8/sleepgraph.8
rm -f $(DESTDIR)$(PREFIX)/share/man/man8/bootgraph.8
rm -f $(DESTDIR)$(PREFIX)/share/man/man8/sleepgraph.8

rm $(DESTDIR)$(PREFIX)/bin/bootgraph
rm $(DESTDIR)$(PREFIX)/bin/sleepgraph
rm -f $(DESTDIR)$(PREFIX)/bin/bootgraph
rm -f $(DESTDIR)$(PREFIX)/bin/sleepgraph

rm $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_boot.py
rm $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_suspend.py
rmdir $(DESTDIR)$(PREFIX)/lib/pm-graph
rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_boot.py
rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/analyze_suspend.py
rm -f $(DESTDIR)$(PREFIX)/lib/pm-graph/*.pyc
if [ -d $(DESTDIR)$(PREFIX)/lib/pm-graph ] ; then \
rmdir $(DESTDIR)$(PREFIX)/lib/pm-graph; \
fi;
Loading

0 comments on commit d97561f

Please sign in to comment.