Mercurial > flash_v2
comparison packages/kernel/current/include/test/stackmon.h @ 10:d3fbcdfa1b2f ecos-sw-1999-05-29
Merge from eCos master repository on 1999-05-29-00:13:11-BST
| author | jlarmour |
|---|---|
| date | Fri, 28 May 1999 16:43:09 +0000 |
| parents | |
| children | c38311975d4f |
comparison
equal
deleted
inserted
replaced
| 9:95cc44ea0068 | 10:d3fbcdfa1b2f |
|---|---|
| 1 #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 //####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 // Note: | |
| 41 // The functions are defined for both C and C++ usage - with different | |
| 42 // argument types. | |
| 43 // | |
| 44 //####DESCRIPTIONEND#### | |
| 45 */ | |
| 46 | |
| 47 #include <pkgconf/system.h> | |
| 48 #include <pkgconf/hal.h> | |
| 49 #include <cyg/hal/hal_arch.h> | |
| 50 #include <cyg/hal/hal_intr.h> | |
| 51 #include <cyg/infra/cyg_type.h> | |
| 52 #ifdef CYGPKG_KERNEL | |
| 53 #include <pkgconf/kernel.h> | |
| 54 # if defined(CYGFUN_KERNEL_API_C) | |
| 55 # include <cyg/kernel/kapi.h> | |
| 56 # endif | |
| 57 # if defined(__cplusplus) | |
| 58 # include <cyg/kernel/sched.hxx> | |
| 59 # include <cyg/kernel/thread.hxx> | |
| 60 # include <cyg/kernel/thread.inl> | |
| 61 # endif | |
| 62 #endif | |
| 63 | |
| 64 #ifndef STACKMON_PRINTF | |
| 65 externC void diag_printf(const char *, ...); | |
| 66 #define STACKMON_PRINTF diag_printf | |
| 67 #endif | |
| 68 | |
| 69 // ------------------------------------------------------------------------ | |
| 70 // Utility function for actually counting a stack | |
| 71 | |
| 72 inline void cyg_test_size_a_stack( char *comment, char *format, | |
| 73 char *base, char *top ) | |
| 74 { | |
| 75 register char *p; | |
| 76 for ( p = base; p < top; p++ ) | |
| 77 if ( *p ) | |
| 78 break; | |
| 79 STACKMON_PRINTF( format, comment, top - p, top - base ); | |
| 80 } | |
| 81 | |
| 82 // ------------------------------------------------------------------------ | |
| 83 | |
| 84 inline void cyg_test_dump_stack_stats( char *comment, | |
| 85 char *base, char *top ) | |
| 86 { | |
| 87 cyg_test_size_a_stack( comment, "%31s : stack used %5d size %5d\n", | |
| 88 base, top ); | |
| 89 } | |
| 90 | |
| 91 // ------------------------------------------------------------------------ | |
| 92 | |
| 93 #ifdef __cplusplus | |
| 94 | |
| 95 inline void cyg_test_dump_thread_stack_stats( char *comment, | |
| 96 Cyg_Thread *p ) | |
| 97 { | |
| 98 #if defined(CYGPKG_KERNEL) | |
| 99 char *base, *top; | |
| 100 base = (char *)p->get_stack_base(); | |
| 101 top = base + p->get_stack_size(); | |
| 102 cyg_test_dump_stack_stats( comment, base, top ); | |
| 103 #endif | |
| 104 } | |
| 105 | |
| 106 #else // __cplusplus | |
| 107 | |
| 108 inline void cyg_test_dump_thread_stack_stats( char *comment, | |
| 109 cyg_handle_t p ) | |
| 110 { | |
| 111 #if defined(CYGPKG_KERNEL) && defined(CYGFUN_KERNEL_API_C) | |
| 112 char *base, *top; | |
| 113 base = (char *) cyg_thread_get_stack_base( p ); | |
| 114 top = base + cyg_thread_get_stack_size( p ); | |
| 115 cyg_test_dump_stack_stats( comment, base, top ); | |
| 116 #endif | |
| 117 } | |
| 118 | |
| 119 #endif // __cplusplus | |
| 120 | |
| 121 // ------------------------------------------------------------------------ | |
| 122 // Print out size of idle thread stack usage since start-of-time. Only | |
| 123 // meaningful if there is a scheduler. | |
| 124 | |
| 125 #ifdef __cplusplus | |
| 126 | |
| 127 inline void cyg_test_dump_idlethread_stack_stats( char *comment ) | |
| 128 { | |
| 129 #if defined(CYGPKG_KERNEL) | |
| 130 extern Cyg_Thread idle_thread; | |
| 131 // idle thread is not really a plain CygThread; danger. | |
| 132 char *ibase = (char *)idle_thread.get_stack_base(); | |
| 133 char *istack = ibase + idle_thread.get_stack_size(); | |
| 134 cyg_test_size_a_stack( comment, | |
| 135 "%20s : Idlethread stack used %5d size %5d\n", | |
| 136 ibase, istack ); | |
| 137 #endif | |
| 138 } | |
| 139 | |
| 140 #else // __cplusplus | |
| 141 | |
| 142 inline void cyg_test_dump_idlethread_stack_stats( char *comment ) | |
| 143 { | |
| 144 #if defined(CYGPKG_KERNEL) && defined(CYGFUN_KERNEL_API_C) | |
| 145 cyg_handle_t idle_thread = cyg_thread_idle_thread(); | |
| 146 | |
| 147 char *ibase = (char *)cyg_thread_get_stack_base( idle_thread ); | |
| 148 char *istack = ibase + cyg_thread_get_stack_size( idle_thread ); | |
| 149 cyg_test_size_a_stack( comment, | |
| 150 "%20s : Idlethread stack used %5d size %5d\n", | |
| 151 ibase, istack ); | |
| 152 #endif | |
| 153 } | |
| 154 | |
| 155 #endif // __cplusplus | |
| 156 | |
| 157 // ------------------------------------------------------------------------ | |
| 158 // Print out size of interrupt stack usage since start-of-time or since it | |
| 159 // was last cleared. NB on some architectures and configurations, the | |
| 160 // interrupt stack is the same as the bootup stack, so clear it in the | |
| 161 // first first thread to execute. Clearing it before scheduler start would | |
| 162 // be fatal! | |
| 163 | |
| 164 #if defined(HAL_INTERRUPT_STACK_BASE) && defined(HAL_INTERRUPT_STACK_TOP) | |
| 165 externC char HAL_INTERRUPT_STACK_BASE[]; | |
| 166 externC char HAL_INTERRUPT_STACK_TOP[]; | |
| 167 #endif | |
| 168 | |
| 169 inline void cyg_test_dump_interrupt_stack_stats( char *comment ) | |
| 170 { | |
| 171 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK | |
| 172 #if defined(HAL_INTERRUPT_STACK_BASE) && defined(HAL_INTERRUPT_STACK_TOP) | |
| 173 cyg_test_size_a_stack( comment, | |
| 174 "%20s : Interrupt stack used %5d size %5d\n", | |
| 175 HAL_INTERRUPT_STACK_BASE, HAL_INTERRUPT_STACK_TOP ); | |
| 176 #endif | |
| 177 #endif | |
| 178 } | |
| 179 | |
| 180 // Clear interrupt stack to reset stats - only after sched has started. | |
| 181 | |
| 182 inline void cyg_test_clear_interrupt_stack( void ) | |
| 183 { | |
| 184 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK | |
| 185 #if defined(HAL_INTERRUPT_STACK_BASE) && defined(HAL_INTERRUPT_STACK_TOP) | |
| 186 cyg_uint32 old_intr; | |
| 187 register char *p; | |
| 188 HAL_DISABLE_INTERRUPTS(old_intr); | |
| 189 for ( p = HAL_INTERRUPT_STACK_BASE; p < HAL_INTERRUPT_STACK_TOP; p++ ) | |
| 190 *p = 0; // zero it for checking later | |
| 191 HAL_RESTORE_INTERRUPTS(old_intr); | |
| 192 #endif | |
| 193 #endif | |
| 194 } | |
| 195 | |
| 196 // ------------------------------------------------------------------------ | |
| 197 | |
| 198 #endif // ifndef CYGONCE_KERNEL_TEST_STACKMON_H | |
| 199 | |
| 200 // EOF stackmon.h |
