/*************************************************************************** * Copyright (c) 2006-2007, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: btrc.c $ * $brcm_Revision: 3 $ * $brcm_Date: 1/15/07 10:50a $ * * Module Description: * * Perfomance counter module * * Revision History: * * $brcm_Log: /BSEAV/lib/bprofile/btrc.c $ * * 3 1/15/07 10:50a vsilyaev * PR 25997: Added 7038 performance counters * * 2 12/8/06 7:21p vsilyaev * PR 25997: Fixed warning * * 1 12/5/06 11:07a vsilyaev * PR 25997: BTRC system level tracing * * *******************************************************************************/ #include "bstd.h" #include "btrc.h" #include "bkni.h" BDBG_MODULE(btrc); void BTRC_P_DoTrace(unsigned event_, unsigned data) { unsigned chn = 0; struct BTRC_P_Stats *stats = &((BTRC_Module *)(event_ & (~0x3)))->stats[chn]; BTRC_P_Sample sample; unsigned i; BSTD_UNUSED(data); switch((event_)&0x3) { case BTRC_P_Event_COUNT: break; case BTRC_P_Event_START: b_perf_read(&stats->last.perf); break; case BTRC_P_Event_STOP: b_perf_read(&sample.perf); for(i=0;ilast.perf.data[i]); if (stats->count==0) { stats->max.perf.data[i] = val; stats->min.perf.data[i] = val; stats->total.perf.data[i] = val; } else { if (val > stats->max.perf.data[i]) { stats->max.perf.data[i] = val; } else if (val < stats->min.perf.data[i]) { stats->min.perf.data[i] = val; } stats->total.perf.data[i] += val; } } stats->count ++; break; } return; } void BTRC_Module_Report(const BTRC_Module *module) { const bperf_counter_mode *mode = bperf_get_mode(); unsigned chn = 0; const struct BTRC_P_Stats *stats = &module->stats[chn]; unsigned i; BDBG_ASSERT(module); BDBG_ASSERT(mode); BKNI_Printf("module %s %u samples\n", module->name, stats->count); if (stats->count==0) { return; } BKNI_Printf("%8c ", ' '); for(i=0;icounter_names[i]); } BKNI_Printf("\n%8s ", "total"); for(i=0;itotal.perf.data[i]); } BKNI_Printf("\n%8s ", "average"); for(i=0;itotal.perf.data[i]/stats->count); } BKNI_Printf("\n%8s ", "max"); for(i=0;imax.perf.data[i]); } BKNI_Printf("\n%8s ", "min"); for(i=0;imin.perf.data[i]); } BKNI_Printf("\n"); return; } void BTRC_Module_Register(BTRC_Module *module, BTRC_ModuleList *list) { BTRC_Module *next; /* check if there is a duplicated */ for(next= BLST_S_FIRST(list); next ; next = BLST_S_NEXT(next, link)) { if (next==module) { break; } } if (next==NULL) { /* no module was found add a new one */ BLST_S_INSERT_HEAD(list, module, link); } return; } void BTRC_Module_Reset(BTRC_Module *module) { unsigned chn = 0; struct BTRC_P_Stats *stats = &module->stats[chn]; BDBG_ASSERT(module); stats->count = 0; return; } void BTRC_List_Init(BTRC_ModuleList *list) { BDBG_ASSERT(list); BLST_S_INIT(list); return; } void BTRC_List_Report(BTRC_ModuleList *list) { const BTRC_Module *module; /* check if there is a duplicated */ for(module=BLST_S_FIRST(list); module ; module = BLST_S_NEXT(module, link)) { BTRC_Module_Report(module); } } void BTRC_Module_Enable(BTRC_Module *module, bool enable) { BDBG_ASSERT(module); module->b_trc_enable = enable; return; }