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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [src/] [instrmnt/] [meminst.cxx] - Blame information for rev 819

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      instrmnt/meminst.cxx
4
//
5
//      Memory buffer instrumentation functions
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):   nickg
43
// Contributors: nickg, andrew.lunn@ascom.ch
44
// Date:        1997-10-27
45
// Purpose:     Instrumentation functions
46
// Description: The functions in this file are implementations of the
47
//              standard instrumentation functions that place records
48
//              into a memory buffer.
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <pkgconf/kernel.h>
55
 
56
#include <cyg/kernel/ktypes.h>         // base kernel types
57
#include <cyg/infra/cyg_trac.h>        // tracing macros
58
#include <cyg/infra/cyg_ass.h>         // assertion macros
59
#include <cyg/kernel/instrmnt.h>       // instrumentation
60
 
61
#include <cyg/kernel/intr.hxx>         // interrupt control
62
#include <cyg/kernel/sched.hxx>        // scheduler defines
63
 
64
#include <cyg/kernel/sched.inl>        // scheduler inlines
65
#include <cyg/kernel/clock.inl>        // clock inlines
66
 
67
#ifdef CYGPKG_KERNEL_INSTRUMENT
68
 
69
// -------------------------------------------------------------------------
70
// Instrumentation record.
71
 
72
struct Instrument_Record
73
{
74
    CYG_WORD16  type;                   // record type
75
    CYG_WORD16  thread;                 // current thread id
76
    CYG_WORD    timestamp;              // 32 bit timestamp
77
    CYG_WORD    arg1;                   // first arg
78
    CYG_WORD    arg2;                   // second arg
79
};
80
 
81
// -------------------------------------------------------------------------
82
// Buffer base and end. This buffer must be a whole number of 
83
 
84
#ifdef CYGVAR_KERNEL_INSTRUMENT_EXTERNAL_BUFFER
85
 
86
externC Instrument_Record       instrument_buffer[];
87
externC cyg_uint32              instrument_buffer_size;
88
 
89
#else
90
 
91
extern "C"
92
{
93
 
94
Instrument_Record       instrument_buffer[CYGNUM_KERNEL_INSTRUMENT_BUFFER_SIZE];
95
 
96
cyg_uint32              instrument_buffer_size = CYGNUM_KERNEL_INSTRUMENT_BUFFER_SIZE;
97
 
98
};
99
 
100
#endif
101
 
102
extern "C"
103
{
104
 
105
#define instrument_buffer_start instrument_buffer[0]
106
#define instrument_buffer_end   instrument_buffer[instrument_buffer_size]
107
 
108
extern "C"
109
{
110
Instrument_Record       *instrument_buffer_pointer = &instrument_buffer_start;
111
};
112
 
113
#ifdef CYGDBG_KERNEL_INSTRUMENT_FLAGS
114
 
115
// This array contains a 32 bit word for each event class. The
116
// bits in the word correspond to events. By setting or clearing
117
// the appropriate bit, the selected instrumentation event may
118
// be enabled or disabled dynamically.
119
 
120
cyg_uint32 instrument_flags[(CYG_INSTRUMENT_CLASS_MAX>>8)+1];
121
 
122
#endif
123
 
124
};
125
 
126
// -------------------------------------------------------------------------
127
 
128
#ifdef CYGPKG_KERNEL_SMP_SUPPORT
129
 
130
HAL_SPINLOCK_TYPE instrument_lock = HAL_SPINLOCK_INIT_CLEAR;
131
 
132
#else
133
 
134
#define HAL_SPINLOCK_SPIN( __lock )
135
 
136
#define HAL_SPINLOCK_CLEAR( __lock )
137
 
138
#endif
139
 
140
// -------------------------------------------------------------------------
141
 
142
void cyg_instrument( cyg_uint32 type, CYG_ADDRWORD arg1, CYG_ADDRWORD arg2 )
143
{
144
 
145
    cyg_uint32 old_ints;
146
 
147
#ifdef CYGDBG_KERNEL_INSTRUMENT_FLAGS    
148
 
149
    cyg_ucount8 cl = (type>>8)&0xff;
150
    cyg_ucount8 event = type&0xff;
151
 
152
    if( instrument_flags[cl] & (1<<event) )
153
#endif        
154
    {
155
        HAL_DISABLE_INTERRUPTS(old_ints);
156
        HAL_SPINLOCK_SPIN( instrument_lock );
157
 
158
        Instrument_Record *p = instrument_buffer_pointer;
159
        Cyg_Thread *t = Cyg_Scheduler::get_current_thread();
160
        p->type             = type;
161
        p->thread           = (t==0)?0x0FFF:t->get_unique_id();
162
#ifdef CYGPKG_KERNEL_SMP_SUPPORT
163
        // Add CPU id to in top 4 bytes of thread id
164
        p->thread           = (p->thread&0x0FFF)|(CYG_KERNEL_CPU_THIS()<<12);
165
#endif        
166
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK        
167
//        p->timestamp        = Cyg_Clock::real_time_clock->current_value_lo();
168
        HAL_CLOCK_READ( &p->timestamp );
169
#else
170
        p->timestamp        = 0;
171
#endif
172
        p->arg1             = arg1;
173
        p->arg2             = arg2;
174
 
175
        p++;
176
#ifdef CYGDBG_KERNEL_INSTRUMENT_BUFFER_WRAP
177
        if( p == &instrument_buffer_end )
178
            instrument_buffer_pointer = &instrument_buffer_start;
179
        else instrument_buffer_pointer = p;
180
#else
181
        // when not wrapping, just continue to put further entries
182
        // in the last slot.
183
        if( p != &instrument_buffer_end )
184
            instrument_buffer_pointer = p;
185
#endif
186
        HAL_SPINLOCK_CLEAR( instrument_lock );
187
        HAL_RESTORE_INTERRUPTS(old_ints);
188
    }
189
 
190
    return;
191
}
192
 
193
// -------------------------------------------------------------------------
194
// Functions to enable and disable selected instrumentation events
195
// when the flags are enabled.
196
 
197
#ifdef CYGDBG_KERNEL_INSTRUMENT_FLAGS
198
 
199
externC void cyg_instrument_enable( cyg_uint32 cl, cyg_uint32 event)
200
{
201
    if( 0 != event )
202
        instrument_flags[cl>>8] |= 1<<event;
203
    else
204
        instrument_flags[cl>>8] = ~0;
205
}
206
 
207
externC void cyg_instrument_disable( cyg_uint32 cl, cyg_uint32 event)
208
{
209
    if( 0 != event )
210
        instrument_flags[cl>>8] &= ~(1<<event);
211
    else
212
        instrument_flags[cl>>8] = 0;
213
 
214
}
215
 
216
externC cyg_bool cyg_instrument_state( cyg_uint32 cl, cyg_uint32 event)
217
{
218
    return (instrument_flags[cl>>8] & (1<<event)) != 0;
219
}
220
 
221
#endif
222
 
223
// -------------------------------------------------------------------------
224
 
225
#ifdef CYGDBG_KERNEL_INSTRUMENT_MSGS
226
#define CYGDBG_KERNEL_INSTRUMENT_MSGS_DEFINE_TABLE
227
#include <cyg/kernel/instrument_desc.h>
228
 
229
externC char * cyg_instrument_msg(CYG_WORD16 type) {
230
 
231
  struct instrument_desc_s *record;
232
  struct instrument_desc_s *end_record;
233
  CYG_WORD cl, event;
234
 
235
  record = instrument_desc;
236
  end_record = &instrument_desc[CYG_NELEM(instrument_desc)-1];
237
  cl = type & 0xff00;
238
  event = type & 0x00ff;
239
 
240
  while ((record != end_record) && (record->num != cl)) {
241
    record++;
242
  }
243
 
244
  if (record->num == cl) {
245
    record++;
246
    while ((record != end_record) && (record->num != event) &&
247
           (record->num < 0xff)) {
248
      record++;
249
    }
250
 
251
    if (record->num == event) {
252
      return (record->msg);
253
    }
254
  }
255
  return("Unknown event");
256
}
257
#endif // CYGDBG_KERNEL_INSTRUMENT_MSGS
258
#endif // CYGPKG_KERNEL_INSTRUMENT
259
 
260
// EOF instrmnt/meminst.cxx

powered by: WebSVN 2.1.0

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