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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [include/] [test/] [stackmon.h] - Blame information for rev 27

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

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

powered by: WebSVN 2.1.0

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