logging: Logger to wake up logs processing thread

Added configurable threshold of number of buffered log messages
on which log wakes up thread which processes buffered logs. Thread
ID is provided during logger initialization. Feature is optional
and can be disabled by setting CONFIG_LOG_PROCESS_TRIGGER_THR to 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2018-06-27 10:47:14 +02:00 committed by Anas Nashif
commit 1ba542c352
3 changed files with 47 additions and 1 deletions

View file

@ -42,6 +42,15 @@ void log_core_init(void);
*/
void log_init(void);
/**
* @brief Function for providing thread which is processing logs.
*
* See CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD.
*
* @param process_tid Process thread id. Used to wake up the thread
*/
void log_thread_set(k_tid_t process_tid);
/**
* @brief Function for providing timestamp function.
*

View file

@ -207,6 +207,14 @@ config LOG_INPLACE_PROCESS
access to work flawlessly in that mode because one log operation can be
interrupted by another one in higher priority context.
config LOG_PROCESS_TRIGGER_THRESHOLD
int "Amount of buffered logs which triggers processing thread."
default 0
help
When number of buffered messages reaches the threshold thread is waken
up. Log processing thread ID is provided during log initialization.
Set 0 to disable the feature.
config LOG_BUFFER_SIZE
int "Number of bytes dedicated for the logger internal buffer."
default 1024

View file

@ -13,6 +13,7 @@
#include <assert.h>
#include <atomic.h>
#include <stdio.h>
#include <atomic.h>
#ifndef CONFIG_LOG_PRINTK_MAX_STRING_LENGTH
#define CONFIG_LOG_PRINTK_MAX_STRING_LENGTH 1
@ -26,6 +27,8 @@ LOG_BACKEND_UART_DEFINE(log_backend_uart);
static struct log_list_t list;
static atomic_t initialized;
static bool panic_mode;
static atomic_t buffered_cnt;
static k_tid_t proc_tid;
static u32_t dummy_timestamp(void);
static timestamp_get_t timestamp_func = dummy_timestamp;
@ -38,9 +41,21 @@ static u32_t dummy_timestamp(void)
static inline void msg_finalize(struct log_msg *msg,
struct log_msg_ids src_level)
{
unsigned int key;
msg->hdr.ids = src_level;
msg->hdr.timestamp = timestamp_func();
unsigned int key = irq_lock();
if (!IS_ENABLED(CONFIG_LOG_INPLACE_PROCESS) &&
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) {
atomic_inc(&buffered_cnt);
if (buffered_cnt == CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD &&
proc_tid) {
k_wakeup(proc_tid);
}
}
key = irq_lock();
log_list_add_tail(&list, msg);
@ -209,6 +224,7 @@ void log_init(void)
timestamp_func = timestamp_get;
log_output_timestamp_freq_set(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
/* Assign ids to backends. */
for (i = 0; i < log_backend_count_get(); i++) {
log_backend_id_set(log_backend_get(i),
@ -223,6 +239,18 @@ void log_init(void)
#endif
}
void log_thread_set(k_tid_t process_tid)
{
proc_tid = process_tid;
if (!IS_ENABLED(CONFIG_LOG_INPLACE_PROCESS) &&
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD &&
process_tid &&
buffered_cnt >= CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) {
k_wakeup(proc_tid);
}
}
int log_set_timestamp_func(timestamp_get_t timestamp_getter, u32_t freq)
{
if (!timestamp_getter) {
@ -297,6 +325,7 @@ bool log_process(bool bypass)
irq_unlock(key);
if (msg != NULL) {
atomic_dec(&buffered_cnt);
msg_process(msg, bypass);
}