[e655f7e] | 1 | /** |
---|
| 2 | * @file |
---|
[ac7d5ef0] | 3 | * |
---|
[e655f7e] | 4 | * @brief Distributed MP Support |
---|
[4c20da4b] | 5 | * @ingroup RTEMSScoreThreadMP |
---|
[e655f7e] | 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[6a07436] | 9 | * COPYRIGHT (c) 1989-2006. |
---|
[ac7d5ef0] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
[98e4ebf5] | 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 15 | */ |
---|
| 16 | |
---|
[a8eed23] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[5618c37a] | 21 | #include <rtems/score/threadimpl.h> |
---|
[84dc9df] | 22 | #include <rtems/score/isrlock.h> |
---|
[15b5678d] | 23 | #include <rtems/score/schedulerimpl.h> |
---|
[ac7d5ef0] | 24 | |
---|
[16832b0] | 25 | #include <string.h> |
---|
| 26 | |
---|
[84dc9df] | 27 | static RBTREE_DEFINE_EMPTY( _Thread_MP_Active_proxies ); |
---|
[358bd740] | 28 | |
---|
[84dc9df] | 29 | static CHAIN_DEFINE_EMPTY( _Thread_MP_Inactive_proxies ); |
---|
| 30 | |
---|
| 31 | ISR_LOCK_DEFINE( static, _Thread_MP_Proxies_lock, "Thread MP Proxies" ) |
---|
| 32 | |
---|
| 33 | static void _Thread_MP_Proxies_acquire( ISR_lock_Context *lock_context ) |
---|
| 34 | { |
---|
| 35 | _ISR_lock_ISR_disable_and_acquire( &_Thread_MP_Proxies_lock, lock_context ); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | static void _Thread_MP_Proxies_release( ISR_lock_Context *lock_context ) |
---|
| 39 | { |
---|
| 40 | _ISR_lock_Release_and_ISR_enable( &_Thread_MP_Proxies_lock, lock_context ); |
---|
| 41 | } |
---|
[358bd740] | 42 | |
---|
[ac7d5ef0] | 43 | void _Thread_MP_Handler_initialization ( |
---|
[3127180] | 44 | uint32_t maximum_proxies |
---|
[ac7d5ef0] | 45 | ) |
---|
| 46 | { |
---|
[16832b0] | 47 | size_t proxy_size; |
---|
| 48 | char *proxies; |
---|
| 49 | uint32_t i; |
---|
[ac7d5ef0] | 50 | |
---|
| 51 | if ( maximum_proxies == 0 ) { |
---|
| 52 | return; |
---|
| 53 | } |
---|
| 54 | |
---|
[21275b58] | 55 | proxy_size = sizeof( Thread_Proxy_control ) + _Thread_queue_Heads_size; |
---|
[1d9f509e] | 56 | proxies = (char *) _Thread_MP_Proxies; |
---|
[ac7d5ef0] | 57 | |
---|
| 58 | _Chain_Initialize( |
---|
| 59 | &_Thread_MP_Inactive_proxies, |
---|
[16832b0] | 60 | proxies, |
---|
[ac7d5ef0] | 61 | maximum_proxies, |
---|
[16832b0] | 62 | proxy_size |
---|
[ac7d5ef0] | 63 | ); |
---|
| 64 | |
---|
[16832b0] | 65 | for ( i = 0 ; i < maximum_proxies ; ++i ) { |
---|
| 66 | Thread_Proxy_control *proxy; |
---|
| 67 | |
---|
| 68 | proxy = (Thread_Proxy_control *) ( proxies + i * proxy_size ); |
---|
| 69 | |
---|
| 70 | _Thread_Timer_initialize( &proxy->Timer, _Per_CPU_Get_by_index( 0 ) ); |
---|
[aaaf9610] | 71 | _RBTree_Initialize_node( &proxy->Active ); |
---|
[16832b0] | 72 | |
---|
[5d6b211] | 73 | proxy->Scheduler.nodes = &proxy->Scheduler_node; |
---|
[15b5678d] | 74 | _Scheduler_Node_do_initialize( |
---|
[947814ca] | 75 | &_Scheduler_Table[ 0 ], |
---|
[15b5678d] | 76 | &proxy->Scheduler_node, |
---|
| 77 | (Thread_Control *) proxy, |
---|
| 78 | 0 |
---|
| 79 | ); |
---|
| 80 | |
---|
[16832b0] | 81 | proxy->Wait.spare_heads = &proxy->Thread_queue_heads[ 0 ]; |
---|
| 82 | _Thread_queue_Heads_initialize( proxy->Wait.spare_heads ); |
---|
| 83 | } |
---|
[ac7d5ef0] | 84 | } |
---|
| 85 | |
---|
[84dc9df] | 86 | #define THREAD_MP_PROXY_OF_ACTIVE_NODE( the_node ) \ |
---|
| 87 | RTEMS_CONTAINER_OF( the_node, Thread_Proxy_control, Active ) |
---|
| 88 | |
---|
| 89 | static bool _Thread_MP_Proxy_equal( |
---|
| 90 | const void *left, |
---|
| 91 | const RBTree_Node *right |
---|
| 92 | ) |
---|
| 93 | { |
---|
| 94 | const Objects_Id *the_left; |
---|
| 95 | const Thread_Proxy_control *the_right; |
---|
| 96 | |
---|
| 97 | the_left = left; |
---|
| 98 | the_right = THREAD_MP_PROXY_OF_ACTIVE_NODE( right ); |
---|
| 99 | |
---|
| 100 | return *the_left == the_right->Object.id; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | static bool _Thread_MP_Proxy_less( |
---|
| 104 | const void *left, |
---|
| 105 | const RBTree_Node *right |
---|
| 106 | ) |
---|
| 107 | { |
---|
| 108 | const Objects_Id *the_left; |
---|
| 109 | const Thread_Proxy_control *the_right; |
---|
| 110 | |
---|
| 111 | the_left = left; |
---|
| 112 | the_right = THREAD_MP_PROXY_OF_ACTIVE_NODE( right ); |
---|
| 113 | |
---|
| 114 | return *the_left < the_right->Object.id; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | static void *_Thread_MP_Proxy_map( RBTree_Node *node ) |
---|
| 118 | { |
---|
| 119 | return THREAD_MP_PROXY_OF_ACTIVE_NODE( node ); |
---|
| 120 | } |
---|
| 121 | |
---|
[ac7d5ef0] | 122 | Thread_Control *_Thread_MP_Allocate_proxy ( |
---|
| 123 | States_Control the_state |
---|
| 124 | ) |
---|
| 125 | { |
---|
| 126 | Thread_Proxy_control *the_proxy; |
---|
[84dc9df] | 127 | ISR_lock_Context lock_context; |
---|
[ac7d5ef0] | 128 | |
---|
[84dc9df] | 129 | _Thread_MP_Proxies_acquire( &lock_context ); |
---|
[ac7d5ef0] | 130 | |
---|
[84dc9df] | 131 | the_proxy = (Thread_Proxy_control *) |
---|
| 132 | _Chain_Get_unprotected( &_Thread_MP_Inactive_proxies ); |
---|
| 133 | if ( the_proxy != NULL ) { |
---|
| 134 | Thread_Control *executing; |
---|
| 135 | MP_packet_Prefix *receive_packet; |
---|
| 136 | Objects_Id source_tid; |
---|
[ac7d5ef0] | 137 | |
---|
[16832b0] | 138 | executing = _Thread_Executing; |
---|
[84dc9df] | 139 | receive_packet = _MPCI_Receive_server_tcb->receive_packet; |
---|
| 140 | source_tid = receive_packet->source_tid; |
---|
[ac7d5ef0] | 141 | |
---|
[f74e806d] | 142 | executing->Wait.return_code = STATUS_PROXY_BLOCKING; |
---|
[ac7d5ef0] | 143 | |
---|
[84dc9df] | 144 | the_proxy->receive_packet = receive_packet; |
---|
| 145 | the_proxy->Object.id = source_tid; |
---|
[300f6a48] | 146 | the_proxy->Real_priority.priority = receive_packet->source_priority; |
---|
[ac7d5ef0] | 147 | the_proxy->current_state = _States_Set( STATES_DORMANT, the_state ); |
---|
| 148 | |
---|
[16832b0] | 149 | the_proxy->Wait.count = executing->Wait.count; |
---|
| 150 | the_proxy->Wait.return_argument = executing->Wait.return_argument; |
---|
| 151 | the_proxy->Wait.return_argument_second = executing->Wait.return_argument_second; |
---|
| 152 | the_proxy->Wait.option = executing->Wait.option; |
---|
| 153 | the_proxy->Wait.return_code = executing->Wait.return_code; |
---|
[ac7d5ef0] | 154 | |
---|
[8f96581] | 155 | the_proxy->thread_queue_callout = _Thread_queue_MP_callout_do_nothing; |
---|
| 156 | |
---|
[84dc9df] | 157 | _RBTree_Insert_inline( |
---|
| 158 | &_Thread_MP_Active_proxies, |
---|
| 159 | &the_proxy->Active, |
---|
| 160 | &source_tid, |
---|
| 161 | _Thread_MP_Proxy_less |
---|
| 162 | ); |
---|
| 163 | |
---|
| 164 | _Thread_MP_Proxies_release( &lock_context ); |
---|
[ac7d5ef0] | 165 | |
---|
[84dc9df] | 166 | return (Thread_Control *) the_proxy; |
---|
[ac7d5ef0] | 167 | } |
---|
| 168 | |
---|
[84dc9df] | 169 | _Thread_MP_Proxies_release( &lock_context ); |
---|
| 170 | |
---|
[3a659b04] | 171 | _Internal_error( INTERNAL_ERROR_OUT_OF_PROXIES ); |
---|
[ac7d5ef0] | 172 | |
---|
| 173 | /* |
---|
[6a07436] | 174 | * NOTE: The following return ensures that the compiler will |
---|
[ac7d5ef0] | 175 | * think that all paths return a value. |
---|
| 176 | */ |
---|
| 177 | |
---|
| 178 | return NULL; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | Thread_Control *_Thread_MP_Find_proxy ( |
---|
| 182 | Objects_Id the_id |
---|
| 183 | ) |
---|
| 184 | { |
---|
[84dc9df] | 185 | Thread_Proxy_control *the_proxy; |
---|
| 186 | ISR_lock_Context lock_context; |
---|
[ac7d5ef0] | 187 | |
---|
[84dc9df] | 188 | _Thread_MP_Proxies_acquire( &lock_context ); |
---|
[ac7d5ef0] | 189 | |
---|
[84dc9df] | 190 | the_proxy = _RBTree_Find_inline( |
---|
| 191 | &_Thread_MP_Active_proxies, |
---|
| 192 | &the_id, |
---|
| 193 | _Thread_MP_Proxy_equal, |
---|
| 194 | _Thread_MP_Proxy_less, |
---|
| 195 | _Thread_MP_Proxy_map |
---|
| 196 | ); |
---|
[ac7d5ef0] | 197 | |
---|
[84dc9df] | 198 | _Thread_MP_Proxies_release( &lock_context ); |
---|
[ac7d5ef0] | 199 | |
---|
[84dc9df] | 200 | return (Thread_Control *) the_proxy; |
---|
| 201 | } |
---|
[ac7d5ef0] | 202 | |
---|
[84dc9df] | 203 | void _Thread_MP_Free_proxy( Thread_Control *the_thread ) |
---|
| 204 | { |
---|
| 205 | Thread_Proxy_control *the_proxy; |
---|
| 206 | ISR_lock_Context lock_context; |
---|
[ac7d5ef0] | 207 | |
---|
[84dc9df] | 208 | the_proxy = (Thread_Proxy_control *) the_thread; |
---|
[ac7d5ef0] | 209 | |
---|
[84dc9df] | 210 | _Thread_MP_Proxies_acquire( &lock_context ); |
---|
[ac7d5ef0] | 211 | |
---|
[84dc9df] | 212 | _RBTree_Extract( &_Thread_MP_Active_proxies, &the_proxy->Active ); |
---|
| 213 | _Chain_Append_unprotected( |
---|
| 214 | &_Thread_MP_Inactive_proxies, |
---|
| 215 | &the_proxy->Object.Node |
---|
| 216 | ); |
---|
[ac7d5ef0] | 217 | |
---|
[84dc9df] | 218 | _Thread_MP_Proxies_release( &lock_context ); |
---|
[ac7d5ef0] | 219 | } |
---|