From 5cde82d8c0ededfc2873ed508758ee068e955ca8 Mon Sep 17 00:00:00 2001 From: Ahreum Jeong Date: Thu, 13 Jul 2017 13:47:56 +0900 Subject: [PATCH] Support flag parameter in logm Gernerally, logm puts entered messages to buffer and flushes them in logm task But sometimes it is needed to print messages directly. So logm supports this functionallity using flags If flag is LOGM_LOWPUT, logm prints messages to low output directly after flushing buffer --- lib/libc/stdio/lib_printf.c | 6 +++++- lib/libc/syslog/lib_lowsyslog.c | 5 +++-- lib/libc/syslog/lib_syslog.c | 5 +++-- os/include/tinyara/logm.h | 18 +++++++++++++++--- os/logm/logm.c | 32 ++++++++++++++++++++++++++++---- 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/lib/libc/stdio/lib_printf.c b/lib/libc/stdio/lib_printf.c index 8f91b6f..ad12934 100644 --- a/lib/libc/stdio/lib_printf.c +++ b/lib/libc/stdio/lib_printf.c @@ -63,6 +63,10 @@ #include "lib_internal.h" +#if defined(CONFIG_LOGM) && defined(CONFIG_PRINTF2LOGM) +#include +#endif + /**************************************************************************** * Definitions ****************************************************************************/ @@ -110,7 +114,7 @@ int printf(FAR const char *fmt, ...) va_start(ap, fmt); #if defined(CONFIG_LOGM) && defined(CONFIG_PRINTF2LOGM) - ret = logm_internal(LOGM_DEF_PRIORITY, fmt, ap); + ret = logm_internal(LOGM_NORMAL, LOGM_UNKNOWN, LOGM_DEF_PRIORITY, fmt, ap); #elif CONFIG_NFILE_STREAMS > 0 ret = vfprintf(stdout, fmt, ap); #elif CONFIG_NFILE_DESCRIPTORS > 0 diff --git a/lib/libc/syslog/lib_lowsyslog.c b/lib/libc/syslog/lib_lowsyslog.c index 9bdd53a..a84076f 100644 --- a/lib/libc/syslog/lib_lowsyslog.c +++ b/lib/libc/syslog/lib_lowsyslog.c @@ -60,8 +60,9 @@ #include #include +#if defined(CONFIG_LOGM) && defined(CONFIG_SYSLOG2LOGM) #include - +#endif #include "syslog/syslog.h" #if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG) @@ -147,7 +148,7 @@ int lowvsyslog(int priority, FAR const char *fmt, va_list ap) if ((g_syslog_mask & LOG_MASK(priority)) != 0) { /* Yes.. let vsylog_internal to the deed */ #if defined(CONFIG_LOGM) && defined(CONFIG_SYSLOG2LOGM) - ret = logm_internal(priority, fmt, ap); + ret = logm_internal(LOGM_LOWPUT, LOGM_UNKNOWN, priority, fmt, ap); #else ret = lowvsyslog_internal(fmt, ap); #endif diff --git a/lib/libc/syslog/lib_syslog.c b/lib/libc/syslog/lib_syslog.c index 599868f..92a3ef9 100644 --- a/lib/libc/syslog/lib_syslog.c +++ b/lib/libc/syslog/lib_syslog.c @@ -61,8 +61,9 @@ #include #include +#if defined(CONFIG_LOGM) && defined(CONFIG_SYSLOG2LOGM) #include - +#endif #include "syslog/syslog.h" /**************************************************************************** @@ -208,7 +209,7 @@ int vsyslog(int priority, FAR const char *fmt, va_list ap) if ((g_syslog_mask & LOG_MASK(priority)) != 0) { /* Yes.. let vsylog_internal do the deed */ #if defined(CONFIG_LOGM) && defined(CONFIG_SYSLOG2LOGM) - ret = logm_internal(priority, fmt, ap); + ret = logm_internal(LOGM_NORMAL, LOGM_UNKNOWN, priority, fmt, ap); #else ret = vsyslog_internal(fmt, ap); #endif diff --git a/os/include/tinyara/logm.h b/os/include/tinyara/logm.h index c4a13df..78020c2 100644 --- a/os/include/tinyara/logm.h +++ b/os/include/tinyara/logm.h @@ -24,7 +24,7 @@ #define LOGM_DEF_PRIORITY (7) /* Log priority levels in logm */ -enum logm_loglevels_e { +enum logm_loglevel_e { LOGM_EMR, /* Emergency */ LOGM_ART, /* Alert */ LOGM_CRT, /* Critical */ @@ -43,6 +43,18 @@ enum logm_param_type_e { /* This would grow later */ }; +/* Log flags for somethings related to logging */ +enum logm_logflag_e { + LOGM_NORMAL, + LOGM_LOWPUT +}; + +/* Log index means where messages are from */ +enum logm_logindex_e { + LOGM_UNKNOWN + /* Not supported yet. This would be updated later */ +}; + #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" @@ -53,8 +65,8 @@ extern "C" #endif void logm_start(void); -int logm_internal(int priority, const char *fmt, va_list valst); -int logm(int flag, int mod, int priority, const char *fmt, ...); +int logm_internal(int flag, int indx, int priority, const char *fmt, va_list valst); +int logm(int flag, int indx, int priority, const char *fmt, ...); int logm_set_values(enum logm_param_type_e type, int value); int logm_get_values(enum logm_param_type_e type, int* value); diff --git a/os/logm/logm.c b/os/logm/logm.c index 24ba3a8..2700487 100644 --- a/os/logm/logm.c +++ b/os/logm/logm.c @@ -49,8 +49,29 @@ static void logm_outstream(FAR struct lib_outstream_s *outstream) outstream->nput = 0; } +#ifdef CONFIG_ARCH_LOWPUTC +static void logm_flush(struct lib_outstream_s *stream) +{ + sched_lock(); + + while (g_logm_head != g_logm_tail) { + stream->put(stream, g_logm_rsvbuf[g_logm_head]); + g_logm_head = (g_logm_head + 1) % logm_bufsize; + } + + if (LOGM_STATUS(LOGM_BUFFER_OVERFLOW)) { + LOGM_STATUS_CLEAR(LOGM_BUFFER_OVERFLOW); + } + + /* Reset nput in stream for next stream */ + stream->nput = 0; + + sched_unlock(); +} +#endif + /* logm_internal hook for syslog & printfs */ -int logm_internal(int priority, const char *fmt, va_list ap) +int logm_internal(int flag, int indx, int priority, const char *fmt, va_list ap) { irqstate_t flags; int ret = 0; @@ -59,7 +80,9 @@ int logm_internal(int priority, const char *fmt, va_list ap) struct timespec ts; #endif - if (LOGM_STATUS(LOGM_READY) && !LOGM_STATUS(LOGM_BUFFER_RESIZE_REQ) && !up_interrupt_context()) { + if (LOGM_STATUS(LOGM_READY) && !LOGM_STATUS(LOGM_BUFFER_RESIZE_REQ) \ + && flag == LOGM_NORMAL && !up_interrupt_context()) { + flags = irqsave(); if (LOGM_STATUS(LOGM_BUFFER_OVERFLOW)) { @@ -78,6 +101,7 @@ int logm_internal(int priority, const char *fmt, va_list ap) } #endif ret = lib_vsprintf(&strm, fmt, ap); + g_logm_tail = (g_logm_tail + ret) % logm_bufsize; if ((g_logm_tail + 1) % logm_bufsize == g_logm_head) { @@ -85,12 +109,12 @@ int logm_internal(int priority, const char *fmt, va_list ap) g_logm_dropmsg_count = 1; g_logm_overflow_offset = g_logm_tail; } - irqrestore(flags); } else { /* Low Output: Sytem is not yet completely ready or this is called from interrupt handler */ #ifdef CONFIG_ARCH_LOWPUTC lib_lowoutstream(&strm); + logm_flush(&strm); ret = lib_vsprintf(&strm, fmt, ap); #endif } @@ -107,7 +131,7 @@ int logm(int flag, int indx, int priority, const char *fmt, ...) /* LOGIC for initial test here */ va_start(ap, fmt); - ret = logm_internal(priority, fmt, ap); + ret = logm_internal(flag, indx, priority, fmt, ap); va_end(ap); return ret; -- 2.7.4