void nhm_cpu::measurement_start(void) { ifstream file; char filename[4096]; cpu_linux::measurement_start(); last_stamp = 0; aperf_before = get_msr(number, MSR_APERF); mperf_before = get_msr(number, MSR_MPERF); tsc_before = get_msr(number, MSR_TSC); insert_cstate("active", _("C0 active"), 0, aperf_before, 1); sprintf(filename, "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); file.open(filename, ios::in); if (file) { char line[1024]; while (file) { uint64_t f; file.getline(line, 1024); f = strtoull(line, NULL, 10); account_freq(f, 0); } file.close(); } account_freq(0, 0); }
void nhm_core::measurement_start(void) { ifstream file; char filename[PATH_MAX]; /* the abstract function needs to be first since it clears all state */ abstract_cpu::measurement_start(); last_stamp = 0; if (this->has_c1_res) c1_before = get_msr(first_cpu, MSR_CORE_C1_RESIDENCY); if (this->has_c3_res) c3_before = get_msr(first_cpu, MSR_CORE_C3_RESIDENCY); c6_before = get_msr(first_cpu, MSR_CORE_C6_RESIDENCY); if (this->has_c7_res) c7_before = get_msr(first_cpu, MSR_CORE_C7_RESIDENCY); tsc_before = get_msr(first_cpu, MSR_TSC); if (this->has_c1_res) insert_cstate("core c1", "C1 (cc1)", 0, c1_before, 1); if (this->has_c3_res) insert_cstate("core c3", "C3 (cc3)", 0, c3_before, 1); insert_cstate("core c6", "C6 (cc6)", 0, c6_before, 1); if (this->has_c7_res) { insert_cstate("core c7", "C7 (cc7)", 0, c7_before, 1); } snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/stats/time_in_state", first_cpu); file.open(filename, ios::in); if (file) { char line[1024]; while (file) { uint64_t f; file.getline(line, 1024); f = strtoull(line, NULL, 10); account_freq(f, 0); } file.close(); } account_freq(0, 0); }
void nhm_package::measurement_start(void) { abstract_cpu::measurement_start(); last_stamp = 0; if (this->has_c2c7_res) c2_before = get_msr(number, MSR_PKG_C2_RESIDENCY); if (this->has_c3_res) c3_before = get_msr(number, MSR_PKG_C3_RESIDENCY); c6_before = get_msr(number, MSR_PKG_C6_RESIDENCY); if (this->has_c2c7_res) c7_before = get_msr(number, MSR_PKG_C7_RESIDENCY); if (this->has_c8c9c10_res) { c8_before = get_msr(number, MSR_PKG_C8_RESIDENCY); c9_before = get_msr(number, MSR_PKG_C9_RESIDENCY); c10_before = get_msr(number, MSR_PKG_C10_RESIDENCY); } tsc_before = get_msr(first_cpu, MSR_TSC); if (this->has_c2c7_res) insert_cstate("pkg c2", "C2 (pc2)", 0, c2_before, 1); if (this->has_c3_res) insert_cstate("pkg c3", "C3 (pc3)", 0, c3_before, 1); insert_cstate("pkg c6", "C6 (pc6)", 0, c6_before, 1); if (this->has_c2c7_res) insert_cstate("pkg c7", "C7 (pc7)", 0, c7_before, 1); if (this->has_c8c9c10_res) { insert_cstate("pkg c8", "C8 (pc8)", 0, c8_before, 1); insert_cstate("pkg c9", "C9 (pc9)", 0, c9_before, 1); insert_cstate("pkg c10", "C10 (pc10)", 0, c10_before, 1); } }
void abstract_cpu::update_cstate(const char *linux_name, const char *human_name, uint64_t usage, uint64_t duration, int count) { unsigned int i; struct idle_state *state = NULL; for (i = 0; i < cstates.size(); i++) { if (strcmp(linux_name, cstates[i]->linux_name) == 0) { state = cstates[i]; break; } } if (!state) { insert_cstate(linux_name, human_name, usage, duration, count); return; } state->usage_before += usage; state->duration_before += duration; state->before_count += count; }