diff options
author | Joel Sherrill <joel.sherrill@oarcorp.com> | 2014-01-05 11:17:08 -0600 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@oarcorp.com> | 2014-01-05 11:17:08 -0600 |
commit | b6c1578bb91fb54c826141e0f8bbd9cb2009f3cf (patch) | |
tree | 6d4c9af3892de78428add886865bae7db15efbc1 /testsuites/rhealstone/rhdeadlockbrk | |
parent | rhealstone/*.c: Add Print_Warning() call to indicate debug enabled (diff) | |
download | rtems-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/rhdeadlockbrk')
-rw-r--r-- | testsuites/rhealstone/rhdeadlockbrk/Makefile.am | 23 | ||||
-rw-r--r-- | testsuites/rhealstone/rhdeadlockbrk/deadlockbrk.c | 210 | ||||
-rw-r--r-- | testsuites/rhealstone/rhdeadlockbrk/rhdeadlockbrk.adoc | 37 |
3 files changed, 270 insertions, 0 deletions
diff --git a/testsuites/rhealstone/rhdeadlockbrk/Makefile.am b/testsuites/rhealstone/rhdeadlockbrk/Makefile.am new file mode 100644 index 0000000000..3f6eebf9ff --- /dev/null +++ b/testsuites/rhealstone/rhdeadlockbrk/Makefile.am @@ -0,0 +1,23 @@ +MANAGERS = all + +rtems_tests_PROGRAMS = rhdeadlockbrk +rhdeadlockbrk_SOURCES = deadlockbrk.c +rhdeadlockbrk_SOURCES += ../../tmtests/include/timesys.h + +dist_rtems_tests_DATA = rhdeadlockbrk.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 = $(rhdeadlockbrk_OBJECTS) $(rhdeadlockbrk_LDADD) +LINK_LIBS = $(rhdeadlockbrk_LDLIBS) + +rhdeadlockbrk$(EXEEXT): $(rhdeadlockbrk_OBJECTS) $(rhdeadlockbrk_DEPENDENCIES) + @rm -f rhdeadlockbrk$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/rhealstone/rhdeadlockbrk/deadlockbrk.c b/testsuites/rhealstone/rhdeadlockbrk/deadlockbrk.c new file mode 100644 index 0000000000..8fdf7f8deb --- /dev/null +++ b/testsuites/rhealstone/rhdeadlockbrk/deadlockbrk.c @@ -0,0 +1,210 @@ +/* + * 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 20000 + +rtems_task Task01( rtems_task_argument ignored ); +rtems_task Task02( rtems_task_argument ignored ); +rtems_task Task03( rtems_task_argument ignored ); +rtems_task Init( rtems_task_argument ignored ); + +rtems_id Task_id[3]; +rtems_name Task_name[3]; +rtems_id sem_id; +rtems_name sem_name; +rtems_status_code status; + +uint32_t count; +uint32_t telapsed; +uint32_t tswitch_overhead; +uint32_t tobtain_overhead; +uint32_t sem_exe; + +rtems_task Init( rtems_task_argument ignored ) +{ + rtems_attribute sem_attr; + rtems_task_priority pri; + rtems_mode prev_mode; + + Print_Warning(); + + sem_attr = RTEMS_INHERIT_PRIORITY | 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], + 26, /* High priority task */ + 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], + 28, /* Mid priority task */ + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &Task_id[1] + ); + directive_failed( status, "rtems_task_create of TA02" ); + + Task_name[2] = rtems_build_name( 'T','A','0','3' ); + status = rtems_task_create( + Task_name[2], + 30, /* Low priority task */ + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &Task_id[2] + ); + directive_failed( status, "rtems_task_create of TA03" ); + + /* find overhead of obtaining semaphore */ + benchmark_timer_initialize(); + rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 ); + tobtain_overhead = benchmark_timer_read(); + rtems_semaphore_release( sem_id ); + + rtems_task_mode( RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &prev_mode ); + /* Lower own priority so tasks can start up and run */ + rtems_task_set_priority( RTEMS_SELF, 40, &pri ); + + /* Get time of benchmark with no semaphores involved, i.e. find overhead */ + sem_exe = 0; + status = rtems_task_start( Task_id[2], Task03, 0 ); + directive_failed( status, "rtems_task_start of TA03" ); + + /* Get time of benchmark with semaphores */ + sem_exe = 1; + status = rtems_task_restart( Task_id[2], 0 ); + directive_failed( status, "rtems_task_start of TA03" ); + + /* Should never reach here */ + rtems_test_assert( false ); +} + +rtems_task Task01( rtems_task_argument ignored ) +{ + /* All tasks have had time to start up once TA01 is running */ + + /* Benchmark code */ + benchmark_timer_initialize(); + for ( count = 0; count < BENCHMARKS; count++ ) { + if ( sem_exe == 1 ) { + /* Block on call */ + rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 ); + } + + if ( sem_exe == 1 ) { + /* Release semaphore immediately after obtaining it */ + rtems_semaphore_release( sem_id ); + } + + /* Suspend self, go to TA02 */ + rtems_task_suspend( RTEMS_SELF ); + } + telapsed = benchmark_timer_read(); + + /* Check which run this was */ + if (sem_exe == 0) { + tswitch_overhead = telapsed; + rtems_task_suspend( Task_id[1] ); + rtems_task_suspend( Task_id[2] ); + rtems_task_suspend( RTEMS_SELF ); + } else { + put_time( + "Rhealstone: Deadlock Break", + telapsed, + BENCHMARKS, /* Total number of times deadlock broken*/ + tswitch_overhead, /* Overhead of loop and task switches */ + tobtain_overhead + ); + rtems_test_exit( 0 ); + } + +} + +rtems_task Task02( rtems_task_argument ignored ) +{ + /* Start up TA01, get preempted */ + if ( sem_exe == 1) { + status = rtems_task_restart( Task_id[0], 0); + directive_failed( status, "rtems_task_start of TA01"); + } else { + status = rtems_task_start( Task_id[0], Task01, 0); + directive_failed( status, "rtems_task_start of TA01"); + } + + /* Benchmark code */ + for ( ; count < BENCHMARKS ; ) { + /* Suspend self, go to TA01 */ + rtems_task_suspend( RTEMS_SELF ); + + /* Wake up TA01, get preempted */ + rtems_task_resume( Task_id[0] ); + } +} + +rtems_task Task03( rtems_task_argument ignored ) +{ + if (sem_exe == 1) { + /* Low priority task holds mutex */ + rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 ); + } + + /* Start up TA02, get preempted */ + if ( sem_exe == 1) { + status = rtems_task_restart( Task_id[1], 0); + directive_failed( status, "rtems_task_start of TA02"); + } else { + status = rtems_task_start( Task_id[1], Task02, 0); + directive_failed( status, "rtems_task_start of TA02"); + } + + /* Benchmark code */ + for ( ; count < BENCHMARKS ; ) { + if ( sem_exe == 1 ) { + /* Preempted by TA01 upon release */ + rtems_semaphore_release( sem_id ); + } + + if ( sem_exe == 1 ) { + /* Prepare for next Benchmark */ + rtems_semaphore_obtain( sem_id, RTEMS_WAIT, 0 ); + } + /* Wake up TA02, get preempted */ + rtems_task_resume( Task_id[1] ); + } +} + +/* configuration information */ +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER + +#define CONFIGURE_TICKS_PER_TIMESLICE 0 +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_MAXIMUM_SEMAPHORES 1 +#define CONFIGURE_MAXIMUM_TASKS 4 + +#define CONFIGURE_INIT +#include <rtems/confdefs.h> diff --git a/testsuites/rhealstone/rhdeadlockbrk/rhdeadlockbrk.adoc b/testsuites/rhealstone/rhdeadlockbrk/rhdeadlockbrk.adoc new file mode 100644 index 0000000000..a26cd47f86 --- /dev/null +++ b/testsuites/rhealstone/rhdeadlockbrk/rhdeadlockbrk.adoc @@ -0,0 +1,37 @@ += Deadlock Break Benchmark + +This benchmark measures the average time to break a deadlock that occurs +when a high priority task preempts a low priority task that is holding a +resource that the high priority task needs. In RTEMS, these situations +are mitigated through use of a semaphore with priority inheritance. A +task holding a semaphore with priority inheritance enabled has its +priority boosted to match that of the highest priority task blocked on +that semaphore. + +== Directives + + * rtems_semaphore_obtain + * rtems_semaphore_release + * rtems_task_suspend + * rtems_task_resume + + +== Methodology + +This benchmark is structured in a way that is very similar to the semaphore- +shuffle benchmark, but instead uses three tasks of differing priorities and +suspend/resume instead of yield directives. + +The benchmark is run and timed once with no semaphore operations. This is the +overhead time. The benchmark starts with the high priority task, which suspends +itself, passing control to the mid priority task. The mid priority task then +suspends itself, passing control to the low priority task. The low priority task +resumes the mid priority task, which then resumes the high priority task. The +process is repeated a total of BENCHMARKS times. This process is then executed +with the low priority task holding a semaphore that the high priority task blocks +on when trying to obtain. Due to priority inheritance (the deadlock break +mechanism) the low priority task will execute instead of the mid priority task. +The same system of suspend/resumes then occurs. + +The average is found and the overhead (the time of the first run) is subtracted +out in the call to put_time. |