source: rtems/cpukit/posix/src/pthreadsetschedparam.c @ 7fec3b7a

4.104.114.84.95
Last change on this file since 7fec3b7a was 7fec3b7a, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 16:01:32

Added call to _Watchdog_Remove to remove the sporadic timer. It was
being reinserted onto the ticks chain.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  13.5.2 Dynamic Thread Scheduling Parameters Access,
3 *         P1003.1c/Draft 10, p. 124
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 the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16
17#include <pthread.h>
18#include <errno.h>
19
20#include <rtems/system.h>
21#include <rtems/posix/pthread.h>
22#include <rtems/posix/priority.h>
23#include <rtems/posix/time.h>
24
25int pthread_setschedparam(
26  pthread_t           thread,
27  int                 policy,
28  struct sched_param *param
29)
30{
31  register Thread_Control             *the_thread;
32  POSIX_API_Control                   *api;
33  Thread_CPU_budget_algorithms         budget_algorithm;
34  Thread_CPU_budget_algorithm_callout  budget_callout;
35  Objects_Locations                    location;
36 
37  /*
38   *  Check all the parameters
39   */
40
41  if ( !param )
42    return EINVAL;
43
44  if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
45    return EINVAL;
46
47  budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
48  budget_callout = NULL;
49
50  switch ( policy ) {
51    case SCHED_OTHER:
52      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
53      break;
54 
55    case SCHED_FIFO:
56      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
57      break;
58 
59    case SCHED_RR:
60      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
61      break;
62 
63    case SCHED_SPORADIC:
64      budget_algorithm  = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
65      budget_callout = _POSIX_Threads_Sporadic_budget_callout;
66 
67      if ( _POSIX_Timespec_to_interval( &param->ss_replenish_period ) <
68           _POSIX_Timespec_to_interval( &param->ss_initial_budget ) )
69        return EINVAL;
70 
71      if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
72        return EINVAL;
73 
74      break;
75 
76    default:
77      return EINVAL;
78  }
79
80  /*
81   *  Actually change the scheduling policy and parameters
82   */
83
84  the_thread = _POSIX_Threads_Get( thread, &location );
85  switch ( location ) {
86    case OBJECTS_ERROR:
87    case OBJECTS_REMOTE:
88      return ESRCH;
89    case OBJECTS_LOCAL:
90      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
91
92      if ( api->schedpolicy == SCHED_SPORADIC )
93        (void) _Watchdog_Remove( &api->Sporadic_timer );
94
95      api->schedpolicy = policy;
96      api->schedparam  = *param;
97      the_thread->budget_algorithm = budget_algorithm;
98      the_thread->budget_callout   = budget_callout;
99
100      switch ( api->schedpolicy ) {
101        case SCHED_OTHER:
102        case SCHED_FIFO:
103        case SCHED_RR:
104          the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
105
106          the_thread->real_priority =
107            _POSIX_Priority_To_core( api->schedparam.sched_priority );
108
109          _Thread_Change_priority(
110             the_thread,
111             the_thread->real_priority,
112             TRUE
113          );
114          break;
115 
116        case SCHED_SPORADIC:
117          api->ss_high_priority = api->schedparam.sched_priority;
118          _Watchdog_Remove( &api->Sporadic_timer );
119          _POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
120          break;
121      }
122
123      _Thread_Enable_dispatch();
124      return 0;
125  }
126  return POSIX_BOTTOM_REACHED();
127}
Note: See TracBrowser for help on using the repository browser.