logging: syst: embed log message source IDs in Sys-T messages

This embeds the log message source IDs inside the origin unit
as module IDs in Sys-T messages. This allows Sys-T message
parsers to see where the log messages are coming from.

This is enabled by default if using Sys-T catalog messages as
the collateral XML file contains the information to interpret
the module ID.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2022-04-07 16:00:22 -07:00 committed by Maureen Helm
parent 2e2c8cc931
commit 6ec1fcc214
3 changed files with 111 additions and 11 deletions

View file

@ -21,15 +21,17 @@ config LOG_FUNC_NAME_PREFIX_DBG
endmenu
config LOG_MIPI_SYST_ENABLE
menuconfig LOG_MIPI_SYST_ENABLE
bool "MIPI SyS-T format output"
select MIPI_SYST_LIB
help
Enable MIPI SyS-T format output for the logger system.
if LOG_MIPI_SYST_ENABLE
config LOG_MIPI_SYST_USE_CATALOG
bool "Use MIPI Sys-T Catalog for logging"
depends on LOG2 && LOG_MIPI_SYST_ENABLE
depends on LOG2
select LOG2_FMT_SECTION
select LOG2_MSG_PKG_ALWAYS_ADD_RO_STRING_IDXS
help
@ -44,6 +46,40 @@ config LOG_MIPI_SYST_CATALOG_ARGS_BUFFER_SIZE
argument list needed for the MIPI Sys-T library for processing
catalog messages.
config LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID
bool "Output Log Message Source ID as Module ID"
default y if LOG_MIPI_SYST_USE_CATALOG
help
Enable this option to output the log message source ID
as the Sys-T message module ID (as in origin unit in Sys-T
message header).
config LOG_MIPI_SYST_MSG_DEFAULT_MODULE_ID
int "Default module ID in Sys-T message"
range 0 127
default 127 if LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID
default 0
help
The default module ID embedded in the origin unit in
Sys-T message header.
If CONFIG_LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID is disabled,
this will be used for all Sys-T messages.
If CONFIG_LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID is enabled,
this will be used for log messages without source IDs,
for example, printk() if CONFIG_LOG_PRINTK is enabled.
config LOG_MIPI_SYST_MSG_DEFAULT_UNIT_ID
int "Default unit ID in Sys-T message"
range 0 15
default 0
help
The default unit ID embedded in the origin unit in
Sys-T message header.
endif # LOG_MIPI_SYST_ENABLE
config LOG_DICTIONARY_SUPPORT
bool
depends on LOG2

View file

@ -63,11 +63,13 @@ extern void log_output_msg2_syst_process(const struct log_output *output,
struct log_msg2 *msg, uint32_t flag);
extern void log_output_string_syst_process(const struct log_output *output,
struct log_msg_ids src_level,
const char *fmt, va_list ap, uint32_t flag);
const char *fmt, va_list ap, uint32_t flag,
int16_t source_id);
extern void log_output_hexdump_syst_process(const struct log_output *output,
struct log_msg_ids src_level,
const char *metadata,
const uint8_t *data, uint32_t length, uint32_t flag);
const uint8_t *data, uint32_t length,
uint32_t flag, int16_t source_id);
/* The RFC 5424 allows very flexible mapping and suggest the value 0 being the
* highest severity and 7 to be the lowest (debugging level) severity.
@ -731,8 +733,8 @@ void log_output_string(const struct log_output *output,
if (IS_ENABLED(CONFIG_LOG_MIPI_SYST_ENABLE) &&
flags & LOG_OUTPUT_FLAG_FORMAT_SYST) {
log_output_string_syst_process(output,
src_level, fmt, ap, flags);
log_output_string_syst_process(output, src_level, fmt, ap,
flags, source_id);
return;
}
@ -769,9 +771,9 @@ void log_output_hexdump(const struct log_output *output,
if (IS_ENABLED(CONFIG_LOG_MIPI_SYST_ENABLE) &&
flags & LOG_OUTPUT_FLAG_FORMAT_SYST) {
log_output_hexdump_syst_process(output,
src_level, metadata,
data, length, flags);
log_output_hexdump_syst_process(output, src_level, metadata,
data, length, flags,
source_id);
return;
}

View file

@ -420,6 +420,29 @@ static void update_systh_platform_data(struct mipi_syst_handle *handle,
#endif
}
#if defined(CONFIG_LOG1) || defined(CONFIG_LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID)
/**
* @brief Set module ID in the origin unit of Sys-T message
*
* Note that this only sets the module ID if
* CONFIG_LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID is enabled.
* Otherwise, this is a no-op as the module ID is set to
* default at boot time, and no need to be set again.
*
* @param handle Pointer to mipi_syst_handle struct
* @param module_id Module ID to be set (range 0x00 - 0x7F)
*/
static void update_handle_origin_unit(struct mipi_syst_handle *handle,
int16_t module_id)
{
handle->systh_tag.et_modunit =
_MIPI_SYST_MK_MODUNIT_ORIGIN(
module_id,
CONFIG_LOG_MIPI_SYST_MSG_DEFAULT_UNIT_ID
);
}
#endif
#if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)
/*
* Platform specific SyS-T handle initialization hook function
@ -717,6 +740,12 @@ void log_output_msg_syst_process(const struct log_output *log_output,
update_systh_platform_data(&log_syst_handle, log_output, flag);
#ifdef CONFIG_LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID
int16_t source_id = (int16_t)log_msg_source_id_get(msg);
update_handle_origin_unit(&log_syst_handle, source_id);
#endif
if (log_msg_is_std(msg)) {
std_print(msg, log_output);
} else if (raw_string) {
@ -728,11 +757,13 @@ void log_output_msg_syst_process(const struct log_output *log_output,
void log_output_string_syst_process(const struct log_output *log_output,
struct log_msg_ids src_level,
const char *fmt, va_list ap, uint32_t flag)
const char *fmt, va_list ap, uint32_t flag,
int16_t source_id)
{
uint32_t severity = level_to_syst_severity((uint32_t)src_level.level);
update_systh_platform_data(&log_syst_handle, log_output, flag);
update_handle_origin_unit(&log_syst_handle, source_id);
MIPI_SYST_VPRINTF(&log_syst_handle, severity, fmt, ap);
}
@ -741,11 +772,12 @@ void log_output_hexdump_syst_process(const struct log_output *log_output,
struct log_msg_ids src_level,
const char *metadata,
const uint8_t *data, uint32_t length,
uint32_t flag)
uint32_t flag, int16_t source_id)
{
uint32_t severity = level_to_syst_severity((uint32_t)src_level.level);
update_systh_platform_data(&log_syst_handle, log_output, flag);
update_handle_origin_unit(&log_syst_handle, source_id);
MIPI_SYST_PRINTF(&log_syst_handle, severity, "%s", metadata);
@ -1180,6 +1212,25 @@ void log_output_msg2_syst_process(const struct log_output *output,
update_systh_platform_data(&log_syst_handle, output, flag);
#ifdef CONFIG_LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID
uint8_t level = log_msg2_get_level(msg);
bool raw_string = (level == LOG_LEVEL_INTERNAL_RAW_STRING);
int16_t source_id = CONFIG_LOG_MIPI_SYST_MSG_DEFAULT_MODULE_ID;
/* Set the log source ID as Sys-T message module ID */
if (!raw_string) {
void *source = (void *)log_msg2_get_source(msg);
if (source != NULL) {
source_id = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ?
log_dynamic_source_id(source) :
log_const_source_id(source);
}
}
update_handle_origin_unit(&log_syst_handle, source_id);
#endif
uint8_t *data = log_msg2_get_package(msg, &len);
if (len) {
@ -1211,6 +1262,17 @@ static int syst_init(const struct device *arg)
MIPI_SYST_INIT_HANDLE_STATE(&log_syst_header,
&log_syst_handle, NULL);
log_syst_handle.systh_tag.et_guid = 0;
#ifndef CONFIG_LOG_MIPI_SYST_OUTPUT_LOG_MSG_SRC_ID
/* Set the default here once as it won't be modified anymore. */
log_syst_handle.systh_tag.et_modunit =
_MIPI_SYST_MK_MODUNIT_ORIGIN(
CONFIG_LOG_MIPI_SYST_MSG_DEFAULT_MODULE_ID,
CONFIG_LOG_MIPI_SYST_MSG_DEFAULT_UNIT_ID
);
#endif
return 0;
}