summaryrefslogtreecommitdiffstats
path: root/testsuites/rhealstone/rhsemshuffle
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@oarcorp.com>2014-01-05 11:17:08 -0600
committerJoel Sherrill <joel.sherrill@oarcorp.com>2014-01-05 11:17:08 -0600
commitb6c1578bb91fb54c826141e0f8bbd9cb2009f3cf (patch)
tree6d4c9af3892de78428add886865bae7db15efbc1 /testsuites/rhealstone/rhsemshuffle
parentrhealstone/*.c: Add Print_Warning() call to indicate debug enabled (diff)
downloadrtems-b6c1578bb91fb54c826141e0f8bbd9cb2009f3cf.tar.bz2
rhealstone: Add rh prefix to all test names
This makes them easier to spot as a group in wildcard searches.
Diffstat (limited to 'testsuites/rhealstone/rhsemshuffle')
-rw-r--r--testsuites/rhealstone/rhsemshuffle/Makefile.am23
-rw-r--r--testsuites/rhealstone/rhsemshuffle/rhsemshuffle.adoc26
-rw-r--r--testsuites/rhealstone/rhsemshuffle/semshuffle.c160
3 files changed, 209 insertions, 0 deletions
diff --git a/testsuites/rhealstone/rhsemshuffle/Makefile.am b/testsuites/rhealstone/rhsemshuffle/Makefile.am
new file mode 100644
index 0000000000..88448297cf
--- /dev/null
+++ b/testsuites/rhealstone/rhsemshuffle/Makefile.am
@@ -0,0 +1,23 @@
+MANAGERS = all
+
+rtems_tests_PROGRAMS = rhsemshuffle
+rhsemshuffle_SOURCES = semshuffle.c
+rhsemshuffle_SOURCES += ../../tmtests/include/timesys.h
+
+dist_rtems_tests_DATA = rhsemshuffle.adoc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../tmtests/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(rhsemshuffle_OBJECTS) $(rhsemshuffle_LDADD)
+LINK_LIBS = $(rhsemshuffle_LDLIBS)
+
+rhsemshuffle$(EXEEXT): $(rhsemshuffle_OBJECTS) $(rhsemshuffle_DEPENDENCIES)
+ @rm -f rhsemshuffle$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/rhealstone/rhsemshuffle/rhsemshuffle.adoc b/testsuites/rhealstone/rhsemshuffle/rhsemshuffle.adoc
new file mode 100644
index 0000000000..c2fc2e49f0
--- /dev/null
+++ b/testsuites/rhealstone/rhsemshuffle/rhsemshuffle.adoc
@@ -0,0 +1,26 @@
+= Semaphore Shuffle Benchmark
+
+This benchmark measures the average delay between a task's release of a
+semaphore and the activation of another task blocked on that semaphore.
+
+== Directives
+
+ * rtems_semaphore_obtain
+ * rtems_semaphore_release
+ * rtems_task_wake_after
+
+
+== Methodology
+
+This benchmark has two equal priority tasks switch between themselves a total
+of BENCHMARKS * 2 times. This is timed, and then execute the same code but
+having the tasks pass a semphore between themselves. A task obtains the
+semphore, then yields to the other task, which blocks on the semaphore. The
+task owning the semaphore then releases it and yields. This process is
+repeated by the other task.
+
+This benchmark has overhead, especially in the time it takes to switch between
+the two tasks, which happens a total of 2 times per semaphore shuffle. By first
+timing how long it takes the tasks to switch between themselves without any
+semaphore related calls, the overhead time is found. This time is then subtracted
+from the total time of the benchmark, with semaphore shuffling occuring.
diff --git a/testsuites/rhealstone/rhsemshuffle/semshuffle.c b/testsuites/rhealstone/rhsemshuffle/semshuffle.c
new file mode 100644
index 0000000000..a4b499f15b
--- /dev/null
+++ b/testsuites/rhealstone/rhsemshuffle/semshuffle.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2014 Daniel Ramirez. (javamonn@gmail.com)
+ *
+ * This file's license is 2-clause BSD as in this distribution's LICENSE file.
+ */
+
+#include <rtems/timerdrv.h>
+#include <timesys.h>
+
+#define BENCHMARKS 50000
+
+rtems_task Task01( rtems_task_argument ignored );
+rtems_task Task02( rtems_task_argument ignored );
+rtems_task Init( rtems_task_argument ignored );
+
+rtems_id Task_id[2];
+rtems_name Task_name[2];
+rtems_id sem_id;
+rtems_name sem_name;
+
+uint32_t telapsed;
+uint32_t tswitch_overhead;
+uint32_t count;
+uint32_t sem_exe;
+
+rtems_task Init( rtems_task_argument ignored )
+{
+ rtems_status_code status;
+ rtems_attribute sem_attr;
+ rtems_task_priority pri;
+ rtems_mode prev_mode;
+
+ Print_Warning();
+
+ sem_attr = RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY;
+
+ sem_name = rtems_build_name( 'S','0',' ',' ' );
+ status = rtems_semaphore_create(
+ sem_name,
+ 1,
+ sem_attr,
+ 0,
+ &sem_id
+ );
+ directive_failed( status, "rtems_semaphore_create of S0" );
+
+ Task_name[0] = rtems_build_name( 'T','A','0','1' );
+ status = rtems_task_create(
+ Task_name[0],
+ 30,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &Task_id[0]
+ );
+ directive_failed( status, "rtems_task_create of TA01" );
+
+ Task_name[1] = rtems_build_name( 'T','A','0','2' );
+ status = rtems_task_create(
+ Task_name[1],
+ 30,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &Task_id[1]
+ );
+ directive_failed( status , "rtems_task_create of TA02\n" );
+
+ rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode );
+ /* Lower own priority so TA01 can start up and run */
+ rtems_task_set_priority( RTEMS_SELF, 40, &pri);
+
+ /* Get time of benchmark with no semaphore shuffling */
+ sem_exe = 0;
+ status = rtems_task_start( Task_id[0], Task01, 0 );
+ directive_failed( status, "rtems_task_start of TA01" );
+
+ /* Get time of benchmark with semaphore shuffling */
+ sem_exe = 1;
+ status = rtems_task_restart( Task_id[0], 0 );
+ directive_failed( status, "rtems_task_restart of TA01" );
+
+ /* Should never reach here */
+ rtems_test_assert( false );
+}
+
+rtems_task Task01( rtems_task_argument ignored )
+{
+ rtems_status_code status;
+
+ /* Start up TA02, yield so it can run */
+ if ( sem_exe == 0 ) {
+ status = rtems_task_start( Task_id[1], Task02, 0 );
+ directive_failed( status, "rtems_task_start of TA02" );
+ } else {
+ status = rtems_task_restart( Task_id[1], 0 );
+ directive_failed( status, "rtems_task_restart of TA02" );
+ }
+ rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
+
+ /* Benchmark code */
+ for ( ; count < BENCHMARKS ; ) {
+ if ( sem_exe == 1 ) {
+ rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
+ }
+ rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
+
+ if ( sem_exe == 1 ) {
+ rtems_semaphore_release( sem_id );
+ }
+ rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
+ }
+
+ /* Should never reach here */
+ rtems_test_assert( false );
+}
+
+rtems_task Task02( rtems_task_argument ignored )
+{
+
+ /* Benchmark code */
+ benchmark_timer_initialize();
+ for ( count = 0; count < BENCHMARKS; count++ ) {
+ if ( sem_exe == 1 ) {
+ rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 );
+ }
+ rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
+
+ if ( sem_exe == 1 ) {
+ rtems_semaphore_release( sem_id );
+ }
+ rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
+ }
+ telapsed = benchmark_timer_read();
+
+ /* Check which run this was */
+ if (sem_exe == 0) {
+ tswitch_overhead = telapsed;
+ rtems_task_suspend( Task_id[0] );
+ rtems_task_suspend( RTEMS_SELF );
+ } else {
+ put_time(
+ "Rhealstone: Semaphore Shuffle",
+ telapsed,
+ (BENCHMARKS * 2), /* Total number of semaphore-shuffles*/
+ tswitch_overhead, /* Overhead of loop and task switches */
+ 0
+ );
+ rtems_test_exit( 0 );
+ }
+}
+
+/* configuration information */
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS 3
+#define CONFIGURE_MAXIMUM_SEMAPHORES 1
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>