comparison packages/kernel/current/include/stackmon.hxx @ 8:ece80412419a ecos-sw-1999-05-21

Merge from eCos master repository on 1999-05-21-22:05:54-BST
author jlarmour
date Fri, 21 May 1999 15:09:30 +0000
parents
children
comparison
equal deleted inserted replaced
7:e55593b6dcea 8:ece80412419a
1 #ifndef CYGONCE_KERNEL_TESTS_STACKMON_H
2 #define CYGONCE_KERNEL_TESTS_STACKMON_H
3
4 /*=================================================================
5 //
6 // stackmon.h
7 //
8 // Auxiliary test header file
9 //
10 //==========================================================================
11 //####COPYRIGHTBEGIN####
12 //
13 // -------------------------------------------
14 // The contents of this file are subject to the Cygnus eCos Public License
15 // Version 1.0 (the "License"); you may not use this file except in
16 // compliance with the License. You may obtain a copy of the License at
17 // http://sourceware.cygnus.com/ecos
18 //
19 // Software distributed under the License is distributed on an "AS IS"
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
21 // License for the specific language governing rights and limitations under
22 // the License.
23 //
24 // The Original Code is eCos - Embedded Cygnus Operating System, released
25 // September 30, 1998.
26 //
27 // The Initial Developer of the Original Code is Cygnus. Portions created
28 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved.
29 // -------------------------------------------
30 //
31 //####COPYRIGHTEND####
32 //==========================================================================
33 //#####DESCRIPTIONBEGIN####
34 //
35 // Author(s): hmt
36 // Contributors: hmt
37 // Date: 1999-05-20
38 // Description:
39 // Defines some convenience functions for stack use output.
40 //
41 //####DESCRIPTIONEND####
42 */
43
44 #include <pkgconf/system.h>
45 #include <pkgconf/hal.h>
46 #include <cyg/hal/hal_arch.h>
47 #include <cyg/hal/hal_intr.h>
48 #ifdef CYGPKG_KERNEL
49 #include <pkgconf/kernel.h>
50 #include <cyg/kernel/sched.hxx>
51 #include <cyg/kernel/thread.hxx>
52 #include <cyg/kernel/thread.inl>
53 #endif
54
55 #ifndef STACKMON_PRINTF
56 externC void diag_printf(const char *, ...);
57 #define STACKMON_PRINTF diag_printf
58 #endif
59
60 // ------------------------------------------------------------------------
61 // Utility function for actually counting a stack
62
63 inline void cyg_test_size_a_stack( char *comment, char *format,
64 char *base, char *top )
65 {
66 register char *p;
67 for ( p = base; p < top; p++ )
68 if ( *p )
69 break;
70 STACKMON_PRINTF( format, comment, top - p, top - base );
71 }
72
73 // ------------------------------------------------------------------------
74
75 inline void cyg_test_dump_stack_stats( char *comment,
76 char *base, char *top )
77 {
78 cyg_test_size_a_stack( comment, "%31s : stack used %5d size %5d\n",
79 base, top );
80 }
81
82 // ------------------------------------------------------------------------
83
84 inline void cyg_test_dump_thread_stack_stats( char *comment,
85 Cyg_Thread *p )
86 {
87 char *base, *top;
88 base = (char *)p->get_stack_base();
89 top = base + p->get_stack_size();
90 cyg_test_dump_stack_stats( comment, base, top );
91 }
92
93 // ------------------------------------------------------------------------
94 // Print out size of idle thread stack usage since start-of-time. Only
95 // meaningful if there is a scheduler.
96
97 inline void cyg_test_dump_idlethread_stack_stats( char *comment )
98 {
99 #ifdef CYGPKG_KERNEL
100 extern Cyg_Thread idle_thread;
101 // idle thread is not really a plain CygThread; danger.
102 char *ibase = (char *)idle_thread.get_stack_base();
103 char *istack = ibase + idle_thread.get_stack_size();
104 cyg_test_size_a_stack( comment,
105 "%20s : Idlethread stack used %5d size %5d\n",
106 ibase, istack );
107 #endif
108 }
109
110 // ------------------------------------------------------------------------
111 // Print out size of interrupt stack usage since start-of-time or since it
112 // was last cleared. NB on some architectures and configurations, the
113 // interrupt stack is the same as the bootup stack, so clear it in the
114 // first first thread to execute. Clearing it before scheduler start would
115 // be fatal!
116
117 inline void cyg_test_dump_interrupt_stack_stats( char *comment )
118 {
119 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
120 #ifdef HAL_INTERRUPT_STACK_BASE
121 #ifdef HAL_INTERRUPT_STACK_TOP
122 extern char HAL_INTERRUPT_STACK_BASE[];
123 extern char HAL_INTERRUPT_STACK_TOP[];
124 cyg_test_size_a_stack( comment,
125 "%20s : Interrupt stack used %5d size %5d\n",
126 HAL_INTERRUPT_STACK_BASE, HAL_INTERRUPT_STACK_TOP );
127 #endif
128 #endif
129 #endif
130 }
131
132 // Clear interrupt stack to reset stats - only after sched has started.
133 inline void cyg_test_clear_interrupt_stack( void )
134 {
135 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
136 #ifdef HAL_INTERRUPT_STACK_BASE
137 #ifdef HAL_INTERRUPT_STACK_TOP
138 cyg_uint32 old_intr;
139 extern char HAL_INTERRUPT_STACK_BASE[];
140 extern char HAL_INTERRUPT_STACK_TOP[];
141 register char *p;
142 HAL_DISABLE_INTERRUPTS(old_intr);
143 for ( p = HAL_INTERRUPT_STACK_BASE; p < HAL_INTERRUPT_STACK_TOP; p++ )
144 *p = 0; // zero it for checking later
145 HAL_RESTORE_INTERRUPTS(old_intr);
146 #endif
147 #endif
148 #endif
149 }
150
151 // ------------------------------------------------------------------------
152
153 #endif // ifndef CYGONCE_KERNEL_TESTS_STACKMON_H
154
155 // EOF stackmon.h