Skip to content

Commit 97812b3

Browse files
committed
subsys/instrument: rework to new ring_buffer api
The instr_buffer.[c,h] was only used in one file, making it possible to rework to use the new ring_buffer api while removing the abstraction layer. Signed-off-by: Måns Ansgariusson <[email protected]>
1 parent ea868d3 commit 97812b3

File tree

4 files changed

+15
-218
lines changed

4 files changed

+15
-218
lines changed

subsys/instrumentation/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ zephyr_sources_ifdef(CONFIG_INSTRUMENTATION
77
transport/uart.c
88
)
99

10-
zephyr_sources_ifdef(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH ringbuffer/ringbuffer.c)
11-
1210
if(CONFIG_INSTRUMENTATION)
1311
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
1412
zephyr_sources(handlers/instr_handlers_gcc.c)

subsys/instrumentation/common/instr_common.c

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <string.h>
1010

1111
#include <zephyr/instrumentation/instrumentation.h>
12-
#include <instr_buffer.h>
1312
#include <instr_timestamp.h>
1413

1514
#include <zephyr/device.h>
@@ -18,6 +17,7 @@
1817
#include <zephyr/kernel_structs.h>
1918
#include <zephyr/retention/retention.h>
2019
#include <zephyr/sys/reboot.h>
20+
#include <zephyr/sys/ring_buffer.h>
2121

2222
#include <kernel_internal.h>
2323
#include <ksched.h>
@@ -86,6 +86,10 @@ extern int INSTR_STOPPER_FUNCTION(void);
8686
static void *k_trigger_callee = INSTR_TRIGGER_FUNCTION;
8787
static void *k_stopper_callee = INSTR_STOPPER_FUNCTION;
8888

89+
#if defined(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH)
90+
RING_BUFFER_DEFINE(trace_buffer, CONFIG_INSTRUMENTATION_MODE_CALLGRAPH_TRACE_BUFFER_SIZE);
91+
#endif
92+
8993
/* Current (live) trigger and stopper addresses */
9094
static void *trigger_callee;
9195
static void *stopper_callee;
@@ -132,11 +136,6 @@ int instr_init(void)
132136
(const uint8_t *)&stopper_callee, sizeof(stopper_callee));
133137
}
134138

135-
#if defined(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH)
136-
/* Initialize ring buffer */
137-
instr_buffer_init();
138-
#endif
139-
140139
/* Init and start counters for timestamping */
141140
instr_timestamp_init();
142141

@@ -276,31 +275,22 @@ __no_instrumentation__
276275
void instr_dump_buffer_uart(void)
277276
{
278277
#if defined(CONFIG_INSTRUMENTATION_MODE_CALLGRAPH)
279-
static const struct device *const uart_dev =
280-
DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
281-
282278
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));
284281

285282
/* Make sure instrumentation is disabled. */
286283
instr_disable();
287284

288285
/* Initiator mark */
289286
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++) {
300290
uart_poll_out(uart_dev, transferring_buf[i]);
301291
}
302292

303-
instr_buffer_get_finish(transferring_length);
293+
ring_buffer_consume(&trace_buffer, transferring_length);
304294
}
305295

306296
/* Terminator mark */
@@ -490,30 +480,12 @@ static void set_up_record(struct instr_record *record, enum instr_event_types ty
490480

491481
static bool instr_record_data_put(struct instr_record *record)
492482
{
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-
498483
/* 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));
514486
}
515487

516-
instr_buffer_put_finish(total_size);
488+
ring_buffer_write(&trace_buffer, (uint8_t *)record, sizeof(struct instr_record));
517489
return true;
518490
}
519491

@@ -569,7 +541,7 @@ void instr_event_handler(enum instr_event_types type, void *callee, void *caller
569541
struct instr_record record;
570542

571543
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)) {
573545
_instr_tracing_disabled = 1;
574546
return;
575547
}

subsys/instrumentation/include/instr_buffer.h

Lines changed: 0 additions & 111 deletions
This file was deleted.

subsys/instrumentation/ringbuffer/ringbuffer.c

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)