source: rtems/cpukit/posix/include/rtems/posix/pthreadimpl.h @ 8f96581

5
Last change on this file since 8f96581 was 8f96581, checked in by Sebastian Huber <sebastian.huber@…>, on 04/01/16 at 09:38:47

score: Rework MP thread queue callout support

The thread queue implementation was heavily reworked to support SMP.
This broke the multiprocessing support of the thread queues. This is
fixed by this patch.

A thread proxy is unblocked due to three reasons

1) timeout,
2) request satisfaction, and
3) extraction.

In case 1) no MPCI message must be sent. This is ensured via the
_Thread_queue_MP_callout_do_nothing() callout set during
_Thread_MP_Allocate_proxy().

In case 2) and 3) an MPCI message must be sent. In case we interrupt
the blocking operation during _Thread_queue_Enqueue_critical(), then
this message must be sent by the blocking thread. For this the new
fields Thread_Proxy_control::thread_queue_callout and
Thread_Proxy_control::thread_queue_id are used.

Delete the individual API MP callout types and use
Thread_queue_MP_callout throughout. This type is only defined in
multiprocessing configurations. Prefix the multiprocessing parameters
with mp_ to ease code review. Multiprocessing specific parameters are
optional due to use of a similar macro pattern. There is no overhead
for non-multiprocessing configurations.

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Threads Private Support
5 *
6 * This include file contains all the private support information for
7 * POSIX threads.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2011.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_POSIX_PTHREADIMPL_H
20#define _RTEMS_POSIX_PTHREADIMPL_H
21
22#include <rtems/posix/pthread.h>
23#include <rtems/posix/config.h>
24#include <rtems/posix/threadsup.h>
25#include <rtems/score/objectimpl.h>
26#include <rtems/score/threadimpl.h>
27#include <rtems/score/assert.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 * @addtogroup POSIX_PTHREAD
35 */
36/**@{**/
37
38#define POSIX_THREAD_JOIN_TQ_OPERATIONS &_Thread_queue_Operations_FIFO
39
40/**
41 * The following sets the minimum stack size for POSIX threads.
42 */
43#define PTHREAD_MINIMUM_STACK_SIZE (_Stack_Minimum() * 2)
44
45/**
46 * The following defines the information control block used to manage
47 * this class of objects.
48 */
49extern Thread_Information _POSIX_Threads_Information;
50
51/**
52 * This variable contains the default POSIX Thread attributes.
53 */
54extern pthread_attr_t _POSIX_Threads_Default_attributes;
55
56/**
57 * @brief Copy POSIX Thread attribute structure.
58 *
59 * This routine copies the attr2 thread attribute structure
60 * to the attr1 Thread Attribute structure.
61 *
62 * @param[in] dst_attr is a pointer to the thread attribute
63 * structure to copy into.
64 *
65 * @param[out] src_attr is a pointer to the thread attribute
66 * structure to copy from.
67 */
68RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
69  pthread_attr_t        *dst_attr,
70  const pthread_attr_t  *src_attr
71);
72
73/**
74 * @brief Free POSIX control block.
75 *
76 * This routine frees a pthread control block to the
77 * inactive chain of free pthread control blocks.
78 *
79 * @param[in] the_pthread is a pointer to the thread to free.
80 */
81RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free(
82  Thread_Control *the_pthread
83);
84
85/**
86 * @brief POSIX threads initialize user threads body.
87 *
88 * This routine initializes the thread attributes structure.
89 */
90RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
91  pthread_attr_t  *attr
92);
93
94/**
95 * @brief POSIX threads sporadic budget callout.
96 *
97 * This routine handles the sporadic scheduling algorithm.
98 *
99 * @param[in] the_thread is a pointer to the thread whose budget
100 * has been exceeded.
101 */
102void _POSIX_Threads_Sporadic_budget_callout(
103  Thread_Control *the_thread
104);
105
106/**
107 * This routine supports the sporadic scheduling algorithm.  It
108 * is scheduled to be executed at the end of each replenishment
109 * period.  In sporadic scheduling a thread will execute at a
110 * high priority for a user specified amount of CPU time.  When
111 * it exceeds that amount of CPU time, its priority is automatically
112 * lowered. This TSR is executed when it is time to replenish
113 * the thread's processor budget and raise its priority.
114 *
115 * @param[in] id is ignored
116 * @param[in] argument is a pointer to the Thread_Control structure
117 *            for the thread being replenished.
118 */
119void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog );
120
121/**
122 * @brief Translate sched_param into SuperCore terms.
123 *
124 * This method translates the POSIX API sched_param into the corresponding
125 * SuperCore settings.
126 *
127 * @param[in] policy is the POSIX scheduling policy
128 * @param[in] param points to the scheduling parameter structure
129 * @param[in] budget_algorithm points to the output CPU Budget algorithm
130 * @param[in] budget_callout points to the output CPU Callout
131 *
132 * @retval 0 Indicates success.
133 * @retval error_code POSIX error code indicating failure.
134 */
135int _POSIX_Thread_Translate_sched_param(
136  int                                  policy,
137  struct sched_param                  *param,
138  Thread_CPU_budget_algorithms        *budget_algorithm,
139  Thread_CPU_budget_algorithm_callout *budget_callout
140);
141
142/*
143 * rtems_pthread_attribute_compare
144 */
145int rtems_pthread_attribute_compare(
146  const pthread_attr_t *attr1,
147  const pthread_attr_t *attr2
148);
149
150RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
151{
152  _Objects_Allocator_lock();
153
154  _Thread_Kill_zombies();
155
156  return (Thread_Control *)
157    _Objects_Allocate_unprotected( &_POSIX_Threads_Information.Objects );
158}
159
160/*
161 * _POSIX_Threads_Copy_attributes
162 */
163
164RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
165  pthread_attr_t        *dst_attr,
166  const pthread_attr_t  *src_attr
167)
168{
169  *dst_attr = *src_attr;
170#if defined(RTEMS_SMP) && defined(__RTEMS_HAVE_SYS_CPUSET_H__)
171  _Assert(
172    dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
173  );
174  dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
175#endif
176}
177
178/*
179 *  _POSIX_Threads_Free
180 */
181
182RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
183  Thread_Control *the_pthread
184)
185{
186  _Objects_Free( &_POSIX_Threads_Information.Objects, &the_pthread->Object );
187}
188
189/*
190 * _POSIX_Threads_Initialize_attributes
191 */
192
193RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
194  pthread_attr_t  *attr
195)
196{
197  _POSIX_Threads_Copy_attributes(
198    attr,
199    &_POSIX_Threads_Default_attributes
200  );
201}
202
203/*
204 *  _POSIX_Threads_Is_null
205 */
206
207RTEMS_INLINE_ROUTINE bool _POSIX_Threads_Is_null (
208  Thread_Control *the_pthread
209)
210{
211  return !the_pthread;
212}
213
214RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Join_dequeue(
215  POSIX_API_Control *api
216)
217{
218  return _Thread_queue_Dequeue(
219    &api->Join_List,
220    POSIX_THREAD_JOIN_TQ_OPERATIONS,
221    NULL,
222    0
223  );
224}
225
226/** @} */
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif
233/*  end of include file */
Note: See TracBrowser for help on using the repository browser.