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/rhtaskpreempt | |
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/rhtaskpreempt')
-rw-r--r-- | testsuites/rhealstone/rhtaskpreempt/Makefile.am | 23 | ||||
-rw-r--r-- | testsuites/rhealstone/rhtaskpreempt/rhtaskpreempt.adoc | 36 | ||||
-rw-r--r-- | testsuites/rhealstone/rhtaskpreempt/taskpreempt.c | 115 |
3 files changed, 174 insertions, 0 deletions
diff --git a/testsuites/rhealstone/rhtaskpreempt/Makefile.am b/testsuites/rhealstone/rhtaskpreempt/Makefile.am new file mode 100644 index 0000000000..d0106aabba --- /dev/null +++ b/testsuites/rhealstone/rhtaskpreempt/Makefile.am @@ -0,0 +1,23 @@ +MANAGERS = all + +rtems_tests_PROGRAMS = rhtaskpreempt +rhtaskpreempt_SOURCES = taskpreempt.c +rhtaskpreempt_SOURCES += ../../tmtests/include/timesys.h + +dist_rtems_tests_DATA = rhtaskpreempt.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 = $(rhtaskpreempt_OBJECTS) $(rhtaskpreempt_LDADD) +LINK_LIBS = $(rhtaskpreempt_LDLIBS) + +rhtaskpreempt$(EXEEXT): $(rhtaskpreempt_OBJECTS) $(rhtaskpreempt_DEPENDENCIES) + @rm -f rhtaskpreempt$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/rhealstone/rhtaskpreempt/rhtaskpreempt.adoc b/testsuites/rhealstone/rhtaskpreempt/rhtaskpreempt.adoc new file mode 100644 index 0000000000..ee53cc87dc --- /dev/null +++ b/testsuites/rhealstone/rhtaskpreempt/rhtaskpreempt.adoc @@ -0,0 +1,36 @@ += Task Preemption Benchmark + +This benchmark measures the average time it takes the system to recognize +a ready higher priority task and switch to it from a lower priority task. +This differs from a task-switch in the sense that there is no explicit +yield, the system forces the context switch. + +== Directives + + * rtems_task_suspend + * rtems_task_resume + +== Methodology + +Preemption usually occurs in a program when a high priority task moves from +a suspended or idle state to a ready state in response to an event. This is +achieved in the benchmark by using rtems_task_suspend and rtems_task_resume +to move the high priority task in between states. + +As this is an average, we structure the benchmark code in a way that results +in some overhead being included that inflates the total elapsed time. This +overhead includes: + * loop overhead (minimal) + * the time it takes to task-switch from the high priority task back to + the low priority task. + * The time it takes to change the state of a task (suspend/resume). + +We instantiate two tasks, one with a higher priority than the other. The +benchmark starts with the high priority task suspended. The benchmark code +has the lower priority task resume the high priority task, at which point +the preemption we are seeking to time occurs. The high priority task, now +executing, suspends it self, and a non-preemptive task switch back to the +low priority task occurs. This is repeated a total of BENCHMARKS times. + +The average time is found by using put_time to divide the total elapsed time +by the number of benchmarks, and subtracting out the overhead found earlier. diff --git a/testsuites/rhealstone/rhtaskpreempt/taskpreempt.c b/testsuites/rhealstone/rhtaskpreempt/taskpreempt.c new file mode 100644 index 0000000000..80e79229ce --- /dev/null +++ b/testsuites/rhealstone/rhtaskpreempt/taskpreempt.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2014 Daniel Ramirez. (javamonn@gmail.com) + * + * This file's license is 2-clause BSD as in this distribution's LICENSE file. + */ + +#include <timesys.h> +#include <rtems/timerdrv.h> +#define BENCHMARKS 50000 /* Number of benchmarks to run and average over */ + +rtems_task Task02( rtems_task_argument ignored ); +rtems_task Task01( rtems_task_argument ignored ); +rtems_task Init( rtems_task_argument ignored ); + +rtems_id Task_id[2]; +rtems_name Task_name[2]; + +uint32_t telapsed; /* total time elapsed during benchmark */ +uint32_t tloop_overhead; /* overhead of loops */ +uint32_t tswitch_overhead; /* overhead of time it takes to switch + * from TA02 to TA01, includes rtems_suspend + * overhead + */ +unsigned long count1; +rtems_status_code status; + +rtems_task Task01( rtems_task_argument ignored ) +{ + /* Start up TA02, get preempted */ + status = rtems_task_start( Task_id[1], Task02, 0); + directive_failed( status, "rtems_task_start of TA02"); + + tswitch_overhead = benchmark_timer_read(); + + benchmark_timer_initialize(); + /* Benchmark code */ + for ( count1 = 0; count1 < BENCHMARKS; count1++ ) { + rtems_task_resume( Task_id[1] ); /* Awaken TA02, preemption occurs */ + } + + /* Should never reach here */ + rtems_test_assert( false ); +} + +rtems_task Task02( rtems_task_argument ignored ) +{ + /* Find overhead of task switch back to TA01 (not a preemption) */ + benchmark_timer_initialize(); + rtems_task_suspend( RTEMS_SELF ); + + /* Benchmark code */ + for ( ; count1 < BENCHMARKS - 1; ) { + rtems_task_suspend( RTEMS_SELF ); + } + + telapsed = benchmark_timer_read(); + put_time( + "Rhealstone: Task Preempt", + telapsed, /* Total time of all benchmarks */ + BENCHMARKS - 1, /* BENCHMARKS - 1 total preemptions */ + tloop_overhead, /* Overhead of loops */ + tswitch_overhead /* Overhead of task switch back to TA01 */ + ); + + rtems_test_exit( 0 ); +} + +rtems_task Init( rtems_task_argument ignored ) +{ + Print_Warning(); + + Task_name[0] = rtems_build_name( 'T','A','0','1' ); + status = rtems_task_create( + Task_name[0], + 30, /* TA01 is low 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, /* TA02 is high priority task */ + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &Task_id[1] + ); + directive_failed( status, "rtems_task_create of TA02"); + + /* Find loop overhead */ + benchmark_timer_initialize(); + for ( count1 = 0; count1 < ( BENCHMARKS * 2 ) - 1; count1++ ); { + /* rtems_task_resume( Task_id[1] ); */ + } + tloop_overhead = benchmark_timer_read(); + + status = rtems_task_start( Task_id[0], Task01, 0 ); + directive_failed( status, "rtems_task_start of TA01"); + + status = rtems_task_delete( RTEMS_SELF ); + directive_failed( status, "rtems_task_delete of INIT"); +} + +/* 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_TASKS 3 +#define CONFIGURE_INIT +#include <rtems/confdefs.h> |