[rtems commit] test: Add rtems_test_busy_cpu_usage()

Sebastian Huber sebh at rtems.org
Fri Feb 2 14:19:31 UTC 2018


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Feb  2 07:43:39 2018 +0100

test: Add rtems_test_busy_cpu_usage()

---

 cpukit/include/rtems/test.h           | 15 ++++++++++++++-
 cpukit/libmisc/testsupport/testbusy.c | 19 ++++++++++++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/cpukit/include/rtems/test.h b/cpukit/include/rtems/test.h
index 3dbdb9e..fbe8acf 100644
--- a/cpukit/include/rtems/test.h
+++ b/cpukit/include/rtems/test.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -290,6 +290,19 @@ void rtems_test_parallel(
 );
 
 /**
+ * @brief Performs a busy loop for the specified seconds and nanoseconds based
+ * on the CPU usage of the executing thread.
+ *
+ * This function continuously reads the CPU usage of the executing thread.
+ * This operation may lead to a scheduler instance lock contention in SMP
+ * configurations.
+ *
+ * @param[in] seconds The busy seconds.
+ * @param[in] nanoseconds The busy nanoseconds.
+ */
+void rtems_test_busy_cpu_usage(time_t seconds, long nanoseconds);
+
+/**
  * @brief Performs a busy loop with the specified iteration count.
  *
  * This function is optimized to not perform memory accesses and should have a
diff --git a/cpukit/libmisc/testsupport/testbusy.c b/cpukit/libmisc/testsupport/testbusy.c
index 2d34a80..4cc8aa0 100644
--- a/cpukit/libmisc/testsupport/testbusy.c
+++ b/cpukit/libmisc/testsupport/testbusy.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -19,6 +19,7 @@
 
 #include <rtems/test.h>
 #include <rtems.h>
+#include <rtems/score/threadimpl.h>
 
 static uint_fast32_t estimate_busy_loop_maximum( void )
 {
@@ -105,3 +106,19 @@ uint_fast32_t rtems_test_get_one_tick_busy_count( void )
 
   return m;
 }
+
+void rtems_test_busy_cpu_usage( time_t seconds, long nanoseconds )
+{
+  Thread_Control    *executing;
+  Timestamp_Control  busy;
+  Timestamp_Control  start;
+  Timestamp_Control  now;
+
+  executing = _Thread_Get_executing();
+  _Thread_Get_CPU_time_used( executing, &start );
+  _Timestamp_Set( &busy, seconds, nanoseconds );
+
+  do {
+    _Thread_Get_CPU_time_used( executing, &now );
+  } while ( now - start < busy );
+}



More information about the vc mailing list