From aa7c21cd23ca7686a8ce38061ea224005617d01f Mon Sep 17 00:00:00 2001 From: Monte Copeland Date: Wed, 7 Dec 2011 10:55:21 -0600 Subject: Configurable trace buffer sizes. Change-Id: I6b1616da00cc6f30b2e6bade5011a3a2869b4660 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/571 Tested-by: Jenkins Server Reviewed-by: Monte K. Copeland --- img/.gitignore | 1 + src/build/debug/Hostboot/Trace.pm | 21 ++-- src/include/usr/trace/trace.H | 19 +++- src/usr/errl/errlentry.C | 22 ++-- src/usr/trace/trace.C | 228 ++++++++++++++++++-------------------- 5 files changed, 144 insertions(+), 147 deletions(-) diff --git a/img/.gitignore b/img/.gitignore index aca92100f..efafc8614 100644 --- a/img/.gitignore +++ b/img/.gitignore @@ -12,3 +12,4 @@ hbotStringFile *.toc errlparser +*.csv diff --git a/src/build/debug/Hostboot/Trace.pm b/src/build/debug/Hostboot/Trace.pm index 347e88e76..c80c1985c 100755 --- a/src/build/debug/Hostboot/Trace.pm +++ b/src/build/debug/Hostboot/Trace.pm @@ -28,10 +28,10 @@ package Hostboot::Trace; use Exporter; our @EXPORT_OK = ('main'); -use constant MAX_NUM_TRACE_BUFFERS => 24; -use constant DESC_ARRAY_ENTRY_ADDR_SIZE => 8; -use constant DESC_ARRAY_ENTRY_COMP_NAME_SIZE => 16; -use constant TRAC_DEFAULT_BUFFER_SIZE => 0x0800; +use constant MAX_NUM_TRACE_BUFFERS => 48; +use constant DESC_ARRAY_ENTRY_SIZE => 24; +use constant OFFSET_TRAC_BUFFER_SIZE => 20; +use constant OFFSET_BUFFER_ADDRESS => 16; use File::Temp ('tempfile'); @@ -62,19 +62,24 @@ sub main for (my $i = 0; $i < MAX_NUM_TRACE_BUFFERS; $i++) { + # component name is first in g_desc_array[$i] my $compName = ::readStr($symAddr); last if ($compName eq ""); - $symAddr += DESC_ARRAY_ENTRY_COMP_NAME_SIZE; + # get the pointer to its trace buffer + my $buffAddr = ::read64($symAddr + OFFSET_BUFFER_ADDRESS); - my $buffAddr = ::read64($symAddr); - $symAddr += DESC_ARRAY_ENTRY_ADDR_SIZE; + # get the size of this trace buffer + my $buffSize = ::read32($buffAddr + OFFSET_TRAC_BUFFER_SIZE); if ((not defined $traceBuffers) or (uc($traceBuffers) =~ m/$compName/)) { $foundBuffer = 1; - print $fh (::readData($buffAddr, TRAC_DEFAULT_BUFFER_SIZE)); + print $fh (::readData($buffAddr, $buffSize )); } + + # increment to next item in g_desc_array[] + $symAddr += DESC_ARRAY_ENTRY_SIZE; } if ($foundBuffer) diff --git a/src/include/usr/trace/trace.H b/src/include/usr/trace/trace.H index 6450a42a1..ccc3449f0 100644 --- a/src/include/usr/trace/trace.H +++ b/src/include/usr/trace/trace.H @@ -149,7 +149,12 @@ public: static Trace& getTheInstance(); /** - * @brief Initialize a trace buffer + * @brief Initialize a trace buffer. + * + * Size is capped at 2KB. You can request larger, but + * the code in src/usr/trace/trace.C imposes + * a maximum size of 2KB. Sizes smaller than 2KB + * will save space. * * @param [out] o_td Trace descriptor to initialize * @param [in] i_comp Component name for trace buffer @@ -159,7 +164,7 @@ public: */ void initBuffer(trace_desc_t **o_td, const char* i_comp, - const size_t i_size ); + size_t i_size ); /** * @brief Write component trace out to input buffer @@ -261,13 +266,15 @@ private: * trace buffer. * * @param [out] o_buf Trace descriptor of component buffer to initialize. - * @param [in] i_comp Component name + * @param [in] i_comp Component name + * @param [in] i_size Size of buffer * * @return void * */ void initValuesBuffer(trace_desc_t *o_buf, - const char *i_comp); + const char *i_comp, + size_t i_size); /** @@ -308,11 +315,11 @@ private: /** * @brief Reset all trace buffers * - * TODO - Not Supported Yet + * TODO - Not Supported, may have no need in Hostboot for it. * * @return Non-zero return code on error */ - int32_t resetBuf(void); + // int32_t resetBuf(void); /** * @brief Convert timestamp diff --git a/src/usr/errl/errlentry.C b/src/usr/errl/errlentry.C index 5c7c39a83..a4e8c6669 100644 --- a/src/usr/errl/errlentry.C +++ b/src/usr/errl/errlentry.C @@ -45,7 +45,7 @@ namespace ERRORLOG // Trace definition trace_desc_t* g_trac_errl = NULL; -TRAC_INIT(&g_trac_errl, "ERRL", 4096); +TRAC_INIT(&g_trac_errl, "ERRL", 1024); /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// @@ -80,7 +80,7 @@ ErrlEntry::ErrlEntry(const errlSeverity_t i_sev, if( NULL == ffdcPtr ) { TRACFCOMP( g_trac_errl, - ERR_MRK"NULL FFDC pointer!" ); + ERR_MRK"NULL FFDC pointer" ); break; } } @@ -122,7 +122,7 @@ ErrlUD * ErrlEntry::addFFDC(const compId_t i_compId, if ( (i_dataPtr == NULL) || (i_ffdcLen == 0) ) { TRACFCOMP( g_trac_errl, - "ErrlEntry::addFFDC(): Invalid FFDC data pointer or size, no add"); + ERR_MRK"ErrlEntry::addFFDC(): Invalid FFDC data pointer or size, no add"); } else { @@ -156,7 +156,7 @@ void ErrlEntry::appendToFFDC(ErrlUD * i_pErrlUD, l_rc = i_pErrlUD->addData( i_dataPtr, i_dataLen ); if( 0 == l_rc ) { - TRACFCOMP( g_trac_errl, "ErrlEntry::appendToFFDC() rets zero" ); + TRACFCOMP( g_trac_errl, ERR_MRK"ErrlEntry::appendToFFDC() rets zero" ); } return; } @@ -182,7 +182,7 @@ bool ErrlEntry::collectTrace(const char i_name[], const uint64_t i_max) { // Problem, likely unknown trace buffer name. TRACFCOMP( g_trac_errl, - "ErrlEntry::collectTrace(): getBuffer(%s) rets zero.",i_name); + ERR_MRK"ErrlEntry::collectTrace(): getBuffer(%s) rets zero.",i_name); break; } @@ -210,7 +210,7 @@ bool ErrlEntry::collectTrace(const char i_name[], const uint64_t i_max) { // Problem. TRACFCOMP( g_trac_errl, - "ErrlEntry::collectTrace(): getBuffer(%s,%ld) rets zero.", + ERR_MRK"ErrlEntry::collectTrace(): getBuffer(%s,%ld) rets zero.", i_name, l_cbBuffer ); break; @@ -338,7 +338,7 @@ uint64_t ErrlEntry::flatten( void * o_pBuffer, uint64_t i_bufsize ) if ( i_bufsize < l_flatCount ) { // buffer is not big enough; return zero - TRACFCOMP( ERRORLOG::g_trac_errl, "Invalid buffer size"); + TRACFCOMP( ERRORLOG::g_trac_errl, ERR_MRK"Invalid buffer size"); l_flatCount = 0; break; } @@ -362,7 +362,7 @@ uint64_t ErrlEntry::flatten( void * o_pBuffer, uint64_t i_bufsize ) if( 0 == l_cb ) { // Rare. - TRACFCOMP( g_trac_errl, "ph.flatten error"); + TRACFCOMP( g_trac_errl, ERR_MRK"ph.flatten error"); l_flatCount = 0; break; } @@ -375,7 +375,7 @@ uint64_t ErrlEntry::flatten( void * o_pBuffer, uint64_t i_bufsize ) if( 0 == l_cb ) { // Rare. - TRACFCOMP( g_trac_errl, "uh.flatten error"); + TRACFCOMP( g_trac_errl, ERR_MRK"uh.flatten error"); l_flatCount = 0; break; } @@ -387,7 +387,7 @@ uint64_t ErrlEntry::flatten( void * o_pBuffer, uint64_t i_bufsize ) if( 0 == l_cb ) { // Rare. - TRACFCOMP( g_trac_errl, "ps.flatten error"); + TRACFCOMP( g_trac_errl, ERR_MRK"ps.flatten error"); l_flatCount = 0; break; } @@ -403,7 +403,7 @@ uint64_t ErrlEntry::flatten( void * o_pBuffer, uint64_t i_bufsize ) if( 0 == l_cb ) { // Rare. - TRACFCOMP( g_trac_errl, "ud.flatten error"); + TRACFCOMP( g_trac_errl, ERR_MRK"ud.flatten error"); l_flatCount = 0; break; } diff --git a/src/usr/trace/trace.C b/src/usr/trace/trace.C index 14a8451bf..bb3ca81e5 100644 --- a/src/usr/trace/trace.C +++ b/src/usr/trace/trace.C @@ -71,28 +71,41 @@ const uint32_t TRAC_TIME_REAL = 0; // upper 32 = seconds, lower 32 = microsec const uint32_t TRAC_TIME_50MHZ = 1; const uint32_t TRAC_TIME_200MHZ = 2; const uint32_t TRAC_TIME_167MHZ = 3; // 166666667Hz -const uint32_t COMP_NAME_SIZE = 16; // NULL terminated string -// Initial implementation is to allocate a fixed 2KB buffer to each -// component on request. -// NOTE: any change to this value will require change to Trace::initBuffer() -const uint64_t TRAC_DEFAULT_BUFFER_SIZE = 0x0800; //2KB -// NOTE: This constant should only be changed to an even number for now. -// Same reason as above. -const uint64_t TRAC_MAX_NUM_BUFFERS = 24; + +// WARNING: Changing the size of the trace buffer name string requires a +// changing OFFSET_BUFFER_ADDRESS in src/build/debug/Hostboot/Trace.pm. +const uint32_t COMP_NAME_SIZE = 16; // includes NULL terminator, so 15 max + + +// Settings for the default buffer. Name must be upper case. const char * const TRAC_DEFAULT_BUFFER_NAME = "DEFAULT"; +const uint64_t TRAC_DEFAULT_BUFFER_SIZE = 0x0800; //2KB + -// Global component trace buffer array. Initially allow for 24 buffers max. -// Keep global so it can be found in syms file -typedef struct trace_desc_array { +// The number of trace buffers. +// NOTE: This constant should only be changed to an even number for now. +// WARNING: Changing the count of buffers requires a co-req change +// in src/build/debug/Hostboot/Trace.pm which has this count hard coded. +const uint64_t TRAC_MAX_NUM_BUFFERS = 48; + +// An array of these structs accounts for all the trace buffers in Hostboot. +// WARNING: Changing the size of trace_desc_array requires a co-req change +// in src/build/debug/Hostboot/Trace.pm which has hard-coded the size of +// this structure. +typedef struct trace_desc_array +{ char comp[COMP_NAME_SIZE]; // the buffer name trace_desc_t * td_entry; // pointer to the buffer }trace_desc_array_t; +// Global: found in syms file and thus the dump. trace_desc_array_t g_desc_array[TRAC_MAX_NUM_BUFFERS]; + + /******************************************************************************/ // TracInit::TracInit() /******************************************************************************/ @@ -124,7 +137,8 @@ Trace::Trace() { mutex_init(&iv_trac_mutex); - memset(g_desc_array, 0, sizeof(g_desc_array)); + // compiler inits global vars to zero + // memset(g_desc_array, 0, sizeof(g_desc_array)); } /******************************************************************************/ @@ -139,160 +153,129 @@ Trace::~Trace() /******************************************************************************/ // trace_adal_init_buffer /******************************************************************************/ -void Trace::initBuffer(trace_desc_t **o_td, const char* i_comp, - const size_t i_size ) +void Trace::initBuffer( trace_desc_t **o_td, + const char* i_comp, + size_t i_size ) { /*------------------------------------------------------------------------*/ /* Local Variables */ /*------------------------------------------------------------------------*/ - uint32_t i = 0; - char * l_td = NULL; + unsigned int i = 0; char l_comp[COMP_NAME_SIZE] = {'\0'}; /*------------------------------------------------------------------------*/ /* Code */ /*------------------------------------------------------------------------*/ - if(*o_td == NULL) - { - // Limit component name to 15 characters. - // Too bad we don't have strncpy(), strncmp() - if (strlen(i_comp) > (COMP_NAME_SIZE -1)) - { - memcpy(l_comp, i_comp, COMP_NAME_SIZE - 1); - } - else - { - strcpy(l_comp, i_comp); - } - - // make string upper case - strupr(l_comp); - // CRITICAL REGION START - mutex_lock(&iv_trac_mutex); - // Search through the descriptor array for the first unallocated buffer. - // The last buffer is the reserved default buffer for any component - // which didn't get its own buffer. - for (i = 0; i < (TRAC_MAX_NUM_BUFFERS - 1); i++) - { - if(!strcmp(l_comp, g_desc_array[i].comp)) - { - //printk("Trace::initBuffer - buffer already allocated %d\n", i); - - // Buffer is already allocated. Return the buffer. - *o_td = g_desc_array[i].td_entry; - - break; - } - else if (strlen(g_desc_array[i].comp) == 0) - { - //printk("Trace::initBuffer - found unallocated buffer %d\n", i); - - // Found the first unallocated buffer; use this one. - - // Set the component name for the buffer - strcpy(g_desc_array[i].comp, l_comp); + // Limit buffer sizes to 2KB + if( i_size > TRAC_DEFAULT_BUFFER_SIZE ) + { + i_size = TRAC_DEFAULT_BUFFER_SIZE; + } - // Allocate memory if needed - if (NULL == g_desc_array[i].td_entry) - { - //printk("Trace::initBuffer - allocate memory\n"); + // Limit component name to 15 characters. + if (strlen(i_comp) > (COMP_NAME_SIZE -1)) + { + memcpy(l_comp, i_comp, COMP_NAME_SIZE - 1); + } + else + { + strcpy(l_comp, i_comp); + } - // Allocate memory - // TODO can't handle i_size yet - everything is coded - // around TRAC_DEFAULT_BUFFER_SIZE - l_td = static_cast(malloc(TRAC_DEFAULT_BUFFER_SIZE)); + // Store buffer name internally in upper case + strupr(l_comp); - g_desc_array[i].td_entry = - reinterpret_cast(l_td); + // CRITICAL REGION START + mutex_lock(&iv_trac_mutex); - } + // Search through the descriptor array for the first unallocated buffer. + // The last buffer is the reserved default buffer for any component + // which didn't get its own buffer. + for (i = 0; i < (TRAC_MAX_NUM_BUFFERS - 1); i++) + { + if( 0 == strcmp(l_comp, g_desc_array[i].comp)) + { + // Buffer is already allocated for the given buffer name. + // Return the pointer to the buffer. + *o_td = g_desc_array[i].td_entry; + break; + } + else if ( '\0' == g_desc_array[i].comp[0] ) + { + // Found an unallocated buffer; use this one. + // Set the component name for the buffer + strcpy(g_desc_array[i].comp, l_comp); - // Initialize the buffer header - initValuesBuffer(g_desc_array[i].td_entry, - g_desc_array[i].comp); + // Allocate memory for the trace buffer. + *o_td = g_desc_array[i].td_entry = + reinterpret_cast(malloc(i_size)); - // Return the newly allocated buffer - *o_td = g_desc_array[i].td_entry; + // Initialize the trace buffer. + initValuesBuffer( g_desc_array[i].td_entry, + g_desc_array[i].comp, + i_size ); - break; - } + break; } + } - if ((TRAC_MAX_NUM_BUFFERS - 1) == i) + + if ((TRAC_MAX_NUM_BUFFERS - 1) == i) + { + // We're out of buffers to allocate. + // Use the default buffer reserved for everyone else. + // Initialize only once + if ( '\0' == g_desc_array[i].comp[0] ) { - //printk("Trace::initBuffer - allocate default buffer %d\n", i); + // Set the component name for the buffer + strcpy(g_desc_array[i].comp, TRAC_DEFAULT_BUFFER_NAME); - // We're out of buffers to allocate. - // Use the default buffer reserved for everyone else. - // Initialize only once - if (strlen(g_desc_array[i].comp) == 0) - { - // Set the component name for the buffer - strcpy(g_desc_array[i].comp, TRAC_DEFAULT_BUFFER_NAME); - - // Allocate memory if needed - // Memory should have already been reserved if - // TRAC_MAX_NUM_BUFFERS is an even # and we're using - // PageManager::allocatePage(). Add check just in - // case TRAC_MAC_NUM_BUFFERS is set to an odd number. - if (NULL == g_desc_array[i].td_entry) - { - //printk("Trace::initBuffer - allocate memory\n"); - - // Allocate memory for buffer - l_td = static_cast(malloc(TRAC_DEFAULT_BUFFER_SIZE)); - - g_desc_array[i].td_entry = - reinterpret_cast(l_td); - } - - // Initialize the buffer header - initValuesBuffer(g_desc_array[i].td_entry, - g_desc_array[i].comp); - } + // Allocate memory for buffer + g_desc_array[i].td_entry = + reinterpret_cast(malloc(TRAC_DEFAULT_BUFFER_SIZE)); - // Return the default buffer - *o_td = g_desc_array[i].td_entry; + // Initialize the buffer header + initValuesBuffer(g_desc_array[i].td_entry, + g_desc_array[i].comp, + TRAC_DEFAULT_BUFFER_SIZE); } - mutex_unlock(&iv_trac_mutex); - // CRITICAL REGION END - + // Return the default buffer + *o_td = g_desc_array[i].td_entry; } + mutex_unlock(&iv_trac_mutex); + // CRITICAL REGION END + return; } /******************************************************************************/ // initValuesBuffer /******************************************************************************/ -void Trace::initValuesBuffer(trace_desc_t *o_buf,const char *i_comp) +void Trace::initValuesBuffer( trace_desc_t *o_buf, + const char *i_comp, + size_t i_size ) { - /*------------------------------------------------------------------------*/ - /* Local Variables */ - /*------------------------------------------------------------------------*/ - - /*------------------------------------------------------------------------*/ - /* Code */ - /*------------------------------------------------------------------------*/ - // Initialize it to all 0's - memset(o_buf,0,(size_t)TRAC_DEFAULT_BUFFER_SIZE); + memset(o_buf,0,i_size); o_buf->ver = TRACE_BUF_VERSION; o_buf->hdr_len = sizeof(trace_buf_head_t); o_buf->time_flg = TRAC_TIME_REAL; o_buf->endian_flg = 'B'; // Big Endian strcpy(o_buf->comp,i_comp); - o_buf->size = TRAC_DEFAULT_BUFFER_SIZE; + o_buf->size = i_size; o_buf->times_wrap = 0; o_buf->next_free = sizeof(trace_buf_head_t); return; } + + /******************************************************************************/ // trace_adal_write_all /******************************************************************************/ @@ -1149,7 +1132,7 @@ uint64_t Trace::getBuffer( const char * i_pComp, - +#if 0 /******************************************************************************/ // resetBuf - TODO /******************************************************************************/ @@ -1167,7 +1150,7 @@ int32_t Trace::resetBuf() /*------------------------------------------------------------------------*/ // Get mutex so no one traces -#if 0 + // TODO l_rc = UTIL_MUTEX_GET(&iv_trac_mutex,TRAC_INTF_MUTEX_TIMEOUT); if(l_rc != TX_SUCCESS) @@ -1192,12 +1175,13 @@ int32_t Trace::resetBuf() } } -#endif + // Always try to release even if fail above // TODO - mutex //UTIL_MUTEX_PUT(&iv_trac_mutex); return(l_rc); } +#endif } // namespace -- cgit v1.2.1