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

Last change on this file since e04699b was f11d18b, checked in by Chris Johns <chrisj@…>, on Oct 15, 2015 at 10:05:29 AM

Change to use the task implemenation interface.

  • Property mode set to 100644
File size: 5.3 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>"
29
30[trace-buffer-tracers]
31code = <<<CODE
32/*
33 * Mode bits.
34 */
35#define RTLD_TRACE_BUFFER_VERSION 0  /* data format version, lower 8bits */
36#if RTLD_TRACE_BUFFER_TIMESTAMP
37 #undef RTLD_TRACE_BUFFER_TIMESTAMP
38 #define RTLD_TRACE_BUFFER_TIMESTAMP (1 << 8)
39#else
40 #define RTLD_TRACE_BUFFER_TIMESTAMP 0
41#endif
42#if defined(RTLD_TRACE_BUFFER_THREAD)
43 #undef RTLD_TRACE_BUFFER_THREAD
44 #define RTLD_TRACE_BUFFER_THREAD    (1 << 9)
45#else
46 #define RTLD_TRACE_BUFFER_THREAD 0
47#endif
48#define RTLD_TRACE_BUFFER_MODE RTLD_TRACE_BUFFER_VERSION | \
49                               RTLD_TRACE_BUFFER_TIMESTAMP | \
50                               RTLD_TRACE_BUFFER_THREAD
51/*
52 * The number of word in the buffer.
53 */
54#define RTLD_TRACE_BUFFER_WORDS (RTLD_TRACE_BUFFER_SIZE / sizeof(uint32_t))
55/*
56 * We log the header record and then a 64bit timestamp.
57 */
58#define RTLD_TBG_REC_OVERHEAD (6 * sizeof(uint32_t))
59/*
60 * Symbols are public to allow external access to the buffers.
61 */
62const bool __rtld_tbg_present = true;
63const uint32_t __rtld_tbg_mode = RTLD_TRACE_BUFFER_MODE;
64const uint32_t __rtld_tbg_buffer_size = RTLD_TRACE_BUFFER_WORDS;
65uint32_t __rtld_tbg_buffer[RTLD_TRACE_BUFFER_WORDS];
66volatile uint32_t __rtld_tbg_buffer_in;
67volatile bool __rtld_tbg_finished;
68volatile bool __rtld_tbg_triggered;
69/*
70 * Lock the access.
71 */
72RTEMS_INTERRUPT_LOCK_DEFINE(static, __rtld_tbg_lock, "rtld-trace-buffer");
73
74static inline uint32_t __rtld_tbg_in_irq(void)
75{
76  return rtems_interrupt_is_in_progress() ? (1 << 31) : 0;
77}
78
79static inline uint32_t __rtld_tbg_executing_id(void)
80{
81  return _Thread_Get_executing()->Object.id;
82}
83
84static inline uint32_t __rtld_tbg_executing_status(void)
85{
86  /* @fixme Add the current CPU for SMP. */
87  struct Thread_Control* tc = _Thread_Get_executing();
88  return (tc->current_priority << 8) | tc->real_priority;
89}
90
91static inline uint32_t __rtld_tbg_executing_state(void)
92{
93  return _Thread_Get_executing()->current_state;
94}
95
96static inline bool __rtld_tbg_is_enabled(const uint32_t index)
97{
98  return (__rtld_trace_enables[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false;
99}
100
101static inline bool __rtld_tbg_has_triggered(const uint32_t index)
102{
103  if (!__rtld_tbg_triggered)
104    __rtld_tbg_triggered =
105        (__rtld_trace_triggers[index / 32] & (1 << (index & (32 - 1)))) != 0 ? true : false;
106  return __rtld_tbg_triggered;
107}
108
109static inline uint8_t* __rtld_tbg_buffer_alloc(const uint32_t index, const uint32_t size)
110{
111  uint8_t* in = NULL;
112  if (!__rtld_tbg_finished && __rtld_tbg_has_triggered(index) && __rtld_tbg_is_enabled(index))
113  {
114    const uint32_t slots = ((size - 1) / sizeof(uint32_t)) + 1;
115    if (__rtld_tbg_buffer_in >= ((RTLD_TRACE_BUFFER_WORDS - slots)))
116    {
117      __rtld_tbg_finished = true;
118    }
119    else
120    {
121      in = (uint8_t*) &__rtld_tbg_buffer[__rtld_tbg_buffer_in];
122      __rtld_tbg_buffer_in += slots;
123    }
124  }
125  return in;
126}
127
128static inline void __rtld_tbg_buffer_entry(uint8_t** in, uint32_t func_index, uint32_t size)
129{
130  if (*in)
131  {
132    uint32_t* in32 = (uint32_t*) *in;
133    uint64_t  now = rtems_clock_get_uptime_nanoseconds();
134    *in32++ = func_index | (size << 16) | __rtld_tbg_in_irq();
135    *in32++ = __rtld_tbg_executing_id();
136    *in32++ = __rtld_tbg_executing_status();
137    *in32++ = __rtld_tbg_executing_state();
138    *in32++ = now >> 32;
139    *in32 = now;
140    *in += sizeof(func_index) + (3 * sizeof(uint32_t)) + sizeof(uint64_t);
141  }
142}
143
144static inline void __rtld_tbg_buffer_arg(uint8_t** in, int arg_size, void* arg)
145{
146  if (*in)
147  {
148    memcpy(*in, arg, arg_size);
149    *in += arg_size;
150  }
151}
152
153static inline void __rtld_tbg_buffer_exit(uint8_t** in, uint32_t func_index, uint32_t size)
154{
155  if (*in)
156  {
157    uint32_t* in32 = (uint32_t*) *in;
158    uint64_t  now = rtems_clock_get_uptime_nanoseconds();
159    *in32++ = (1 << 30) | func_index | (size << 16) | __rtld_tbg_in_irq();
160    *in32++ = __rtld_tbg_executing_id();
161    *in32++ = __rtld_tbg_executing_status();
162    *in32++ = __rtld_tbg_executing_state();
163    *in32++ = now >> 32;
164    *in32 = now;
165    *in += sizeof(func_index) + (3 * sizeof(uint32_t)) + sizeof(uint64_t);
166  }
167}
168
169static inline void __rtld_tbg_buffer_ret(uint8_t* in, int ret_size, void* ret)
170{
171  if (in)
172  {
173    memcpy(in, ret, ret_size);
174  }
175}
176CODE
Note: See TracBrowser for help on using the repository browser.