/*************************************************************************** * 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: bprofile_tick.h $ * $brcm_Revision: 10 $ * $brcm_Date: 1/15/07 10:50a $ * * Module Description: * * Embeddeble profiler library * Data acquisition module * * Revision History: * * $brcm_Log: /BSEAV/lib/bprofile/bprofile_tick.h $ * * 10 1/15/07 10:50a vsilyaev * PR 25997: Added 7038 performance counters * * 9 12/13/06 7:43p vsilyaev * PR 25997: Added support for MIPS3300 * * 8 12/7/06 4:33p vsilyaev * PR 25997: Fixed lowercase defined * * 7 12/7/06 2:43p vsilyaev * PR 25997: Added fixes for 3.4 GCC compiler * * 6 12/5/06 11:58a vsilyaev * PR 25997: Added faster, single threaded, probe routine * * 5 12/1/06 4:18p vsilyaev * PR 25997: Improved time accuracy * * 4 11/27/06 11:54a vsilyaev * PR 25997: Fixed compile issue for the Linux * * 3 11/20/06 4:54p vsilyaev * PR 25997: Decoupled profiling and symbol table * * 2 11/16/06 6:59p vsilyaev * PR 25997: Added UCOS support * * 1 11/16/06 5:24p vsilyaev * PR 25997: Embeddable profiler * *******************************************************************************/ #if defined(LINUX) && !defined(__KERNEL__) #include BSTD_INLINE unsigned __attribute__((no_instrument_function)) b_gettick(void) { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_usec+((unsigned)tv.tv_sec)*1000000; } BSTD_INLINE void __attribute__((no_instrument_function)) b_sample(bprofile_sample *sample) { sample->time = b_gettick(); return ; } #define b_get_stack(stack) do{uint8_t sp; *(stack)=(unsigned)&sp;} while(0) #define b_tick2ms_init() #define b_tick2_100us(tick) ((tick)/100) #elif defined(CONFIG_UCOS) #include "bprofile_tick_mips.h" #include "bos.h" /* these are OS headers that have clock information */ #define b_get_stack(stack) do{uint8_t sp; *(stack)=(unsigned)&sp;} while(0) #define b_tick2ms_init() unsigned clock__=(g_running_clock.clock_freq/10000); #define b_tick2_100us(tick) ((tick)/(clock__)) #elif defined(LINUX) && defined(__KERNEL__) #include "bperf_counter.h" #if B_PERF_BMIPS3300 /* linux kernel adjusts MIPS C0 counter, therefore it's not monotonic counter and not good source for interval measurements */ /* for BCM MIPS300 we could use 4-th performance counter, and it shall be mapped to the MIPS cycle counter */ #define b_gettick(void) (~(b_perf_read_one(3))) #endif #include "bprofile_tick_mips.h" #include "batomic.h" /* in the Linux there is no dedicated task for the interrupt handler, therefore special trick is required to mark the interrupt context */ extern batomic_t b_in_isr; /* this is mask, where the most significant bit is cleared/set in the entry/exit point of the ISR routine */ BSTD_INLINE void __attribute__((no_instrument_function)) b_get_stack(unsigned *stack) { uint8_t sp; *(stack)=((unsigned)batomic_get(&b_in_isr))&(unsigned)&sp; } /* this variable shall be initialized to number of ticks in 100us */ extern unsigned b_ticks_100us; #define b_tick2ms_init() unsigned clock__=b_ticks_100us #define b_tick2_100us(tick) ((tick)/(clock__)) #else #warning "Not supported" #define b_get_stack(stack) do{uint8_t sp; *(stack)=(unsigned)&sp;} while(0) #define b_sample(s) (void) #define b_tick2ms_init() (void) #define b_tick2_100us(tick) (tick) #endif #define b_tick2ms(n) (b_tick2_100us(n)/10)