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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [include/] [test/] [stackmon.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_KERNEL_TEST_STACKMON_H
2
#define CYGONCE_KERNEL_TEST_STACKMON_H
3
 
4
/*=================================================================
5
//
6
//        stackmon.h
7
//
8
//        Auxiliary test header file
9
//
10
//==========================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//==========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):     hmt
46
// Contributors:  hmt
47
// Date:          1999-05-20
48
// Description:
49
//     Defines some convenience functions for stack use output.
50
// Note:
51
//     The functions are defined for both C and C++ usage - with different
52
//     argument types.
53
//
54
//####DESCRIPTIONEND####
55
*/
56
 
57
#include <pkgconf/system.h>
58
#include <pkgconf/hal.h>
59
#include <cyg/hal/hal_arch.h>
60
#include <cyg/hal/hal_intr.h>
61
#include <cyg/infra/cyg_type.h>
62
#ifdef CYGPKG_KERNEL
63
#include <pkgconf/kernel.h>
64
# if defined(CYGFUN_KERNEL_API_C)
65
#  include <cyg/kernel/kapi.h>
66
# endif
67
# if defined(__cplusplus)
68
#  include <cyg/kernel/sched.hxx>
69
#  include <cyg/kernel/thread.hxx>
70
#  include <cyg/kernel/thread.inl>
71
# endif
72
# include <cyg/kernel/smp.hxx>
73
#endif
74
 
75
#ifndef STACKMON_PRINTF
76
#include <cyg/infra/diag.h>
77
#define STACKMON_PRINTF diag_printf
78
#endif
79
 
80
// ------------------------------------------------------------------------
81
// Utility function for actually counting a stack
82
 
83
inline void cyg_test_size_a_stack( char *comment, char *format,
84
                                   char *base, char *top )
85
{
86
#ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
87
    cyg_uint32* cur32   = (cyg_uint32*) ((((CYG_ADDRWORD)&(base[CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE])) + 3) & ~3);
88
    cyg_uint32* top32   = (cyg_uint32*) ((((CYG_ADDRWORD)top) + 3) & ~3);
89
    for ( ; cur32 < top32; cur32++) {
90
        if (*cur32 != 0xDEADBEEF) {
91
            break;
92
        }
93
    }
94
    STACKMON_PRINTF( format, comment, (CYG_ADDRWORD)top32 - (CYG_ADDRWORD)cur32, top - base );
95
#else    
96
    register char *p;
97
    for ( p = base; p < top; p++ )
98
        if ( *p )
99
            break;
100
    STACKMON_PRINTF( format, comment, top - p, top - base );
101
#endif    
102
}
103
 
104
// ------------------------------------------------------------------------
105
 
106
inline void cyg_test_dump_stack_stats( char *comment,
107
                                       char *base, char *top )
108
{
109
    cyg_test_size_a_stack( comment, "%31s : stack used %5d size %5d\n",
110
                           base, top );
111
}
112
 
113
// ------------------------------------------------------------------------
114
 
115
#ifdef __cplusplus
116
 
117
inline void cyg_test_dump_thread_stack_stats( char *comment,
118
                                              Cyg_Thread *p )
119
{
120
#if defined(CYGPKG_KERNEL)
121
    char *base, *top;
122
    base = (char *)p->get_stack_base();
123
    top =   base + p->get_stack_size();
124
    cyg_test_dump_stack_stats( comment, base, top );
125
#endif
126
}
127
 
128
#else // __cplusplus
129
 
130
inline void cyg_test_dump_thread_stack_stats( char *comment,
131
                                              cyg_handle_t p )
132
{
133
#if defined(CYGPKG_KERNEL) && defined(CYGFUN_KERNEL_API_C)
134
    char *base, *top;
135
    base = (char *) cyg_thread_get_stack_base( p );
136
    top =   base + cyg_thread_get_stack_size( p );
137
    cyg_test_dump_stack_stats( comment, base, top );
138
#endif
139
}
140
 
141
#endif // __cplusplus
142
 
143
// ------------------------------------------------------------------------
144
// Print out size of idle thread stack usage since start-of-time.  Only
145
// meaningful if there is a scheduler.
146
 
147
#ifdef __cplusplus
148
 
149
inline void cyg_test_dump_idlethread_stack_stats( char *comment )
150
{
151
#if defined(CYGPKG_KERNEL)
152
    int i;
153
    extern Cyg_Thread idle_thread[CYGNUM_KERNEL_CPU_MAX];
154
    for( i = 0; i < CYGNUM_KERNEL_CPU_MAX; i++ )
155
    {
156
        // idle thread is not really a plain CygThread; danger.
157
        char *ibase  = (char *)idle_thread[i].get_stack_base();
158
        char *istack = ibase + idle_thread[i].get_stack_size();
159
        cyg_test_size_a_stack( comment,
160
                               "%20s : Idlethread stack used %5d size %5d\n",
161
                               ibase, istack );
162
    }
163
#endif
164
}
165
 
166
#else // __cplusplus
167
 
168
inline void cyg_test_dump_idlethread_stack_stats( char *comment )
169
{
170
#if defined(CYGPKG_KERNEL) && defined(CYGFUN_KERNEL_API_C)
171
    cyg_handle_t idle_thread = cyg_thread_idle_thread();
172
 
173
    char *ibase  = (char *)cyg_thread_get_stack_base( idle_thread );
174
    char *istack = ibase + cyg_thread_get_stack_size( idle_thread );
175
    cyg_test_size_a_stack( comment,
176
              "%20s : Idlethread stack used %5d size %5d\n",
177
              ibase, istack );
178
#endif
179
}
180
 
181
#endif // __cplusplus
182
 
183
// ------------------------------------------------------------------------
184
// Print out size of interrupt stack usage since start-of-time or since it
185
// was last cleared.  NB on some architectures and configurations, the
186
// interrupt stack is the same as the bootup stack, so clear it in the
187
// first first thread to execute.  Clearing it before scheduler start would
188
// be fatal!
189
 
190
#if defined(HAL_INTERRUPT_STACK_BASE) && defined(HAL_INTERRUPT_STACK_TOP)
191
externC char HAL_INTERRUPT_STACK_BASE[];
192
externC char HAL_INTERRUPT_STACK_TOP[];
193
#endif
194
 
195
inline void cyg_test_dump_interrupt_stack_stats( char *comment )
196
{
197
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
198
#if defined(HAL_INTERRUPT_STACK_BASE) && defined(HAL_INTERRUPT_STACK_TOP)
199
    cyg_test_size_a_stack( comment,
200
              "%20s :  Interrupt stack used %5d size %5d\n",
201
              HAL_INTERRUPT_STACK_BASE, HAL_INTERRUPT_STACK_TOP );
202
#endif
203
#endif
204
}
205
 
206
// Clear interrupt stack to reset stats - only after sched has started.
207
 
208
inline void cyg_test_clear_interrupt_stack( void )
209
{
210
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
211
#if defined(HAL_INTERRUPT_STACK_BASE) && defined(HAL_INTERRUPT_STACK_TOP)
212
    cyg_uint32  old_intr;
213
    HAL_DISABLE_INTERRUPTS(old_intr);
214
# ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
215
    {
216
        cyg_uint32* cur32   = (cyg_uint32*) ((((CYG_ADDRWORD)HAL_INTERRUPT_STACK_BASE) + 3) & ~3);
217
        cyg_uint32* top32   = (cyg_uint32*) ((((CYG_ADDRWORD)HAL_INTERRUPT_STACK_TOP) + 3) & ~3);
218
        for ( ; cur32 < top32; cur32++) {
219
            *cur32 = 0xDEADBEEF;
220
        }
221
    }
222
# else
223
    {
224
        register char *p;
225
        for ( p = HAL_INTERRUPT_STACK_BASE; p < HAL_INTERRUPT_STACK_TOP; p++ )
226
            *p = 0;                         // zero it for checking later
227
    }
228
# endif    
229
    HAL_RESTORE_INTERRUPTS(old_intr);
230
#endif
231
#endif
232
}
233
 
234
// ------------------------------------------------------------------------
235
 
236
#endif // ifndef CYGONCE_KERNEL_TEST_STACKMON_H
237
 
238
// EOF stackmon.h

powered by: WebSVN 2.1.0

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