|
9 | 9 | #include <string.h> |
10 | 10 |
|
11 | 11 | #include <zephyr/instrumentation/instrumentation.h> |
12 | | -#include <instr_buffer.h> |
13 | 12 | #include <instr_timestamp.h> |
14 | 13 |
|
15 | 14 | #include <zephyr/device.h> |
|
18 | 17 | #include <zephyr/kernel_structs.h> |
19 | 18 | #include <zephyr/retention/retention.h> |
20 | 19 | #include <zephyr/sys/reboot.h> |
| 20 | +#include <zephyr/sys/ring_buffer.h> |
21 | 21 |
|
22 | 22 | #include <kernel_internal.h> |
23 | 23 | #include <ksched.h> |
@@ -86,6 +86,10 @@ extern int INSTR_STOPPER_FUNCTION(void); |
86 | 86 | static void *k_trigger_callee = INSTR_TRIGGER_FUNCTION; |
87 | 87 | static void *k_stopper_callee = INSTR_STOPPER_FUNCTION; |
88 | 88 |
|
| 89 | +#if defined(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH) |
| 90 | +RING_BUFFER_DEFINE(trace_buffer, CONFIG_INSTRUMENTATION_MODE_CALLGRAPH_TRACE_BUFFER_SIZE); |
| 91 | +#endif |
| 92 | + |
89 | 93 | /* Current (live) trigger and stopper addresses */ |
90 | 94 | static void *trigger_callee; |
91 | 95 | static void *stopper_callee; |
@@ -132,11 +136,6 @@ int instr_init(void) |
132 | 136 | (const uint8_t *)&stopper_callee, sizeof(stopper_callee)); |
133 | 137 | } |
134 | 138 |
|
135 | | -#if defined(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH) |
136 | | - /* Initialize ring buffer */ |
137 | | - instr_buffer_init(); |
138 | | -#endif |
139 | | - |
140 | 139 | /* Init and start counters for timestamping */ |
141 | 140 | instr_timestamp_init(); |
142 | 141 |
|
@@ -276,31 +275,22 @@ __no_instrumentation__ |
276 | 275 | void instr_dump_buffer_uart(void) |
277 | 276 | { |
278 | 277 | #if defined(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH) |
279 | | - static const struct device *const uart_dev = |
280 | | - DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); |
281 | | - |
282 | 278 | uint8_t *transferring_buf; |
283 | | - uint32_t transferring_length, instr_buffer_max_length; |
| 279 | + size_t transferring_length; |
| 280 | + static const struct device *const uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); |
284 | 281 |
|
285 | 282 | /* Make sure instrumentation is disabled. */ |
286 | 283 | instr_disable(); |
287 | 284 |
|
288 | 285 | /* Initiator mark */ |
289 | 286 | printk("-*-#"); |
290 | | - |
291 | | - instr_buffer_max_length = instr_buffer_capacity_get(); |
292 | | - |
293 | | - while (!instr_buffer_is_empty()) { |
294 | | - transferring_length = |
295 | | - instr_buffer_get_claim( |
296 | | - &transferring_buf, |
297 | | - instr_buffer_max_length); |
298 | | - |
299 | | - for (uint32_t i = 0; i < transferring_length; i++) { |
| 287 | + while (!ring_buffer_empty(&trace_buffer)) { |
| 288 | + transferring_length = ring_buffer_read_ptr(&trace_buffer, &transferring_buf); |
| 289 | + for (size_t i = 0; i < transferring_length; i++) { |
300 | 290 | uart_poll_out(uart_dev, transferring_buf[i]); |
301 | 291 | } |
302 | 292 |
|
303 | | - instr_buffer_get_finish(transferring_length); |
| 293 | + ring_buffer_consume(&trace_buffer, transferring_length); |
304 | 294 | } |
305 | 295 |
|
306 | 296 | /* Terminator mark */ |
@@ -490,30 +480,12 @@ static void set_up_record(struct instr_record *record, enum instr_event_types ty |
490 | 480 |
|
491 | 481 | static bool instr_record_data_put(struct instr_record *record) |
492 | 482 | { |
493 | | - uint32_t total_size = 0U; |
494 | | - |
495 | | - uint8_t *data = (uint8_t *) record, *buf; |
496 | | - uint32_t length = sizeof(struct instr_record), claimed_size; |
497 | | - |
498 | 483 | /* If record won't fit, free enough space in the buffer */ |
499 | | - if (instr_buffer_space_get() < sizeof(struct instr_record)) { |
500 | | - instr_buffer_get(NULL, sizeof(struct instr_record)); |
501 | | - } |
502 | | - |
503 | | - do { |
504 | | - claimed_size = instr_buffer_put_claim(&buf, length); |
505 | | - memcpy(buf, data, claimed_size); |
506 | | - total_size += claimed_size; |
507 | | - length -= claimed_size; |
508 | | - data += claimed_size; |
509 | | - } while (length && claimed_size); |
510 | | - |
511 | | - if (length && claimed_size == 0) { |
512 | | - instr_buffer_put_finish(0); |
513 | | - return false; |
| 484 | + if (ring_buffer_space(&trace_buffer) < sizeof(struct instr_record)) { |
| 485 | + ring_buffer_consume(&trace_buffer, sizeof(struct instr_record)); |
514 | 486 | } |
515 | 487 |
|
516 | | - instr_buffer_put_finish(total_size); |
| 488 | + ring_buffer_write(&trace_buffer, (uint8_t *)record, sizeof(struct instr_record)); |
517 | 489 | return true; |
518 | 490 | } |
519 | 491 |
|
@@ -569,7 +541,7 @@ void instr_event_handler(enum instr_event_types type, void *callee, void *caller |
569 | 541 | struct instr_record record; |
570 | 542 |
|
571 | 543 | if (!IS_ENABLED(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH_BUFFER_OVERWRITE) && |
572 | | - instr_buffer_space_get() < sizeof(struct instr_record)) { |
| 544 | + ring_buffer_space(&trace_buffer) < sizeof(struct instr_record)) { |
573 | 545 | _instr_tracing_disabled = 1; |
574 | 546 | return; |
575 | 547 | } |
|
0 commit comments