From patchwork Tue Dec 11 12:04:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/4] acpi: cstates: use new fwts_cpu_performance() helper function Date: Tue, 11 Dec 2012 02:04:05 -0000 From: Colin King X-Patchwork-Id: 205187 Message-Id: <1355227446-14380-4-git-send-email-colin.king@canonical.com> To: fwts-devel@lists.ubuntu.com From: Colin Ian King Remove duplicated code by using fwts_cpu_performance() Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu --- src/acpi/cstates/cstates.c | 55 +++++++++------------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c index 26cf2e6..79170df 100644 --- a/src/acpi/cstates/cstates.c +++ b/src/acpi/cstates/cstates.c @@ -34,9 +34,6 @@ #include #include #include -#include -#include -#include #include #define MIN_CSTATE 1 @@ -51,46 +48,6 @@ typedef struct { static int statecount = -1; static int firstcpu = -1; -static void keep_busy_for_one_second(int cpu) -{ - cpu_set_t mask, oldset; - time_t current; - unsigned long loopcount = 0; - - /* First, go to the right cpu */ - - sched_getaffinity(0, sizeof(oldset), &oldset); - - CPU_ZERO(&mask); - CPU_SET(cpu, &mask); - sched_setaffinity(0, sizeof(mask), &mask); - current = time(NULL); - - do { - double A, B; - int i; - A = 1.234567; - B = 3.121213; - for (i=0; i<100; i++) { - A = A * B; - B = A * A; - A = A - B + sqrt(A); - A = A * B; - B = A * A; - A = A - B + sqrt(A); - A = A * B; - B = A * A; - A = A - B + sqrt(A); - A = A * B; - B = A * A; - A = A - B + sqrt(A); - } - loopcount++; - } while (current == time(NULL)); - - sched_setaffinity(0, sizeof(oldset), &oldset); -} - static void get_cstates(char *path, fwts_cstates *state) { struct dirent *entry; @@ -167,8 +124,16 @@ static void do_cpu(fwts_framework *fw, int nth, int cpus, int cpu, char *path) if ((i & 7) < 4) sleep(1); - else - keep_busy_for_one_second(cpu); + else { + uint64_t loop_count; + + if (fwts_cpu_performance(fw, cpu, &loop_count) != FWTS_OK) { + fwts_failed(fw, LOG_LEVEL_HIGH, "CPUFailedPerformance", + "Could not determine the CPU performance, this " + "may be due to not being able to get or set the " + "CPU affinity for CPU %i.", cpu); + } + } get_cstates(path, ¤t);