source: rtems/cpukit/score/src/threadmp.c @ f74e806d

5
Last change on this file since f74e806d was f74e806d, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 2, 2020 at 10:30:33 AM

mpci: Fix blocking proxy status

Remove THREAD_STATUS_PROXY_BLOCKING and replace it with
STATUS_PROXY_BLOCKING.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Distributed MP Support
5 *  @ingroup RTEMSScoreThreadMP
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/threadimpl.h>
22#include <rtems/score/isrlock.h>
23#include <rtems/score/schedulerimpl.h>
24
25#include <string.h>
26
27static RBTREE_DEFINE_EMPTY( _Thread_MP_Active_proxies );
28
29static CHAIN_DEFINE_EMPTY( _Thread_MP_Inactive_proxies );
30
31ISR_LOCK_DEFINE( static, _Thread_MP_Proxies_lock, "Thread MP Proxies" )
32
33static 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
38static 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}
42
43void _Thread_MP_Handler_initialization (
44  uint32_t    maximum_proxies
45)
46{
47  size_t    proxy_size;
48  char     *proxies;
49  uint32_t  i;
50
51  if ( maximum_proxies == 0 ) {
52    return;
53  }
54
55  proxy_size = sizeof( Thread_Proxy_control ) + _Thread_queue_Heads_size;
56  proxies = (char *) _Thread_MP_Proxies;
57
58  _Chain_Initialize(
59    &_Thread_MP_Inactive_proxies,
60    proxies,
61    maximum_proxies,
62    proxy_size
63  );
64
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 ) );
71    _RBTree_Initialize_node( &proxy->Active );
72
73    proxy->Scheduler.nodes = &proxy->Scheduler_node;
74    _Scheduler_Node_do_initialize(
75      &_Scheduler_Table[ 0 ],
76      &proxy->Scheduler_node,
77      (Thread_Control *) proxy,
78      0
79    );
80
81    proxy->Wait.spare_heads = &proxy->Thread_queue_heads[ 0 ];
82    _Thread_queue_Heads_initialize( proxy->Wait.spare_heads );
83  }
84}
85
86#define THREAD_MP_PROXY_OF_ACTIVE_NODE( the_node ) \
87  RTEMS_CONTAINER_OF( the_node, Thread_Proxy_control, Active )
88
89static 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
103static 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
117static void *_Thread_MP_Proxy_map( RBTree_Node *node )
118{
119  return THREAD_MP_PROXY_OF_ACTIVE_NODE( node );
120}
121
122Thread_Control *_Thread_MP_Allocate_proxy (
123  States_Control  the_state
124)
125{
126  Thread_Proxy_control *the_proxy;
127  ISR_lock_Context      lock_context;
128
129  _Thread_MP_Proxies_acquire( &lock_context );
130
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;
137
138    executing = _Thread_Executing;
139    receive_packet = _MPCI_Receive_server_tcb->receive_packet;
140    source_tid = receive_packet->source_tid;
141
142    executing->Wait.return_code = STATUS_PROXY_BLOCKING;
143
144    the_proxy->receive_packet = receive_packet;
145    the_proxy->Object.id = source_tid;
146    the_proxy->Real_priority.priority = receive_packet->source_priority;
147    the_proxy->current_state = _States_Set( STATES_DORMANT, the_state );
148
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;
154
155    the_proxy->thread_queue_callout = _Thread_queue_MP_callout_do_nothing;
156
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 );
165
166    return (Thread_Control *) the_proxy;
167  }
168
169  _Thread_MP_Proxies_release( &lock_context );
170
171  _Internal_error( INTERNAL_ERROR_OUT_OF_PROXIES );
172
173  /*
174   *  NOTE: The following return ensures that the compiler will
175   *        think that all paths return a value.
176   */
177
178  return NULL;
179}
180
181Thread_Control *_Thread_MP_Find_proxy (
182  Objects_Id  the_id
183)
184{
185  Thread_Proxy_control *the_proxy;
186  ISR_lock_Context      lock_context;
187
188  _Thread_MP_Proxies_acquire( &lock_context );
189
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  );
197
198  _Thread_MP_Proxies_release( &lock_context );
199
200  return (Thread_Control *) the_proxy;
201}
202
203void _Thread_MP_Free_proxy( Thread_Control *the_thread )
204{
205  Thread_Proxy_control *the_proxy;
206  ISR_lock_Context      lock_context;
207
208  the_proxy = (Thread_Proxy_control *) the_thread;
209
210  _Thread_MP_Proxies_acquire( &lock_context );
211
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  );
217
218  _Thread_MP_Proxies_release( &lock_context );
219}
Note: See TracBrowser for help on using the repository browser.