From 8ba5c8afdfab1098e1400669269eccb8ea0a44c4 Mon Sep 17 00:00:00 2001 From: Vincent Brillault Date: Sat, 23 Aug 2014 09:32:04 +0200 Subject: [PATCH] Turbostat: Refactor migrate CPU before get_MSR In two out of three "get_msr" calls, there is a CPU migration, which does not seem to be used by something else (in one case, it was used by the rdtsc call). Move the migrate call directly into the open_msr function --- src/turbostat.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/turbostat.c b/src/turbostat.c index c7778604..d602ffe6 100644 --- a/src/turbostat.c +++ b/src/turbostat.c @@ -271,6 +271,12 @@ open_msr(int cpu) { char pathname[32]; + /* FIXME: Do we really need this, why? */ + if (cpu_migrate(cpu)) { + ERROR("Could not migrate to CPU %d\n", cpu); + return -ERR_CPU_MIGRATE; + } + ssnprintf(pathname, 32, "/dev/cpu/%d/msr", cpu); return open(pathname, O_RDONLY); } @@ -438,11 +444,6 @@ get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) int msr_fd; int retval = 0; - if (cpu_migrate(cpu)) { - WARNING("Could not migrate to CPU %d\n", cpu); - return -ERR_CPU_MIGRATE; - } - msr_fd = open_msr(cpu); if (msr_fd < 0) return -ERR_CANT_OPEN_MSR; @@ -968,7 +969,6 @@ set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_da { unsigned long long msr; unsigned int target_c_local; - int cpu; /* tcc_activation_temp is used only for dts or ptm */ if (!(do_dts || do_ptm)) @@ -978,12 +978,6 @@ set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_da if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) return 0; - cpu = t->cpu_id; - if (cpu_migrate(cpu)) { - ERROR("Could not migrate to CPU %d\n", cpu); - return -ERR_CPU_MIGRATE; - } - if (tcc_activation_temp_override != 0) { tcc_activation_temp = tcc_activation_temp_override; ERROR("cpu%d: Using cmdline TCC Target (%d C)\n", @@ -991,7 +985,7 @@ set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_da return 0; } - if (get_msr(cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) + if (get_msr(t->cpu_id, MSR_IA32_TEMPERATURE_TARGET, &msr)) goto guess; target_c_local = (msr >> 16) & 0x7F; @@ -1006,7 +1000,7 @@ set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_da guess: tcc_activation_temp = TJMAX_DEFAULT; WARNING("cpu%d: Guessing tjMax %d C, Please use -T to specify\n", - cpu, tcc_activation_temp); + t->cpu_id, tcc_activation_temp); return 0; } -- 2.11.0