OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [pthreadsetschedparam.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.