source: rtems/cpukit/rtems/src/ratemongetstatus.c @ ebe61382

4.104.114.95
Last change on this file since ebe61382 was ebe61382, checked in by Joel Sherrill <joel.sherrill@…>, on 11/30/07 at 21:49:41

2007-11-30 Joel Sherrill <joel.sherrill@…>

  • rtems/src/barrierdelete.c, rtems/src/barrierrelease.c, rtems/src/barriertranslatereturncode.c, rtems/src/barrierwait.c, rtems/src/clockget.c, rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c, rtems/src/dpmeminternal2external.c, rtems/src/eventsend.c, rtems/src/eventtimeout.c, rtems/src/msgqbroadcast.c, rtems/src/msgqdelete.c, rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c, rtems/src/msgqreceive.c, rtems/src/msgqsend.c, rtems/src/msgqurgent.c, rtems/src/partdelete.c, rtems/src/partgetbuffer.c, rtems/src/partreturnbuffer.c, rtems/src/ratemoncancel.c, rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c, rtems/src/ratemontimeout.c, rtems/src/semdelete.c, rtems/src/semflush.c, rtems/src/semobtain.c, rtems/src/semrelease.c, rtems/src/semtranslatereturncode.c, rtems/src/signalsend.c, rtems/src/taskdelete.c, rtems/src/taskgetnote.c, rtems/src/taskissuspended.c, rtems/src/taskrestart.c, rtems/src/taskresume.c, rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c, rtems/src/taskstart.c, rtems/src/tasksuspend.c, rtems/src/taskvariableadd.c, rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c, rtems/src/timercancel.c, rtems/src/timerdelete.c, rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c, rtems/src/timerreset.c, rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c: Restructured all code with the switch (location) pattern so that OBJECTS_LOCAL is first and we can fall into it and the OBJECTS_ERROR case breaks to a return RTEMS_INVALID_ID. This eliminates the return RTEMS_INTERNAL_ERROR at the bottom of each of these files which was unreachable and untestable code. This resulted in a code savings of approximately 20 bytes per file on the SPARC/ERC32.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  Rate Monotonic Manager -- Get Status
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/rtems/status.h>
20#include <rtems/rtems/support.h>
21#include <rtems/score/isr.h>
22#include <rtems/score/object.h>
23#include <rtems/rtems/ratemon.h>
24#include <rtems/score/thread.h>
25
26#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
27    defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
28  #include <rtems/score/timespec.h>
29#endif
30
31/*PAGE
32 *
33 *  rtems_rate_monotonic_get_status
34 *
35 *  This directive allows a thread to obtain status information on a
36 *  period.
37 *
38 *  Input parameters:
39 *    id     - rate monotonic id
40 *    status - pointer to status control block
41 *
42 *  Output parameters:
43 *    RTEMS_SUCCESSFUL - if successful
44 *    error code        - if unsuccessful
45 *
46 */
47
48rtems_status_code rtems_rate_monotonic_get_status(
49  Objects_Id                           id,
50  rtems_rate_monotonic_period_status  *status
51)
52{
53  Objects_Locations              location;
54  Rate_monotonic_Control        *the_period;
55
56  if ( !status )
57    return RTEMS_INVALID_ADDRESS;
58
59  the_period = _Rate_monotonic_Get( id, &location );
60  switch ( location ) {
61
62    case OBJECTS_LOCAL:
63      status->owner = ((the_period->owner) ? the_period->owner->Object.id : 0);
64      status->state = the_period->state;
65
66      if ( status->state == RATE_MONOTONIC_INACTIVE ) {
67        #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
68          status->since_last_period.tv_sec = 0;
69          status->since_last_period.tv_nsec = 0;
70        #else
71          status->ticks_since_last_period = 0;
72        #endif
73        #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
74          status->executed_since_last_period.tv_sec = 0;
75          status->executed_since_last_period.tv_nsec = 0;
76        #else
77          status->ticks_executed_since_last_period = 0;
78        #endif
79      } else {
80        /*
81         *  Both nanoseconds granularity options have to know the uptime.
82         *  This lets them share one single invocation of _TOD_Get_uptime().
83         */
84        #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
85            defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
86          struct timespec uptime;
87          _TOD_Get_uptime( &uptime );
88        #endif
89
90        #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
91          _Timespec_Subtract(
92            &the_period->time_at_period,
93            &uptime,
94            &status->since_last_period
95          );
96        #else
97          status->ticks_since_last_period =
98            _Watchdog_Ticks_since_boot - the_period->time_at_period;
99        #endif
100
101        #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
102          _Timespec_Subtract(
103            &_Thread_Time_of_last_context_switch,
104            &uptime,
105            &status->executed_since_last_period
106          );
107        #else
108          status->ticks_executed_since_last_period =
109            the_period->owner->ticks_executed -
110              the_period->owner_ticks_executed_at_period;
111        #endif
112      }
113
114      _Thread_Enable_dispatch();
115      return RTEMS_SUCCESSFUL;
116
117#if defined(RTEMS_MULTIPROCESSING)
118    case OBJECTS_REMOTE:            /* should never return this */
119#endif
120    case OBJECTS_ERROR:
121      break;
122  }
123
124  return RTEMS_INVALID_ID;
125}
Note: See TracBrowser for help on using the repository browser.