[rtems commit] tmtests/tmcontext01: Improve cache dirty function

Sebastian Huber sebh at rtems.org
Thu Sep 11 05:25:27 UTC 2014


Module:    rtems
Branch:    master
Commit:    f3508c44b5caeead9ae7a5fe8b800f978652ae75
Changeset: http://git.rtems.org/rtems/commit/?id=f3508c44b5caeead9ae7a5fe8b800f978652ae75

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Sep 11 07:33:16 2014 +0200

tmtests/tmcontext01: Improve cache dirty function

Increment by cache line size to allow more cycles per second.

---

 testsuites/tmtests/tmcontext01/init.c |   38 ++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/testsuites/tmtests/tmcontext01/init.c b/testsuites/tmtests/tmcontext01/init.c
index 444f2af..a27cf82 100644
--- a/testsuites/tmtests/tmcontext01/init.c
+++ b/testsuites/tmtests/tmcontext01/init.c
@@ -38,19 +38,22 @@ static rtems_counter_ticks t[SAMPLES];
 
 static volatile bool always_true = true;
 
+static size_t cache_line_size;
+
 static size_t data_size;
 
 static volatile int *main_data;
 
 static Context_Control ctx;
 
-static int dirty_data_cache(volatile int *d, int j)
+static int dirty_data_cache(volatile int *data, size_t n, size_t clsz, int j)
 {
-  size_t n = data_size / sizeof(*d);
+  size_t m = n / sizeof(*data);
+  size_t k = clsz / sizeof(*data);
   size_t i;
 
-  for (i = 0; i < n; ++i) {
-    d[i] = i + j;
+  for (i = 0; i < m; i += k) {
+    data[i] = i + j;
   }
 
   return i + j;
@@ -90,7 +93,7 @@ static int call_at_level(int start, int fl, int s, bool dirty)
     rtems_counter_ticks b;
 
     if (dirty) {
-      dirty_data_cache(main_data, fl);
+      dirty_data_cache(main_data, data_size, cache_line_size, fl);
       rtems_cache_invalidate_entire_instruction();
     }
 
@@ -112,10 +115,12 @@ static int call_at_level(int start, int fl, int s, bool dirty)
 static void load_task(rtems_task_argument arg)
 {
   volatile int *load_data = (volatile int *) arg;
+  size_t n = data_size;
+  size_t clsz = cache_line_size;
   int j = (int) rtems_get_current_processor();
 
   while (true) {
-    j = dirty_data_cache(load_data, j);
+    j = dirty_data_cache(load_data, n, clsz, j);
   }
 }
 
@@ -208,12 +213,19 @@ static void Init(rtems_task_argument arg)
 
   printf("<Test>\n");
 
+  cache_line_size = rtems_cache_get_data_line_size();
+  if (cache_line_size == 0) {
+    cache_line_size = 32;
+  }
+
   data_size = rtems_cache_get_data_cache_size(0);
-  if (data_size > 0) {
-    main_data = malloc(data_size);
-    rtems_test_assert(main_data != NULL);
+  if (data_size == 0) {
+    data_size = cache_line_size;
   }
 
+  main_data = malloc(data_size);
+  rtems_test_assert(main_data != NULL);
+
   test(false, load);
   test(true, load);
 
@@ -222,11 +234,9 @@ static void Init(rtems_task_argument arg)
     rtems_id id;
     volatile int *load_data = NULL;
 
-    if (data_size > 0) {
-      load_data = malloc(data_size);
-      if (load_data == NULL) {
-        load_data = main_data;
-      }
+    load_data = malloc(data_size);
+    if (load_data == NULL) {
+      load_data = main_data;
     }
 
     sc = rtems_task_create(




More information about the vc mailing list