Commit b510b541 authored by Dominik Brodowski's avatar Dominik Brodowski

cpupowerutils: idle_monitor - ConfigStyle bugfixes

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