Skip to content

Commit

Permalink
cpupowerutils: idle_monitor - ConfigStyle bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
  • Loading branch information
Dominik Brodowski committed Jul 29, 2011
1 parent 6c2b818 commit b510b54
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 115 deletions.
20 changes: 9 additions & 11 deletions tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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));
}

Expand Down
65 changes: 38 additions & 27 deletions tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
64 changes: 33 additions & 31 deletions tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -211,15 +209,15 @@ 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;
char *tmp = param, *token;
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;
Expand All @@ -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, "
Expand All @@ -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];
/*
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit b510b54

Please sign in to comment.