[PATCH 4/8] rtems: Add cache size functions

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Feb 26 15:52:45 UTC 2014


Add rtems_cache_get_data_cache_size() and
rtems_cache_get_instruction_cache_size().
---
 c/src/lib/libcpu/shared/src/cache_manager.c |   21 +++++++++++++++
 cpukit/rtems/include/rtems/rtems/cache.h    |   20 ++++++++++++++
 testsuites/sptests/spcache01/init.c         |   38 ++++++++++++++++++++++++---
 testsuites/sptests/spcache01/spcache01.scn  |    2 +
 4 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/c/src/lib/libcpu/shared/src/cache_manager.c b/c/src/lib/libcpu/shared/src/cache_manager.c
index 8fa0477..c55f12c 100644
--- a/c/src/lib/libcpu/shared/src/cache_manager.c
+++ b/c/src/lib/libcpu/shared/src/cache_manager.c
@@ -160,6 +160,16 @@ rtems_cache_get_data_line_size( void )
 }
 
 
+size_t
+rtems_cache_get_data_cache_size( uint32_t level )
+{
+#if defined(CPU_CACHE_SUPPORT_PROVIDES_CACHE_SIZE_FUNCTIONS)
+  return _CPU_cache_get_data_cache_size( level );
+#else
+  return 0;
+#endif
+}
+
 /*
  * This function freezes the data cache; cache lines
  * are not replaced.
@@ -275,6 +285,17 @@ rtems_cache_get_instruction_line_size( void )
 }
 
 
+size_t
+rtems_cache_get_instruction_cache_size( uint32_t level )
+{
+#if defined(CPU_CACHE_SUPPORT_PROVIDES_CACHE_SIZE_FUNCTIONS)
+  return _CPU_cache_get_instruction_cache_size( level );
+#else
+  return 0;
+#endif
+}
+
+
 /*
  * This function freezes the instruction cache; cache lines
  * are not replaced.
diff --git a/cpukit/rtems/include/rtems/rtems/cache.h b/cpukit/rtems/include/rtems/rtems/cache.h
index 2faf620..8da143f 100644
--- a/cpukit/rtems/include/rtems/rtems/cache.h
+++ b/cpukit/rtems/include/rtems/rtems/cache.h
@@ -61,6 +61,26 @@ size_t rtems_cache_get_data_line_size( void );
 size_t rtems_cache_get_instruction_line_size( void );
 
 /**
+ * @brief Returns the data cache size in bytes.
+ *
+ * @param[in] level The cache level of interest.  The cache level zero
+ * specifies the entire data cache.
+ *
+ * @returns The data cache size in bytes of the specified level.
+ */
+size_t rtems_cache_get_data_cache_size( uint32_t level );
+
+/**
+ * @brief Returns the instruction cache size in bytes.
+ *
+ * @param[in] level The cache level of interest.  The cache level zero
+ * specifies the entire instruction cache.
+ *
+ * @returns The instruction cache size in bytes of the specified level.
+ */
+size_t rtems_cache_get_instruction_cache_size( uint32_t level );
+
+/**
  * @brief Flushes multiple data cache lines.
  *
  * Dirty cache lines covering the area are transfered to memory.  Depending on
diff --git a/testsuites/sptests/spcache01/init.c b/testsuites/sptests/spcache01/init.c
index f302837..858aedc 100644
--- a/testsuites/sptests/spcache01/init.c
+++ b/testsuites/sptests/spcache01/init.c
@@ -163,12 +163,28 @@ static void test_timing(void)
   rtems_interrupt_lock lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
   size_t data_size = sizeof(data);
   uint64_t d[3];
+  uint32_t cache_level;
+  size_t cache_size;
 
   printf(
-    "data cache line size %zi bytes\n",
-    rtems_cache_get_data_line_size()
+    "data cache line size %zi bytes\n"
+    "data cache size %zi bytes\n",
+    rtems_cache_get_data_line_size(),
+    rtems_cache_get_data_cache_size(0)
   );
 
+  cache_level = 1;
+  cache_size = rtems_cache_get_data_cache_size(cache_level);
+  while (cache_size > 0) {
+    printf(
+      "data cache level %" PRIu32 " size %zi bytes\n",
+      cache_level,
+      cache_size
+    );
+    ++cache_level;
+    cache_size = rtems_cache_get_data_cache_size(cache_level);
+  }
+
   rtems_interrupt_lock_acquire(&lock, level);
 
   d[0] = load();
@@ -290,10 +306,24 @@ static void test_timing(void)
   );
 
   printf(
-    "instruction cache line size %zi bytes\n",
-    rtems_cache_get_instruction_line_size()
+    "instruction cache line size %zi bytes\n"
+    "instruction cache size %zi bytes\n",
+    rtems_cache_get_instruction_line_size(),
+    rtems_cache_get_instruction_cache_size(0)
   );
 
+  cache_level = 1;
+  cache_size = rtems_cache_get_instruction_cache_size(cache_level);
+  while (cache_size > 0) {
+    printf(
+      "instruction cache level %" PRIu32 " size %zi bytes\n",
+      cache_level,
+      cache_size
+    );
+    ++cache_level;
+    cache_size = rtems_cache_get_instruction_cache_size(cache_level);
+  }
+
   rtems_interrupt_lock_acquire(&lock, level);
 
   d[0] = do_some_work();
diff --git a/testsuites/sptests/spcache01/spcache01.scn b/testsuites/sptests/spcache01/spcache01.scn
index c2f1eb6..22ff364 100644
--- a/testsuites/sptests/spcache01/spcache01.scn
+++ b/testsuites/sptests/spcache01/spcache01.scn
@@ -3,6 +3,7 @@ data cache flush and invalidate test
 data cache operations by line passed the test
 data cache operations by line passed the test (copy-back cache detected)
 data cache line size 32 bytes
+data cache size 0 bytes
 load 4096 bytes with flush entire data
   duration with normal cache 12660 ns
   duration with warm cache 2580 ns
@@ -28,6 +29,7 @@ store 4096 bytes with invalidate multiple data
   duration with warm cache 2580 ns
   duration with invalidated cache 2640 ns
 instruction cache line size 32 bytes
+instruction cache size 0 bytes
 invalidate entire instruction
   duration with normal cache 5780 ns
   duration with warm cache 640 ns
-- 
1.7.7




More information about the devel mailing list