pthread_exit (NULL);
}
-double estimate_clock (void)
+double estimate_tics_clock (void)
{
int n = 4;
int64_t diff_nc = 0;
int64_t nc2 = rdtsc ();
diff_nc = nc2 - nc1;
- double delta = ((double)tv2.tv_sec + tv2.tv_usec * 1e-6) -
+ double runtime = ((double)tv2.tv_sec + tv2.tv_usec * 1e-6) -
((double)tv1.tv_sec + tv1.tv_usec * 1e-6);
- clock = diff_nc / delta;
+
+ clock = diff_nc / runtime;
}
return clock;
}
+double estimate_cpu_clock (void)
+{
+ struct timeval tv1;
+ gettimeofday (&tv1, NULL);
+
+ int instructions = 0;
+ while (instructions < 10000000) {
+#define INST0 "add %[i], %[i], #1\n\t"
+#define INST1 INST0 INST0 INST0 INST0 INST0 INST0 INST0 INST0 \
+ INST0 INST0 INST0 INST0 INST0 INST0 INST0 INST0
+#define INST2 INST1 INST1 INST1 INST1 INST1 INST1 INST1 INST1 \
+ INST1 INST1 INST1 INST1 INST1 INST1 INST1 INST1
+#define INST3 INST2 INST2 INST2 INST2 INST2 INST2 INST2 INST2 \
+ INST2 INST2 INST2 INST2 INST2 INST2 INST2 INST2
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ asm volatile (INST3 : [i] "+r" (instructions) :: "cc");
+ }
+
+ struct timeval tv2;
+ gettimeofday (&tv2, NULL);
+
+ double runtime = ((double)tv2.tv_sec + tv2.tv_usec * 1e-6) -
+ ((double)tv1.tv_sec + tv1.tv_usec * 1e-6);
+
+ return instructions / runtime;
+}
+
/* main function */
int main (int argc, char *argv[])
if (mode) {
while (mode--) {
- printf ("Clock: %.0fMHz\n", estimate_clock () / 1e6);
+ printf ("\r");
+ printf ("Tics clock: %.0fMHz", estimate_tics_clock () / 1e6);
+ printf ("\t");
+ printf ("CPU clock: %.0fMHz", estimate_cpu_clock () / 1e6);
}
+ printf ("\n");
} else if (nb_threads == 0) {
while (1) {
sleep (60);