source: rtems/cpukit/score/src/threadinitialize.c @ b568ccb

4.104.114.84.95
Last change on this file since b568ccb was f94e76ba, checked in by Joel Sherrill <joel.sherrill@…>, on 07/28/99 at 18:03:20

Fix after this report from Peter Pointner <pr@…>:

Problem: a posix thread which is created by

pthread_attr_init(&tattr);
pthread_attr_setinheritsched(&tattr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&tattr, SCHED_RR);
pthread_create(&th, &tattr, func, arg);

has a first timeslice of 232 ticks (changing a running thread to
SCHED_RR id ok).

I use RTEMS-4.0.0. I am not sure if the problem exists in the current CVS
head revision. If it's not fixed, the patch at the end should do it.

Peter

--- pthreadcreate.c.orig Wed Jul 28 14:45:58 1999
+++ pthreadcreate.c Wed Jul 28 15:06:09 1999
@@ -199,6 +199,10 @@

api->schedpolicy = schedpolicy;
api->schedparam = schedparam;

+ if ( schedpolicy == SCHED_RR ) {
+ the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
+ }
+

/*

  • This insures we evaluate the process-wide signals pending when we
  • first run.
  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/score/apiext.h>
18#include <rtems/score/context.h>
19#include <rtems/score/interr.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/object.h>
22#include <rtems/score/priority.h>
23#include <rtems/score/states.h>
24#include <rtems/score/sysstate.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/threadq.h>
27#include <rtems/score/userext.h>
28#include <rtems/score/wkspace.h>
29
30/*PAGE
31 *
32 *  _Thread_Initialize
33 *
34 *  XXX
35 */
36
37boolean _Thread_Initialize(
38  Objects_Information                  *information,
39  Thread_Control                       *the_thread,
40  void                                 *stack_area,
41  unsigned32                            stack_size,
42  boolean                               is_fp,
43  Priority_Control                      priority,
44  boolean                               is_preemptible,
45  Thread_CPU_budget_algorithms          budget_algorithm,
46  Thread_CPU_budget_algorithm_callout   budget_callout,
47  unsigned32                            isr_level,
48  Objects_Name                          name
49)
50{
51  unsigned32           actual_stack_size = 0;
52  void                *stack = NULL;
53  void                *fp_area;
54  void                *extensions_area;
55
56  /*
57   *  Initialize the Ada self pointer
58   */
59
60  the_thread->rtems_ada_self = NULL;
61
62  /*
63   *  Allocate and Initialize the stack for this thread.
64   */
65
66
67  if ( !stack_area ) {
68    if ( !_Stack_Is_enough( stack_size ) )
69      actual_stack_size = STACK_MINIMUM_SIZE;
70    else
71      actual_stack_size = stack_size;
72
73    actual_stack_size = _Thread_Stack_Allocate( the_thread, actual_stack_size );
74 
75    if ( !actual_stack_size )
76      return FALSE;                     /* stack allocation failed */
77
78    stack = the_thread->Start.stack;
79    the_thread->Start.core_allocated_stack = TRUE;
80  } else {
81    stack = stack_area;
82    actual_stack_size = stack_size;
83    the_thread->Start.core_allocated_stack = FALSE;
84  }
85
86  _Stack_Initialize(
87     &the_thread->Start.Initial_stack,
88     stack,
89     actual_stack_size
90  );
91
92  /*
93   *  Allocate the floating point area for this thread
94   */
95 
96  if ( is_fp ) {
97
98    fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
99    if ( !fp_area ) {
100      _Thread_Stack_Free( the_thread );
101      return FALSE;
102    }
103    fp_area = _Context_Fp_start( fp_area, 0 );
104
105  } else
106    fp_area = NULL;
107
108  the_thread->fp_context       = fp_area;
109  the_thread->Start.fp_context = fp_area;
110
111  /*
112   *  Allocate the extensions area for this thread
113   */
114
115  if ( _Thread_Maximum_extensions ) {
116    extensions_area = _Workspace_Allocate(
117      (_Thread_Maximum_extensions + 1) * sizeof( void * )
118    );
119
120    if ( !extensions_area ) {
121      if ( fp_area )
122        (void) _Workspace_Free( fp_area );
123
124      _Thread_Stack_Free( the_thread );
125
126      return FALSE;
127    }
128  } else
129    extensions_area = NULL;
130 
131  the_thread->extensions = (void **) extensions_area;
132
133  /*
134   *  General initialization
135   */
136
137  the_thread->Start.is_preemptible   = is_preemptible;
138  the_thread->Start.budget_algorithm = budget_algorithm;
139  the_thread->Start.budget_callout   = budget_callout;
140
141  switch ( budget_algorithm ) {
142    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
143    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
144      break;
145    case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
146      the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
147      break;
148    case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
149      break;
150  }
151
152  the_thread->Start.isr_level        = isr_level;
153
154  the_thread->current_state          = STATES_DORMANT;
155  the_thread->resource_count         = 0;
156  the_thread->real_priority          = priority;
157  the_thread->Start.initial_priority = priority;
158  the_thread->ticks_executed         = 0;
159 
160  _Thread_Set_priority( the_thread, priority );
161
162  /*
163   *  Open the object
164   */
165
166  _Objects_Open( information, &the_thread->Object, name );
167
168  /*
169   *  Invoke create extensions
170   */
171
172  if ( !_User_extensions_Thread_create( the_thread ) ) {
173
174    if ( extensions_area )
175      (void) _Workspace_Free( extensions_area );
176
177    if ( fp_area )
178      (void) _Workspace_Free( fp_area );
179
180    _Thread_Stack_Free( the_thread );
181
182    return FALSE;
183  }
184
185  return TRUE;
186   
187}
Note: See TracBrowser for help on using the repository browser.