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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [posix/] [src/] [pthreadsetschedparam.c] - Blame information for rev 1026

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

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  pthreadsetschedparam.c,v 1.4 2001/01/24 14:17:28 joel Exp
13
 */
14
 
15
#if HAVE_CONFIG_H
16
#include "config.h"
17
#endif
18
 
19
#include <pthread.h>
20
#include <errno.h>
21
 
22
#include <rtems/system.h>
23
#include <rtems/posix/pthread.h>
24
#include <rtems/posix/priority.h>
25
#include <rtems/posix/time.h>
26
 
27
int pthread_setschedparam(
28
  pthread_t           thread,
29
  int                 policy,
30
  struct sched_param *param
31
)
32
{
33
  register Thread_Control             *the_thread;
34
  POSIX_API_Control                   *api;
35
  Thread_CPU_budget_algorithms         budget_algorithm;
36
  Thread_CPU_budget_algorithm_callout  budget_callout;
37
  Objects_Locations                    location;
38
 
39
  /*
40
   *  Check all the parameters
41
   */
42
 
43
  if ( !param )
44
    return EINVAL;
45
 
46
  if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
47
    return EINVAL;
48
 
49
  budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
50
  budget_callout = NULL;
51
 
52
  switch ( policy ) {
53
    case SCHED_OTHER:
54
      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
55
      break;
56
 
57
    case SCHED_FIFO:
58
      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
59
      break;
60
 
61
    case SCHED_RR:
62
      budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
63
      break;
64
 
65
    case SCHED_SPORADIC:
66
      budget_algorithm  = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
67
      budget_callout = _POSIX_Threads_Sporadic_budget_callout;
68
 
69
      if ( _POSIX_Timespec_to_interval( &param->ss_replenish_period ) <
70
           _POSIX_Timespec_to_interval( &param->ss_initial_budget ) )
71
        return EINVAL;
72
 
73
      if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
74
        return EINVAL;
75
 
76
      break;
77
 
78
    default:
79
      return EINVAL;
80
  }
81
 
82
  /*
83
   *  Actually change the scheduling policy and parameters
84
   */
85
 
86
  the_thread = _POSIX_Threads_Get( thread, &location );
87
  switch ( location ) {
88
    case OBJECTS_ERROR:
89
    case OBJECTS_REMOTE:
90
      return ESRCH;
91
    case OBJECTS_LOCAL:
92
      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
93
 
94
      if ( api->schedpolicy == SCHED_SPORADIC )
95
        (void) _Watchdog_Remove( &api->Sporadic_timer );
96
 
97
      api->schedpolicy = policy;
98
      api->schedparam  = *param;
99
      the_thread->budget_algorithm = budget_algorithm;
100
      the_thread->budget_callout   = budget_callout;
101
 
102
      switch ( api->schedpolicy ) {
103
        case SCHED_OTHER:
104
        case SCHED_FIFO:
105
        case SCHED_RR:
106
          the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
107
 
108
          the_thread->real_priority =
109
            _POSIX_Priority_To_core( api->schedparam.sched_priority );
110
 
111
          _Thread_Change_priority(
112
             the_thread,
113
             the_thread->real_priority,
114
             TRUE
115
          );
116
          break;
117
 
118
        case SCHED_SPORADIC:
119
          api->ss_high_priority = api->schedparam.sched_priority;
120
          _Watchdog_Remove( &api->Sporadic_timer );
121
          _POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
122
          break;
123
      }
124
 
125
      _Thread_Enable_dispatch();
126
      return 0;
127
  }
128
  return POSIX_BOTTOM_REACHED();
129
}

powered by: WebSVN 2.1.0

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