Răsfoiți Sursa

Measure time to read data

Matthias Vogelgesang 7 ani în urmă
părinte
comite
dd53b1683b
1 a modificat fișierele cu 22 adăugiri și 0 ștergeri
  1. 22 0
      ddrio.c

+ 22 - 0
ddrio.c

@@ -6,6 +6,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <getopt.h>
+#include <time.h>
 #include <pcilib.h>
 #include <pcilib/bar.h>
 #include <pcilib/kmem.h>
@@ -141,6 +142,13 @@ parse_options (int argc, char *const *argv, Options *opts)
     }
 }
 
+static double
+elapsed_seconds (struct timespec *start, struct timespec *end)
+{
+    return (end->tv_sec + end->tv_nsec / 1000000000.0) - (start->tv_sec + start->tv_nsec / 1000000000.0);
+}
+
+
 static void
 reset_ddr_data (pcilib_t *pci, volatile void *bar, Options *opts)
 {
@@ -247,6 +255,8 @@ read_from_ddr (pcilib_t *pci, volatile void *bar, Options *opts)
     int started = 0;
     const size_t mem_size = 4096;
     const int flag_index = 2;
+    struct timespec start;
+    struct timespec end;
 
     if (opts->size == 0) {
         fprintf (stderr, "Read size is zero, not going to read\n");
@@ -277,6 +287,8 @@ read_from_ddr (pcilib_t *pci, volatile void *bar, Options *opts)
     if (opts->verbose)
         printf ("Reading %i times %zu B\n", opts->number, opts->size);
 
+    clock_gettime (CLOCK_MONOTONIC, &start);
+
     for (int i = 0; i < opts->number; i++) {
         size = opts->size;
         hardware_ptr = 0;
@@ -339,6 +351,8 @@ read_from_ddr (pcilib_t *pci, volatile void *bar, Options *opts)
             printf ("Descriptor: update_pattern=%x empty=%x last_address=%lx\n", desc[0], 1 & desc[1], desc[2] | (((uint64_t) desc[3]) << 32));
     }
 
+    clock_gettime (CLOCK_MONOTONIC, &end);
+
     WR32_sleep (HF_REG_DMA, HF_DMA_STOP);
 
     if (fp)
@@ -346,6 +360,14 @@ read_from_ddr (pcilib_t *pci, volatile void *bar, Options *opts)
 
     pcilib_free_kernel_memory (pci, kmem_data, KMEM_DEFAULT_FLAGS);
     pcilib_free_kernel_memory (pci, kmem_desc, KMEM_DEFAULT_FLAGS);
+
+    if (opts->verbose) {
+        double time;
+
+        time = elapsed_seconds (&start, &end);
+        printf ("Read in %f s equivalent to %3.5f MB/s\n",
+                time, opts->size * opts->number / 1024. / 1024. / time);
+    }
 }
 
 int