source: rtems/cpukit/rtems/src/taskmp.c @ 453bb4b

5
Last change on this file since 453bb4b was 453bb4b, checked in by Sebastian Huber <sebastian.huber@…>, on 12/29/19 at 16:43:46

rtems: Fix MPCI initialization

Update #2408.

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Tasks MP Send Process Packet
5 * @ingroup ClassicTaskMP Task MP Support
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
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/rtems/tasksimpl.h>
22#include <rtems/rtems/optionsimpl.h>
23#include <rtems/rtems/statusimpl.h>
24#include <rtems/score/statesimpl.h>
25#include <rtems/score/threadimpl.h>
26#include <rtems/score/threadqimpl.h>
27#include <rtems/sysinit.h>
28
29/**
30 *  The following data structure defines the packet used to perform
31 *  remote task operations.
32 */
33typedef struct {
34  rtems_packet_prefix               Prefix;
35  RTEMS_tasks_MP_Remote_operations  operation;
36  rtems_name                        name;
37  rtems_task_priority               the_priority;
38}   RTEMS_tasks_MP_Packet;
39
40RTEMS_STATIC_ASSERT(
41  sizeof(RTEMS_tasks_MP_Packet) <= MP_PACKET_MINIMUM_PACKET_SIZE,
42  RTEMS_tasks_MP_Packet
43);
44
45static RTEMS_tasks_MP_Packet *_RTEMS_tasks_MP_Get_packet( void )
46{
47  return (RTEMS_tasks_MP_Packet *) _MPCI_Get_packet();
48}
49
50static RTEMS_tasks_MP_Packet *_RTEMS_tasks_MP_Get_request_packet(
51  Objects_Id id
52)
53{
54  if ( !_Thread_MP_Is_remote( id ) ) {
55    return NULL;
56  }
57
58  return _RTEMS_tasks_MP_Get_packet();
59}
60
61/*
62 *  _RTEMS_tasks_MP_Send_process_packet
63 *
64 */
65
66void _RTEMS_tasks_MP_Send_process_packet (
67  RTEMS_tasks_MP_Remote_operations operation,
68  Objects_Id                       task_id,
69  rtems_name                       name
70)
71{
72  RTEMS_tasks_MP_Packet *the_packet;
73
74  switch ( operation ) {
75
76    case RTEMS_TASKS_MP_ANNOUNCE_CREATE:
77    case RTEMS_TASKS_MP_ANNOUNCE_DELETE:
78
79      the_packet                    = _RTEMS_tasks_MP_Get_packet();
80      the_packet->Prefix.the_class  = MP_PACKET_TASKS;
81      the_packet->Prefix.length     = sizeof ( RTEMS_tasks_MP_Packet );
82      the_packet->Prefix.to_convert = sizeof ( RTEMS_tasks_MP_Packet );
83      the_packet->operation         = operation;
84      the_packet->Prefix.id         = task_id;
85      the_packet->name              = name;
86
87      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
88      break;
89
90    case RTEMS_TASKS_MP_SUSPEND_REQUEST:
91    case RTEMS_TASKS_MP_SUSPEND_RESPONSE:
92    case RTEMS_TASKS_MP_RESUME_REQUEST:
93    case RTEMS_TASKS_MP_RESUME_RESPONSE:
94    case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST:
95    case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE:
96      break;
97  }
98}
99
100static rtems_status_code _RTEMS_tasks_MP_Send_request_packet(
101  RTEMS_tasks_MP_Packet            *the_packet,
102  Objects_Id                        id,
103  RTEMS_tasks_MP_Remote_operations  operation
104)
105{
106  Status_Control status;
107
108  the_packet->Prefix.the_class  = MP_PACKET_TASKS;
109  the_packet->Prefix.length     = sizeof( *the_packet );
110  the_packet->Prefix.to_convert = sizeof( *the_packet );
111  the_packet->Prefix.id         = id;
112  the_packet->operation         = operation;
113
114  status = _MPCI_Send_request_packet(
115    _Objects_Get_node( id ),
116    &the_packet->Prefix,
117    STATES_READY /* Not used */
118  );
119  return _Status_Get( status );
120}
121
122rtems_status_code _RTEMS_tasks_MP_Set_priority(
123  rtems_id             id,
124  rtems_task_priority  new_priority,
125  rtems_task_priority *old_priority
126)
127{
128  RTEMS_tasks_MP_Packet *the_packet;
129
130  the_packet = _RTEMS_tasks_MP_Get_request_packet( id );
131  if ( the_packet == NULL ) {
132    return RTEMS_INVALID_ID;
133  }
134
135  the_packet->the_priority = new_priority;
136  _Thread_Executing->Wait.return_argument = old_priority;
137  return _RTEMS_tasks_MP_Send_request_packet(
138    the_packet,
139    id,
140    RTEMS_TASKS_MP_SET_PRIORITY_REQUEST
141  );
142}
143
144rtems_status_code _RTEMS_tasks_MP_Suspend( rtems_id id )
145{
146  RTEMS_tasks_MP_Packet *the_packet;
147
148  the_packet = _RTEMS_tasks_MP_Get_request_packet( id );
149  if ( the_packet == NULL ) {
150    return RTEMS_INVALID_ID;
151  }
152
153  return _RTEMS_tasks_MP_Send_request_packet(
154    the_packet,
155    id,
156    RTEMS_TASKS_MP_SUSPEND_REQUEST
157  );
158}
159
160rtems_status_code _RTEMS_tasks_MP_Resume( rtems_id id )
161{
162  RTEMS_tasks_MP_Packet *the_packet;
163
164  the_packet = _RTEMS_tasks_MP_Get_request_packet( id );
165  if ( the_packet == NULL ) {
166    return RTEMS_INVALID_ID;
167  }
168
169  return _RTEMS_tasks_MP_Send_request_packet(
170    the_packet,
171    id,
172    RTEMS_TASKS_MP_RESUME_REQUEST
173  );
174}
175
176/*
177 *  _RTEMS_tasks_MP_Send_response_packet
178 *
179 */
180
181static void _RTEMS_tasks_MP_Send_response_packet (
182  RTEMS_tasks_MP_Remote_operations  operation,
183  Thread_Control                   *the_thread
184)
185{
186  RTEMS_tasks_MP_Packet *the_packet;
187
188  switch ( operation ) {
189
190    case RTEMS_TASKS_MP_SUSPEND_RESPONSE:
191    case RTEMS_TASKS_MP_RESUME_RESPONSE:
192    case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE:
193
194      the_packet = (RTEMS_tasks_MP_Packet *) the_thread->receive_packet;
195
196/*
197 *  The packet being returned already contains the class, length, and
198 *  to_convert fields, therefore they are not set in this routine.
199 */
200      the_packet->operation    = operation;
201      the_packet->Prefix.id    = the_packet->Prefix.source_tid;
202
203      _MPCI_Send_response_packet(
204        _Objects_Get_node( the_packet->Prefix.source_tid ),
205        &the_packet->Prefix
206      );
207      break;
208
209    case RTEMS_TASKS_MP_ANNOUNCE_CREATE:
210    case RTEMS_TASKS_MP_ANNOUNCE_DELETE:
211    case RTEMS_TASKS_MP_SUSPEND_REQUEST:
212    case RTEMS_TASKS_MP_RESUME_REQUEST:
213    case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST:
214      break;
215
216  }
217}
218
219/*
220 *
221 *  _RTEMS_tasks_MP_Process_packet
222 *
223 */
224
225static void _RTEMS_tasks_MP_Process_packet (
226  rtems_packet_prefix  *the_packet_prefix
227)
228{
229  RTEMS_tasks_MP_Packet *the_packet;
230  Thread_Control   *the_thread;
231
232  the_packet = (RTEMS_tasks_MP_Packet *) the_packet_prefix;
233
234  switch ( the_packet->operation ) {
235
236    case RTEMS_TASKS_MP_ANNOUNCE_CREATE:
237
238      _Objects_MP_Allocate_and_open(
239        &_RTEMS_tasks_Information.Objects,
240        the_packet->name,
241        the_packet->Prefix.id,
242        true
243      );
244
245      _MPCI_Return_packet( the_packet_prefix );
246      break;
247
248    case RTEMS_TASKS_MP_ANNOUNCE_DELETE:
249
250      _Objects_MP_Close(
251        &_RTEMS_tasks_Information.Objects,
252        the_packet->Prefix.id
253      );
254
255      _MPCI_Return_packet( the_packet_prefix );
256      break;
257
258    case RTEMS_TASKS_MP_SUSPEND_REQUEST:
259
260      the_packet->Prefix.return_code = rtems_task_suspend(
261        the_packet->Prefix.id
262      );
263
264      _RTEMS_tasks_MP_Send_response_packet(
265        RTEMS_TASKS_MP_SUSPEND_RESPONSE,
266        _Thread_Executing
267      );
268      break;
269
270    case RTEMS_TASKS_MP_SUSPEND_RESPONSE:
271    case RTEMS_TASKS_MP_RESUME_RESPONSE:
272
273      the_thread = _MPCI_Process_response( the_packet_prefix );
274
275      _MPCI_Return_packet( the_packet_prefix );
276      break;
277
278    case RTEMS_TASKS_MP_RESUME_REQUEST:
279
280      the_packet->Prefix.return_code = rtems_task_resume(
281        the_packet->Prefix.id
282      );
283
284      _RTEMS_tasks_MP_Send_response_packet(
285        RTEMS_TASKS_MP_RESUME_RESPONSE,
286        _Thread_Executing
287      );
288      break;
289
290    case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST:
291
292      the_packet->Prefix.return_code = rtems_task_set_priority(
293        the_packet->Prefix.id,
294        the_packet->the_priority,
295        &the_packet->the_priority
296      );
297
298      _RTEMS_tasks_MP_Send_response_packet(
299        RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE,
300        _Thread_Executing
301      );
302      break;
303
304    case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE:
305
306      the_thread = _MPCI_Process_response( the_packet_prefix );
307
308      *(rtems_task_priority *)the_thread->Wait.return_argument =
309                                               the_packet->the_priority;
310
311      _MPCI_Return_packet( the_packet_prefix );
312      break;
313  }
314}
315
316static void _RTEMS_tasks_MP_Initialize( void )
317{
318  _MPCI_Register_packet_processor(
319    MP_PACKET_TASKS,
320    _RTEMS_tasks_MP_Process_packet
321  );
322}
323
324RTEMS_SYSINIT_ITEM(
325  _RTEMS_tasks_MP_Initialize,
326  RTEMS_SYSINIT_CLASSIC_TASKS_MP,
327  RTEMS_SYSINIT_ORDER_MIDDLE
328);
Note: See TracBrowser for help on using the repository browser.