logging: log_frontend: Add optional API for common messages

Extend frontend API with optional set of functions which can
be used when simplified log message handling is enabled. If this
mode is enabled then there are dedicated macros for processing the
most common messages (string + 0-2 word arguments). Using this API
can speed up the processing of messages that are the most common.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2023-10-19 14:40:16 +02:00 committed by Carles Cufí
parent 1a0e8d6f9e
commit 900f9c3b24
3 changed files with 125 additions and 52 deletions

View file

@ -12,7 +12,7 @@
*/
void log_frontend_init(void);
/** @brief Log message.
/** @brief Log generic message.
*
* Message details does not contain timestamp. Since function is called in the
* context of log message call, implementation can use its own timestamping scheme.
@ -32,6 +32,52 @@ void log_frontend_msg(const void *source,
const struct log_msg_desc desc,
uint8_t *package, const void *data);
/** @brief Log message with 0 arguments.
*
* Optimized version for log message which does not have arguments (only string).
* This API is optional and is used only if optimizing common log messages is enabled.
*
* @param source Pointer to a structure associated with given source. It points to
* static structure or dynamic structure if runtime filtering is enabled.
* @ref log_const_source_id or @ref log_dynamic_source_id can be used to determine
* source id.
* @param level Severity level.
* @param fmt String.
*/
void log_frontend_simple_0(const void *source, uint32_t level, const char *fmt);
/** @brief Log message with 1 argument.
*
* Optimized version for log message which has one argument that fits in a 32 bit word.
* This API is optional and is used only if optimizing common log messages is enabled.
*
* @param source Pointer to a structure associated with given source. It points to
* static structure or dynamic structure if runtime filtering is enabled.
* @ref log_const_source_id or @ref log_dynamic_source_id can be used to determine
* source id.
* @param level Severity level.
* @param fmt String.
* @param arg Argument passed to the string.
*/
void log_frontend_simple_1(const void *source, uint32_t level, const char *fmt, uint32_t arg);
/** @brief Log message with 2 arguments.
*
* Optimized version for log message which has two arguments that fit in a 32 bit word.
* This API is optional and is used only if optimizing common log messages is enabled.
*
* @param source Pointer to a structure associated with given source. It points to
* static structure or dynamic structure if runtime filtering is enabled.
* @ref log_const_source_id or @ref log_dynamic_source_id can be used to determine
* source id.
* @param level Severity level.
* @param fmt String.
* @param arg0 First argument passed to the string.
* @param arg1 Second argument passed to the string.
*/
void log_frontend_simple_2(const void *source, uint32_t level,
const char *fmt, uint32_t arg0, uint32_t arg1);
/** @brief Panic state notification. */
void log_frontend_panic(void);

View file

@ -53,6 +53,12 @@ config LOG_FRONTEND_ONLY
Option indicates that there are no backends intended to be used.
Code asserts if any backend is enabled.
config LOG_FRONTEND_OPT_API
bool "Frontend optimized API"
help
When enabled, frontend implements functions which are optimized versions
used for the most common log messages.
config LOG_CUSTOM_HEADER
bool "Include Custom Log Header"
help

View file

@ -97,23 +97,30 @@ void z_impl_z_log_msg_simple_create_0(const void *source, uint32_t level, const
{
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
uint32_t plen32 = CBPRINTF_DESC_SIZE32 + 1;
union cbprintf_package_hdr hdr = {
.desc = {
.len = plen32
}
};
uint32_t package[] = {
(uint32_t)(uintptr_t)hdr.raw,
(uint32_t)(uintptr_t)fmt,
};
struct log_msg_desc desc = {
.level = level,
.package_len = plen32 * sizeof(uint32_t),
.data_len = 0,
};
if (IS_ENABLED(CONFIG_LOG_FRONTEND_OPT_API)) {
log_frontend_simple_0(source, level, fmt);
} else {
/* If frontend does not support optimized API prepare data for
* the generic call.
*/
uint32_t plen32 = CBPRINTF_DESC_SIZE32 + 1;
union cbprintf_package_hdr hdr = {
.desc = {
.len = plen32
}
};
uint32_t package[] = {
(uint32_t)(uintptr_t)hdr.raw,
(uint32_t)(uintptr_t)fmt,
};
struct log_msg_desc desc = {
.level = level,
.package_len = plen32 * sizeof(uint32_t),
.data_len = 0,
};
log_frontend_msg(source, desc, (uint8_t *)package, NULL);
log_frontend_msg(source, desc, (uint8_t *)package, NULL);
}
}
if (!BACKENDS_IN_USE()) {
@ -129,24 +136,31 @@ void z_impl_z_log_msg_simple_create_1(const void *source, uint32_t level,
const char *fmt, uint32_t arg)
{
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
uint32_t plen32 = CBPRINTF_DESC_SIZE32 + 2;
union cbprintf_package_hdr hdr = {
.desc = {
.len = plen32
}
};
uint32_t package[] = {
(uint32_t)(uintptr_t)hdr.raw,
(uint32_t)(uintptr_t)fmt,
arg
};
struct log_msg_desc desc = {
.level = level,
.package_len = plen32 * sizeof(uint32_t),
.data_len = 0,
};
if (IS_ENABLED(CONFIG_LOG_FRONTEND_OPT_API)) {
log_frontend_simple_1(source, level, fmt, arg);
} else {
/* If frontend does not support optimized API prepare data for
* the generic call.
*/
uint32_t plen32 = CBPRINTF_DESC_SIZE32 + 2;
union cbprintf_package_hdr hdr = {
.desc = {
.len = plen32
}
};
uint32_t package[] = {
(uint32_t)(uintptr_t)hdr.raw,
(uint32_t)(uintptr_t)fmt,
arg
};
struct log_msg_desc desc = {
.level = level,
.package_len = plen32 * sizeof(uint32_t),
.data_len = 0,
};
log_frontend_msg(source, desc, (uint8_t *)package, NULL);
log_frontend_msg(source, desc, (uint8_t *)package, NULL);
}
}
if (!BACKENDS_IN_USE()) {
@ -162,25 +176,32 @@ void z_impl_z_log_msg_simple_create_2(const void *source, uint32_t level,
const char *fmt, uint32_t arg0, uint32_t arg1)
{
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
uint32_t plen32 = CBPRINTF_DESC_SIZE32 + 3;
union cbprintf_package_hdr hdr = {
.desc = {
.len = plen32
}
};
uint32_t package[] = {
[0](uint32_t)(uintptr_t)hdr.raw,
(uint32_t)(uintptr_t)fmt,
arg0,
arg1
};
struct log_msg_desc desc = {
.level = level,
.package_len = plen32 * sizeof(uint32_t),
.data_len = 0,
};
if (IS_ENABLED(CONFIG_LOG_FRONTEND_OPT_API)) {
log_frontend_simple_2(source, level, fmt, arg0, arg1);
} else {
/* If frontend does not support optimized API prepare data for
* the generic call.
*/
uint32_t plen32 = CBPRINTF_DESC_SIZE32 + 3;
union cbprintf_package_hdr hdr = {
.desc = {
.len = plen32
}
};
uint32_t package[] = {
[0](uint32_t)(uintptr_t)hdr.raw,
(uint32_t)(uintptr_t)fmt,
arg0,
arg1
};
struct log_msg_desc desc = {
.level = level,
.package_len = plen32 * sizeof(uint32_t),
.data_len = 0,
};
log_frontend_msg(source, desc, (uint8_t *)package, NULL);
log_frontend_msg(source, desc, (uint8_t *)package, NULL);
}
}
if (!BACKENDS_IN_USE()) {