Message ID | 1355227446-14380-4-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
On Tue, Dec 11, 2012 at 8:04 PM, Colin King <colin.king@canonical.com> wrote: > From: Colin Ian King <colin.king@canonical.com> > > Remove duplicated code by using fwts_cpu_performance() > > Signed-off-by: Colin Ian King <colin.king@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, ¤t); > > -- > 1.8.0 > Acked-by: Keng-Yu Lin <kengyu@canonical.com>
On 12/11/2012 08:04 PM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > Remove duplicated code by using fwts_cpu_performance() > > Signed-off-by: Colin Ian King <colin.king@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, ¤t); > > Acked-by: Ivan Hu <ivan.hu@canonical.com>
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, ¤t);