From 9cdf45006ed170a6bc9ba946cbe4baedf3732832 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Mon, 17 Nov 2008 22:00:46 +0000 Subject: Use libproccpuinfo git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@79 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- Makefile | 2 +- hardware.c | 109 +++++++++++++------------------------------------------------ 2 files changed, 23 insertions(+), 88 deletions(-) diff --git a/Makefile b/Makefile index d77d86d..ae6e191 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC=gcc CFLAGS=-O3 -march=k8 -msse3 -ftree-vectorize -funroll-loops -pipe -static -Wunused -Wextra -Wall -pedantic #CC=icc #CFLAGS=-O3 -ipo -xP -gcc -static -LIBS=-lm +LIBS=-lm -lproccpuinfo OBJS=emfloat.o randnum.o hardware.o cleanbench.o numsort.o stringsort.o bitfield.o fpemulation.o fourier.o assignment.o idea.o huffman.o neural.o linear.o diff --git a/hardware.c b/hardware.c index 06b0096..46ecfc8 100644 --- a/hardware.c +++ b/hardware.c @@ -2,6 +2,8 @@ #include #include +#include + #define BUF_SIZ 1024 /****************** @@ -47,94 +49,27 @@ static void runCommand (const char *command, char *result) { ** The pointers must point to pre-allocated arrays of at least BUF_SIZ */ static void readProcCpuInfo (char *model, char *cache) { - FILE * info; - char * cp; - int cpus = 0; - char * buffer_end; - char buffer[BUF_SIZ]; - char vendor_id[BUF_SIZ]; - char model_name[BUF_SIZ]; - char cpu_MHz[BUF_SIZ]; - int i; - float f; + char format[32]; + proccpuinfo *info = proccpuinfo_read(); - vendor_id[0] = model_name[0] = cpu_MHz[0] = model[0] = cache[0] = '\0'; - info = fopen("/proc/cpuinfo", "r"); - if(info != NULL) { - /* command did not fail */ - while(NULL != fgets(buffer, BUF_SIZ, info)){ - buffer_end = buffer + strlen(buffer); - cp = buffer; - if(! strncmp(buffer, "processor", 9)) { - cpus++; - } else if(! strncmp(buffer, "vendor_id", 9)) { - cp+=strlen("vendor_id"); - while(cp < buffer_end && ( *cp == ' ' || *cp == ':'|| *cp == '\t')) - cp++; - if(cp1) { - if (cpus==2) { - strcpy(model, "Dual"); - } else { - sprintf(model, "%d CPU", cpus); - } - } - cp = model + strlen(model); - if(vendor_id[0] != '\0'){ - if(cp != model){ - *cp++ = ' '; - } - strcpy(cp, vendor_id); - cp += strlen(vendor_id); - } - if(model_name[0] != '\0'){ - if(cp != model){ - *cp++ = ' '; - } - strcpy(cp, model_name); - cp += strlen(model_name); - } - if(cpu_MHz[0] != '\0'){ - if(cp != model){ - *cp++ = ' '; - } - f = atof(cpu_MHz); - i = (int)(f+0.5f); - sprintf(cpu_MHz, "%dMHz", i); - strcpy(cp, cpu_MHz); - cp += strlen(cpu_MHz); - } - fclose(info); - } + if (!info) { + return; + } + + switch (info->cpus) { + case 1: + strncpy(format, "%s %s %.0fMHz", 32); + break; + case 2: + strncpy(format, "Dual %s %s %.0fMHz", 32); + break; + default: + strncpy(format, "%d CPUs %s %s %.0fMHz", 32); + break; + } + snprintf(model, BUF_SIZ, format, info->hardware_platform, info->architecture, info->frequency); + snprintf(cache, BUF_SIZ, "%d KB", info->cache); + proccpuinfo_free(info); } -- cgit v1.2.3