Changeset 917884c in rtems
- Timestamp:
- 06/15/16 08:39:09 (7 years ago)
- Branches:
- 5, master
- Children:
- 661e0e63
- Parents:
- d6467102
- git-author:
- Sebastian Huber <sebastian.huber@…> (06/15/16 08:39:09)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (06/15/16 08:43:34)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/posix/include/rtems/posix/pthreadimpl.h
rd6467102 r917884c 55 55 56 56 RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert( 57 Thread_Control *the_thread, 57 58 POSIX_API_Control *api 58 59 ) 59 60 { 61 the_thread->cpu_time_budget = 62 _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_init_budget ); 63 60 64 _Watchdog_Per_CPU_insert_relative( 61 65 &api->Sporadic_timer, -
cpukit/posix/src/pthread.c
rd6467102 r917884c 114 114 _Thread_State_acquire( the_thread, &lock_context ); 115 115 116 the_thread->cpu_time_budget =117 _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );118 119 116 _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer ); 120 _POSIX_Threads_Sporadic_timer_insert( api );117 _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); 121 118 122 119 new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority ); -
cpukit/posix/src/pthreadcreate.c
rd6467102 r917884c 230 230 api->schedparam = schedparam; 231 231 232 if ( schedpolicy == SCHED_SPORADIC ) { 233 _ISR_lock_ISR_disable( &lock_context ); 234 _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); 235 _ISR_lock_ISR_enable( &lock_context ); 236 } 237 232 238 /* 233 239 * POSIX threads are allocated and started in one operation. … … 250 256 #endif 251 257 252 if ( schedpolicy == SCHED_SPORADIC ) {253 _ISR_lock_ISR_disable( &lock_context );254 _POSIX_Threads_Sporadic_timer_insert( api );255 _ISR_lock_ISR_enable( &lock_context );256 }257 258 258 /* 259 259 * Return the id and indicate we successfully created the thread -
testsuites/psxtests/psx12/init.c
rd6467102 r917884c 12 12 #endif 13 13 14 #include <sys/time.h> 15 #include <errno.h> 16 #include <inttypes.h> 14 17 #include <sched.h> 15 #include <errno.h> 18 #include <stdint.h> 19 #include <unistd.h> 16 20 17 21 #include <pmacros.h> … … 19 23 const char rtems_test_name[] = "PSX 12"; 20 24 25 #define SS_REPL_PERIOD_US 200000 26 27 #define SS_INIT_BUDGET_US 100000 28 29 #define SS_PRIO_LOW 1 30 31 #define SS_PRIO_HIGH 2 32 33 #define SS_SAMPLE_PERIODS 3 34 35 typedef struct { 36 uint64_t start; 37 struct { 38 uint64_t high; 39 uint64_t low; 40 } samples[ SS_SAMPLE_PERIODS ]; 41 } test_context; 42 43 static test_context test_instance; 44 45 static void wait_for_prio( int prio ) 46 { 47 int status; 48 int policy; 49 struct sched_param param; 50 51 do { 52 status = pthread_getschedparam( pthread_self(), &policy, ¶m ); 53 rtems_test_assert( status == 0 ); 54 } while ( prio != param.sched_priority ); 55 } 56 57 static uint64_t timeval_to_us( const struct timeval *tv ) 58 { 59 uint64_t t; 60 61 t = tv->tv_sec; 62 t *= 1000000; 63 t += tv->tv_usec; 64 65 return t; 66 } 67 68 static uint64_t now( void ) 69 { 70 struct timeval now; 71 72 gettimeofday( &now, NULL ); 73 74 return timeval_to_us( &now ); 75 } 76 77 static uint64_t delta( test_context *ctx ) 78 { 79 return now() - ctx->start; 80 } 81 21 82 static void *sporadic_server( void *argument ) 22 83 { 84 test_context *ctx; 85 size_t i; 86 87 ctx = argument; 88 89 for ( i = 0 ; i < SS_SAMPLE_PERIODS ; ++i ) { 90 wait_for_prio( SS_PRIO_LOW ); 91 ctx->samples[ i ].high = delta( ctx ); 92 wait_for_prio( SS_PRIO_HIGH ); 93 ctx->samples[ i ].low = delta( ctx ); 94 } 95 23 96 puts( "Sporadic Server: exitting" ); 24 97 … … 28 101 static void *POSIX_Init( void *argument ) 29 102 { 103 test_context *ctx; 30 104 int status; 31 105 pthread_attr_t attr; 32 106 pthread_t thread; 33 107 struct sched_param schedparam; 108 size_t i; 34 109 35 110 TEST_BEGIN(); 111 112 ctx = &test_instance; 36 113 37 114 /* set the time of day, and print our buffer in multiple ways */ … … 87 164 /* invalid sched_ss_low_priority error */ 88 165 89 schedparam.sched_ss_repl_period.tv_sec = 2;90 schedparam.sched_ss_repl_period.tv_nsec = 0;91 schedparam.sched_ss_init_budget.tv_sec = 1;92 schedparam.sched_ss_init_budget.tv_nsec = 0;93 94 schedparam.sched_priority = 200;166 schedparam.sched_ss_repl_period.tv_sec = 0; 167 schedparam.sched_ss_repl_period.tv_nsec = SS_REPL_PERIOD_US * 1000; 168 schedparam.sched_ss_init_budget.tv_sec = 0; 169 schedparam.sched_ss_init_budget.tv_nsec = SS_INIT_BUDGET_US * 1000; 170 171 schedparam.sched_priority = SS_PRIO_HIGH; 95 172 schedparam.sched_ss_low_priority = -1; 96 173 … … 104 181 /* create a thread as a sporadic server */ 105 182 106 schedparam.sched_ss_repl_period.tv_sec = 2;107 schedparam.sched_ss_repl_period.tv_nsec = 0;108 schedparam.sched_ss_init_budget.tv_sec = 1;109 schedparam.sched_ss_init_budget.tv_nsec = 0;110 111 schedparam.sched_priority = sched_get_priority_max( SCHED_FIFO );112 schedparam.sched_ss_low_priority = sched_get_priority_max( SCHED_FIFO ) - 6;183 schedparam.sched_ss_repl_period.tv_sec = 0; 184 schedparam.sched_ss_repl_period.tv_nsec = SS_REPL_PERIOD_US * 1000; 185 schedparam.sched_ss_init_budget.tv_sec = 0; 186 schedparam.sched_ss_init_budget.tv_nsec = SS_INIT_BUDGET_US * 1000; 187 188 schedparam.sched_priority = SS_PRIO_HIGH; 189 schedparam.sched_ss_low_priority = SS_PRIO_LOW; 113 190 114 191 status = pthread_attr_setschedparam( &attr, &schedparam ); … … 116 193 117 194 puts( "Init: pthread_create - SUCCESSFUL" ); 118 status = pthread_create( &thread, &attr, sporadic_server, NULL ); 195 196 /* Align with clock tick */ 197 usleep( 1 ); 198 199 ctx->start = now(); 200 201 status = pthread_create( &thread, &attr, sporadic_server, ctx ); 119 202 rtems_test_assert( !status ); 120 203 … … 122 205 rtems_test_assert( !status ); 123 206 124 /* switch to Task_1 */ 207 for ( i = 0 ; i < SS_SAMPLE_PERIODS ; ++i ) { 208 printf( "[%zu] H %6" PRIu64 "us\n", i, ctx->samples[ i ].high ); 209 printf( "[%zu] L %6" PRIu64 "us\n", i, ctx->samples[ i ].low ); 210 rtems_test_assert( ctx->samples[ i ].low / SS_REPL_PERIOD_US == i + 1 ); 211 } 125 212 126 213 TEST_END(); -
testsuites/psxtests/psx12/psx12.scn
rd6467102 r917884c 9 9 Init: pthread_create - SUCCESSFUL 10 10 Sporadic Server: exitting 11 [0] H 99902us 12 [0] L 200008us 13 [1] H 289908us 14 [1] L 400009us 15 [2] H 489903us 16 [2] L 600009us 11 17 *** END OF TEST PSX 12 ***
Note: See TracChangeset
for help on using the changeset viewer.