logging: log_backend_rb: Make message buffer size configurable
Make slot size configurable making it easy to use with other platforms. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
f4357837af
commit
dbf1d5d87d
2 changed files with 30 additions and 15 deletions
|
@ -513,7 +513,15 @@ config LOG_BACKEND_RB_MEM_BASE
|
||||||
config LOG_BACKEND_RB_MEM_SIZE
|
config LOG_BACKEND_RB_MEM_SIZE
|
||||||
hex "Size of the ring buffer"
|
hex "Size of the ring buffer"
|
||||||
help
|
help
|
||||||
Size of the ring buffer.
|
Size of the ring buffer. Must be multiply of the message slot
|
||||||
|
size.
|
||||||
|
|
||||||
|
config LOG_BACKEND_RB_SLOT_SIZE
|
||||||
|
int "Size of the message slot"
|
||||||
|
default 64
|
||||||
|
help
|
||||||
|
Size of the message slot inside ring buffer. All log messages
|
||||||
|
are split to similar sized logging slots.
|
||||||
|
|
||||||
endif # LOG_BACKEND_RB
|
endif # LOG_BACKEND_RB
|
||||||
|
|
||||||
|
|
|
@ -10,19 +10,24 @@
|
||||||
#include <logging/log_output.h>
|
#include <logging/log_output.h>
|
||||||
#include <sys/ring_buffer.h>
|
#include <sys/ring_buffer.h>
|
||||||
|
|
||||||
#define BUF_SIZE 64
|
|
||||||
|
|
||||||
BUILD_ASSERT(CONFIG_LOG_BACKEND_RB_MEM_SIZE % BUF_SIZE == 0);
|
|
||||||
|
|
||||||
static struct ring_buf ringbuf;
|
static struct ring_buf ringbuf;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Log message format:
|
* Log message format:
|
||||||
* Logging started with magic number 0x55aa followed by log message id.
|
* Logging started with magic number 0x55aa followed by log message id.
|
||||||
* Log message ended with null terminator and takes BUF_SIZE slot. The
|
* Log message ended with null terminator and takes
|
||||||
* long log message can occupy several logging slots.
|
* CONFIG_LOG_BACKEND_RB_SLOT_SIZE slot. The long log message can occupy
|
||||||
|
* several logging slots.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* All log messages are split to similar sized logging slots. Since ring
|
||||||
|
* buffer slots get rewritten we need to check that all slots are fit to
|
||||||
|
* the ring buffer
|
||||||
|
*/
|
||||||
|
BUILD_ASSERT(CONFIG_LOG_BACKEND_RB_MEM_SIZE %
|
||||||
|
CONFIG_LOG_BACKEND_RB_SLOT_SIZE == 0);
|
||||||
|
|
||||||
static void init(void)
|
static void init(void)
|
||||||
{
|
{
|
||||||
ring_buf_init(&ringbuf, CONFIG_LOG_BACKEND_RB_MEM_SIZE,
|
ring_buf_init(&ringbuf, CONFIG_LOG_BACKEND_RB_MEM_SIZE,
|
||||||
|
@ -38,15 +43,17 @@ static void trace(const u8_t *data, size_t length)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
space = ring_buf_space_get(&ringbuf);
|
space = ring_buf_space_get(&ringbuf);
|
||||||
if (space < BUF_SIZE) {
|
if (space < CONFIG_LOG_BACKEND_RB_SLOT_SIZE) {
|
||||||
u8_t *dummy;
|
u8_t *dummy;
|
||||||
|
|
||||||
/* Remove oldest entry */
|
/* Remove oldest entry */
|
||||||
ring_buf_get_claim(&ringbuf, &dummy, BUF_SIZE);
|
ring_buf_get_claim(&ringbuf, &dummy,
|
||||||
ring_buf_get_finish(&ringbuf, BUF_SIZE);
|
CONFIG_LOG_BACKEND_RB_SLOT_SIZE);
|
||||||
|
ring_buf_get_finish(&ringbuf, CONFIG_LOG_BACKEND_RB_SLOT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ring_buf_put_claim(&ringbuf, (u8_t **)&t, BUF_SIZE);
|
ring_buf_put_claim(&ringbuf, (u8_t **)&t,
|
||||||
|
CONFIG_LOG_BACKEND_RB_SLOT_SIZE);
|
||||||
region = t;
|
region = t;
|
||||||
|
|
||||||
/* Add magic number at the beginning of the slot */
|
/* Add magic number at the beginning of the slot */
|
||||||
|
@ -57,13 +64,13 @@ static void trace(const u8_t *data, size_t length)
|
||||||
*(u16_t *)t = log_id++;
|
*(u16_t *)t = log_id++;
|
||||||
t += 2;
|
t += 2;
|
||||||
|
|
||||||
for (i = 0; i < MIN(length, BUF_SIZE - 4); i++) {
|
for (i = 0; i < MIN(length, CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4); i++) {
|
||||||
*t++ = data[i];
|
*t++ = data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
SOC_DCACHE_FLUSH((void *)region, BUF_SIZE);
|
SOC_DCACHE_FLUSH((void *)region, CONFIG_LOG_BACKEND_RB_SLOT_SIZE);
|
||||||
|
|
||||||
ring_buf_put_finish(&ringbuf, BUF_SIZE);
|
ring_buf_put_finish(&ringbuf, CONFIG_LOG_BACKEND_RB_SLOT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int char_out(u8_t *data, size_t length, void *ctx)
|
static int char_out(u8_t *data, size_t length, void *ctx)
|
||||||
|
@ -74,7 +81,7 @@ static int char_out(u8_t *data, size_t length, void *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* magic and log id takes space */
|
/* magic and log id takes space */
|
||||||
static u8_t buf[BUF_SIZE - 4];
|
static u8_t buf[CONFIG_LOG_BACKEND_RB_SLOT_SIZE - 4];
|
||||||
|
|
||||||
LOG_OUTPUT_DEFINE(log_output, char_out, buf, sizeof(buf));
|
LOG_OUTPUT_DEFINE(log_output, char_out, buf, sizeof(buf));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue