source: rtems-tools/linkers/rtld-trace-buffer.ini @ 14a1c097

Last change on this file since 14a1c097 was 14a1c097, checked in by Vidushi Vashishth <reachvidu@…>, on Jun 1, 2018 at 10:32:59 PM

Updating trace buffer configuration

  • Property mode set to 100644
File size: 5.4 KB
Line 
1;
2; RTEMS Trace Linker Trace Buffer
3;
4; Copyright 2015 Chris Johns <chrisj@rtems.org>
5;
6
7;
8; A trace buffer generator buffers records to a buffer that can be extracted
9; latter.
10;
11[trace-buffer-generator]
12headers = trace-buffer-generator-headers
13code-blocks = trace-buffer-tracers
14lock-local = " rtems_interrupt_lock_context lcontext;"
15lock-acquire = " rtems_interrupt_lock_acquire(&__rtld_tbg_lock, &lcontext);"
16lock-release = " rtems_interrupt_lock_release(&__rtld_tbg_lock, &lcontext);"
17entry-trace = "__rtld_tbg_buffer_entry(&in, @FUNC_INDEX@, RTLD_TBG_REC_OVERHEAD + @FUNC_DATA_ENTRY_SIZE@);"
18entry-alloc = "in = __rtld_tbg_buffer_alloc(@FUNC_INDEX@, RTLD_TBG_REC_OVERHEAD + @FUNC_DATA_ENTRY_SIZE@);"
19arg-trace = "__rtld_tbg_buffer_arg(&in, @ARG_SIZE@, (void*) &@ARG_LABEL@);"
20exit-trace = "__rtld_tbg_buffer_exit(&in, @FUNC_INDEX@, RTLD_TBG_REC_OVERHEAD + @FUNC_DATA_RET_SIZE@);"
21exit-alloc = "in = __rtld_tbg_buffer_alloc(@FUNC_INDEX@, RTLD_TBG_REC_OVERHEAD + @FUNC_DATA_RET_SIZE@);"
22ret-trace = "__rtld_tbg_buffer_ret(in, @RET_SIZE@, (void*) &@RET_LABEL@);"
23buffer-local = " uint8_t* in;"
24
25[trace-buffer-generator-headers]
26header = "#include <stdint.h>"
27header = "#include <rtems.h>"
28header = "#include <rtems/rtems/tasksimpl.h>"
29header = "#include <rtems/score/threadimpl.h>"
30
31[trace-buffer-tracers]
32code = <<<CODE
33/*
34 * Mode bits.
35 */
36#define RTLD_TRACE_BUFFER_VERSION 0  /* data format version, lower 8bits */
37#if RTLD_TRACE_BUFFER_TIMESTAMP
38 #undef RTLD_TRACE_BUFFER_TIMESTAMP
39 #define RTLD_TRACE_BUFFER_TIMESTAMP (1 << 8)
40#else
41 #define RTLD_TRACE_BUFFER_TIMESTAMP 0
42#endif
43#if defined(RTLD_TRACE_BUFFER_THREAD)
44 #undef RTLD_TRACE_BUFFER_THREAD
45 #define RTLD_TRACE_BUFFER_THREAD    (1 << 9)
46#else
47 #define RTLD_TRACE_BUFFER_THREAD 0
48#endif
49#define RTLD_TRACE_BUFFER_MODE RTLD_TRACE_BUFFER_VERSION | \
50                               RTLD_TRACE_BUFFER_TIMESTAMP | \
51                               RTLD_TRACE_BUFFER_THREAD
52/*
53 * The number of word in the buffer.
54 */
55#define RTLD_TRACE_BUFFER_WORDS (RTLD_TRACE_BUFFER_SIZE / sizeof(uint32_t))
56/*
57 * We log the header record and then a 64bit timestamp.
58 */
59#define RTLD_TBG_REC_OVERHEAD (6 * sizeof(uint32_t))
60/*
61 * Symbols are public to allow external access to the buffers.
62 */
63const bool __rtld_tbg_present = true;
64const uint32_t __rtld_tbg_mode = RTLD_TRACE_BUFFER_MODE;
65const uint32_t __rtld_tbg_buffer_size = RTLD_TRACE_BUFFER_WORDS;
66uint32_t __rtld_tbg_buffer[RTLD_TRACE_BUFFER_WORDS];
67volatile uint32_t __rtld_tbg_buffer_in;
68volatile bool __rtld_tbg_finished;
69volatile bool __rtld_tbg_triggered;
70/*
71 * Lock the access.
72 */
73RTEMS_INTERRUPT_LOCK_DEFINE(static, __rtld_tbg_lock, "rtld-trace-buffer");
74
75static inline uint32_t __rtld_tbg_in_irq(void)
76{
77  return rtems_interrupt_is_in_progress() ? (1 << 31) : 0;
78}
79
80static inline uint32_t __rtld_tbg_executing_id(void)
81{
82  return _Thread_Get_executing()->Object.id;
83}
84
85static inline uint32_t __rtld_tbg_executing_status(void)
86{
87  /* @fixme Add the current CPU for SMP. */
88  Thread_Control* tc = _Thread_Get_executing();
89  return (_Thread_Get_priority(tc) << 8) | tc->Real_priority.priority;
90}
91
92static inline uint32_t __rtld_tbg_executing_state(void)
93{
94  return _Thread_Get_executing()->current_state;
95}
96
97static inline bool __rtld_tbg_is_enabled(const uint32_t index)
98{
99  return (__rtld_trace_enables[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false;
100}
101
102static inline bool __rtld_tbg_has_triggered(const uint32_t index)
103{
104  if (!__rtld_tbg_triggered)
105    __rtld_tbg_triggered =
106        (__rtld_trace_triggers[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false;
107  return __rtld_tbg_triggered;
108}
109
110static inline uint8_t* __rtld_tbg_buffer_alloc(const uint32_t index, const uint32_t size)
111{
112  uint8_t* in = NULL;
113  if (!__rtld_tbg_finished && __rtld_tbg_has_triggered(index) && __rtld_tbg_is_enabled(index))
114  {
115    const uint32_t slots = ((size - 1) / sizeof(uint32_t)) + 1;
116    if (__rtld_tbg_buffer_in >= ((RTLD_TRACE_BUFFER_WORDS - slots)))
117    {
118      __rtld_tbg_finished = true;
119    }
120    else
121    {
122      in = (uint8_t*) &__rtld_tbg_buffer[__rtld_tbg_buffer_in];
123      __rtld_tbg_buffer_in += slots;
124    }
125  }
126  return in;
127}
128
129static inline void __rtld_tbg_buffer_entry(uint8_t** in, uint32_t func_index, uint32_t size)
130{
131  if (*in)
132  {
133    uint32_t* in32 = (uint32_t*) *in;
134    uint64_t  now = rtems_clock_get_uptime_nanoseconds();
135    *in32++ = func_index | (size << 16) | __rtld_tbg_in_irq();
136    *in32++ = __rtld_tbg_executing_id();
137    *in32++ = __rtld_tbg_executing_status();
138    *in32++ = __rtld_tbg_executing_state();
139    *in32++ = now >> 32;
140    *in32 = now;
141    *in += sizeof(func_index) + (3 * sizeof(uint32_t)) + sizeof(uint64_t);
142  }
143}
144
145static inline void __rtld_tbg_buffer_arg(uint8_t** in, int arg_size, void* arg)
146{
147  if (*in)
148  {
149    memcpy(*in, arg, arg_size);
150    *in += arg_size;
151  }
152}
153
154static inline void __rtld_tbg_buffer_exit(uint8_t** in, uint32_t func_index, uint32_t size)
155{
156  if (*in)
157  {
158    uint32_t* in32 = (uint32_t*) *in;
159    uint64_t  now = rtems_clock_get_uptime_nanoseconds();
160    *in32++ = (1 << 30) | func_index | (size << 16) | __rtld_tbg_in_irq();
161    *in32++ = __rtld_tbg_executing_id();
162    *in32++ = __rtld_tbg_executing_status();
163    *in32++ = __rtld_tbg_executing_state();
164    *in32++ = now >> 32;
165    *in32 = now;
166    *in += sizeof(func_index) + (3 * sizeof(uint32_t)) + sizeof(uint64_t);
167  }
168}
169
170static inline void __rtld_tbg_buffer_ret(uint8_t* in, int ret_size, void* ret)
171{
172  if (in)
173  {
174    memcpy(in, ret, ret_size);
175  }
176}
177CODE
Note: See TracBrowser for help on using the repository browser.