diff options
author | Arjan van de Ven <arjan@linux.intel.com> | 2010-08-13 11:48:44 -0400 |
---|---|---|
committer | Arjan van de Ven <arjan@linux.intel.com> | 2010-08-13 11:48:44 -0400 |
commit | 2202e23f3b4974248f535dfb37be50e14b239dca (patch) | |
tree | 58e70f595fc042f23d12c4adfd176fc424e48ea4 /cpu | |
parent | 30d8eecf6cc2ebb3c70bcc58471ed5ba15a0ac08 (diff) | |
download | powertop-2202e23f3b4974248f535dfb37be50e14b239dca.tar.gz |
somehow this debugging fixed the issue
time to commit and then unwrap
Diffstat (limited to 'cpu')
-rw-r--r-- | cpu/abstract_cpu.cpp | 51 | ||||
-rw-r--r-- | cpu/cpu.cpp | 18 | ||||
-rw-r--r-- | cpu/cpu.h | 7 | ||||
-rw-r--r-- | cpu/intel_cpus.cpp | 30 |
4 files changed, 92 insertions, 14 deletions
diff --git a/cpu/abstract_cpu.cpp b/cpu/abstract_cpu.cpp index 002b847..d92d7ab 100644 --- a/cpu/abstract_cpu.cpp +++ b/cpu/abstract_cpu.cpp @@ -21,6 +21,8 @@ void abstract_cpu::measurement_start(void) pstates.resize(0); current_frequency = 0; + idle = true; + old_idle = true; sprintf(filename, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_available_frequencies", number); @@ -334,3 +336,52 @@ void abstract_cpu::wiggle(void) ofile.close(); } +uint64_t abstract_cpu::total_pstate_time(void) +{ + unsigned int i; + uint64_t total_stamp = 0; + + for (i = 0; i < pstates.size(); i++) + total_stamp += pstates[i]->time_after; + + return total_stamp; +} + + +void abstract_cpu::validate(void) +{ + unsigned int i; + uint64_t my_time; + + my_time = total_pstate_time(); + + for (i = 0; i < children.size(); i++) { + + if (children[i]) { + if (my_time != children[i]->total_pstate_time()) + printf("My (%i) time %llu is not the same as child (%i) time %llu\n", + first_cpu, my_time, children[i]->number, children[i]->total_pstate_time()); + children[i]->validate(); + } + } +} + +void abstract_cpu::reset_pstate_data(void) +{ + unsigned int i; + uint64_t my_time; + + my_time = total_pstate_time(); + + printf("reset\n"); + + for (i = 0; i < pstates.size(); i++) { + pstates[i]->time_before = 0; + pstates[i]->time_after = 0; + } + + for (i = 0; i < children.size(); i++) + if (children[i]) + children[i]->reset_pstate_data(); +} + diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp index 7edd849..9e35a9c 100644 --- a/cpu/cpu.cpp +++ b/cpu/cpu.cpp @@ -96,7 +96,7 @@ static void handle_one_cpu(unsigned int number, char *vendor, int family, int mo if (system_level.children.size() <= package_number) - system_level.children.resize(package_number + 1); + system_level.children.resize(package_number + 1, NULL); if (!system_level.children[package_number]) { system_level.children[package_number] = new_package(package_number, number, vendor, family, model); @@ -107,7 +107,7 @@ static void handle_one_cpu(unsigned int number, char *vendor, int family, int mo package->parent = &system_level; if (package->children.size() <= core_number) - package->children.resize(core_number + 1); + package->children.resize(core_number + 1, NULL); if (!package->children[core_number]) { package->children[core_number] = new_core(core_number, number, vendor, family, model); @@ -412,6 +412,7 @@ void perf_power_bundle::handle_trace_point(int type, void *trace, int cpunr, uin { const char *event_name; class abstract_cpu *cpu; + unsigned int i; if (type >= (int)event_names.size()) return; @@ -424,6 +425,12 @@ void perf_power_bundle::handle_trace_point(int type, void *trace, int cpunr, uin cpu = all_cpus[cpunr]; + printf("Time is %llu \n", time); + for (i = 0; i < system_level.children.size(); i++) + if (system_level.children[i]) + system_level.children[i]->validate(); + + if (strcmp(event_name, "power:power_frequency")==0) { struct power_entry *pe = (struct power_entry *)trace; cpu->change_freq(time, pe->value); @@ -432,9 +439,16 @@ void perf_power_bundle::handle_trace_point(int type, void *trace, int cpunr, uin cpu->go_idle(time); if (strcmp(event_name, "power:power_end")==0) cpu->go_unidle(time); + + for (i = 0; i < system_level.children.size(); i++) + if (system_level.children[i]) + system_level.children[i]->validate(); + } void process_cpu_data(void) { + system_level.reset_pstate_data(); + perf_events->process(); }
\ No newline at end of file @@ -35,8 +35,8 @@ struct frequency { uint64_t freq; - uint64_t time_before; uint64_t time_after; + uint64_t time_before; int before_count; int after_count; @@ -105,6 +105,11 @@ public: virtual void change_effective_frequency(uint64_t time, uint64_t freq); virtual void wiggle(void); + + virtual uint64_t total_pstate_time(void); + + virtual void validate(void); + virtual void reset_pstate_data(void); }; extern vector<class abstract_cpu *> all_cpus; diff --git a/cpu/intel_cpus.cpp b/cpu/intel_cpus.cpp index d43a075..6d9dcc0 100644 --- a/cpu/intel_cpus.cpp +++ b/cpu/intel_cpus.cpp @@ -75,11 +75,11 @@ void nhm_core::measurement_start(void) uint64_t f; file.getline(line, 1024); f = strtoull(line, NULL, 10); - account_freq(f, 1); + account_freq(f, 0); } file.close(); } - account_freq(0, 1); + account_freq(0, 0); } void nhm_core::measurement_end(void) @@ -159,6 +159,7 @@ void nhm_core::account_freq(uint64_t freq, uint64_t duration) } } + if (!state) { state = new struct frequency; @@ -170,7 +171,7 @@ void nhm_core::account_freq(uint64_t freq, uint64_t duration) pstates.push_back(state); state->freq = freq; - sprintf(state->human_name, "%s", hz_to_human(freq, state->human_name)); + hz_to_human(freq, state->human_name); if (freq == 0) strcpy(state->human_name, "Idle"); if (is_turbo(freq, max_frequency, max_minus_one_frequency)) @@ -181,7 +182,6 @@ void nhm_core::account_freq(uint64_t freq, uint64_t duration) state->time_after += duration; - } @@ -190,6 +190,7 @@ void nhm_core::calculate_freq(uint64_t time) uint64_t freq = 0; bool is_idle = true; unsigned int i; + /* calculate the maximum frequency of all children */ for (i = 0; i < children.size(); i++) @@ -222,6 +223,7 @@ void nhm_core::change_effective_frequency(uint64_t time, uint64_t frequency) time_delta = 1; fr = effective_frequency; + if (old_idle) fr = 0; @@ -244,7 +246,6 @@ char * nhm_core::fill_pstate_line(int line_nr, char *buffer) total_stamp = 1; } - if (line_nr == LEVEL_HEADER) { sprintf(buffer," Core"); return buffer; @@ -290,6 +291,8 @@ void nhm_package::measurement_start(void) { abstract_cpu::measurement_start(); + last_stamp = 0; + c3_before = get_msr(number, MSR_PKG_C3_RESIDENCY); c6_before = get_msr(number, MSR_PKG_C6_RESIDENCY); tsc_before = get_msr(first_cpu, MSR_TSC); @@ -354,6 +357,7 @@ void nhm_package::measurement_end(void) finalize_pstate(state->freq, state->time_after, state->after_count); } } + total_stamp = 0; } void nhm_package::account_freq(uint64_t freq, uint64_t duration) @@ -368,6 +372,7 @@ void nhm_package::account_freq(uint64_t freq, uint64_t duration) } } + if (!state) { state = new struct frequency; @@ -379,7 +384,7 @@ void nhm_package::account_freq(uint64_t freq, uint64_t duration) pstates.push_back(state); state->freq = freq; - sprintf(state->human_name, "%s", hz_to_human(freq, state->human_name)); + hz_to_human(freq, state->human_name); if (freq == 0) strcpy(state->human_name, "Idle"); if (is_turbo(freq, max_frequency, max_minus_one_frequency)) @@ -472,11 +477,11 @@ void nhm_cpu::measurement_start(void) uint64_t f; file.getline(line, 1024); f = strtoull(line, NULL, 10); - account_freq(f, 1); + account_freq(f, 0); } file.close(); } - account_freq(0, 1); + account_freq(0, 0); } void nhm_cpu::measurement_end(void) @@ -511,6 +516,8 @@ void nhm_cpu::measurement_end(void) state->duration_delta = ratio * (state->duration_after - state->duration_before) / state->after_count; } + total_stamp = 0; + } @@ -541,7 +548,7 @@ char * nhm_cpu::fill_pstate_line(int line_nr, char *buffer) if (line_nr == LEVEL_C0) { double F; F = 1.0 * (tsc_after - tsc_before) * (aperf_after - aperf_before) / (mperf_after - mperf_before) / time_factor * 1000; - sprintf(buffer, "%s", hz_to_human(F, buffer, 1)); + hz_to_human(F, buffer, 1); return buffer; } if (line_nr >= (int)pstates.size() || line_nr < 0) @@ -566,6 +573,7 @@ void nhm_cpu::account_freq(uint64_t freq, uint64_t duration) struct frequency *state = NULL; unsigned int i; + for (i = 0; i < pstates.size(); i++) { if (freq == pstates[i]->freq) { state = pstates[i]; @@ -584,7 +592,7 @@ void nhm_cpu::account_freq(uint64_t freq, uint64_t duration) pstates.push_back(state); state->freq = freq; - sprintf(state->human_name, "%s", hz_to_human(freq, state->human_name)); + hz_to_human(freq, state->human_name); if (freq == 0) strcpy(state->human_name, "Idle"); state->after_count = 1; @@ -593,6 +601,7 @@ void nhm_cpu::account_freq(uint64_t freq, uint64_t duration) state->time_after += duration; + } void nhm_cpu::change_freq(uint64_t time, int frequency) @@ -637,7 +646,6 @@ void nhm_cpu::go_idle(uint64_t time) void nhm_cpu::go_unidle(uint64_t time) { idle = false; - if (parent) parent->calculate_freq(time); old_idle = idle; |