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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libmisc/] [rtmonuse/] [rtmonuse.c] - Blame information for rev 751

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

Line No. Rev Author Line
1 30 unneback
/*
2
 *  $Id: rtmonuse.c,v 1.2 2001-09-27 12:01:44 chris Exp $
3
 */
4
 
5
#include <rtems.h>
6
#include <stdlib.h>
7
#include <stdio.h>
8
#include <assert.h>
9
 
10
#include <rtems/rtmonuse.h>
11
 
12
typedef struct {
13
  rtems_id     id;
14
  unsigned32   count;
15
  unsigned32   missed_count;
16
  unsigned32   min_cpu_time;
17
  unsigned32   max_cpu_time;
18
  unsigned32   total_cpu_time;
19
  unsigned32   min_wall_time;
20
  unsigned32   max_wall_time;
21
  unsigned32   total_wall_time;
22
}  Period_usage_t;
23
 
24
Period_usage_t *Period_usage_Information;
25
 
26
/*PAGE
27
 *
28
 *  Period_usage_Initialize
29
 */
30
 
31
void Period_usage_Initialize( void )
32
{
33
  int             maximum;
34
 
35
  maximum = _Configuration_Table->RTEMS_api_configuration->maximum_periods;
36
 
37
  Period_usage_Information = malloc( sizeof(Period_usage_t) * (maximum+1) );
38
 
39
  Period_usage_Reset();
40
}
41
 
42
/*PAGE
43
 *
44
 *  Period_usage_Reset
45
 */
46
 
47
void Period_usage_Reset( void )
48
{
49
  unsigned32      i;
50
  Period_usage_t *the_usage;
51
 
52
  for ( i=0 ;
53
        i<_Configuration_Table->RTEMS_api_configuration->maximum_periods ;
54
        i++ ) {
55
    the_usage = &Period_usage_Information[ i ];
56
 
57
    the_usage->count           = 0;
58
    the_usage->missed_count    = 0;
59
    the_usage->min_cpu_time    = 0xFFFFFFFF;
60
    the_usage->max_cpu_time    = 0;
61
    the_usage->total_cpu_time  = 0;
62
    the_usage->min_wall_time   = 0xFFFFFFFF;
63
    the_usage->max_wall_time   = 0;
64
    the_usage->total_wall_time = 0;
65
 
66
  }
67
}
68
 
69
/*PAGE
70
 *
71
 *  Period_usage_Update
72
 */
73
 
74
void Period_usage_Update(
75
  rtems_id     id
76
)
77
{
78
  rtems_rate_monotonic_period_status rm_status;
79
  rtems_status_code                  status;
80
  Period_usage_t                    *the_usage;
81
 
82
  assert( Period_usage_Information );
83
 
84
  status = rtems_rate_monotonic_get_status( id, &rm_status );
85
  assert( status == RTEMS_SUCCESSFUL );
86
 
87
  the_usage = &Period_usage_Information[ rtems_get_index( id ) ];
88
 
89
  the_usage->id = id;
90
  the_usage->count++;
91
  if ( rm_status.state == RATE_MONOTONIC_EXPIRED )
92
    the_usage->missed_count++;
93
  the_usage->total_cpu_time  += rm_status.ticks_executed_since_last_period;
94
  the_usage->total_wall_time += rm_status.ticks_since_last_period;
95
 
96
  /*
97
   *  Update CPU time
98
   */
99
 
100
  if ( rm_status.ticks_executed_since_last_period < the_usage->min_cpu_time )
101
    the_usage->min_cpu_time = rm_status.ticks_executed_since_last_period;
102
 
103
  if ( rm_status.ticks_executed_since_last_period > the_usage->max_cpu_time )
104
    the_usage->max_cpu_time = rm_status.ticks_executed_since_last_period;
105
 
106
  /*
107
   *  Update Wall time
108
   */
109
 
110
  if ( rm_status.ticks_since_last_period < the_usage->min_wall_time )
111
    the_usage->min_wall_time = rm_status.ticks_since_last_period;
112
 
113
  if ( rm_status.ticks_since_last_period > the_usage->max_wall_time )
114
    the_usage->max_wall_time = rm_status.ticks_since_last_period;
115
 
116
}
117
 
118
/*PAGE
119
 *
120
 *  Period_usage_Dump
121
 */
122
 
123
void Period_usage_Dump( void )
124
{
125
  unsigned32              i;
126
  Period_usage_t         *the_usage;
127
  Rate_monotonic_Control *the_period;
128
  unsigned32              u32_name;
129
  char                    name[5];
130
 
131
  if ( !Period_usage_Information ) {
132
    printf( "Period statistics library is not initialized\n" );
133
    return;
134
  }
135
 
136
  printf( "Period information by period\n" );
137
  printf( "   ID      OWNER   PERIODS  MISSED    CPU TIME    WALL TIME\n" );
138
 
139
  /*
140
   *  RTEMS does not use an index of zero for object ids.
141
   */
142
 
143
  for ( i=1 ;
144
        i<_Configuration_Table->RTEMS_api_configuration->maximum_periods ;
145
        i++ ) {
146
    the_usage = &Period_usage_Information[ i ];
147
    if ( the_usage->count == 0 )
148
      continue;
149
 
150
    the_period =
151
      (Rate_monotonic_Control *)_Rate_monotonic_Information.local_table[ i ];
152
 
153
    if ( the_period->owner )
154
      u32_name = *(unsigned32 *)the_period->owner->Object.name;
155
    else
156
      u32_name = rtems_build_name(' ', ' ', ' ', ' ');
157
 
158
    name[ 0 ] = (u32_name >> 24) & 0xff;
159
    name[ 1 ] = (u32_name >> 16) & 0xff;
160
    name[ 2 ] = (u32_name >>  8) & 0xff;
161
    name[ 3 ] = (u32_name >>  0) & 0xff;
162
    name[ 4 ] = '\0';
163
 
164
    printf(
165
      "0x%08x  %4s   %6d   %3d       %d/%d/%5.2f    %d/%d/%3.2f\n",
166
      the_usage->id,
167
      name,
168
      the_usage->count,
169
      the_usage->missed_count,
170
      the_usage->min_cpu_time,
171
      the_usage->max_cpu_time,
172
      (double) the_usage->total_cpu_time / (double) the_usage->count,
173
      the_usage->min_wall_time,
174
      the_usage->max_wall_time,
175
      (double) the_usage->total_wall_time / (double) the_usage->count
176
    );
177
  }
178
}

powered by: WebSVN 2.1.0

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