source: rtems/cpukit/posix/include/rtems/posix/pthreadimpl.h @ 917884c

5
Last change on this file since 917884c was 917884c, checked in by Sebastian Huber <sebastian.huber@…>, on 06/15/16 at 08:39:09

posix: Fix poradic server initial CPU budget

Update #2738.

  • Property mode set to 100644
File size: 4.4 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/assert.h>
26#include <rtems/score/objectimpl.h>
27#include <rtems/score/timespec.h>
28#include <rtems/score/threadimpl.h>
29#include <rtems/score/watchdogimpl.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/**
36 * @addtogroup POSIX_PTHREAD
37 */
38/**@{**/
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
56RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
57  Thread_Control    *the_thread,
58  POSIX_API_Control *api
59)
60{
61  the_thread->cpu_time_budget =
62    _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_init_budget );
63
64  _Watchdog_Per_CPU_insert_relative(
65    &api->Sporadic_timer,
66    _Per_CPU_Get(),
67    _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_repl_period )
68  );
69}
70
71/**
72 * @brief POSIX threads sporadic budget callout.
73 *
74 * This routine handles the sporadic scheduling algorithm.
75 *
76 * @param[in] the_thread is a pointer to the thread whose budget
77 * has been exceeded.
78 */
79void _POSIX_Threads_Sporadic_budget_callout(
80  Thread_Control *the_thread
81);
82
83/**
84 * This routine supports the sporadic scheduling algorithm.  It
85 * is scheduled to be executed at the end of each replenishment
86 * period.  In sporadic scheduling a thread will execute at a
87 * high priority for a user specified amount of CPU time.  When
88 * it exceeds that amount of CPU time, its priority is automatically
89 * lowered. This TSR is executed when it is time to replenish
90 * the thread's processor budget and raise its priority.
91 *
92 * @param[in] id is ignored
93 * @param[in] argument is a pointer to the Thread_Control structure
94 *            for the thread being replenished.
95 */
96void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog );
97
98/**
99 * @brief Translate sched_param into SuperCore terms.
100 *
101 * This method translates the POSIX API sched_param into the corresponding
102 * SuperCore settings.
103 *
104 * @param[in] policy is the POSIX scheduling policy
105 * @param[in] param points to the scheduling parameter structure
106 * @param[in] budget_algorithm points to the output CPU Budget algorithm
107 * @param[in] budget_callout points to the output CPU Callout
108 *
109 * @retval 0 Indicates success.
110 * @retval error_code POSIX error code indicating failure.
111 */
112int _POSIX_Thread_Translate_sched_param(
113  int                                  policy,
114  struct sched_param                  *param,
115  Thread_CPU_budget_algorithms        *budget_algorithm,
116  Thread_CPU_budget_algorithm_callout *budget_callout
117);
118
119/*
120 * rtems_pthread_attribute_compare
121 */
122int rtems_pthread_attribute_compare(
123  const pthread_attr_t *attr1,
124  const pthread_attr_t *attr2
125);
126
127RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
128{
129  _Objects_Allocator_lock();
130
131  _Thread_Kill_zombies();
132
133  return (Thread_Control *)
134    _Objects_Allocate_unprotected( &_POSIX_Threads_Information.Objects );
135}
136
137RTEMS_INLINE_ROUTINE void _POSIX_Threads_Copy_attributes(
138  pthread_attr_t        *dst_attr,
139  const pthread_attr_t  *src_attr
140)
141{
142  *dst_attr = *src_attr;
143#if defined(RTEMS_SMP) && defined(__RTEMS_HAVE_SYS_CPUSET_H__)
144  _Assert(
145    dst_attr->affinitysetsize == sizeof(dst_attr->affinitysetpreallocated)
146  );
147  dst_attr->affinityset = &dst_attr->affinitysetpreallocated;
148#endif
149}
150
151RTEMS_INLINE_ROUTINE void _POSIX_Threads_Free (
152  Thread_Control *the_pthread
153)
154{
155  _Objects_Free( &_POSIX_Threads_Information.Objects, &the_pthread->Object );
156}
157
158RTEMS_INLINE_ROUTINE void _POSIX_Threads_Initialize_attributes(
159  pthread_attr_t  *attr
160)
161{
162  _POSIX_Threads_Copy_attributes(
163    attr,
164    &_POSIX_Threads_Default_attributes
165  );
166}
167
168/** @} */
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif
175/*  end of include file */
Note: See TracBrowser for help on using the repository browser.