Ticket #2795: patch.diff
File patch.diff, 27.1 KB (added by Kuan, on 10/08/16 at 11:56:50) |
---|
-
cpukit/rtems/include/rtems/rtems/ratemon.h
diff --git a/cpukit/rtems/include/rtems/rtems/ratemon.h b/cpukit/rtems/include/rtems/rtems/ratemon.h index 50b8478..0455fab 100644
a b 22 22 23 23 /* COPYRIGHT (c) 1989-2009, 2016. 24 24 * On-Line Applications Research Corporation (OAR). 25 * Copyright (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 25 26 * 26 27 * The license and distribution terms for this file may be 27 28 * found in the file LICENSE in this distribution or at … … typedef struct { 240 241 * This field contains the statistics maintained for the period. 241 242 */ 242 243 Rate_monotonic_Statistics Statistics; 244 245 /** 246 * This field contains the number of postponed jobs. When the 247 * watchdog timeouts, this variable will be increased immediately. 248 */ 249 uint32_t postponed_jobs; 250 251 /** 252 * This field contains the tick of the latest deadline decided 253 * by the period watchdog. 254 */ 255 uint64_t latest_deadline; 243 256 } Rate_monotonic_Control; 244 257 245 258 /** … … rtems_status_code rtems_rate_monotonic_period( 403 416 rtems_interval length 404 417 ); 405 418 419 /** 420 * @brief RTEMS Return the number of postponed jobs 421 * 422 * This is a helper function to return the number of postponed jobs by this 423 * given period. This number is only increased by the corresponding watchdog, 424 * and is decreased by RMS manager with the postponed job releasing. 425 * 426 * @param[in] id is the period id 427 * 428 * @retval This helper function returns the number of postponed jobs with 429 * given period_id. 430 * 431 */ 432 uint32_t rtems_rate_monotonic_Postponed_num( 433 rtems_id period_id 434 ); 435 406 436 /**@}*/ 407 437 408 438 #ifdef __cplusplus -
cpukit/rtems/include/rtems/rtems/ratemonimpl.h
diff --git a/cpukit/rtems/include/rtems/rtems/ratemonimpl.h b/cpukit/rtems/include/rtems/rtems/ratemonimpl.h index b6b3ffd..420d3e0 100644
a b 9 9 /* COPYRIGHT (c) 1989-2008. 10 10 * On-Line Applications Research Corporation (OAR). 11 11 * Copyright (c) 2016 embedded brains GmbH. 12 * Copyright (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 12 13 * 13 14 * The license and distribution terms for this file may be 14 15 * found in the file LICENSE in this distribution or at … … bool _Rate_monotonic_Get_status( 116 117 Timestamp_Control *cpu_since_last_period 117 118 ); 118 119 120 /** 121 * @brief Renew the watchdog deadline 122 * 123 * This routine is prepared for the watchdog timeout to renew its deadline 124 * without releasing jobs. 125 */ 126 void _Rate_monotonic_Renew_deadline( 127 Rate_monotonic_Control *the_period, 128 Thread_Control *owner, 129 ISR_lock_Context *lock_context 130 }; 131 119 132 void _Rate_monotonic_Restart( 120 133 Rate_monotonic_Control *the_period, 121 134 Thread_Control *owner, -
cpukit/rtems/src/ratemonperiod.c
diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c index 77bd996..f631071 100644
a b 9 9 * COPYRIGHT (c) 1989-2010. 10 10 * On-Line Applications Research Corporation (OAR). 11 11 * Copyright (c) 2016 embedded brains GmbH. 12 * Copyright (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 12 13 * 13 14 * The license and distribution terms for this file may be 14 15 * found in the file LICENSE in this distribution or at … … bool _Rate_monotonic_Get_status( 63 64 return true; 64 65 } 65 66 67 /* This funciton only releases the postponed jobs. */ 68 static void _Rate_monotonic_Release_postponedjob( 69 Rate_monotonic_Control *the_period, 70 Thread_Control *owner, 71 rtems_interval next_length, 72 ISR_lock_Context *lock_context 73 ) 74 { 75 Per_CPU_Control *cpu_self; 76 cpu_self = _Thread_Dispatch_disable_critical( lock_context ); 77 _Rate_monotonic_Release( owner, lock_context ); 78 79 the_period->postponed_jobs -=1; 80 _Scheduler_Release_job( owner, the_period->latest_deadline ); 81 _Thread_Dispatch_enable( cpu_self ); 82 } 83 66 84 static void _Rate_monotonic_Release_job( 67 85 Rate_monotonic_Control *the_period, 68 86 Thread_Control *owner, … … static void _Rate_monotonic_Release_job( 93 111 _Thread_Dispatch_enable( cpu_self ); 94 112 } 95 113 114 void _Rate_monotonic_Renew_deadline( 115 Rate_monotonic_Control *the_period, 116 Thread_Control *owner, 117 ISR_lock_Context *lock_context 118 ) 119 { 120 Per_CPU_Control *cpu_self; 121 uint64_t deadline; 122 123 cpu_self = _Thread_Dispatch_disable_critical( lock_context ); 124 _Rate_monotonic_Release( owner, lock_context )l 125 126 _ISR_lock_ISR_disable( lock_context ); 127 deadline = _Watchdog_Per_CPU_insert_relative( 128 &the_period->Timer, 129 cpu_self, 130 the_period->next_length 131 ); 132 the_period->latest_deadline = deadline; 133 _ISR_lock_ISR_enable( lock_context ); 134 _Thread_Dispatch_enable( cpu_self ); 135 136 } 137 96 138 void _Rate_monotonic_Restart( 97 139 Rate_monotonic_Control *the_period, 98 140 Thread_Control *owner, … … void _Rate_monotonic_Restart( 113 155 ); 114 156 } 115 157 158 uint32_t rtems_rate_monotonic_Postponed_num( 159 rtems_id period_id 160 ) 161 { 162 Rate_monotonic_Control *the_period; 163 ISR_lock_Context lock_context; 164 Thread_Control *owner; 165 166 the_period = _Rate_monotonic_Get( period_id, &lock_context ); 167 _Assert(the_period != NULL); 168 uint32_t jobs = the_period->postponed_jobs; 169 owner = the_period->owner; 170 _Rate_monotonic_Release( owner, &lock_context ); 171 return jobs; 172 } 173 116 174 static void _Rate_monotonic_Update_statistics( 117 175 Rate_monotonic_Control *the_period 118 176 ) … … static rtems_status_code _Rate_monotonic_Activate( 190 248 ISR_lock_Context *lock_context 191 249 ) 192 250 { 251 /* Initialize the number of postponed job variable */ 252 the_period->postponed_jobs = 0; 253 193 254 the_period->state = RATE_MONOTONIC_ACTIVE; 194 255 the_period->next_length = length; 195 256 _Rate_monotonic_Restart( the_period, executing, lock_context ); … … static rtems_status_code _Rate_monotonic_Block_while_active( 241 302 return RTEMS_SUCCESSFUL; 242 303 } 243 304 305 /** 306 * There are two possible cases: one is that the previous deadline is missed, 307 * the other is that the number of postponed jos is not 0, but the current 308 * deadline is still not expired, i.e., state = RATE_MONOTONIC_ACTIVE. 309 */ 244 310 static rtems_status_code _Rate_monotonic_Block_while_expired( 245 311 Rate_monotonic_Control *the_period, 246 312 rtems_interval length, … … static rtems_status_code _Rate_monotonic_Block_while_expired( 248 314 ISR_lock_Context *lock_context 249 315 ) 250 316 { 317 /** 318 * No matter the just finished job in time or not, 319 * it is in fact already missing its deadline. 320 */ 321 the_period->state = RATE_MONOTONIC_EXPIRED; 251 322 /* 252 323 * Update statistics from the concluding period 253 324 */ … … static rtems_status_code _Rate_monotonic_Block_while_expired( 256 327 the_period->state = RATE_MONOTONIC_ACTIVE; 257 328 the_period->next_length = length; 258 329 259 _Rate_monotonic_Release_ job( the_period, executing, length, lock_context );330 _Rate_monotonic_Release_postponedjob( the_period, executing, length, lock_context ); 260 331 return RTEMS_TIMEOUT; 261 332 } 262 333 … … rtems_status_code rtems_rate_monotonic_period( 292 363 } else { 293 364 switch ( state ) { 294 365 case RATE_MONOTONIC_ACTIVE: 295 status = _Rate_monotonic_Block_while_active( 296 the_period, 297 length, 298 executing, 299 &lock_context 300 ); 366 if(the_period->postponed_jobs > 0){ 367 status = _Rate_monotonic_Block_while_expired( 368 the_period, 369 length, 370 executing, 371 &lock_context 372 ); 373 }else{ 374 status = _Rate_monotonic_Block_while_active( 375 the_period, 376 length, 377 executing, 378 &lock_context 379 ); 380 } 301 381 break; 302 382 case RATE_MONOTONIC_INACTIVE: 303 383 status = _Rate_monotonic_Activate( … … rtems_status_code rtems_rate_monotonic_period( 308 388 ); 309 389 break; 310 390 default: 391 /** 392 * As now this period was already timeout, there must be at least one 393 * postponed job recorded by the watchdog. The one which exceeded 394 * the previous deadline"s" was just finished. 395 */ 311 396 _Assert( state == RATE_MONOTONIC_EXPIRED ); 312 397 status = _Rate_monotonic_Block_while_expired( 313 398 the_period, -
cpukit/rtems/src/ratemontimeout.c
diff --git a/cpukit/rtems/src/ratemontimeout.c b/cpukit/rtems/src/ratemontimeout.c index e514a31..61931ea 100644
a b 9 9 * COPYRIGHT (c) 1989-2009. 10 10 * On-Line Applications Research Corporation (OAR). 11 11 * 12 * Copyright (c) 2016, Kuan-Hsun Chen, TU Dortmund University (TUDo). 13 * 14 * 12 15 * The license and distribution terms for this file may be 13 16 * found in the file LICENSE in this distribution or at 14 17 * http://www.rtems.org/license/LICENSE. … … void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog ) 62 65 _Thread_Unblock( owner ); 63 66 } 64 67 } else { 68 /** 69 * If the watchdog is timeout, it means there is an additional postponed 70 * job in the next period but it is not available to release now: 71 * Either the current task is still executed, or it is preempted by 72 * other higher priority tasks. 73 */ 74 the_period->postponed_jobs += 1; 65 75 the_period->state = RATE_MONOTONIC_EXPIRED; 66 _Rate_monotonic_Re lease( the_period, &lock_context );76 _Rate_monotonic_Renew_deadline( the_period, owner, &lock_context ); 67 77 } 68 78 } -
testsuites/sptests/Makefile.am
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am index 20ea9d5..d432747 100644
a b _SUBDIRS = \ 36 36 _SUBDIRS += spmutex01 37 37 _SUBDIRS += spextensions01 38 38 _SUBDIRS += spsysinit01 39 _SUBDIRS += sprmsched01 39 40 if HAS_SMP 40 41 else 41 42 _SUBDIRS += sp29 -
testsuites/sptests/configure.ac
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac index c96edd3..bd7ae76 100644
a b spprintk/Makefile 230 230 spprivenv01/Makefile 231 231 spqreslib/Makefile 232 232 spratemon_err01/Makefile 233 sprmsched01/Makefile 233 234 sprbtree01/Makefile 234 235 spsem_err01/Makefile 235 236 spsem_err02/Makefile -
new file testsuites/sptests/sprmsched01/Makefile.am
diff --git a/testsuites/sptests/sprmsched01/Makefile.am b/testsuites/sptests/sprmsched01/Makefile.am new file mode 100644 index 0000000..f837b52
- + 1 2 rtems_tests_PROGRAMS = sprmsched01 3 sprmsched01_SOURCES = init.c tasks.c system.h 4 5 dist_rtems_tests_DATA = sprmsched01.scn 6 dist_rtems_tests_DATA += sprmsched01.doc 7 8 include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg 9 include $(top_srcdir)/../automake/compile.am 10 include $(top_srcdir)/../automake/leaf.am 11 12 AM_CPPFLAGS += -I$(top_srcdir)/../support/include 13 14 LINK_OBJS = $(sprmsched01_OBJECTS) 15 LINK_LIBS = $(sprmsched01_LDLIBS) 16 17 sprmsched01$(EXEEXT): $(sprmsched01_OBJECTS) $(sprmsched01_DEPENDENCIES) 18 @rm -f sprmsched01$(EXEEXT) 19 $(make-exe) 20 21 include $(top_srcdir)/../automake/local.am -
new file testsuites/sptests/sprmsched01/exampletask.c
diff --git a/testsuites/sptests/sprmsched01/exampletask.c b/testsuites/sptests/sprmsched01/exampletask.c new file mode 100644 index 0000000..84a93ed
- + 1 /** 2 * @file sprmsched01/tasks.c 3 * 4 * @brief A heuristic example to demonstrate how the postponed jobs are handled. 5 * 6 * Given two tasks with implicit deadline. To force deadline misses, we reverse 7 * the rate-monotonic priority assignment and only execute the highest priority 8 * task twice. In the original implementation, no matter how many periods are 9 * expired, RMS manager only releases a job with a shifted deadline assignment 10 * in the watchdog. 11 * 12 * In more general real-time task model, e.g., soft real-time task, the postponed 13 * jobs are still required to be released when the task is available to execute. 14 */ 15 16 /* 17 * COPYRIGHT (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 18 * 19 * The license and distribution terms for this file may be 20 * found in the file LICENSE in this distribution or at 21 * http://www.rtems.com/license/LICENSE. 22 */ 23 24 #ifdef HAVE_CONFIG_H 25 #include "config.h" 26 #endif 27 28 #include "system.h" 29 30 /* CPU usage and Rate monotonic manger statistics */ 31 #include "rtems/cpuuse.h" 32 33 /* Periods for the various tasks [ticks] */ 34 #define PERIOD_TASK_1 10000 35 #define PERIOD_TASK_2 2000 36 37 /* Task Id */ 38 #define ID_TASK_1 0 39 #define ID_TASK_2 1 40 41 /* Execution time for each task [ticks] */ 42 #define task_1_normal_et 6000 43 #define task_2_normal_et 1000 44 45 /** 46 * @brief Task 1 body 47 */ 48 rtems_task Task_1( 49 rtems_task_argument unused 50 ) 51 { 52 rtems_status_code status; 53 rtems_name period_name; 54 rtems_id RM_period; 55 rtems_id selfid=rtems_task_self(); 56 int start, end; 57 int tsk_counter = 0; 58 59 /*create period*/ 60 period_name = rtems_build_name( 'P', 'E', 'R', '1' ); 61 status = rtems_rate_monotonic_create( period_name, &RM_period ); 62 if( RTEMS_SUCCESSFUL != status ) { 63 printf("RM failed with status: %d\n", status); 64 rtems_test_exit(0); 65 } 66 67 while( 1 ) { 68 status = rtems_rate_monotonic_period( RM_period,PERIOD_TASK_1); 69 /*......................*/ 70 start = rtems_clock_get_ticks_since_boot(); 71 printf("Task 1 starts at tick %d.\n", start); 72 LOOP(task_1_normal_et,task_id); 73 end = rtems_clock_get_ticks_since_boot(); 74 printf(" Task 1 ends at tick %d.\n", end); 75 tsk_counter += 1; 76 } 77 } 78 79 /** 80 * @brief Task 2 body 81 */ 82 rtems_task Task_2( 83 rtems_task_argument unused 84 ) 85 { 86 rtems_status_code status; 87 rtems_name period_name; 88 rtems_id RM_period; 89 int start, end; 90 int tsk_counter = 0; 91 92 /*create period*/ 93 94 period_name = rtems_build_name( 'P', 'E', 'R', '2' ); 95 status = rtems_rate_monotonic_create( period_name, &RM_period ); 96 if( RTEMS_SUCCESSFUL != status ) { 97 printf("RM failed with status: %d\n", status); 98 exit( 0 ); 99 } 100 101 while( 1 ) { 102 status = rtems_rate_monotonic_period( RM_period, PERIOD_TASK_2); 103 if(tsk_counter == testnumber){ 104 rtems_rate_monotonic_report_statistics(); 105 status = rtems_rate_monotonic_delete(RM_period); 106 if(status != RTEMS_SUCCESSFUL){ 107 printf("BUG: Cannot delete the period 2\n"); 108 rtems_test_exit(0); 109 } 110 /* The example is finished */ 111 TEST_END(); 112 rtems_test_exit(0); 113 } 114 start = rtems_clock_get_ticks_since_boot(); 115 printf("Task 2 starts at tick %d.\n", start); 116 LOOP(task_2_normal_et,task_id); 117 end = rtems_clock_get_ticks_since_boot(); 118 printf(" Job %d Task 2 ends at tick %d.\n", tsk_counter+1, end); 119 tsk_counter += 1; 120 } 121 } 122 -
new file testsuites/sptests/sprmsched01/init.c
diff --git a/testsuites/sptests/sprmsched01/init.c b/testsuites/sptests/sprmsched01/init.c new file mode 100644 index 0000000..ea85fc3
- + 1 /** 2 * @file sprmsched01/init.c 3 * 4 * @brief A init task body for sprmsched01 example. 5 * 6 */ 7 8 /* 9 * COPYRIGHT (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 10 * 11 * The license and distribution terms for this file may be 12 * found in the file LICENSE in this distribution or at 13 * http://www.rtems.com/license/LICENSE. 14 */ 15 16 #ifdef HAVE_CONFIG_H 17 #include "config.h" 18 #endif 19 20 #define CONFIGURE_INIT 21 #include "system.h" 22 23 #include <rtems/rtems/tasksimpl.h> 24 #include <rtems/test.h> 25 #include <rtems/status-checks.h> 26 27 const char rtems_test_name[] = "Rate Monotonic 01"; 28 29 /* Global variables */ 30 rtems_id Task_id[ 2 ]; /* array of task ids */ 31 rtems_name Task_name[ 2 ]; /* array of task names */ 32 uint32_t tick_per_second; /* time reference */ 33 int testnumber = 15; /* stop condition */ 34 35 rtems_task Init( 36 rtems_task_argument argument 37 ) 38 { 39 TEST_BEGIN(); 40 rtems_status_code status; 41 rtems_time_of_day time; 42 43 44 tick_per_second = rtems_clock_get_ticks_per_second(); 45 printf("\nTicks per second in your system: %" PRIu32 "\n", tick_per_second); 46 47 Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ); 48 Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' ); 49 50 /* Create two tasks */ 51 status = rtems_task_create( 52 Task_name[ 1 ], 2, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, 53 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ] 54 ); 55 if ( status != RTEMS_SUCCESSFUL) { 56 printf( "rtems_task_create 1 failed with status of %d.\n", status ); 57 rtems_test_exit(0); 58 } 59 60 status = rtems_task_create( 61 Task_name[ 2 ], 5, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, 62 RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ] 63 ); 64 if ( status != RTEMS_SUCCESSFUL) { 65 printf( "rtems_task_create 2 failed with status of %d.\n", status ); 66 rtems_test_exit(0); 67 } 68 69 /* After creating the periods for tasks, start to run them sequencially. */ 70 71 status = rtems_task_start( Task_id[ 1 ], Task_1, 1); 72 if ( status != RTEMS_SUCCESSFUL) { 73 printf( "rtems_task_start 1 failed with status of %d.\n", status ); 74 rtems_test_exit(0); 75 } 76 status = rtems_task_start( Task_id[ 2 ], Task_2, 1); 77 if ( status != RTEMS_SUCCESSFUL) { 78 printf( "rtems_task_start 2 failed with status of %d.\n", status ); 79 rtems_test_exit(0); 80 } 81 82 status = rtems_task_delete( RTEMS_SELF ); 83 } -
new file testsuites/sptests/sprmsched01/sprmsched01.doc
diff --git a/testsuites/sptests/sprmsched01/sprmsched01.doc b/testsuites/sptests/sprmsched01/sprmsched01.doc new file mode 100644 index 0000000..7153af8
- + 1 # 2 # COPYRIGHT (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 3 # 4 # The license and distribution terms for this file may be 5 # found in the file LICENSE in this distribution or at 6 # http://www.rtems.com/license/LICENSE. 7 # 8 9 This file describes the directives and concepts tested by this test set. 10 11 test set name: sprmsched01 12 13 directives: 14 15 - rtems_rate_monotonic_report_statistics() 16 - rtems_rate_monotonic_period() 17 - rtems_rate_monotonic_Postponed_num() 18 - _Rate_monotonic_Timeout() 19 - _Rate_monotonic_Renew_deadline() 20 - _Rate_monotonic_Release_postponedjob() 21 - _Rate_monotonic_Block_while_expired() 22 23 24 concepts: 25 26 - Verify that watchdog deadline is renewed on time without shift via 27 _Rate_monotonic_Renew_deadline(). 28 - Verify that postponed jobs are released with a correct number via 29 _Rate_monotonic_Release_postponedjob(). 30 - Verify that rtems_rate_monotonic_report_statistics() reports correct number 31 of deadline misses. 32 - Verify that rtems_rate_monotonic_period() and 33 _Rate_monotonic_Block_while_expired() are operational. -
new file testsuites/sptests/sprmsched01/sprmsched01.scn
diff --git a/testsuites/sptests/sprmsched01/sprmsched01.scn b/testsuites/sptests/sprmsched01/sprmsched01.scn new file mode 100644 index 0000000..4c840a7
- + 1 2 3 *** BEGIN OF TEST Rate Monotonic 01 *** 4 5 Ticks per second in your system: 1000 6 Task 1 starts at tick 13. 7 Task 1 ends at tick 6013. 8 Task 2 starts at tick 6014. 9 Job 1 Task 2 ends at tick 7014. 10 Task 2 starts at tick 8014. 11 Job 2 Task 2 ends at tick 9014. 12 Task 1 starts at tick 10013. 13 Task 1 ends at tick 16013. 14 Task 2 starts at tick 16014. 15 Job 3 Task 2 ends at tick 17014. 16 Task 2 starts at tick 17014. 17 Job 4 Task 2 ends at tick 18014. 18 Task 2 starts at tick 18014. 19 Job 5 Task 2 ends at tick 19014. 20 Task 2 starts at tick 19014. 21 Job 6 Task 2 ends at tick 20014. 22 Task 2 starts at tick 20014. 23 Job 7 Task 2 ends at tick 21014. 24 Task 2 starts at tick 21014. 25 Job 8 Task 2 ends at tick 22014. 26 Task 2 starts at tick 22014. 27 Job 9 Task 2 ends at tick 23014. 28 Task 2 starts at tick 24014. 29 Job 10 Task 2 ends at tick 25014. 30 Task 2 starts at tick 26014. 31 Job 11 Task 2 ends at tick 27014. 32 Task 2 starts at tick 28014. 33 Job 12 Task 2 ends at tick 29014. 34 Task 2 starts at tick 30014. 35 Job 13 Task 2 ends at tick 31014. 36 Task 2 starts at tick 32014. 37 Job 14 Task 2 ends at tick 33014. 38 Task 2 starts at tick 34014. 39 Job 15 Task 2 ends at tick 35014. 40 Period information by period 41 --- CPU times are in seconds --- 42 --- Wall times are in seconds --- 43 ID OWNER COUNT MISSED CPU TIME WALL TIME 44 MIN/MAX/AVG MIN/MAX/AVG 45 0x42010002 TA2 15 5 0.999841/6.999920/2.399988 0.999848/13.000245/5.200154 46 *** END OF TEST Rate Monotonic 01 *** -
new file testsuites/sptests/sprmsched01/system.h
diff --git a/testsuites/sptests/sprmsched01/system.h b/testsuites/sptests/sprmsched01/system.h new file mode 100644 index 0000000..12fc62f
- + 1 /** 2 * @file sprmsched01/system.h 3 * 4 * @brief sprmsched01 example header 5 */ 6 7 /* 8 * COPYRIGHT (c) 1989-2007. 9 * On-Line Applications Research Corporation (OAR). 10 * 11 * COPYRIGHT (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 12 * 13 * The license and distribution terms for this file may be 14 * found in the file LICENSE in this distribution or at 15 * http://www.rtems.com/license/LICENSE. 16 */ 17 18 19 #include <inttypes.h> 20 #include <rtems.h> 21 22 #include <tmacros.h> 23 24 /* function prototypes */ 25 26 rtems_task Init( 27 rtems_task_argument argument 28 ); 29 30 rtems_task Task_1( 31 rtems_task_argument argument 32 ); 33 34 rtems_task Task_2( 35 rtems_task_argument argument 36 ); 37 38 /* 39 * Keep the names and IDs in global variables so another task can use them. 40 */ 41 42 extern rtems_id Task_id[ 2 ]; /* array of task ids */ 43 extern rtems_name Task_name[ 2 ]; /* array of task names */ 44 extern uint32_t tick_per_second; /* time reference */ 45 extern int testnumber; /* stop condition */ 46 47 /* configuration information */ 48 49 #include <bsp.h> /* for device driver prototypes */ 50 51 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER 52 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER 53 #define CONFIGURE_MICROSECONDS_PER_TICK 1000 // NB: 10 and lower gives system failure for erc32 simulator 54 #define CONFIGURE_MAXIMUM_TASKS 3 55 #define CONFIGURE_MAXIMUM_SEMAPHORES 1 56 #define CONFIGURE_MAXIMUM_PRIORITY 15 57 #define CONFIGURE_EXTRA_TASK_STACKS (20 * RTEMS_MINIMUM_STACK_SIZE) 58 #define CONFIGURE_MAXIMUM_PERIODS 3 59 60 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE 61 62 #include <rtems/confdefs.h> 63 64 /* 65 * Macro to loop/simulate the execution time. 66 */ 67 68 69 #define LOOP(_et, taskID){ \ 70 \ 71 int start = 0; \ 72 int now = 0; \ 73 start = rtems_clock_get_ticks_since_boot();\ 74 while(1){\ 75 \ 76 now = rtems_clock_get_ticks_since_boot();\ 77 if(now-start >= _et){\ 78 break;\ 79 }\ 80 }\ 81 } 82 /* end of include file */ -
new file testsuites/sptests/sprmsched01/tasks.c
diff --git a/testsuites/sptests/sprmsched01/tasks.c b/testsuites/sptests/sprmsched01/tasks.c new file mode 100644 index 0000000..5eeb338
- + 1 /** 2 * @file sprmsched01/tasks.c 3 * 4 * @brief A heuristic example to demonstrate how the postponed jobs are handled. 5 * 6 * Given two tasks with implicit deadline. To force deadline misses, we reverse 7 * the rate-monotonic priority assignment and only execute the highest priority 8 * task twice. In the original implementation, no matter how many periods are 9 * expired, RMS manager only releases a job with a shifted deadline assignment 10 * in the watchdog. 11 * 12 * In more general real-time task model, e.g., soft real-time task, the postponed 13 * jobs are still required to be released when the task is available to execute. 14 */ 15 16 /* 17 * COPYRIGHT (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo). 18 * 19 * The license and distribution terms for this file may be 20 * found in the file LICENSE in this distribution or at 21 * http://www.rtems.com/license/LICENSE. 22 */ 23 24 #ifdef HAVE_CONFIG_H 25 #include "config.h" 26 #endif 27 28 #include "system.h" 29 30 /* CPU usage and Rate monotonic manger statistics */ 31 #include "rtems/cpuuse.h" 32 33 /* Periods for the various tasks [ticks] */ 34 #define PERIOD_TASK_1 10000 35 #define PERIOD_TASK_2 2000 36 37 /* Task Id */ 38 #define ID_TASK_1 0 39 #define ID_TASK_2 1 40 41 /* Execution time for each task [ticks] */ 42 #define task_1_normal_et 6000 43 #define task_2_normal_et 1000 44 45 /** 46 * @brief Task 1 body 47 */ 48 rtems_task Task_1( 49 rtems_task_argument unused 50 ) 51 { 52 rtems_status_code status; 53 rtems_name period_name; 54 rtems_id RM_period; 55 rtems_id selfid=rtems_task_self(); 56 int start, end; 57 int tsk_counter = 0; 58 59 /*create period*/ 60 period_name = rtems_build_name( 'P', 'E', 'R', '1' ); 61 status = rtems_rate_monotonic_create( period_name, &RM_period ); 62 if( RTEMS_SUCCESSFUL != status ) { 63 printf("RM failed with status: %d\n", status); 64 rtems_test_exit(0); 65 } 66 while( 1 ) { 67 if(tsk_counter == 2){ 68 status = rtems_rate_monotonic_delete(RM_period); 69 if(status != RTEMS_SUCCESSFUL){ 70 printf("BUG: Cannot delete the period 1\n"); 71 rtems_test_exit(0); 72 } 73 status=rtems_task_delete(selfid); 74 if(status != RTEMS_SUCCESSFUL){ 75 printf("BUG: Cannot delete the task 1\n"); 76 rtems_test_exit(0); 77 } 78 } 79 status = rtems_rate_monotonic_period( RM_period,PERIOD_TASK_1); 80 start = rtems_clock_get_ticks_since_boot(); 81 printf("Task 1 starts at tick %d.\n", start); 82 LOOP(task_1_normal_et,task_id); 83 end = rtems_clock_get_ticks_since_boot(); 84 printf(" Task 1 ends at tick %d.\n", end); 85 tsk_counter += 1; 86 } 87 } 88 89 /** 90 * @brief Task 2 body 91 */ 92 rtems_task Task_2( 93 rtems_task_argument unused 94 ) 95 { 96 rtems_status_code status; 97 rtems_name period_name; 98 rtems_id RM_period; 99 int start, end; 100 int tsk_counter = 0; 101 102 /*create period*/ 103 104 period_name = rtems_build_name( 'P', 'E', 'R', '2' ); 105 status = rtems_rate_monotonic_create( period_name, &RM_period ); 106 if( RTEMS_SUCCESSFUL != status ) { 107 printf("RM failed with status: %d\n", status); 108 exit( 0 ); 109 } 110 111 while( 1 ) { 112 status = rtems_rate_monotonic_period( RM_period, PERIOD_TASK_2); 113 if(tsk_counter == testnumber){ 114 rtems_rate_monotonic_report_statistics(); 115 status = rtems_rate_monotonic_delete(RM_period); 116 if(status != RTEMS_SUCCESSFUL){ 117 printf("BUG: Cannot delete the period 2\n"); 118 rtems_test_exit(0); 119 } 120 /* The example is finished */ 121 TEST_END(); 122 rtems_test_exit(0); 123 } 124 start = rtems_clock_get_ticks_since_boot(); 125 printf("Task 2 starts at tick %d.\n", start); 126 LOOP(task_2_normal_et,task_id); 127 end = rtems_clock_get_ticks_since_boot(); 128 printf(" Job %d Task 2 ends at tick %d.\n", tsk_counter+1, end); 129 tsk_counter += 1; 130 } 131 } 132