| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006-2007, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bprofile_tick.h $ |
|---|
| 11 | * $brcm_Revision: 10 $ |
|---|
| 12 | * $brcm_Date: 1/15/07 10:50a $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Embeddeble profiler library |
|---|
| 17 | * Data acquisition module |
|---|
| 18 | * |
|---|
| 19 | * Revision History: |
|---|
| 20 | * |
|---|
| 21 | * $brcm_Log: /BSEAV/lib/bprofile/bprofile_tick.h $ |
|---|
| 22 | * |
|---|
| 23 | * 10 1/15/07 10:50a vsilyaev |
|---|
| 24 | * PR 25997: Added 7038 performance counters |
|---|
| 25 | * |
|---|
| 26 | * 9 12/13/06 7:43p vsilyaev |
|---|
| 27 | * PR 25997: Added support for MIPS3300 |
|---|
| 28 | * |
|---|
| 29 | * 8 12/7/06 4:33p vsilyaev |
|---|
| 30 | * PR 25997: Fixed lowercase defined |
|---|
| 31 | * |
|---|
| 32 | * 7 12/7/06 2:43p vsilyaev |
|---|
| 33 | * PR 25997: Added fixes for 3.4 GCC compiler |
|---|
| 34 | * |
|---|
| 35 | * 6 12/5/06 11:58a vsilyaev |
|---|
| 36 | * PR 25997: Added faster, single threaded, probe routine |
|---|
| 37 | * |
|---|
| 38 | * 5 12/1/06 4:18p vsilyaev |
|---|
| 39 | * PR 25997: Improved time accuracy |
|---|
| 40 | * |
|---|
| 41 | * 4 11/27/06 11:54a vsilyaev |
|---|
| 42 | * PR 25997: Fixed compile issue for the Linux |
|---|
| 43 | * |
|---|
| 44 | * 3 11/20/06 4:54p vsilyaev |
|---|
| 45 | * PR 25997: Decoupled profiling and symbol table |
|---|
| 46 | * |
|---|
| 47 | * 2 11/16/06 6:59p vsilyaev |
|---|
| 48 | * PR 25997: Added UCOS support |
|---|
| 49 | * |
|---|
| 50 | * 1 11/16/06 5:24p vsilyaev |
|---|
| 51 | * PR 25997: Embeddable profiler |
|---|
| 52 | * |
|---|
| 53 | *******************************************************************************/ |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | #if defined(LINUX) && !defined(__KERNEL__) |
|---|
| 57 | #include <sys/time.h> |
|---|
| 58 | |
|---|
| 59 | BSTD_INLINE unsigned __attribute__((no_instrument_function)) |
|---|
| 60 | b_gettick(void) |
|---|
| 61 | { |
|---|
| 62 | struct timeval tv; |
|---|
| 63 | gettimeofday(&tv, NULL); |
|---|
| 64 | return tv.tv_usec+((unsigned)tv.tv_sec)*1000000; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | BSTD_INLINE void __attribute__((no_instrument_function)) |
|---|
| 68 | b_sample(bprofile_sample *sample) |
|---|
| 69 | { |
|---|
| 70 | sample->time = b_gettick(); |
|---|
| 71 | return ; |
|---|
| 72 | } |
|---|
| 73 | #define b_get_stack(stack) do{uint8_t sp; *(stack)=(unsigned)&sp;} while(0) |
|---|
| 74 | |
|---|
| 75 | #define b_tick2ms_init() |
|---|
| 76 | #define b_tick2_100us(tick) ((tick)/100) |
|---|
| 77 | #elif defined(CONFIG_UCOS) |
|---|
| 78 | #include "bprofile_tick_mips.h" |
|---|
| 79 | #include "bos.h" /* these are OS headers that have clock information */ |
|---|
| 80 | #define b_get_stack(stack) do{uint8_t sp; *(stack)=(unsigned)&sp;} while(0) |
|---|
| 81 | |
|---|
| 82 | #define b_tick2ms_init() unsigned clock__=(g_running_clock.clock_freq/10000); |
|---|
| 83 | #define b_tick2_100us(tick) ((tick)/(clock__)) |
|---|
| 84 | #elif defined(LINUX) && defined(__KERNEL__) |
|---|
| 85 | #include "bperf_counter.h" |
|---|
| 86 | #if B_PERF_BMIPS3300 |
|---|
| 87 | /* linux kernel adjusts MIPS C0 counter, therefore it's not monotonic counter and not good source for interval measurements */ |
|---|
| 88 | /* for BCM MIPS300 we could use 4-th performance counter, and it shall be mapped to the MIPS cycle counter */ |
|---|
| 89 | #define b_gettick(void) (~(b_perf_read_one(3))) |
|---|
| 90 | #endif |
|---|
| 91 | #include "bprofile_tick_mips.h" |
|---|
| 92 | #include "batomic.h" |
|---|
| 93 | /* in the Linux there is no dedicated task for the interrupt handler, therefore special trick is required to mark the interrupt context */ |
|---|
| 94 | 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 */ |
|---|
| 95 | BSTD_INLINE void __attribute__((no_instrument_function)) |
|---|
| 96 | b_get_stack(unsigned *stack) |
|---|
| 97 | { |
|---|
| 98 | uint8_t sp; |
|---|
| 99 | *(stack)=((unsigned)batomic_get(&b_in_isr))&(unsigned)&sp; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | /* this variable shall be initialized to number of ticks in 100us */ |
|---|
| 103 | extern unsigned b_ticks_100us; |
|---|
| 104 | #define b_tick2ms_init() unsigned clock__=b_ticks_100us |
|---|
| 105 | #define b_tick2_100us(tick) ((tick)/(clock__)) |
|---|
| 106 | #else |
|---|
| 107 | #warning "Not supported" |
|---|
| 108 | #define b_get_stack(stack) do{uint8_t sp; *(stack)=(unsigned)&sp;} while(0) |
|---|
| 109 | #define b_sample(s) (void) |
|---|
| 110 | #define b_tick2ms_init() (void) |
|---|
| 111 | #define b_tick2_100us(tick) (tick) |
|---|
| 112 | #endif |
|---|
| 113 | |
|---|
| 114 | #define b_tick2ms(n) (b_tick2_100us(n)/10) |
|---|
| 115 | |
|---|
| 116 | |
|---|