Ticket #1462: pr1462-49.diff
File pr1462-49.diff, 8.6 KB (added by Joel Sherrill, on 10/30/09 at 16:55:39) |
---|
-
cpukit/rtems/src/ratemonperiod.c
? cpukit/rtems/src/.ratemonperiod.c.swp RCS file: /usr1/CVS/rtems/cpukit/rtems/src/ratemonperiod.c,v retrieving revision 1.17.2.1 diff -u -r1.17.2.1 ratemonperiod.c
1 1 /* 2 2 * Rate Monotonic Manager - Period Blocking and Status 3 3 * 4 * COPYRIGHT (c) 1989-200 7.4 * COPYRIGHT (c) 1989-2009. 5 5 * On-Line Applications Research Corporation (OAR). 6 6 * 7 7 * The license and distribution terms for this file may be … … 28 28 extern struct timespec _Thread_Time_of_last_context_switch; 29 29 #endif 30 30 31 void _Rate_monotonic_Initiate_statistics( 32 Rate_monotonic_Control *the_period 33 ) 34 { 35 Thread_Control *owning_thread = the_period->owner; 36 37 /* 38 * If any statistics are at nanosecond granularity, we need to 39 * obtain the uptime. 40 */ 41 #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ 42 defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) 43 44 struct timespec uptime; 45 46 _TOD_Get_uptime( &uptime ); 47 #endif 48 49 /* 50 * Set the starting point and the CPU time used for the statistics. 51 */ 52 #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS 53 the_period->time_at_period = uptime; 54 #else 55 the_period->time_at_period = _Watchdog_Ticks_since_boot; 56 #endif 57 58 the_period->owner_executed_at_period = owning_thread->cpu_time_used; 59 60 /* 61 * If using nanosecond granularity for CPU Usage Statistics and the 62 * period's thread is currently executing, then we need to take into 63 * account how much time the executing thread has run since the last 64 * context switch. When this routine is invoked from 65 * rtems_rate_monotonic_period, the owner will be the executing thread. 66 * When this routine is invoked from _Rate_monotonic_Timeout, it will not. 67 */ 68 #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS 69 if (owning_thread == _Thread_Executing) { 70 71 rtems_thread_cpu_usage_t ran; 72 73 /* 74 * Adjust the CPU time used to account for the time since last 75 * context switch. 76 */ 77 _Timespec_Subtract( 78 &_Thread_Time_of_last_context_switch, &uptime, &ran 79 ); 80 81 _Timespec_Add_to( &the_period->owner_executed_at_period, &ran ); 82 } 83 #endif 84 } 85 31 86 void _Rate_monotonic_Update_statistics( 32 87 Rate_monotonic_Control *the_period 33 88 ) … … 55 110 */ 56 111 57 112 /* 58 * Grab basic information 113 * Update the counts. 114 */ 115 116 stats = &the_period->Statistics; 117 stats->count++; 118 119 if ( the_period->state == RATE_MONOTONIC_EXPIRED ) 120 stats->missed_count++; 121 122 /* 123 * Grab basic information for time statistics. 59 124 */ 60 125 61 126 #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS … … 86 151 87 152 /* executed = current cpu usage - value at start of period */ 88 153 _Timespec_Subtract( 89 &the_period->owner_executed_at_period, 90 &used, 91 &executed 154 &the_period->owner_executed_at_period, &used, &executed 92 155 ); 93 156 } 94 157 #else … … 97 160 #endif 98 161 99 162 /* 100 * Now update the statistics101 */102 103 stats = &the_period->Statistics;104 stats->count++;105 106 107 if ( the_period->state == RATE_MONOTONIC_EXPIRED )108 stats->missed_count++;109 110 /*111 163 * Update CPU time 112 164 */ 113 165 … … 180 232 ISR_Level level; 181 233 182 234 the_period = _Rate_monotonic_Get( id, &location ); 183 switch ( location ) {184 235 236 switch ( location ) { 185 237 case OBJECTS_LOCAL: 186 238 if ( !_Thread_Is_executing( the_period->owner ) ) { 187 239 _Thread_Enable_dispatch(); … … 207 259 } 208 260 209 261 _ISR_Disable( level ); 262 210 263 switch ( the_period->state ) { 211 264 case RATE_MONOTONIC_INACTIVE: { 212 #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \213 defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)214 struct timespec uptime;215 #endif216 217 /*218 * No need to update statistics -- there are not a period active219 */220 265 221 266 _ISR_Enable( level ); 222 267 223 224 #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ 225 defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) 226 _TOD_Get_uptime( &uptime ); 227 #endif 228 229 #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS 230 /* 231 * Since the statistics didn't update the starting time, 232 * we do it here. 233 */ 234 the_period->time_at_period = uptime; 235 #else 236 the_period->time_at_period = _Watchdog_Ticks_since_boot; 237 #endif 238 239 #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS 240 { 241 rtems_thread_cpu_usage_t ran; 242 243 the_period->owner_executed_at_period = 244 _Thread_Executing->cpu_time_used; 245 246 /* How much time time since last context switch */ 247 _Timespec_Subtract( 248 &_Thread_Time_of_last_context_switch, 249 &uptime, 250 &ran 251 ); 252 253 /* The thread had executed before the last context switch also. 254 * 255 * the_period->owner_executed_at_period += ran 256 */ 257 _Timespec_Add_to( &the_period->owner_executed_at_period, &ran ); 258 } 259 #else 260 the_period->owner_executed_at_period = 261 _Thread_Executing->cpu_time_used; 262 #endif 268 /* 269 * Baseline statistics information for the beginning of a period. 270 */ 271 _Rate_monotonic_Initiate_statistics( the_period ); 263 272 264 273 the_period->state = RATE_MONOTONIC_ACTIVE; 265 274 _Watchdog_Initialize( … … 278 287 case RATE_MONOTONIC_ACTIVE: 279 288 280 289 /* 281 * Update statistics from the concluding period 290 * Update statistics from the concluding period. 282 291 */ 283 292 _Rate_monotonic_Update_statistics( the_period ); 284 293 … … 287 296 * in the process of blocking on the period and that we 288 297 * may be changing the length of the next period. 289 298 */ 290 291 299 the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING; 292 300 the_period->next_length = length; 293 301 … … 300 308 * Did the watchdog timer expire while we were actually blocking 301 309 * on it? 302 310 */ 303 304 311 _ISR_Disable( level ); 305 312 local_state = the_period->state; 306 313 the_period->state = RATE_MONOTONIC_ACTIVE; … … 310 317 * If it did, then we want to unblock ourself and continue as 311 318 * if nothing happen. The period was reset in the timeout routine. 312 319 */ 313 314 320 if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING ) 315 321 _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD ); 316 322 … … 319 325 break; 320 326 321 327 case RATE_MONOTONIC_EXPIRED: 328 322 329 /* 323 330 * Update statistics from the concluding period 324 331 */ -
cpukit/rtems/src/ratemontimeout.c
RCS file: /usr1/CVS/rtems/cpukit/rtems/src/ratemontimeout.c,v retrieving revision 1.9 diff -u -r1.9 ratemontimeout.c
1 1 /* 2 2 * Rate Monotonic Manager -- Period End Timeout Handler 3 3 * 4 * COPYRIGHT (c) 1989-200 7.4 * COPYRIGHT (c) 1989-2009. 5 5 * On-Line Applications Research Corporation (OAR). 6 6 * 7 7 * The license and distribution terms for this file may be … … 51 51 * When we get here, the Timer is already off the chain so we do not 52 52 * have to worry about that -- hence no _Watchdog_Remove(). 53 53 */ 54 55 54 the_period = _Rate_monotonic_Get( id, &location ); 56 55 switch ( location ) { 57 56 … … 61 60 the_thread->Wait.id == the_period->Object.id ) { 62 61 _Thread_Unblock( the_thread ); 63 62 63 _Rate_monotonic_Initiate_statistics( the_period ); 64 64 65 _Watchdog_Insert_ticks( &the_period->Timer, the_period->next_length ); 65 66 } else if ( the_period->state == RATE_MONOTONIC_OWNER_IS_BLOCKING ) { 66 67 the_period->state = RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING; 67 68 69 _Rate_monotonic_Initiate_statistics( the_period ); 70 68 71 _Watchdog_Insert_ticks( &the_period->Timer, the_period->next_length ); 69 72 } else 70 73 the_period->state = RATE_MONOTONIC_EXPIRED;