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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psx09/] [init.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
 *  COPYRIGHT (c) 1989-1999.
3
 *  On-Line Applications Research Corporation (OAR).
4
 *
5
 *  The license and distribution terms for this file may be
6
 *  found in the file LICENSE in this distribution or at
7
 *  http://www.OARcorp.com/rtems/license.html.
8
 *
9
 *  init.c,v 1.7 2002/08/02 00:53:20 joel Exp
10
 */
11
 
12
#define CONFIGURE_INIT
13
#include "system.h"
14
#include <errno.h>
15
 
16
void print_schedparam(
17
  char               *prefix,
18
  struct sched_param *schedparam
19
)
20
{
21
  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
22
#if defined(_POSIX_SPORADIC_SERVER)
23
  printf( "%sss_low_priority     = %d\n", prefix, schedparam->ss_low_priority );
24
  printf( "%sss_replenish_period = (%ld, %ld)\n", prefix,
25
     schedparam->ss_replenish_period.tv_sec,
26
     schedparam->ss_replenish_period.tv_nsec );
27
  printf( "%sss_initial_budget = (%ld, %ld)\n", prefix,
28
     schedparam->ss_initial_budget.tv_sec,
29
     schedparam->ss_initial_budget.tv_nsec );
30
#else
31
  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
32
#endif
33
}
34
 
35
void *POSIX_Init(
36
  void *argument
37
)
38
{
39
  int                  status;
40
  int                  passes;
41
  int                  schedpolicy;
42
  int                  priority;
43
  struct sched_param   schedparam;
44
  char                 buffer[ 80 ];
45
  pthread_mutexattr_t  attr;
46
 
47
  puts( "\n\n*** POSIX TEST 9 ***" );
48
 
49
  /* set the time of day, and print our buffer in multiple ways */
50
 
51
  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
52
 
53
  /* get id of this thread */
54
 
55
  Init_id = pthread_self();
56
  printf( "Init's ID is 0x%08x\n", Init_id );
57
 
58
  /* try to use this thread as a sporadic server */
59
 
60
  puts( "Init: pthread_getschedparam - SUCCESSFUL" );
61
  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
62
  assert( !status );
63
 
64
  priority = schedparam.sched_priority;
65
  sprintf( buffer, " - current priority = %d", priority );
66
  print_current_time( "Init: ", buffer );
67
 
68
  schedparam.ss_replenish_period.tv_sec = 0;
69
  schedparam.ss_replenish_period.tv_nsec = 500000000;  /* 1/2 second */
70
  schedparam.ss_initial_budget.tv_sec = 0;
71
  schedparam.ss_initial_budget.tv_nsec = 250000000;    /* 1/4 second */
72
 
73
  schedparam.sched_priority = 200;
74
  schedparam.ss_low_priority = 100;
75
 
76
  puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
77
  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
78
  assert( !status );
79
 
80
  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
81
  assert( !status );
82
 
83
  priority = schedparam.sched_priority;
84
  sprintf( buffer, " - new priority = %d", priority );
85
  print_current_time( "Init: ", buffer );
86
 
87
  /* go into a loop consuming CPU time to watch our priority change */
88
 
89
  for ( passes=0 ; passes <= 3 ; ) {
90
    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
91
    assert( !status );
92
 
93
    if ( priority != schedparam.sched_priority ) {
94
      priority = schedparam.sched_priority;
95
      sprintf( buffer, " - new priority = %d", priority );
96
      print_current_time( "Init: ", buffer );
97
      passes++;
98
    }
99
  }
100
 
101
  /* now see if this works if we are holding a priority ceiling mutex */
102
 
103
  empty_line();
104
 
105
 
106
  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
107
  assert( !status );
108
 
109
  schedparam.ss_replenish_period.tv_sec = 0;
110
  schedparam.ss_replenish_period.tv_nsec = 500000000;  /* 1/2 second */
111
  schedparam.ss_initial_budget.tv_sec = 0;
112
  schedparam.ss_initial_budget.tv_nsec = 250000000;    /* 1/4 second */
113
 
114
#define HIGH_PRIORITY 150
115
#define MEDIUM_PRIORITY 131
116
#define LOW_PRIORITY 100
117
 
118
  schedparam.sched_priority = HIGH_PRIORITY;
119
  schedparam.ss_low_priority = LOW_PRIORITY;
120
 
121
  puts( "Init: pthread_setschedparam - SUCCESSFUL (sporadic server)" );
122
  status = pthread_setschedparam( pthread_self(), SCHED_SPORADIC, &schedparam );
123
  assert( !status );
124
 
125
  puts( "Init: Initializing mutex attributes for priority ceiling" );
126
  status = pthread_mutexattr_init( &attr );
127
  assert( !status );
128
 
129
  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_PROTECT );
130
  assert( !status );
131
 
132
  status = pthread_mutexattr_setprioceiling( &attr, MEDIUM_PRIORITY );
133
  assert( !status );
134
 
135
  puts( "Init: Creating a mutex" );
136
  status = pthread_mutex_init( &Mutex_id, &attr );
137
  if ( status )
138
    printf( "status = %d\n", status );
139
  assert( !status );
140
 
141
  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
142
  assert( !status );
143
 
144
  priority = schedparam.sched_priority;
145
  sprintf( buffer, " - new priority = %d", priority );
146
  print_current_time( "Init: ", buffer );
147
 
148
  /* go into a loop consuming CPU time to watch our priority lower */
149
 
150
  for ( ; ; ) {
151
    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
152
    assert( !status );
153
 
154
    if ( schedparam.sched_priority != LOW_PRIORITY )
155
      continue;
156
 
157
    priority = schedparam.sched_priority;
158
    sprintf( buffer, " - new priority = %d", priority );
159
    print_current_time( "Init: ", buffer );
160
 
161
    puts( "Init: pthread_mutex_lock acquire the lock" );
162
    status = pthread_mutex_lock( &Mutex_id );
163
    if ( status )
164
      printf( "status = %d\n", status );
165
    assert( !status );
166
 
167
    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
168
    assert( !status );
169
 
170
    priority = schedparam.sched_priority;
171
    sprintf( buffer, " - new priority = %d", priority );
172
    print_current_time( "Init: ", buffer );
173
 
174
    break;
175
  }
176
 
177
  /* now spin waiting for our budget to be replenished */
178
 
179
  for ( ; ; ) {
180
    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
181
    assert( !status );
182
 
183
    if ( schedparam.sched_priority == HIGH_PRIORITY )
184
      break;
185
  }
186
 
187
  priority = schedparam.sched_priority;
188
  sprintf( buffer, " - new priority = %d", priority );
189
  print_current_time( "Init: ", buffer );
190
 
191
  /* with this unlock we should be able to go to low priority */
192
 
193
  puts( "Init: unlock mutex" );
194
  status = pthread_mutex_unlock( &Mutex_id );
195
  if ( status )
196
    printf( "status = %d\n", status );
197
  assert( !status );
198
 
199
  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
200
  assert( !status );
201
 
202
  priority = schedparam.sched_priority;
203
  sprintf( buffer, " - new priority = %d", priority );
204
  print_current_time( "Init: ", buffer );
205
 
206
  for ( ; ; ) {
207
    status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
208
    assert( !status );
209
 
210
    if ( schedparam.sched_priority == LOW_PRIORITY )
211
      break;
212
  }
213
 
214
  status = pthread_getschedparam( pthread_self(), &schedpolicy, &schedparam );
215
  assert( !status );
216
 
217
  priority = schedparam.sched_priority;
218
  sprintf( buffer, " - new priority = %d", priority );
219
  print_current_time( "Init: ", buffer );
220
 
221
  puts( "*** END OF POSIX TEST 9 ***" );
222
  rtems_test_exit( 0 );
223
 
224
  return NULL; /* just so the compiler thinks we returned something */
225
}

powered by: WebSVN 2.1.0

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