aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c20
-rw-r--r--tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c65
-rw-r--r--tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c64
-rw-r--r--tools/power/cpupower/utils/idle_monitor/mperf_monitor.c33
-rw-r--r--tools/power/cpupower/utils/idle_monitor/nhm_idle.c30
-rw-r--r--tools/power/cpupower/utils/idle_monitor/snb_idle.c31
6 files changed, 128 insertions, 115 deletions
diff --git a/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c b/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
index 3de94322dfb..202e555988b 100644
--- a/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
+++ b/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
@@ -104,7 +104,7 @@ static int amd_fam14h_get_pci_info(struct cstate *state,
unsigned int *enable_bit,
unsigned int cpu)
{
- switch(state->id) {
+ switch (state->id) {
case NON_PC0:
*enable_bit = PCI_NON_PC0_ENABLE_BIT;
*pci_offset = PCI_NON_PC0_OFFSET;
@@ -177,7 +177,7 @@ static int amd_fam14h_disable(cstate_t *state, unsigned int cpu)
/* was the bit whether NBP1 got entered set? */
nbp1_entered = (val & (1 << PCI_NBP1_ACTIVE_BIT)) |
(val & (1 << PCI_NBP1_ENTERED_BIT));
-
+
dprint("NBP1 was %sentered - 0x%x - enable_bit: "
"%d - pci_offset: 0x%x\n",
nbp1_entered ? "" : "not ",
@@ -214,7 +214,7 @@ static int fam14h_get_count_percent(unsigned int id, double *percent,
unsigned int cpu)
{
unsigned long diff;
-
+
if (id >= AMD_FAM14H_STATE_NUM)
return -1;
/* residency count in 80ns -> divide through 12.5 to get us residency */
@@ -236,9 +236,8 @@ static int amd_fam14h_start(void)
int num, cpu;
clock_gettime(CLOCK_REALTIME, &start_time);
for (num = 0; num < AMD_FAM14H_STATE_NUM; num++) {
- for (cpu = 0; cpu < cpu_count; cpu++) {
+ for (cpu = 0; cpu < cpu_count; cpu++)
amd_fam14h_init(&amd_fam14h_cstates[num], cpu);
- }
}
#ifdef DEBUG
clock_gettime(CLOCK_REALTIME, &dbg_time);
@@ -257,9 +256,8 @@ static int amd_fam14h_stop(void)
clock_gettime(CLOCK_REALTIME, &end_time);
for (num = 0; num < AMD_FAM14H_STATE_NUM; num++) {
- for (cpu = 0; cpu < cpu_count; cpu++) {
+ for (cpu = 0; cpu < cpu_count; cpu++)
amd_fam14h_disable(&amd_fam14h_cstates[num], cpu);
- }
}
#ifdef DEBUG
clock_gettime(CLOCK_REALTIME, &dbg_time);
@@ -281,8 +279,8 @@ static int is_nbp1_capable(void)
return val & (1 << 31);
}
-struct cpuidle_monitor* amd_fam14h_register(void) {
-
+struct cpuidle_monitor *amd_fam14h_register(void)
+{
int num;
if (cpupower_cpu_info.vendor != X86_VENDOR_AMD)
@@ -299,9 +297,9 @@ struct cpuidle_monitor* amd_fam14h_register(void) {
/* We do not alloc for nbp1 machine wide counter */
for (num = 0; num < AMD_FAM14H_STATE_NUM - 1; num++) {
- previous_count[num] = calloc (cpu_count,
+ previous_count[num] = calloc(cpu_count,
sizeof(unsigned long long));
- current_count[num] = calloc (cpu_count,
+ current_count[num] = calloc(cpu_count,
sizeof(unsigned long long));
}
diff --git a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c b/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c
index 63f6d670517..d048b96a615 100644
--- a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c
+++ b/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c
@@ -36,10 +36,10 @@ static int cpuidle_get_count_percent(unsigned int id, double *percent,
*percent = 0.0;
else
*percent = ((100.0 * statediff) / timediff);
-
+
dprint("%s: - timediff: %llu - statediff: %llu - percent: %f (%u)\n",
cpuidle_cstates[id].name, timediff, statediff, *percent, cpu);
-
+
return 0;
}
@@ -55,7 +55,6 @@ static int cpuidle_start(void)
dprint("CPU %d - State: %d - Val: %llu\n",
cpu, state, previous_count[cpu][state]);
}
-
};
return 0;
}
@@ -83,40 +82,51 @@ void fix_up_intel_idle_driver_name(char *tmp, int num)
{
/* fix up cpuidle name for intel idle driver */
if (!strncmp(tmp, "NHM-", 4)) {
- switch(num) {
- case 1: strcpy(tmp, "C1");
+ switch (num) {
+ case 1:
+ strcpy(tmp, "C1");
break;
- case 2: strcpy(tmp, "C3");
+ case 2:
+ strcpy(tmp, "C3");
break;
- case 3: strcpy(tmp, "C6");
+ case 3:
+ strcpy(tmp, "C6");
break;
}
} else if (!strncmp(tmp, "SNB-", 4)) {
- switch(num) {
- case 1: strcpy(tmp, "C1");
+ switch (num) {
+ case 1:
+ strcpy(tmp, "C1");
break;
- case 2: strcpy(tmp, "C3");
+ case 2:
+ strcpy(tmp, "C3");
break;
- case 3: strcpy(tmp, "C6");
+ case 3:
+ strcpy(tmp, "C6");
break;
- case 4: strcpy(tmp, "C7");
+ case 4:
+ strcpy(tmp, "C7");
break;
}
} else if (!strncmp(tmp, "ATM-", 4)) {
- switch(num) {
- case 1: strcpy(tmp, "C1");
+ switch (num) {
+ case 1:
+ strcpy(tmp, "C1");
break;
- case 2: strcpy(tmp, "C2");
+ case 2:
+ strcpy(tmp, "C2");
break;
- case 3: strcpy(tmp, "C4");
+ case 3:
+ strcpy(tmp, "C4");
break;
- case 4: strcpy(tmp, "C6");
+ case 4:
+ strcpy(tmp, "C6");
break;
}
}
}
-static struct cpuidle_monitor* cpuidle_register(void)
+static struct cpuidle_monitor *cpuidle_register(void)
{
int num;
char *tmp;
@@ -127,7 +137,7 @@ static struct cpuidle_monitor* cpuidle_register(void)
if (cpuidle_sysfs_monitor.hw_states_num == 0)
return NULL;
- for (num = 0; num < cpuidle_sysfs_monitor.hw_states_num; num ++) {
+ for (num = 0; num < cpuidle_sysfs_monitor.hw_states_num; num++) {
tmp = sysfs_get_idlestate_name(0, num);
if (tmp == NULL)
continue;
@@ -144,17 +154,18 @@ static struct cpuidle_monitor* cpuidle_register(void)
cpuidle_cstates[num].range = RANGE_THREAD;
cpuidle_cstates[num].id = num;
- cpuidle_cstates[num].get_count_percent = cpuidle_get_count_percent;
- };
+ cpuidle_cstates[num].get_count_percent =
+ cpuidle_get_count_percent;
+ };
/* Free this at program termination */
- previous_count = malloc(sizeof (long long*) * cpu_count);
- current_count = malloc(sizeof (long long*) * cpu_count);
+ previous_count = malloc(sizeof(long long *) * cpu_count);
+ current_count = malloc(sizeof(long long *) * cpu_count);
for (num = 0; num < cpu_count; num++) {
- previous_count[num] = malloc (sizeof(long long) *
- cpuidle_sysfs_monitor.hw_states_num);
- current_count[num] = malloc (sizeof(long long) *
- cpuidle_sysfs_monitor.hw_states_num);
+ previous_count[num] = malloc(sizeof(long long) *
+ cpuidle_sysfs_monitor.hw_states_num);
+ current_count[num] = malloc(sizeof(long long) *
+ cpuidle_sysfs_monitor.hw_states_num);
}
cpuidle_sysfs_monitor.name_len = strlen(cpuidle_sysfs_monitor.name);
diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
index 3e96e79de3c..ba4bf068380 100644
--- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
@@ -24,7 +24,7 @@
/* Define pointers to all monitors. */
#define DEF(x) & x ## _monitor ,
-struct cpuidle_monitor * all_monitors[] = {
+struct cpuidle_monitor *all_monitors[] = {
#include "idle_monitors.def"
0
};
@@ -76,19 +76,19 @@ void print_n_spaces(int n)
int x;
for (x = 0; x < n; x++)
printf(" ");
-}
+}
/* size of s must be at least n + 1 */
int fill_string_with_spaces(char *s, int n)
{
- int len = strlen(s);
+ int len = strlen(s);
if (len > n)
return -1;
- for (; len < n; len++)
- s[len] = ' ';
- s[len] = '\0';
+ for (; len < n; len++)
+ s[len] = ' ';
+ s[len] = '\0';
return 0;
-}
+}
void print_header(int topology_depth)
{
@@ -107,7 +107,7 @@ void print_header(int topology_depth)
- 1;
if (mon != 0) {
printf("|| ");
- need_len --;
+ need_len--;
}
sprintf(buf, "%s", monitors[mon]->name);
fill_string_with_spaces(buf, need_len);
@@ -169,26 +169,24 @@ void print_results(int topology_depth, int cpu)
if (s.get_count_percent) {
ret = s.get_count_percent(s.id, &percent,
cpu_top.core_info[cpu].cpu);
- if (ret) {
+ if (ret)
printf("******");
- } else if (percent >= 100.0)
+ else if (percent >= 100.0)
printf("%6.1f", percent);
else
printf("%6.2f", percent);
- }
- else if (s.get_count) {
+ } else if (s.get_count) {
ret = s.get_count(s.id, &result,
cpu_top.core_info[cpu].cpu);
- if (ret) {
+ if (ret)
printf("******");
- } else
+ else
printf("%6llu", result);
- }
- else {
+ } else {
printf(_("Monitor %s, Counter %s has no count "
"function. Implementation error\n"),
monitors[mon]->name, s.name);
- exit (EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
}
}
@@ -211,7 +209,7 @@ void print_results(int topology_depth, int cpu)
* Monitors get sorted in the same order the user passes them
*/
-static void parse_monitor_param(char* param)
+static void parse_monitor_param(char *param)
{
unsigned int num;
int mon, hits = 0;
@@ -219,7 +217,7 @@ static void parse_monitor_param(char* param)
struct cpuidle_monitor *tmp_mons[MONITORS_MAX];
- for (mon = 0; mon < MONITORS_MAX;mon++, tmp = NULL) {
+ for (mon = 0; mon < MONITORS_MAX; mon++, tmp = NULL) {
token = strtok(tmp, ",");
if (token == NULL)
break;
@@ -235,7 +233,7 @@ static void parse_monitor_param(char* param)
tmp_mons[hits] = monitors[num];
hits++;
}
- }
+ }
}
if (hits == 0) {
printf(_("No matching monitor found in %s, "
@@ -244,20 +242,23 @@ static void parse_monitor_param(char* param)
exit(EXIT_FAILURE);
}
/* Override detected/registerd monitors array with requested one */
- memcpy(monitors, tmp_mons, sizeof(struct cpuidle_monitor*) * MONITORS_MAX);
+ memcpy(monitors, tmp_mons,
+ sizeof(struct cpuidle_monitor *) * MONITORS_MAX);
avail_monitors = hits;
}
-void list_monitors(void) {
+void list_monitors(void)
+{
unsigned int mon;
int state;
cstate_t s;
for (mon = 0; mon < avail_monitors; mon++) {
printf(_("Monitor \"%s\" (%d states) - Might overflow after %u "
- "s\n"), monitors[mon]->name, monitors[mon]->hw_states_num,
- monitors[mon]->overflow_s);
-
+ "s\n"),
+ monitors[mon]->name, monitors[mon]->hw_states_num,
+ monitors[mon]->overflow_s);
+
for (state = 0; state < monitors[mon]->hw_states_num; state++) {
s = monitors[mon]->hw_states[state];
/*
@@ -308,7 +309,8 @@ int fork_it(char **argv)
timediff = timespec_diff_us(start, end);
if (WIFEXITED(status))
printf(_("%s took %.5f seconds and exited with status %d\n"),
- argv[0], timediff / (1000.0 * 1000), WEXITSTATUS(status));
+ argv[0], timediff / (1000.0 * 1000),
+ WEXITSTATUS(status));
return 0;
}
@@ -322,9 +324,9 @@ int do_interval_measure(int i)
monitors[num]->start();
}
sleep(i);
- for (num = 0; num < avail_monitors; num++) {
+ for (num = 0; num < avail_monitors; num++)
monitors[num]->stop();
- }
+
return 0;
}
@@ -384,7 +386,7 @@ int cmd_monitor(int argc, char **argv)
}
dprint("System has up to %d CPU cores\n", cpu_count);
-
+
for (num = 0; all_monitors[num]; num++) {
dprint("Try to register: %s\n", all_monitors[num]->name);
test_mon = all_monitors[num]->do_register();
@@ -438,9 +440,9 @@ int cmd_monitor(int argc, char **argv)
print_results(1, cpu);
}
- for (num = 0; num < avail_monitors; num++) {
+ for (num = 0; num < avail_monitors; num++)
monitors[num]->unregister();
- }
+
cpu_topology_release(cpu_top);
return 0;
}
diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
index f8545e40e23..63ca87a05e5 100644
--- a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
@@ -79,7 +79,7 @@ static int mperf_init_stats(unsigned int cpu)
ret |= read_msr(cpu, MSR_MPERF, &val);
mperf_previous_count[cpu] = val;
is_valid[cpu] = !ret;
-
+
return 0;
}
@@ -93,7 +93,7 @@ static int mperf_measure_stats(unsigned int cpu)
ret |= read_msr(cpu, MSR_MPERF, &val);
mperf_current_count[cpu] = val;
is_valid[cpu] = !ret;
-
+
return 0;
}
@@ -145,14 +145,14 @@ static int mperf_get_count_percent(unsigned int id, double *percent,
if (id == Cx)
*percent = 100.0 - *percent;
- dprint("%s: previous: %llu - current: %llu - (%u)\n", mperf_cstates[id].name,
- mperf_diff, aperf_diff, cpu);
+ dprint("%s: previous: %llu - current: %llu - (%u)\n",
+ mperf_cstates[id].name, mperf_diff, aperf_diff, cpu);
dprint("%s: %f\n", mperf_cstates[id].name, *percent);
return 0;
}
static int mperf_get_count_freq(unsigned int id, unsigned long long *count,
- unsigned int cpu)
+ unsigned int cpu)
{
unsigned long long aperf_diff, mperf_diff;
@@ -206,8 +206,8 @@ static int mperf_stop(void)
struct cpuidle_monitor mperf_monitor;
-struct cpuidle_monitor* mperf_register(void) {
-
+struct cpuidle_monitor *mperf_register(void)
+{
unsigned long min;
if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_APERF))
@@ -221,21 +221,18 @@ struct cpuidle_monitor* mperf_register(void) {
}
/* Free this at program termination */
- is_valid = calloc(cpu_count, sizeof (int));
- mperf_previous_count = calloc (cpu_count,
- sizeof(unsigned long long));
- aperf_previous_count = calloc (cpu_count,
- sizeof(unsigned long long));
- mperf_current_count = calloc (cpu_count,
- sizeof(unsigned long long));
- aperf_current_count = calloc (cpu_count,
- sizeof(unsigned long long));
-
+ is_valid = calloc(cpu_count, sizeof(int));
+ mperf_previous_count = calloc(cpu_count, sizeof(unsigned long long));
+ aperf_previous_count = calloc(cpu_count, sizeof(unsigned long long));
+ mperf_current_count = calloc(cpu_count, sizeof(unsigned long long));
+ aperf_current_count = calloc(cpu_count, sizeof(unsigned long long));
+
mperf_monitor.name_len = strlen(mperf_monitor.name);
return &mperf_monitor;
}
-void mperf_unregister(void) {
+void mperf_unregister(void)
+{
free(mperf_previous_count);
free(aperf_previous_count);
free(mperf_current_count);
diff --git a/tools/power/cpupower/utils/idle_monitor/nhm_idle.c b/tools/power/cpupower/utils/idle_monitor/nhm_idle.c
index 6424b6dd3fa..d2a91dd0d56 100644
--- a/tools/power/cpupower/utils/idle_monitor/nhm_idle.c
+++ b/tools/power/cpupower/utils/idle_monitor/nhm_idle.c
@@ -69,11 +69,12 @@ static unsigned long long *current_count[NHM_CSTATE_COUNT];
/* valid flag for all CPUs. If a MSR read failed it will be zero */
static int *is_valid;
-static int nhm_get_count(enum intel_nhm_id id, unsigned long long *val, unsigned int cpu)
+static int nhm_get_count(enum intel_nhm_id id, unsigned long long *val,
+ unsigned int cpu)
{
int msr;
- switch(id) {
+ switch (id) {
case C3:
msr = MSR_CORE_C3_RESIDENCY;
break;
@@ -106,12 +107,13 @@ static int nhm_get_count_percent(unsigned int id, double *percent,
if (!is_valid[cpu])
return -1;
- *percent = (100.0 * (current_count[id][cpu] - previous_count[id][cpu])) /
+ *percent = (100.0 *
+ (current_count[id][cpu] - previous_count[id][cpu])) /
(tsc_at_measure_end - tsc_at_measure_start);
- dprint("%s: previous: %llu - current: %llu - (%u)\n", nhm_cstates[id].name,
- previous_count[id][cpu], current_count[id][cpu],
- cpu);
+ dprint("%s: previous: %llu - current: %llu - (%u)\n",
+ nhm_cstates[id].name, previous_count[id][cpu],
+ current_count[id][cpu], cpu);
dprint("%s: tsc_diff: %llu - count_diff: %llu - percent: %2.f (%u)\n",
nhm_cstates[id].name,
@@ -162,7 +164,8 @@ static int nhm_stop(void)
struct cpuidle_monitor intel_nhm_monitor;
-struct cpuidle_monitor* intel_nhm_register(void) {
+struct cpuidle_monitor *intel_nhm_register(void)
+{
int num;
if (cpupower_cpu_info.vendor != X86_VENDOR_INTEL)
@@ -175,19 +178,20 @@ struct cpuidle_monitor* intel_nhm_register(void) {
return NULL;
/* Free this at program termination */
- is_valid = calloc(cpu_count, sizeof (int));
+ is_valid = calloc(cpu_count, sizeof(int));
for (num = 0; num < NHM_CSTATE_COUNT; num++) {
- previous_count[num] = calloc (cpu_count,
- sizeof(unsigned long long));
- current_count[num] = calloc (cpu_count,
- sizeof(unsigned long long));
+ previous_count[num] = calloc(cpu_count,
+ sizeof(unsigned long long));
+ current_count[num] = calloc(cpu_count,
+ sizeof(unsigned long long));
}
intel_nhm_monitor.name_len = strlen(intel_nhm_monitor.name);
return &intel_nhm_monitor;
}
-void intel_nhm_unregister(void) {
+void intel_nhm_unregister(void)
+{
int num;
for (num = 0; num < NHM_CSTATE_COUNT; num++) {
diff --git a/tools/power/cpupower/utils/idle_monitor/snb_idle.c b/tools/power/cpupower/utils/idle_monitor/snb_idle.c
index 8cc80a5b530..a1bc07cd53e 100644
--- a/tools/power/cpupower/utils/idle_monitor/snb_idle.c
+++ b/tools/power/cpupower/utils/idle_monitor/snb_idle.c
@@ -58,11 +58,12 @@ static unsigned long long *current_count[SNB_CSTATE_COUNT];
/* valid flag for all CPUs. If a MSR read failed it will be zero */
static int *is_valid;
-static int snb_get_count(enum intel_snb_id id, unsigned long long *val, unsigned int cpu)
+static int snb_get_count(enum intel_snb_id id, unsigned long long *val,
+ unsigned int cpu)
{
int msr;
- switch(id) {
+ switch (id) {
case C7:
msr = MSR_CORE_C7_RESIDENCY;
break;
@@ -91,18 +92,18 @@ static int snb_get_count_percent(unsigned int id, double *percent,
if (!is_valid[cpu])
return -1;
- *percent = (100.0 * (current_count[id][cpu] - previous_count[id][cpu])) /
+ *percent = (100.0 *
+ (current_count[id][cpu] - previous_count[id][cpu])) /
(tsc_at_measure_end - tsc_at_measure_start);
- dprint("%s: previous: %llu - current: %llu - (%u)\n", snb_cstates[id].name,
- previous_count[id][cpu], current_count[id][cpu],
- cpu);
+ dprint("%s: previous: %llu - current: %llu - (%u)\n",
+ snb_cstates[id].name, previous_count[id][cpu],
+ current_count[id][cpu], cpu);
dprint("%s: tsc_diff: %llu - count_diff: %llu - percent: %2.f (%u)\n",
snb_cstates[id].name,
(unsigned long long) tsc_at_measure_end - tsc_at_measure_start,
- current_count[id][cpu]
- - previous_count[id][cpu],
+ current_count[id][cpu] - previous_count[id][cpu],
*percent, cpu);
return 0;
@@ -141,8 +142,8 @@ static int snb_stop(void)
struct cpuidle_monitor intel_snb_monitor;
-static struct cpuidle_monitor* snb_register(void) {
-
+static struct cpuidle_monitor *snb_register(void)
+{
int num;
if (cpupower_cpu_info.vendor != X86_VENDOR_INTEL
@@ -153,12 +154,12 @@ static struct cpuidle_monitor* snb_register(void) {
&& cpupower_cpu_info.model != 0x2D)
return NULL;
- is_valid = calloc(cpu_count, sizeof (int));
+ is_valid = calloc(cpu_count, sizeof(int));
for (num = 0; num < SNB_CSTATE_COUNT; num++) {
- previous_count[num] = calloc (cpu_count,
- sizeof(unsigned long long));
- current_count[num] = calloc (cpu_count,
- sizeof(unsigned long long));
+ previous_count[num] = calloc(cpu_count,
+ sizeof(unsigned long long));
+ current_count[num] = calloc(cpu_count,
+ sizeof(unsigned long long));
}
intel_snb_monitor.name_len = strlen(intel_snb_monitor.name);
return &intel_snb_monitor;