From e2967396ac73cb7410787886cdaf072a184ffc49 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 2 Jul 2013 09:53:34 -0400 Subject: Added NaCl crypto library. --- nacl/cpucycles/sgi.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 nacl/cpucycles/sgi.c (limited to 'nacl/cpucycles/sgi.c') diff --git a/nacl/cpucycles/sgi.c b/nacl/cpucycles/sgi.c new file mode 100644 index 00000000..c232af09 --- /dev/null +++ b/nacl/cpucycles/sgi.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +static double cpufrequency = 0; + +static void init(void) +{ + FILE *f; + + f = popen("hinv -c processor | awk '{if ($3==\"MHZ\") print $2*1000000}'","r"); + if (!f) return; + if (fscanf(f,"%lf",&cpufrequency) < 1) cpufrequency = 0; + pclose(f); + if (!cpufrequency) return; +} + +long long cpucycles_sgi(void) +{ + double result; + struct timespec t; + if (!cpufrequency) init(); + clock_gettime(CLOCK_SGI_CYCLE,&t); + result = t.tv_nsec; + result *= 0.000000001; + result += (double) t.tv_sec; + result *= cpufrequency; + return result; +} + +long long cpucycles_sgi_persecond(void) +{ + if (!cpufrequency) init(); + return cpufrequency; +} -- cgit v1.2.3