[PATCH 3/4] acpi: cstates: use new fwts_cpu_performance() helper function

Colin King colin.king at canonical.com
Tue Dec 11 12:04:05 UTC 2012


From: Colin Ian King <colin.king at canonical.com>

Remove duplicated code by using fwts_cpu_performance()

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 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 <sys/types.h>
 #include <dirent.h>
 #include <stdint.h>
-#include <sched.h>
-#include <time.h>
-#include <math.h>
 #include <ctype.h>
 
 #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, &current);
 
-- 
1.8.0




More information about the fwts-devel mailing list