Program to benchmark the speed of the different file system options versus placing data directly into arrays.

Dependencies:   DMBasicGUI DMSupport

This program is used to measure the performance of the different file system options on the LPC4088 Display Module.

The performance wiki page and more specifically the software part describes this program and the output.

As the program doesn't use the display at all it can be used on both the 4.3" and 5" display modules.

Files at this revision

API Documentation at this revision

Comitter:
alindvall
Date:
Thu Mar 26 16:02:38 2015 +0000
Parent:
4:38ccf7138017
Child:
6:47b4bed9fa13
Commit message:
Added workaround to problem with MCIFileSystem write sizes

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Mar 20 14:51:54 2015 +0000
+++ b/main.cpp	Thu Mar 26 16:02:38 2015 +0000
@@ -296,6 +296,31 @@
   return true;
 }
 
+static uint32_t writeInChunks(FILE* f, const uint8_t* src, uint32_t len, bool destIsMCI)
+{
+  if (destIsMCI) {
+    uint32_t left = len;
+    uint32_t written = 0;
+    uint32_t chunk;
+    while (left > 0) {
+      // MCI File system only supports writing 512 bytes at a time
+      chunk = ((left < 512) ? left : 512);
+      uint32_t tmp = fwrite(src+written, 1, chunk, f);
+      if (tmp != chunk) {
+        // failed, return what we have written so far
+        return written;
+      }
+      left -= chunk;
+      written += chunk;
+    }
+    return written;
+  } else {
+    // All file systems except for MCI supports complete fwrites and will split it into
+    // chunks (if needed) internally.
+    return fwrite(src, 1, len, f);
+  }
+}
+
 static bool createFiles(const char* prefix) {
   RtosLog* log = DMBoard::instance().logger();
   char buff[512] = {0};
@@ -312,15 +337,9 @@
     }
     uint32_t written;
     if (BENCHMARK_INPUT[i].iflash_direct == NULL) {
-      // Need to copy from QSPI to SDRAM before attempting to write to the
-      // file as it will fail otherwise.
-      uint8_t* dest = (uint8_t*)malloc(COPYBUF_SIZE);
-      memcpy(dest, BENCHMARK_INPUT[i].qspi_direct, BENCHMARK_INPUT[i].size);
-      written = fwrite(dest, 1, BENCHMARK_INPUT[i].size, f);
-      free(dest);
-      //written = fwrite(BENCHMARK_INPUT[i].qspi_direct, 1, BENCHMARK_INPUT[i].size, f);
+      written = writeInChunks(f, BENCHMARK_INPUT[i].qspi_direct, BENCHMARK_INPUT[i].size, (prefix[1]=='m'));
     } else {
-      written = fwrite(BENCHMARK_INPUT[i].iflash_direct, 1, BENCHMARK_INPUT[i].size, f);
+      written = writeInChunks(f, BENCHMARK_INPUT[i].iflash_direct, BENCHMARK_INPUT[i].size, (prefix[1]=='m'));
     }
     if (written != BENCHMARK_INPUT[i].size) {
       log->printf("Failed to write %u (only wrote %u) bytes to %s - ABORTING\n", BENCHMARK_INPUT[i].size, written, buff);
@@ -407,10 +426,9 @@
   do {
     if (qspifs->isformatted()) {
       uint32_t start, end;
+      log->printf("QSPI file system detected\n");
       qspifs->getMemoryBoundaries(&start, &end);
       if ((end-start) >= QSPIFS_SIZE) {
-        log->printf("QSPI file system detected\n");
-
         if (haveAllFiles("/qspi/")) {
           log->printf("QSPI file system prepared!\n");
           ok = true;
@@ -615,7 +633,6 @@
 static uint32_t writeFile(const char* fname, int benchId, Timer* t, uint8_t* buff) {
   uint32_t size = BENCHMARK_INPUT[benchId].size;
 
-  // For uSD cards it is not possible to read the data from QSPI flash.
   // To make all tests equal all source data is copied to external SDRAM
   // and from there to the destination file. Only the time from SDRAM to
   // file is meassured.
@@ -629,7 +646,7 @@
   int written = 0;
   FILE* f = fopen(fname, "w");
   if (f != NULL) {
-    written = fwrite(buff, 1, size, f);
+    written = writeInChunks(f, buff, size, (fname[1]=='m'));
     fclose(f);
   }
   if (written == size) {
@@ -648,7 +665,6 @@
   
   log->printf("Preparing to run WRITE tests...\n");
 
-  // For uSD cards it is not possible to read the data from QSPI flash.
   // To make all tests equal all source data is copied to external SDRAM
   // and from there to the destination file. Only the time from SDRAM to
   // file is meassured.