Changeset eec08ef in rtems
- Timestamp:
- 06/15/16 04:59:57 (7 years ago)
- Branches:
- 5, master
- Children:
- 5a32c48
- Parents:
- 6bab009
- git-author:
- Sebastian Huber <sebastian.huber@…> (06/15/16 04:59:57)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (06/22/16 12:00:28)
- Location:
- cpukit
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/posix/include/rtems/posix/pthreadimpl.h
r6bab009 reec08ef 63 63 64 64 _Watchdog_Per_CPU_insert_relative( 65 &api->Sporadic _timer,65 &api->Sporadic.Timer, 66 66 _Per_CPU_Get(), 67 67 _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_repl_period ) … … 80 80 Thread_Control *the_thread 81 81 ); 82 83 /**84 * This routine supports the sporadic scheduling algorithm. It85 * is scheduled to be executed at the end of each replenishment86 * period. In sporadic scheduling a thread will execute at a87 * high priority for a user specified amount of CPU time. When88 * it exceeds that amount of CPU time, its priority is automatically89 * lowered. This TSR is executed when it is time to replenish90 * the thread's processor budget and raise its priority.91 *92 * @param[in] id is ignored93 * @param[in] argument is a pointer to the Thread_Control structure94 * for the thread being replenished.95 */96 void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog );97 82 98 83 /** -
cpukit/posix/include/rtems/posix/threadsup.h
r6bab009 reec08ef 19 19 #define _RTEMS_POSIX_THREADSUP_H 20 20 21 #include <rtems/score/coresem.h>22 #include <rtems/score/isrlock.h>23 21 #include <rtems/score/thread.h> 24 #include <rtems/score/threadq.h>25 22 #include <rtems/score/watchdog.h> 26 23 … … 51 48 52 49 /** 53 * This is the timer which controls when the thread executes at 54 * high and low priority when using the sporadic scheduler. 50 * @brief Control block for the sporadic server scheduling policy. 55 51 */ 56 Watchdog_Control Sporadic_timer; 52 struct { 53 /** 54 * @brief This is the timer which controls when the thread executes at high 55 * and low priority when using the sporadic server scheduling policy. 56 */ 57 Watchdog_Control Timer; 58 59 /** 60 * @brief The low priority when using the sporadic server scheduling 61 * policy. 62 */ 63 Priority_Control low_priority; 64 65 /** 66 * @brief The high priority when using the sporadic server scheduling 67 * policy. 68 */ 69 Priority_Control high_priority; 70 } Sporadic; 57 71 58 72 /** This is the set of signals which are currently unblocked. */ -
cpukit/posix/src/psxtransschedparam.c
r6bab009 reec08ef 22 22 #include <errno.h> 23 23 24 #include <rtems/system.h>25 24 #include <rtems/posix/pthreadimpl.h> 26 #include <rtems/posix/priorityimpl.h>27 25 28 26 int _POSIX_Thread_Translate_sched_param( … … 33 31 ) 34 32 { 35 if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )36 return EINVAL;37 38 33 *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; 39 34 *budget_callout = NULL; … … 67 62 return EINVAL; 68 63 69 if ( !_POSIX_Priority_Is_valid( param->sched_ss_low_priority ) )70 return EINVAL;71 72 64 *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT; 73 65 *budget_callout = _POSIX_Threads_Sporadic_budget_callout; -
cpukit/posix/src/pthread.c
r6bab009 reec08ef 82 82 }; 83 83 84 static bool _POSIX_Threads_Sporadic_ budget_TSR_filter(84 static bool _POSIX_Threads_Sporadic_timer_filter( 85 85 Thread_Control *the_thread, 86 Priority_Control *new_priority ,86 Priority_Control *new_priority_p, 87 87 void *arg 88 88 ) 89 89 { 90 the_thread->real_priority = *new_priority; 91 92 /* 93 * If holding a resource, then do not change it. 94 * 95 * If this would make them less important, then do not change it. 96 */ 97 return !_Thread_Owns_resources( the_thread ) && 98 _Thread_Priority_less_than( the_thread->current_priority, *new_priority ); 99 } 100 101 /* 102 * _POSIX_Threads_Sporadic_budget_TSR 103 */ 104 void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog ) 105 { 106 POSIX_API_Control *api; 107 Thread_Control *the_thread; 108 ISR_lock_Context lock_context; 109 Priority_Control new_priority; 110 111 api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic_timer ); 90 POSIX_API_Control *api; 91 Priority_Control current_priority; 92 Priority_Control new_priority; 93 94 api = arg; 95 96 new_priority = api->Sporadic.high_priority; 97 *new_priority_p = new_priority; 98 99 current_priority = the_thread->current_priority; 100 the_thread->real_priority = new_priority; 101 102 _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer ); 103 _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); 104 105 return _Thread_Priority_less_than( current_priority, new_priority ) 106 || !_Thread_Owns_resources( the_thread ); 107 } 108 109 static void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog ) 110 { 111 POSIX_API_Control *api; 112 Thread_Control *the_thread; 113 114 api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic.Timer ); 112 115 the_thread = api->thread; 113 114 _Thread_State_acquire( the_thread, &lock_context );115 116 _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );117 _POSIX_Threads_Sporadic_timer_insert( the_thread, api );118 119 new_priority = _POSIX_Priority_To_core(120 api->Attributes.schedparam.sched_priority121 );122 123 _Thread_State_release( the_thread, &lock_context );124 116 125 117 _Thread_Change_priority( 126 118 the_thread, 127 new_priority,128 NULL,129 _POSIX_Threads_Sporadic_ budget_TSR_filter,119 0, 120 api, 121 _POSIX_Threads_Sporadic_timer_filter, 130 122 true 131 123 ); … … 134 126 static bool _POSIX_Threads_Sporadic_budget_callout_filter( 135 127 Thread_Control *the_thread, 136 Priority_Control *new_priority ,128 Priority_Control *new_priority_p, 137 129 void *arg 138 130 ) 139 131 { 140 the_thread->real_priority = *new_priority; 141 142 /* 143 * If holding a resource, then do not change it. 144 * 145 * Make sure we are actually lowering it. If they have lowered it 146 * to logically lower than sched_ss_low_priority, then we do not want to 147 * change it. 148 */ 149 return !_Thread_Owns_resources( the_thread ) && 150 _Thread_Priority_less_than( *new_priority, the_thread->current_priority ); 151 } 152 153 /* 154 * _POSIX_Threads_Sporadic_budget_callout 155 */ 156 void _POSIX_Threads_Sporadic_budget_callout( 157 Thread_Control *the_thread 158 ) 159 { 160 POSIX_API_Control *api; 132 POSIX_API_Control *api; 133 Priority_Control current_priority; 134 Priority_Control new_priority; 161 135 162 136 api = the_thread->API_Extensions[ THREAD_API_POSIX ]; … … 168 142 the_thread->cpu_time_budget = UINT32_MAX; 169 143 144 new_priority = api->Sporadic.low_priority; 145 *new_priority_p = new_priority; 146 147 current_priority = the_thread->current_priority; 148 the_thread->real_priority = new_priority; 149 150 return _Thread_Priority_less_than( current_priority, new_priority ) 151 || !_Thread_Owns_resources( the_thread ); 152 } 153 154 void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread ) 155 { 170 156 _Thread_Change_priority( 171 157 the_thread, 172 _POSIX_Priority_To_core( 173 api->Attributes.schedparam.sched_ss_low_priority 174 ), 158 0, 175 159 NULL, 176 160 _POSIX_Threads_Sporadic_budget_callout_filter, … … 218 202 } 219 203 220 _Watchdog_Preinitialize( &api->Sporadic_timer, _Per_CPU_Get_by_index( 0 ) ); 221 _Watchdog_Initialize( 222 &api->Sporadic_timer, 223 _POSIX_Threads_Sporadic_budget_TSR 224 ); 204 _Watchdog_Preinitialize( &api->Sporadic.Timer, _Per_CPU_Get_by_index( 0 ) ); 205 _Watchdog_Initialize( &api->Sporadic.Timer, _POSIX_Threads_Sporadic_timer ); 225 206 226 207 return true; … … 237 218 238 219 if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) { 239 _Watchdog_Per_CPU_remove_relative( &api->Sporadic _timer );220 _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer ); 240 221 } 241 222 -
cpukit/posix/src/pthreadcreate.c
r6bab009 reec08ef 61 61 }; 62 62 const pthread_attr_t *the_attr; 63 Priority_Control core_priority; 63 int low_prio; 64 int high_prio; 65 Priority_Control core_low_prio; 66 Priority_Control core_high_prio; 64 67 Thread_CPU_budget_algorithms budget_algorithm; 65 68 Thread_CPU_budget_algorithm_callout budget_callout; … … 72 75 struct sched_param schedparam; 73 76 Objects_Name name; 74 int rc;77 int error; 75 78 ISR_lock_Context lock_context; 76 79 … … 131 134 return ENOTSUP; 132 135 133 /* 134 * Interpret the scheduling parameters. 135 */ 136 if ( !_POSIX_Priority_Is_valid( schedparam.sched_priority ) ) 137 return EINVAL; 138 139 core_priority = _POSIX_Priority_To_core( schedparam.sched_priority ); 140 141 /* 142 * Set the core scheduling policy information. 143 */ 144 rc = _POSIX_Thread_Translate_sched_param( 136 error = _POSIX_Thread_Translate_sched_param( 145 137 schedpolicy, 146 138 &schedparam, … … 148 140 &budget_callout 149 141 ); 150 if ( rc ) 151 return rc; 142 if ( error != 0 ) { 143 return error; 144 } 145 146 if ( schedpolicy == SCHED_SPORADIC ) { 147 low_prio = schedparam.sched_ss_low_priority; 148 high_prio = schedparam.sched_priority; 149 } else { 150 low_prio = schedparam.sched_priority; 151 high_prio = low_prio; 152 } 153 154 if ( !_POSIX_Priority_Is_valid( low_prio ) ) { 155 return EINVAL; 156 } 157 158 if ( !_POSIX_Priority_Is_valid( high_prio ) ) { 159 return EINVAL; 160 } 161 162 core_low_prio = _POSIX_Priority_To_core( low_prio ); 163 core_high_prio = _POSIX_Priority_To_core( high_prio ); 152 164 153 165 #if defined(RTEMS_SMP) … … 187 199 _POSIX_Threads_Ensure_minimum_stack(the_attr->stacksize), 188 200 is_fp, 189 core_ priority,201 core_high_prio, 190 202 true, /* preemptible */ 191 203 budget_algorithm, … … 227 239 228 240 _POSIX_Threads_Copy_attributes( &api->Attributes, the_attr ); 241 api->Sporadic.low_priority = core_low_prio; 242 api->Sporadic.high_priority = core_high_prio; 229 243 230 244 if ( schedpolicy == SCHED_SPORADIC ) { -
cpukit/posix/src/pthreadgetschedparam.c
r6bab009 reec08ef 49 49 } 50 50 51 _Thread_State_acquire_critical( the_thread, &lock_context );51 api = the_thread->API_Extensions[ THREAD_API_POSIX ]; 52 52 53 api = the_thread->API_Extensions[ THREAD_API_POSIX ]; 53 _Thread_Lock_acquire_default_critical( the_thread, &lock_context ); 54 54 55 *policy = api->Attributes.schedpolicy; 55 56 *param = api->Attributes.schedparam; … … 58 59 ); 59 60 60 _Thread_ State_release( the_thread, &lock_context );61 _Thread_Lock_release_default( the_thread, &lock_context ); 61 62 return 0; 62 63 } -
cpukit/posix/src/pthreadsetschedparam.c
r6bab009 reec08ef 29 29 #include <rtems/posix/priorityimpl.h> 30 30 #include <rtems/score/threadimpl.h> 31 #include <rtems/score/watchdogimpl.h> 32 #include <rtems/config.h> 31 32 typedef struct { 33 int policy; 34 const struct sched_param *param; 35 Thread_CPU_budget_algorithms budget_algorithm; 36 Thread_CPU_budget_algorithm_callout budget_callout; 37 int error; 38 } POSIX_Set_sched_param_context; 39 40 static bool _POSIX_Set_sched_param_filter( 41 Thread_Control *the_thread, 42 Priority_Control *new_priority_p, 43 void *arg 44 ) 45 { 46 POSIX_Set_sched_param_context *context; 47 const struct sched_param *param; 48 POSIX_API_Control *api; 49 int low_prio; 50 int high_prio; 51 Priority_Control core_low_prio; 52 Priority_Control core_high_prio; 53 Priority_Control current_priority; 54 55 context = arg; 56 param = context->param; 57 58 if ( context->policy == SCHED_SPORADIC ) { 59 low_prio = param->sched_ss_low_priority; 60 high_prio = param->sched_priority; 61 } else { 62 low_prio = param->sched_priority; 63 high_prio = low_prio; 64 } 65 66 if ( !_POSIX_Priority_Is_valid( low_prio ) ) { 67 context->error = EINVAL; 68 return false; 69 } 70 71 if ( !_POSIX_Priority_Is_valid( high_prio ) ) { 72 context->error = EINVAL; 73 return false; 74 } 75 76 core_low_prio = _POSIX_Priority_To_core( low_prio ); 77 core_high_prio = _POSIX_Priority_To_core( high_prio ); 78 79 *new_priority_p = core_high_prio; 80 81 current_priority = the_thread->current_priority; 82 the_thread->real_priority = core_high_prio; 83 84 api = the_thread->API_Extensions[ THREAD_API_POSIX ]; 85 86 _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer ); 87 88 api->Attributes.schedpolicy = context->policy; 89 api->Attributes.schedparam = *param; 90 api->Sporadic.low_priority = core_low_prio; 91 api->Sporadic.high_priority = core_high_prio; 92 93 the_thread->budget_algorithm = context->budget_algorithm; 94 the_thread->budget_callout = context->budget_callout; 95 96 if ( context->policy == SCHED_SPORADIC ) { 97 _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); 98 } else { 99 the_thread->cpu_time_budget = 100 rtems_configuration_get_ticks_per_timeslice(); 101 } 102 103 context->error = 0; 104 return _Thread_Priority_less_than( current_priority, core_high_prio ) 105 || !_Thread_Owns_resources( the_thread ); 106 } 33 107 34 108 int pthread_setschedparam( … … 38 112 ) 39 113 { 40 Thread_Control *the_thread; 41 Per_CPU_Control *cpu_self; 42 POSIX_API_Control *api; 43 Thread_CPU_budget_algorithms budget_algorithm; 44 Thread_CPU_budget_algorithm_callout budget_callout; 45 int eno; 46 Priority_Control unused; 47 ISR_lock_Context lock_context; 48 Priority_Control new_priority; 49 50 /* 51 * Check all the parameters 52 */ 114 Thread_Control *the_thread; 115 Per_CPU_Control *cpu_self; 116 POSIX_Set_sched_param_context context; 117 ISR_lock_Context lock_context; 118 int error; 53 119 54 120 if ( param == NULL ) { … … 56 122 } 57 123 58 e no= _POSIX_Thread_Translate_sched_param(124 error = _POSIX_Thread_Translate_sched_param( 59 125 policy, 60 126 param, 61 & budget_algorithm,62 & budget_callout127 &context.budget_algorithm, 128 &context.budget_callout 63 129 ); 64 if ( e no!= 0 ) {65 return e no;130 if ( error != 0 ) { 131 return error; 66 132 } 133 134 context.policy = policy; 135 context.param = param; 67 136 68 137 the_thread = _Thread_Get( thread, &lock_context ); … … 72 141 } 73 142 74 /* 75 * Actually change the scheduling policy and parameters 76 */ 143 cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); 144 _ISR_lock_ISR_enable( &lock_context ); 77 145 78 cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); 79 _Thread_State_acquire_critical( the_thread, &lock_context ); 80 81 api = the_thread->API_Extensions[ THREAD_API_POSIX ]; 82 83 if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) { 84 _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer ); 85 } 86 87 api->Attributes.schedpolicy = policy; 88 api->Attributes.schedparam = *param; 89 90 the_thread->budget_algorithm = budget_algorithm; 91 the_thread->budget_callout = budget_callout; 92 93 switch ( policy ) { 94 case SCHED_OTHER: 95 case SCHED_FIFO: 96 case SCHED_RR: 97 the_thread->cpu_time_budget = 98 rtems_configuration_get_ticks_per_timeslice(); 99 new_priority = _POSIX_Priority_To_core( 100 api->Attributes.schedparam.sched_priority 101 ); 102 break; 103 } 104 105 _Thread_State_release( the_thread, &lock_context ); 106 107 switch ( policy ) { 108 case SCHED_OTHER: 109 case SCHED_FIFO: 110 case SCHED_RR: 111 _Thread_Set_priority( the_thread, new_priority, &unused, false ); 112 break; 113 114 case SCHED_SPORADIC: 115 _POSIX_Threads_Sporadic_budget_TSR( &api->Sporadic_timer ); 116 break; 117 } 146 _Thread_Change_priority( 147 the_thread, 148 0, 149 &context, 150 _POSIX_Set_sched_param_filter, 151 false 152 ); 118 153 119 154 _Thread_Dispatch_enable( cpu_self ); 120 return 0;155 return context.error; 121 156 } -
cpukit/posix/src/pthreadsetschedprio.c
r6bab009 reec08ef 18 18 #include <rtems/score/threadimpl.h> 19 19 20 int pthread_setschedprio( pthread_t thread, int prio ) 20 typedef struct { 21 int prio; 22 int error; 23 } POSIX_Set_sched_prio_context; 24 25 static bool _POSIX_Set_sched_prio_filter( 26 Thread_Control *the_thread, 27 Priority_Control *new_priority_p, 28 void *arg 29 ) 21 30 { 22 Thread_Control *the_thread; 23 Per_CPU_Control *cpu_self; 24 POSIX_API_Control *api; 25 Priority_Control unused; 26 ISR_lock_Context lock_context; 27 Priority_Control new_priority; 31 POSIX_Set_sched_prio_context *context; 32 int prio; 33 POSIX_API_Control *api; 34 Priority_Control current_priority; 35 Priority_Control new_priority; 36 37 context = arg; 38 prio = context->prio; 28 39 29 40 if ( !_POSIX_Priority_Is_valid( prio ) ) { 30 return EINVAL; 41 context->error = EINVAL; 42 return false; 31 43 } 32 44 33 45 new_priority = _POSIX_Priority_To_core( prio ); 46 *new_priority_p = new_priority; 47 48 current_priority = the_thread->current_priority; 49 the_thread->real_priority = new_priority; 50 51 api = the_thread->API_Extensions[ THREAD_API_POSIX ]; 52 53 api->Sporadic.high_priority = new_priority; 54 55 if ( api->Sporadic.low_priority < new_priority ) { 56 api->Sporadic.low_priority = new_priority; 57 } 58 59 context->error = 0; 60 return _Thread_Priority_less_than( current_priority, new_priority ) 61 || !_Thread_Owns_resources( the_thread ); 62 } 63 64 int pthread_setschedprio( pthread_t thread, int prio ) 65 { 66 Thread_Control *the_thread; 67 Per_CPU_Control *cpu_self; 68 POSIX_Set_sched_prio_context context; 69 ISR_lock_Context lock_context; 70 71 context.prio = prio; 34 72 35 73 the_thread = _Thread_Get( thread, &lock_context ); … … 39 77 } 40 78 41 api = the_thread->API_Extensions[ THREAD_API_POSIX ]; 79 cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); 80 _ISR_lock_ISR_enable( &lock_context ); 42 81 43 cpu_self = _Thread_Dispatch_disable_critical( &lock_context );44 45 _Thread_State_acquire_critical( the_thread, &lock_context );46 api->Attributes.schedparam.sched_priority = prio;47 _Thread_State_release( the_thread, &lock_context );48 49 _Thread_Set_priority( the_thread, new_priority, &unused, true);82 _Thread_Change_priority( 83 the_thread, 84 0, 85 &context, 86 _POSIX_Set_sched_prio_filter, 87 true 88 ); 50 89 51 90 _Thread_Dispatch_enable( cpu_self ); 52 return 0;91 return context.error; 53 92 } -
cpukit/score/include/rtems/score/thread.h
r6bab009 reec08ef 658 658 * 659 659 * The thread lock protects the following thread variables 660 * - POSIX_API_Control::Attributes, 660 661 * - Thread_Control::current_priority, 661 662 * - Thread_Control::Wait::queue, and … … 711 712 * the following fields 712 713 * 713 * - POSIX_API_Control::Attributes,714 714 * - RTEMS_API_Control::Signal, 715 715 * - Thread_Control::budget_algorithm,
Note: See TracChangeset
for help on using the changeset viewer.