logging: Initial multidomain support
Adding multidomain support by introducing log_link module which acts as a receiver of log messages created by another domain. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
7fb54e221b
commit
e322447109
21 changed files with 1206 additions and 196 deletions
|
@ -137,8 +137,6 @@ after which logging thread is started.
|
|||
:kconfig:option:`CONFIG_LOG_BUFFER_SIZE`: Number of bytes dedicated for the circular
|
||||
packet buffer.
|
||||
|
||||
:kconfig:option:`CONFIG_LOG_DOMAIN_ID`: Domain ID. Valid in multi-domain systems.
|
||||
|
||||
:kconfig:option:`CONFIG_LOG_FRONTEND`: Direct logs to a custom frontend.
|
||||
|
||||
:kconfig:option:`CONFIG_LOG_FRONTEND_ONLY`: No backends are used when messages goes to frontend.
|
||||
|
|
|
@ -1346,7 +1346,7 @@ uint32_t mdm_hl7800_log_filter_set(uint32_t level)
|
|||
|
||||
#ifdef CONFIG_LOG
|
||||
new_log_level =
|
||||
log_filter_set(NULL, CONFIG_LOG_DOMAIN_ID,
|
||||
log_filter_set(NULL, Z_LOG_LOCAL_DOMAIN_ID,
|
||||
log_source_id_get(STRINGIFY(LOG_MODULE_NAME)),
|
||||
level);
|
||||
#endif
|
||||
|
|
|
@ -66,6 +66,9 @@
|
|||
__shell_cmd_end = .;
|
||||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
|
||||
ITERABLE_SECTION_RAM_GC_ALLOWED(log_mpsc_pbuf, 4)
|
||||
ITERABLE_SECTION_RAM(log_msg_ptr, 4)
|
||||
|
||||
SECTION_DATA_PROLOGUE(log_dynamic_sections,,)
|
||||
{
|
||||
__log_dynamic_start = .;
|
||||
|
|
|
@ -15,3 +15,5 @@
|
|||
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
|
||||
ITERABLE_SECTION_ROM(log_backend, 4)
|
||||
|
||||
ITERABLE_SECTION_ROM(log_link, 4)
|
||||
|
|
|
@ -82,6 +82,9 @@ struct log_backend_control_block {
|
|||
void *ctx;
|
||||
uint8_t id;
|
||||
bool active;
|
||||
|
||||
/* Initialization level. */
|
||||
uint8_t level;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,9 +31,8 @@ extern "C" {
|
|||
#define CONFIG_LOG_MAX_LEVEL 0U
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_LOG) || defined(CONFIG_LOG_MODE_MINIMAL)
|
||||
#define CONFIG_LOG_DOMAIN_ID 0U
|
||||
#endif
|
||||
/* Id of local domain. */
|
||||
#define Z_LOG_LOCAL_DOMAIN_ID 0
|
||||
|
||||
#define LOG_FUNCTION_PREFIX_MASK \
|
||||
(((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_ERR) << \
|
||||
|
@ -238,7 +237,7 @@ static inline char z_log_minimal_level_to_char(int level)
|
|||
void *_src = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
|
||||
(void *)_dsource : (void *)_source; \
|
||||
Z_LOG_MSG2_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), _mode, \
|
||||
CONFIG_LOG_DOMAIN_ID, _src, _level, NULL,\
|
||||
Z_LOG_LOCAL_DOMAIN_ID, _src, _level, NULL,\
|
||||
0, __VA_ARGS__); \
|
||||
(void)_mode; \
|
||||
if (false) { \
|
||||
|
@ -314,7 +313,7 @@ static inline char z_log_minimal_level_to_char(int level)
|
|||
void *_src = IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
|
||||
(void *)_dsource : (void *)_source; \
|
||||
Z_LOG_MSG2_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), mode, \
|
||||
CONFIG_LOG_DOMAIN_ID, _src, _level, \
|
||||
Z_LOG_LOCAL_DOMAIN_ID, _src, _level, \
|
||||
_data, _len, \
|
||||
COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \
|
||||
(), \
|
||||
|
@ -411,7 +410,7 @@ extern struct log_source_const_data __log_const_end[];
|
|||
z_log_printf_arg_checker(__VA_ARGS__); \
|
||||
} \
|
||||
Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), _mode, \
|
||||
CONFIG_LOG_DOMAIN_ID, (uintptr_t)_is_raw, \
|
||||
Z_LOG_LOCAL_DOMAIN_ID, (uintptr_t)_is_raw, \
|
||||
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
|
||||
} while (0)
|
||||
|
||||
|
@ -472,7 +471,7 @@ void z_log_printf_arg_checker(const char *fmt, ...)
|
|||
*/
|
||||
static inline void log2_generic(uint8_t level, const char *fmt, va_list ap)
|
||||
{
|
||||
z_log_msg_runtime_vcreate(CONFIG_LOG_DOMAIN_ID, NULL, level,
|
||||
z_log_msg_runtime_vcreate(Z_LOG_LOCAL_DOMAIN_ID, NULL, level,
|
||||
NULL, 0, 0, fmt, ap);
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,17 @@ uint32_t log_src_cnt_get(uint32_t domain_id);
|
|||
*/
|
||||
const char *log_source_name_get(uint32_t domain_id, uint32_t source_id);
|
||||
|
||||
/** @brief Return number of domains present in the system.
|
||||
*
|
||||
* There will be at least one local domain.
|
||||
*
|
||||
* @return Number of domains.
|
||||
*/
|
||||
static inline uint8_t log_domains_count(void)
|
||||
{
|
||||
return 1 + (IS_ENABLED(CONFIG_LOG_MULTIDOMAIN) ? z_log_ext_domain_count() : 0);
|
||||
}
|
||||
|
||||
/** @brief Get name of the domain.
|
||||
*
|
||||
* @param domain_id Domain ID.
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <zephyr/types.h>
|
||||
#include <zephyr/sys/__assert.h>
|
||||
#include <zephyr/logging/log_core.h>
|
||||
#include <zephyr/sys/mpsc_pbuf.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -19,6 +20,16 @@ extern "C" {
|
|||
* not intended to be used outside, including logging backends.
|
||||
*/
|
||||
|
||||
/** @brief Structure wrapper to be used for memory section. */
|
||||
struct log_mpsc_pbuf {
|
||||
struct mpsc_pbuf_buffer buf;
|
||||
};
|
||||
|
||||
/** @brief Structure wrapper to be used for memory section. */
|
||||
struct log_msg_ptr {
|
||||
union log_msg_generic *msg;
|
||||
};
|
||||
|
||||
/** @brief Indicate to the log core that one log message has been dropped.
|
||||
*
|
||||
* @param buffered True if dropped message was already buffered and it is being
|
||||
|
@ -49,6 +60,21 @@ void z_log_free(void *buf);
|
|||
/* Initialize runtime filters */
|
||||
void z_log_runtime_filters_init(void);
|
||||
|
||||
/* Initialize links. */
|
||||
void z_log_links_initiate(void);
|
||||
|
||||
/* Activate links.
|
||||
* Attemp to activate links,
|
||||
*
|
||||
* @param active_mask Mask with links to activate. N bit set indicates that Nth
|
||||
* link should be activated.
|
||||
*
|
||||
* @param[in, out] offset Offset assigned to domains. Initialize to 0 before first use.
|
||||
*
|
||||
* @return Mask with links that still remain inactive.
|
||||
*/
|
||||
uint32_t z_log_links_activate(uint32_t active_mask, uint8_t *offset);
|
||||
|
||||
/* Notify log_core that a backend was enabled. */
|
||||
void z_log_notify_backend_enabled(void);
|
||||
|
||||
|
@ -69,6 +95,12 @@ static inline uint32_t z_log_sources_count(void)
|
|||
return log_const_source_id(__log_const_end);
|
||||
}
|
||||
|
||||
/** @brief Return number of external domains.
|
||||
*
|
||||
* @return Number of external domains.
|
||||
*/
|
||||
uint8_t z_log_ext_domain_count(void);
|
||||
|
||||
/** @brief Initialize module for handling logging message. */
|
||||
void z_log_msg_init(void);
|
||||
|
||||
|
@ -80,11 +112,12 @@ void z_log_msg_commit(struct log_msg *msg);
|
|||
|
||||
/** @brief Get pending log message.
|
||||
*
|
||||
* @param[out] len Message length in bytes is written is @p len is not null.
|
||||
* @param[out] backoff Recommended backoff needed to maintain ordering of processed
|
||||
* messages. Used only when links are using dedicated buffers.
|
||||
*
|
||||
* @param Message or null if no pending messages.
|
||||
*/
|
||||
union log_msg_generic *z_log_msg_claim(void);
|
||||
union log_msg_generic *z_log_msg_claim(k_timeout_t *backoff);
|
||||
|
||||
/** @brief Free message.
|
||||
*
|
||||
|
@ -99,12 +132,33 @@ void z_log_msg_free(union log_msg_generic *msg);
|
|||
*/
|
||||
bool z_log_msg_pending(void);
|
||||
|
||||
static inline void z_log_notify_drop(const struct mpsc_pbuf_buffer *buffer,
|
||||
const union mpsc_pbuf_generic *item)
|
||||
{
|
||||
ARG_UNUSED(buffer);
|
||||
ARG_UNUSED(item);
|
||||
|
||||
z_log_dropped(true);
|
||||
}
|
||||
|
||||
/** @brief Get tag.
|
||||
*
|
||||
* @return Tag. Null if feature is disabled.
|
||||
*/
|
||||
const char *z_log_get_tag(void);
|
||||
|
||||
/** @brief Check if domain is local.
|
||||
*
|
||||
* @param domain_id Domain ID.
|
||||
*
|
||||
* @return True if domain is local.
|
||||
*/
|
||||
static inline bool z_log_is_local_domain(uint8_t domain_id)
|
||||
{
|
||||
return !IS_ENABLED(CONFIG_LOG_MULTIDOMAIN) ||
|
||||
(domain_id == Z_LOG_LOCAL_DOMAIN_ID);
|
||||
}
|
||||
|
||||
/** @brief Get timestamp.
|
||||
*
|
||||
* @return Timestamp.
|
||||
|
|
291
include/zephyr/logging/log_link.h
Normal file
291
include/zephyr/logging/log_link.h
Normal file
|
@ -0,0 +1,291 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_
|
||||
#define ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <zephyr/sys/__assert.h>
|
||||
#include <zephyr/logging/log_msg.h>
|
||||
#include <zephyr/logging/log_internal.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Log link API
|
||||
* @defgroup log_link Log link API
|
||||
* @ingroup logger
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct log_link;
|
||||
|
||||
typedef void (*log_link_callback_t)(const struct log_link *link,
|
||||
union log_msg_generic *msg);
|
||||
|
||||
typedef void (*log_link_dropped_cb_t)(const struct log_link *link,
|
||||
uint32_t dropped);
|
||||
|
||||
struct log_link_config {
|
||||
log_link_callback_t msg_cb;
|
||||
log_link_dropped_cb_t dropped_cb;
|
||||
};
|
||||
|
||||
struct log_link_api {
|
||||
int (*initiate)(const struct log_link *link, struct log_link_config *config);
|
||||
int (*activate)(const struct log_link *link);
|
||||
int (*get_domain_name)(const struct log_link *link, uint32_t domain_id,
|
||||
char *buf, size_t *length);
|
||||
int (*get_source_name)(const struct log_link *link, uint32_t domain_id,
|
||||
uint16_t source_id, char *buf, size_t *length);
|
||||
int (*get_levels)(const struct log_link *link, uint32_t domain_id,
|
||||
uint16_t source_id, uint8_t *level,
|
||||
uint8_t *runtime_level);
|
||||
int (*set_runtime_level)(const struct log_link *link, uint32_t domain_id,
|
||||
uint16_t source_id, uint8_t level);
|
||||
};
|
||||
|
||||
struct log_link_ctrl_blk {
|
||||
uint32_t domain_cnt;
|
||||
uint16_t source_cnt[1 + COND_CODE_1(CONFIG_LOG_MULTIDOMAIN,
|
||||
(CONFIG_LOG_REMOTE_DOMAIN_MAX_COUNT),
|
||||
(0))];
|
||||
uint32_t domain_offset;
|
||||
uint32_t *filters;
|
||||
};
|
||||
|
||||
struct log_link {
|
||||
const struct log_link_api *api;
|
||||
const char *name;
|
||||
struct log_link_ctrl_blk *ctrl_blk;
|
||||
void *ctx;
|
||||
struct mpsc_pbuf_buffer *mpsc_pbuf;
|
||||
const struct mpsc_pbuf_buffer_config *mpsc_pbuf_config;
|
||||
};
|
||||
|
||||
/** @brief Create instance of a log link.
|
||||
*
|
||||
* Link can have dedicated buffer for messages if @p _buf_len is positive. In
|
||||
* that case messages will be processed in an order since logging core will
|
||||
* attempt to fetch message from all available buffers (default and links) and
|
||||
* process the one with the earliest timestamp. If strict ordering is not needed
|
||||
* then dedicated buffer may be omitted (@p _buf_len set to 0). That results in
|
||||
* better memory utilization but unordered messages passed to backends.
|
||||
*
|
||||
* @param _name Instance name.
|
||||
* @param _api API list. See @ref log_link_api.
|
||||
* @param _buf_wlen Size (in words) of dedicated buffer for messages from this buffer.
|
||||
* If 0 default buffer is used.
|
||||
* @param _ctx Context (void *) associated with the link.
|
||||
*/
|
||||
#define LOG_LINK_DEF(_name, _api, _buf_wlen, _ctx) \
|
||||
static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT) _name##_buf32[_buf_wlen]; \
|
||||
static const struct mpsc_pbuf_buffer_config _name##_mpsc_pbuf_config = { \
|
||||
.buf = (uint32_t *)_name##_buf32, \
|
||||
.size = _buf_wlen, \
|
||||
.notify_drop = z_log_notify_drop, \
|
||||
.get_wlen = log_msg_generic_get_wlen, \
|
||||
.flags = IS_ENABLED(CONFIG_LOG_MODE_OVERFLOW) ? \
|
||||
MPSC_PBUF_MODE_OVERWRITE : 0 \
|
||||
}; \
|
||||
COND_CODE_0(_buf_wlen, (), (static STRUCT_SECTION_ITERABLE(log_msg_ptr, \
|
||||
_name##_log_msg_ptr);)) \
|
||||
static STRUCT_SECTION_ITERABLE_ALTERNATE(log_mpsc_pbuf, \
|
||||
mpsc_pbuf_buffer, \
|
||||
_name##_log_mpsc_pbuf); \
|
||||
static struct log_link_ctrl_blk _name##_ctrl_blk; \
|
||||
static const STRUCT_SECTION_ITERABLE(log_link, _name) = \
|
||||
{ \
|
||||
.api = &_api, \
|
||||
.name = STRINGIFY(_name), \
|
||||
.ctrl_blk = &_name##_ctrl_blk, \
|
||||
.ctx = _ctx, \
|
||||
.mpsc_pbuf = _buf_wlen ? &_name##_log_mpsc_pbuf : NULL, \
|
||||
.mpsc_pbuf_config = _buf_wlen ? &_name##_mpsc_pbuf_config : NULL \
|
||||
}
|
||||
|
||||
/** @brief Initiate log link.
|
||||
*
|
||||
* Function initiates the link. Since initialization procedure may be time
|
||||
* consuming, function returns before link is ready to not block logging
|
||||
* initialization. @ref log_link_activate is called to complete link initialization.
|
||||
*
|
||||
* @param link Log link instance.
|
||||
* @param config Configuration.
|
||||
*
|
||||
* @return 0 on success or error code.
|
||||
*/
|
||||
static inline int log_link_initiate(const struct log_link *link,
|
||||
struct log_link_config *config)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
|
||||
return link->api->initiate(link, config);
|
||||
}
|
||||
|
||||
/** @brief Activate log link.
|
||||
*
|
||||
* Function checks if link is initilized and completes initialization process.
|
||||
* When successfully returns, link is ready with domain and sources count fetched
|
||||
* and timestamp details updated.
|
||||
*
|
||||
* @param link Log link instance.
|
||||
*
|
||||
* @retval 0 When successfully activated.
|
||||
* @retval -EINPROGRESS Activation in progress.
|
||||
*/
|
||||
static inline int log_link_activate(const struct log_link *link)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
|
||||
return link->api->activate(link);
|
||||
}
|
||||
|
||||
/** @brief Check if link is activated.
|
||||
*
|
||||
* @param link Log link instance.
|
||||
*
|
||||
* @retval 0 When successfully activated.
|
||||
* @retval -EINPROGRESS Activation in progress.
|
||||
*/
|
||||
static inline int log_link_is_active(const struct log_link *link)
|
||||
{
|
||||
return link->ctrl_blk->domain_offset > 0 ? 0 : -EINPROGRESS;
|
||||
}
|
||||
|
||||
/** @brief Get number of domains in the link.
|
||||
*
|
||||
* @param[in] link Log link instance.
|
||||
*
|
||||
* @return Number of domains.
|
||||
*/
|
||||
static inline uint8_t log_link_domains_count(const struct log_link *link)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
|
||||
return link->ctrl_blk->domain_cnt;
|
||||
}
|
||||
|
||||
/** @brief Get number of sources in the domain.
|
||||
*
|
||||
* @param[in] link Log link instance.
|
||||
* @param[in] domain_id Relative domain ID.
|
||||
*
|
||||
* @return Source count.
|
||||
*/
|
||||
static inline uint16_t log_link_sources_count(const struct log_link *link,
|
||||
uint32_t domain_id)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
|
||||
return link->ctrl_blk->source_cnt[domain_id];
|
||||
}
|
||||
|
||||
/** @brief Get domain name.
|
||||
*
|
||||
* @param[in] link Log link instance.
|
||||
* @param[in] domain_id Relative domain ID.
|
||||
* @param[out] buf Output buffer filled with domain name. If NULL
|
||||
* then name length is returned.
|
||||
* @param[in,out] length Buffer size. Name is trimmed if it does not fit
|
||||
* in the buffer and field is set to actual name
|
||||
* length.
|
||||
*
|
||||
* @return 0 on success or error code.
|
||||
*/
|
||||
static inline int log_link_get_domain_name(const struct log_link *link,
|
||||
uint32_t domain_id, char *buf,
|
||||
size_t *length)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
|
||||
return link->api->get_domain_name(link, domain_id, buf, length);
|
||||
}
|
||||
|
||||
/** @brief Get source name.
|
||||
*
|
||||
* @param[in] link Log link instance.
|
||||
* @param[in] domain_id Relative domain ID.
|
||||
* @param[in] source_id Source ID.
|
||||
* @param[out] buf Output buffer filled with source name.
|
||||
* @param[in,out] length Buffer size. Name is trimmed if it does not fit
|
||||
* in the buffer and field is set to actual name
|
||||
* length.
|
||||
*
|
||||
* @return 0 on success or error code.
|
||||
*/
|
||||
static inline int log_link_get_source_name(const struct log_link *link,
|
||||
uint32_t domain_id, uint16_t source_id,
|
||||
char *buf, size_t *length)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
__ASSERT_NO_MSG(buf);
|
||||
|
||||
return link->api->get_source_name(link, domain_id, source_id,
|
||||
buf, length);
|
||||
}
|
||||
|
||||
/** @brief Get level settings of the given source.
|
||||
*
|
||||
* @param[in] link Log link instance.
|
||||
* @param[in] domain_id Relative domain ID.
|
||||
* @param[in] source_id Source ID.
|
||||
* @param[out] level Location to store requested compile time level.
|
||||
* @param[out] runtime_level Location to store requested runtime time level.
|
||||
*
|
||||
* @return 0 on success or error code.
|
||||
*/
|
||||
static inline int log_link_get_levels(const struct log_link *link,
|
||||
uint32_t domain_id, uint16_t source_id,
|
||||
uint8_t *level, uint8_t *runtime_level)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
|
||||
return link->api->get_levels(link, domain_id, source_id,
|
||||
level, runtime_level);
|
||||
}
|
||||
|
||||
/** @brief Set runtime level of the given source.
|
||||
*
|
||||
* @param[in] link Log link instance.
|
||||
* @param[in] domain_id Relative domain ID.
|
||||
* @param[in] source_id Source ID.
|
||||
* @param[out] level Requested level.
|
||||
*
|
||||
* @return 0 on success or error code.
|
||||
*/
|
||||
static inline int log_link_set_runtime_level(const struct log_link *link,
|
||||
uint32_t domain_id, uint16_t source_id,
|
||||
uint8_t level)
|
||||
{
|
||||
__ASSERT_NO_MSG(link);
|
||||
__ASSERT_NO_MSG(level);
|
||||
|
||||
return link->api->set_runtime_level(link, domain_id, source_id, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enqueue external log message.
|
||||
*
|
||||
* Add log message to processing queue. Log message is created outside local
|
||||
* core. For example it maybe coming from external domain.
|
||||
*
|
||||
* @param link Log link instance.
|
||||
* @param data Message from remote domain.
|
||||
* @param len Length in bytes.
|
||||
*/
|
||||
void z_log_msg_enqueue(const struct log_link *link, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_LINK_H_ */
|
|
@ -273,15 +273,15 @@ static void log_demo_thread(void *p1, void *p2, void *p3)
|
|||
/* Re-enabling filters before processing.
|
||||
* Note: Same filters are used to for gathering logs and processing.
|
||||
*/
|
||||
log_filter_set(NULL, CONFIG_LOG_DOMAIN_ID,
|
||||
log_filter_set(NULL, Z_LOG_LOCAL_DOMAIN_ID,
|
||||
log_source_id_get(sample_module_name_get()),
|
||||
CONFIG_LOG_DEFAULT_LEVEL);
|
||||
|
||||
log_filter_set(NULL, CONFIG_LOG_DOMAIN_ID,
|
||||
log_filter_set(NULL, Z_LOG_LOCAL_DOMAIN_ID,
|
||||
log_source_id_get(INST1_NAME),
|
||||
CONFIG_LOG_DEFAULT_LEVEL);
|
||||
|
||||
log_filter_set(NULL, CONFIG_LOG_DOMAIN_ID,
|
||||
log_filter_set(NULL, Z_LOG_LOCAL_DOMAIN_ID,
|
||||
log_source_id_get(INST2_NAME),
|
||||
CONFIG_LOG_DEFAULT_LEVEL);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ if(NOT CONFIG_LOG_MODE_MINIMAL)
|
|||
CONFIG_LOG
|
||||
log_core.c
|
||||
log_mgmt.c
|
||||
log_cache.c
|
||||
log_msg.c
|
||||
log_cache.c
|
||||
)
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
menu "Misc"
|
||||
|
||||
config LOG_DOMAIN_ID
|
||||
int "Domain ID"
|
||||
int "Domain ID [DEPRECATED]"
|
||||
depends on !LOG_MODE_MINIMAL
|
||||
default 0
|
||||
range 0 7
|
||||
help
|
||||
In multicore system each application/core must have unique domain ID.
|
||||
Deprecated. It is not used in the code.
|
||||
|
||||
config LOG_CMDS
|
||||
bool "Shell commands"
|
||||
|
@ -81,4 +81,26 @@ config LOG_MSG_APPEND_RO_STRING_LOC
|
|||
read-only string arguments in the package. This should be selected by
|
||||
backends if required.
|
||||
|
||||
config LOG_FAILURE_REPORT_PERIOD
|
||||
int "Failure report period (in milliseconds)"
|
||||
default 1000
|
||||
depends on LOG_MODE_DEFERRED
|
||||
help
|
||||
Determines how often failures are reported. Report contains number
|
||||
of dropped messages. It may contain additional information depending
|
||||
on the mode.
|
||||
|
||||
config LOG_DOMAIN_NAME
|
||||
string "Domain name"
|
||||
default ""
|
||||
|
||||
if LOG_MULTIDOMAIN
|
||||
|
||||
config LOG_REMOTE_DOMAIN_MAX_COUNT
|
||||
int "Maximum number of link domains"
|
||||
default 4
|
||||
help
|
||||
Number of domains that can be handled by a link
|
||||
|
||||
endif
|
||||
endmenu
|
||||
|
|
|
@ -54,3 +54,7 @@ config LOG_FRONTEND_ONLY
|
|||
|
||||
config LOG_DEFAULT_MINIMAL
|
||||
bool
|
||||
|
||||
config LOG_MULTIDOMAIN
|
||||
bool "Multi-domain logger"
|
||||
select LOG_TIMESTAMP_64BIT
|
||||
|
|
|
@ -90,6 +90,17 @@ config LOG_PROCESS_THREAD_STACK_SIZE
|
|||
help
|
||||
Set the internal stack size for log processing thread.
|
||||
|
||||
config LOG_PROCESSING_LATENCY_US
|
||||
int "Maximum remote message latency (in microseconds)"
|
||||
default 100000
|
||||
depends on LOG_MULTIDOMAIN
|
||||
help
|
||||
Arbitrary time between log message creation in the remote domain and
|
||||
processing in the local domain. Higher value increases message processing
|
||||
latency but increases chances of maintaining correct ordering of the
|
||||
messages. Option is used only if links are using dedicated buffers
|
||||
for remote messages.
|
||||
|
||||
config LOG_PROCESS_THREAD_CUSTOM_PRIORITY
|
||||
bool "Custom log thread priority"
|
||||
help
|
||||
|
@ -114,6 +125,26 @@ config LOG_BUFFER_SIZE
|
|||
|
||||
endif # LOG_MODE_DEFERRED && !LOG_FRONTEND_ONLY
|
||||
|
||||
if LOG_MULTIDOMAIN
|
||||
|
||||
config LOG_DOMAIN_NAME_CACHE_ENTRY_SIZE
|
||||
int "Cache slot size of domain name"
|
||||
default 8
|
||||
|
||||
config LOG_DOMAIN_NAME_CACHE_ENTRY_COUNT
|
||||
int "Number of entries in domain name cache"
|
||||
default 2
|
||||
|
||||
config LOG_SOURCE_NAME_CACHE_ENTRY_SIZE
|
||||
int "Cache slot size of source name"
|
||||
default 16
|
||||
|
||||
config LOG_SOURCE_NAME_CACHE_ENTRY_COUNT
|
||||
int "Number of entries in source name cache"
|
||||
default 8
|
||||
|
||||
endif # LOG_MULTIDOMAIN
|
||||
|
||||
config LOG_TRACE_SHORT_TIMESTAMP
|
||||
bool "Use 24 bit timestamp for tracing"
|
||||
default y
|
||||
|
|
|
@ -91,7 +91,7 @@ static int log_status(const struct shell *shell,
|
|||
const struct log_backend *backend,
|
||||
size_t argc, char **argv)
|
||||
{
|
||||
uint32_t modules_cnt = z_log_sources_count();
|
||||
uint32_t modules_cnt = log_src_cnt_get(Z_LOG_LOCAL_DOMAIN_ID);
|
||||
uint32_t dynamic_lvl;
|
||||
uint32_t compiled_lvl;
|
||||
|
||||
|
@ -105,13 +105,13 @@ static int log_status(const struct shell *shell,
|
|||
"----------------------------------------------------------\r\n");
|
||||
|
||||
for (int16_t i = 0U; i < modules_cnt; i++) {
|
||||
dynamic_lvl = log_filter_get(backend, CONFIG_LOG_DOMAIN_ID,
|
||||
dynamic_lvl = log_filter_get(backend, Z_LOG_LOCAL_DOMAIN_ID,
|
||||
i, true);
|
||||
compiled_lvl = log_filter_get(backend, CONFIG_LOG_DOMAIN_ID,
|
||||
compiled_lvl = log_filter_get(backend, Z_LOG_LOCAL_DOMAIN_ID,
|
||||
i, false);
|
||||
|
||||
shell_fprintf(shell, SHELL_NORMAL, "%-40s | %-7s | %s\r\n",
|
||||
log_source_name_get(CONFIG_LOG_DOMAIN_ID, i),
|
||||
log_source_name_get(Z_LOG_LOCAL_DOMAIN_ID, i),
|
||||
severity_lvls[dynamic_lvl],
|
||||
severity_lvls[compiled_lvl]);
|
||||
}
|
||||
|
@ -139,12 +139,12 @@ static int cmd_log_backend_status(const struct shell *shell,
|
|||
|
||||
static int module_id_get(const char *name)
|
||||
{
|
||||
uint32_t modules_cnt = z_log_sources_count();
|
||||
uint32_t modules_cnt = log_src_cnt_get(Z_LOG_LOCAL_DOMAIN_ID);
|
||||
const char *tmp_name;
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0U; i < modules_cnt; i++) {
|
||||
tmp_name = log_source_name_get(CONFIG_LOG_DOMAIN_ID, i);
|
||||
tmp_name = log_source_name_get(Z_LOG_LOCAL_DOMAIN_ID, i);
|
||||
|
||||
if (strncmp(tmp_name, name, 64) == 0) {
|
||||
return i;
|
||||
|
@ -160,7 +160,7 @@ static void filters_set(const struct shell *shell,
|
|||
int i;
|
||||
int id;
|
||||
bool all = argc ? false : true;
|
||||
int cnt = all ? z_log_sources_count() : argc;
|
||||
int cnt = all ? log_src_cnt_get(Z_LOG_LOCAL_DOMAIN_ID) : argc;
|
||||
|
||||
if (!backend->cb->active) {
|
||||
shell_warn(shell, "Backend not active.");
|
||||
|
@ -170,15 +170,14 @@ static void filters_set(const struct shell *shell,
|
|||
id = all ? i : module_id_get(argv[i]);
|
||||
if (id >= 0) {
|
||||
uint32_t set_lvl = log_filter_set(backend,
|
||||
CONFIG_LOG_DOMAIN_ID,
|
||||
Z_LOG_LOCAL_DOMAIN_ID,
|
||||
id, level);
|
||||
|
||||
if (set_lvl != level) {
|
||||
const char *name;
|
||||
|
||||
name = all ?
|
||||
log_source_name_get(
|
||||
CONFIG_LOG_DOMAIN_ID, i) :
|
||||
log_source_name_get(Z_LOG_LOCAL_DOMAIN_ID, i) :
|
||||
argv[i];
|
||||
shell_warn(shell, "%s: level set to %s.",
|
||||
name, severity_lvls[set_lvl]);
|
||||
|
@ -270,7 +269,7 @@ static void module_name_get(size_t idx, struct shell_static_entry *entry)
|
|||
entry->handler = NULL;
|
||||
entry->help = NULL;
|
||||
entry->subcmd = &dsub_module_name;
|
||||
entry->syntax = log_source_name_get(CONFIG_LOG_DOMAIN_ID, idx);
|
||||
entry->syntax = log_source_name_get(Z_LOG_LOCAL_DOMAIN_ID, idx);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <zephyr/logging/log_output.h>
|
||||
#include <zephyr/logging/log_internal.h>
|
||||
#include <zephyr/sys/mpsc_pbuf.h>
|
||||
#include <zephyr/logging/log_link.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/sys_clock.h>
|
||||
#include <zephyr/init.h>
|
||||
|
@ -39,6 +40,10 @@ LOG_MODULE_REGISTER(log);
|
|||
#define CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_PROCESSING_LATENCY_US
|
||||
#define CONFIG_LOG_PROCESSING_LATENCY_US 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_BUFFER_SIZE
|
||||
#define CONFIG_LOG_BUFFER_SIZE 4
|
||||
#endif
|
||||
|
@ -53,6 +58,10 @@ LOG_MODULE_REGISTER(log);
|
|||
#define CONFIG_LOG_TAG_MAX_LEN 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_FAILURE_REPORT_PERIOD
|
||||
#define CONFIG_LOG_FAILURE_REPORT_PERIOD 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_ALWAYS_RUNTIME
|
||||
BUILD_ASSERT(!IS_ENABLED(CONFIG_NO_OPTIMIZATIONS),
|
||||
"Option must be enabled when CONFIG_NO_OPTIMIZATIONS is set");
|
||||
|
@ -93,18 +102,26 @@ static struct k_timer log_process_thread_timer;
|
|||
|
||||
static log_timestamp_t dummy_timestamp(void);
|
||||
static log_timestamp_get_t timestamp_func = dummy_timestamp;
|
||||
static uint32_t timestamp_freq;
|
||||
static log_timestamp_t proc_latency;
|
||||
static log_timestamp_t prev_timestamp;
|
||||
static atomic_t unordered_cnt;
|
||||
static uint64_t last_failure_report;
|
||||
|
||||
static STRUCT_SECTION_ITERABLE(log_msg_ptr, log_msg_ptr);
|
||||
static STRUCT_SECTION_ITERABLE_ALTERNATE(log_mpsc_pbuf, mpsc_pbuf_buffer, log_buffer);
|
||||
static struct mpsc_pbuf_buffer *curr_log_buffer;
|
||||
|
||||
struct mpsc_pbuf_buffer log_buffer;
|
||||
static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT)
|
||||
buf32[CONFIG_LOG_BUFFER_SIZE / sizeof(int)];
|
||||
|
||||
static void notify_drop(const struct mpsc_pbuf_buffer *buffer,
|
||||
static void z_log_notify_drop(const struct mpsc_pbuf_buffer *buffer,
|
||||
const union mpsc_pbuf_generic *item);
|
||||
|
||||
static const struct mpsc_pbuf_buffer_config mpsc_config = {
|
||||
.buf = (uint32_t *)buf32,
|
||||
.size = ARRAY_SIZE(buf32),
|
||||
.notify_drop = notify_drop,
|
||||
.notify_drop = z_log_notify_drop,
|
||||
.get_wlen = log_msg_generic_get_wlen,
|
||||
.flags = (IS_ENABLED(CONFIG_LOG_MODE_OVERFLOW) ?
|
||||
MPSC_PBUF_MODE_OVERWRITE : 0) |
|
||||
|
@ -182,7 +199,7 @@ void z_log_vprintk(const char *fmt, va_list ap)
|
|||
return;
|
||||
}
|
||||
|
||||
z_log_msg_runtime_vcreate(CONFIG_LOG_DOMAIN_ID, NULL,
|
||||
z_log_msg_runtime_vcreate(Z_LOG_LOCAL_DOMAIN_ID, NULL,
|
||||
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0,
|
||||
Z_LOG_MSG2_CBPRINTF_FLAGS(0),
|
||||
fmt, ap);
|
||||
|
@ -202,9 +219,6 @@ static log_timestamp_t default_lf_get_timestamp(void)
|
|||
|
||||
void log_core_init(void)
|
||||
{
|
||||
uint32_t freq;
|
||||
log_timestamp_get_t _timestamp_func;
|
||||
|
||||
panic_mode = false;
|
||||
dropped_cnt = 0;
|
||||
|
||||
|
@ -217,15 +231,12 @@ void log_core_init(void)
|
|||
|
||||
/* Set default timestamp. */
|
||||
if (sys_clock_hw_cycles_per_sec() > 1000000) {
|
||||
_timestamp_func = default_lf_get_timestamp;
|
||||
freq = 1000U;
|
||||
log_set_timestamp_func(default_lf_get_timestamp, 1000U);
|
||||
} else {
|
||||
_timestamp_func = default_get_timestamp;
|
||||
freq = sys_clock_hw_cycles_per_sec();
|
||||
log_set_timestamp_func(default_get_timestamp,
|
||||
sys_clock_hw_cycles_per_sec());
|
||||
}
|
||||
|
||||
log_set_timestamp_func(_timestamp_func, freq);
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_MODE_DEFERRED)) {
|
||||
z_log_msg_init();
|
||||
}
|
||||
|
@ -270,6 +281,10 @@ static uint32_t z_log_init(bool blocking, bool can_sleep)
|
|||
}
|
||||
|
||||
int i = 0;
|
||||
if (IS_ENABLED(CONFIG_LOG_MULTIDOMAIN)) {
|
||||
z_log_links_initiate();
|
||||
}
|
||||
|
||||
|
||||
/* Assign ids to backends. */
|
||||
STRUCT_SECTION_FOREACH(log_backend, backend) {
|
||||
|
@ -340,6 +355,11 @@ int log_set_timestamp_func(log_timestamp_get_t timestamp_getter, uint32_t freq)
|
|||
}
|
||||
|
||||
timestamp_func = timestamp_getter;
|
||||
timestamp_freq = freq;
|
||||
if (CONFIG_LOG_PROCESSING_LATENCY_US) {
|
||||
proc_latency = (freq * CONFIG_LOG_PROCESSING_LATENCY_US) / 1000000;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_OUTPUT)) {
|
||||
log_output_timestamp_freq_set(freq);
|
||||
}
|
||||
|
@ -409,17 +429,19 @@ static bool msg_filter_check(struct log_backend const *backend,
|
|||
source = (struct log_source_dynamic_data *)log_msg_get_source(&msg->log);
|
||||
level = log_msg_get_level(&msg->log);
|
||||
domain_id = log_msg_get_domain(&msg->log);
|
||||
source_id = source ? log_dynamic_source_id(source) : -1;
|
||||
|
||||
/* Accept all non-logging messages. */
|
||||
if (level == LOG_LEVEL_NONE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
backend_level = log_filter_get(backend, domain_id,
|
||||
source_id, true);
|
||||
if (source) {
|
||||
source_id = log_dynamic_source_id(source);
|
||||
backend_level = log_filter_get(backend, domain_id, source_id, true);
|
||||
|
||||
return (level <= backend_level);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static void msg_process(union log_msg_generic *msg)
|
||||
|
@ -443,6 +465,13 @@ void dropped_notify(void)
|
|||
}
|
||||
}
|
||||
|
||||
void unordered_notify(void)
|
||||
{
|
||||
uint32_t unordered = atomic_set(&unordered_cnt, 0);
|
||||
|
||||
LOG_WRN("%d unordered messages since last report", unordered);
|
||||
}
|
||||
|
||||
void z_log_notify_backend_enabled(void)
|
||||
{
|
||||
/* Wakeup logger thread after attaching first backend. It might be
|
||||
|
@ -455,29 +484,58 @@ void z_log_notify_backend_enabled(void)
|
|||
backend_attached = true;
|
||||
}
|
||||
|
||||
static inline bool z_log_unordered_pending(void)
|
||||
{
|
||||
return IS_ENABLED(CONFIG_LOG_MULTIDOMAIN) && unordered_cnt;
|
||||
}
|
||||
|
||||
bool z_impl_log_process(void)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_LOG_MODE_DEFERRED)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
k_timeout_t backoff = K_NO_WAIT;
|
||||
union log_msg_generic *msg;
|
||||
|
||||
if (!backend_attached) {
|
||||
return false;
|
||||
}
|
||||
|
||||
msg = z_log_msg_claim();
|
||||
msg = z_log_msg_claim(&backoff);
|
||||
|
||||
if (msg) {
|
||||
atomic_dec(&buffered_cnt);
|
||||
msg_process(msg);
|
||||
z_log_msg_free(msg);
|
||||
} else if (CONFIG_LOG_PROCESSING_LATENCY_US > 0 && !K_TIMEOUT_EQ(backoff, K_NO_WAIT)) {
|
||||
/* If backoff is requested, it means that there are pending
|
||||
* messages but they are too new and processing shall back off
|
||||
* to allow arrival of newer messages from remote domains.
|
||||
*/
|
||||
k_timer_start(&log_process_thread_timer, backoff, K_NO_WAIT);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (z_log_dropped_pending()) {
|
||||
if (IS_ENABLED(CONFIG_LOG_MODE_DEFERRED)) {
|
||||
bool dropped_pend = z_log_dropped_pending();
|
||||
bool unordered_pend = z_log_unordered_pending();
|
||||
|
||||
if ((dropped_pend || unordered_pend) &&
|
||||
(k_uptime_get() - last_failure_report) > CONFIG_LOG_FAILURE_REPORT_PERIOD) {
|
||||
if (dropped_pend) {
|
||||
dropped_notify();
|
||||
}
|
||||
|
||||
if (unordered_pend) {
|
||||
unordered_notify();
|
||||
}
|
||||
}
|
||||
|
||||
last_failure_report += CONFIG_LOG_FAILURE_REPORT_PERIOD;
|
||||
}
|
||||
|
||||
return z_log_msg_pending();
|
||||
}
|
||||
|
||||
|
@ -520,59 +578,193 @@ bool z_log_dropped_pending(void)
|
|||
return dropped_cnt > 0;
|
||||
}
|
||||
|
||||
static void notify_drop(const struct mpsc_pbuf_buffer *buffer,
|
||||
const union mpsc_pbuf_generic *item)
|
||||
{
|
||||
ARG_UNUSED(buffer);
|
||||
ARG_UNUSED(item);
|
||||
|
||||
z_log_dropped(true);
|
||||
}
|
||||
|
||||
void z_log_msg_init(void)
|
||||
{
|
||||
mpsc_pbuf_init(&log_buffer, &mpsc_config);
|
||||
curr_log_buffer = &log_buffer;
|
||||
}
|
||||
|
||||
struct log_msg *z_log_msg_alloc(uint32_t wlen)
|
||||
static struct log_msg *msg_alloc(struct mpsc_pbuf_buffer *buffer, uint32_t wlen)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_LOG_MODE_DEFERRED)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct log_msg *)mpsc_pbuf_alloc(&log_buffer, wlen,
|
||||
return (struct log_msg *)mpsc_pbuf_alloc(buffer, wlen,
|
||||
K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS));
|
||||
}
|
||||
|
||||
void z_log_msg_commit(struct log_msg *msg)
|
||||
struct log_msg *z_log_msg_alloc(uint32_t wlen)
|
||||
{
|
||||
return msg_alloc(&log_buffer, wlen);
|
||||
}
|
||||
|
||||
static void msg_commit(struct mpsc_pbuf_buffer *buffer, struct log_msg *msg)
|
||||
{
|
||||
union log_msg_generic *m = (union log_msg_generic *)msg;
|
||||
|
||||
msg->hdr.timestamp = timestamp_func();
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE)) {
|
||||
msg_process(m);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mpsc_pbuf_commit(&log_buffer, &m->buf);
|
||||
mpsc_pbuf_commit(buffer, &m->buf);
|
||||
z_log_msg_post_finalize();
|
||||
}
|
||||
|
||||
union log_msg_generic *z_log_msg_claim(void)
|
||||
void z_log_msg_commit(struct log_msg *msg)
|
||||
{
|
||||
msg->hdr.timestamp = timestamp_func();
|
||||
msg_commit(&log_buffer, msg);
|
||||
}
|
||||
|
||||
union log_msg_generic *z_log_msg_local_claim(void)
|
||||
{
|
||||
return (union log_msg_generic *)mpsc_pbuf_claim(&log_buffer);
|
||||
}
|
||||
|
||||
/* If there are buffers dedicated for each link, claim the oldest message (lowest timestamp). */
|
||||
union log_msg_generic *z_log_msg_claim_oldest(k_timeout_t *backoff)
|
||||
{
|
||||
union log_msg_generic *msg = NULL;
|
||||
struct log_msg_ptr *chosen;
|
||||
log_timestamp_t t_min = sizeof(log_timestamp_t) > sizeof(uint32_t) ?
|
||||
UINT64_MAX : UINT32_MAX;
|
||||
int i = 0;
|
||||
|
||||
/* Else iterate on all available buffers and get the oldest message. */
|
||||
STRUCT_SECTION_FOREACH(log_msg_ptr, msg_ptr) {
|
||||
struct log_mpsc_pbuf *buf;
|
||||
|
||||
STRUCT_SECTION_GET(log_mpsc_pbuf, i, &buf);
|
||||
|
||||
if (msg_ptr->msg == NULL) {
|
||||
msg_ptr->msg = (union log_msg_generic *)mpsc_pbuf_claim(&buf->buf);
|
||||
}
|
||||
|
||||
if (msg_ptr->msg) {
|
||||
log_timestamp_t t = log_msg_get_timestamp(&msg_ptr->msg->log);
|
||||
|
||||
if (t < t_min) {
|
||||
t_min = t;
|
||||
msg = msg_ptr->msg;
|
||||
chosen = msg_ptr;
|
||||
curr_log_buffer = &buf->buf;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
if (CONFIG_LOG_PROCESSING_LATENCY_US > 0) {
|
||||
int32_t diff = t_min - (timestamp_func() - proc_latency);
|
||||
|
||||
if (diff > 0) {
|
||||
/* Entry is too new. Back off for sometime to allow new
|
||||
* remote messages to arrive which may have been captured
|
||||
* earlier (but on other platform). Calculate for how
|
||||
* long processing shall back off.
|
||||
*/
|
||||
if (timestamp_freq == sys_clock_hw_cycles_per_sec()) {
|
||||
*backoff = K_TICKS(diff);
|
||||
} else {
|
||||
*backoff = K_TICKS((diff * sys_clock_hw_cycles_per_sec()) /
|
||||
timestamp_freq);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
(*chosen).msg = NULL;
|
||||
}
|
||||
|
||||
if (t_min < prev_timestamp) {
|
||||
atomic_inc(&unordered_cnt);
|
||||
}
|
||||
|
||||
prev_timestamp = t_min;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
union log_msg_generic *z_log_msg_claim(k_timeout_t *backoff)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
STRUCT_SECTION_COUNT(log_mpsc_pbuf, &len);
|
||||
|
||||
/* Use only one buffer if others are not registered. */
|
||||
if (IS_ENABLED(CONFIG_LOG_MULTIDOMAIN) && len > 1) {
|
||||
return z_log_msg_claim_oldest(backoff);
|
||||
}
|
||||
|
||||
return z_log_msg_local_claim();
|
||||
}
|
||||
|
||||
static void msg_free(struct mpsc_pbuf_buffer *buffer, const union log_msg_generic *msg)
|
||||
{
|
||||
mpsc_pbuf_free(buffer, &msg->buf);
|
||||
}
|
||||
|
||||
void z_log_msg_free(union log_msg_generic *msg)
|
||||
{
|
||||
mpsc_pbuf_free(&log_buffer, (union mpsc_pbuf_generic *)msg);
|
||||
msg_free(curr_log_buffer, msg);
|
||||
}
|
||||
|
||||
static bool msg_pending(struct mpsc_pbuf_buffer *buffer)
|
||||
{
|
||||
return mpsc_pbuf_is_pending(buffer);
|
||||
}
|
||||
|
||||
bool z_log_msg_pending(void)
|
||||
{
|
||||
return mpsc_pbuf_is_pending(&log_buffer);
|
||||
size_t len;
|
||||
int i = 0;
|
||||
|
||||
STRUCT_SECTION_COUNT(log_mpsc_pbuf, &len);
|
||||
|
||||
if (!IS_ENABLED(CONFIG_LOG_MULTIDOMAIN) || (len == 1)) {
|
||||
return msg_pending(&log_buffer);
|
||||
}
|
||||
|
||||
STRUCT_SECTION_FOREACH(log_msg_ptr, msg_ptr) {
|
||||
struct log_mpsc_pbuf *buf;
|
||||
|
||||
if (msg_ptr->msg) {
|
||||
return true;
|
||||
}
|
||||
|
||||
STRUCT_SECTION_GET(log_mpsc_pbuf, i, &buf);
|
||||
|
||||
if (msg_pending(&buf->buf)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void z_log_msg_enqueue(const struct log_link *link, const void *data, size_t len)
|
||||
{
|
||||
struct log_msg *log_msg = (struct log_msg *)data;
|
||||
size_t wlen = ceiling_fraction(ROUND_UP(len, Z_LOG_MSG2_ALIGNMENT), sizeof(int));
|
||||
struct mpsc_pbuf_buffer *mpsc_pbuffer = link->mpsc_pbuf ? link->mpsc_pbuf : &log_buffer;
|
||||
struct log_msg *local_msg = msg_alloc(mpsc_pbuffer, wlen);
|
||||
|
||||
if (!local_msg) {
|
||||
z_log_dropped(false);
|
||||
return;
|
||||
}
|
||||
|
||||
log_msg->hdr.desc.valid = 0;
|
||||
log_msg->hdr.desc.busy = 0;
|
||||
log_msg->hdr.desc.domain += link->ctrl_blk->domain_offset;
|
||||
memcpy((void *)local_msg, data, len);
|
||||
msg_commit(mpsc_pbuffer, local_msg);
|
||||
}
|
||||
|
||||
const char *z_log_get_tag(void)
|
||||
|
@ -645,7 +837,8 @@ static void log_process_thread_timer_expiry_fn(struct k_timer *timer)
|
|||
static void log_process_thread_func(void *dummy1, void *dummy2, void *dummy3)
|
||||
{
|
||||
__ASSERT_NO_MSG(log_backend_count_get() > 0);
|
||||
|
||||
uint32_t links_active_mask = 0xFFFFFFFF;
|
||||
uint8_t domain_offset = 0;
|
||||
uint32_t activate_mask = z_log_init(false, false);
|
||||
/* If some backends are not activated yet set periodical thread wake up
|
||||
* to poll backends for readiness. Period is set arbitrary.
|
||||
|
@ -653,7 +846,6 @@ static void log_process_thread_func(void *dummy1, void *dummy2, void *dummy3)
|
|||
*/
|
||||
k_timeout_t timeout = (activate_mask != 0) ? K_MSEC(50) : K_FOREVER;
|
||||
bool processed_any = false;
|
||||
|
||||
thread_set(k_current_get());
|
||||
|
||||
/* Logging thread is periodically waken up until all backends that
|
||||
|
@ -670,6 +862,13 @@ static void log_process_thread_func(void *dummy1, void *dummy2, void *dummy3)
|
|||
}
|
||||
}
|
||||
|
||||
/* Keep trying to activate links until all links are active. */
|
||||
if (IS_ENABLED(CONFIG_LOG_MULTIDOMAIN) && links_active_mask) {
|
||||
links_active_mask =
|
||||
z_log_links_activate(links_active_mask, &domain_offset);
|
||||
}
|
||||
|
||||
|
||||
if (log_process() == false) {
|
||||
if (processed_any) {
|
||||
processed_any = false;
|
||||
|
|
|
@ -6,20 +6,331 @@
|
|||
#include <zephyr/logging/log_internal.h>
|
||||
#include <zephyr/logging/log_ctrl.h>
|
||||
#include <zephyr/syscall_handler.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/logging/log_link.h>
|
||||
#include "log_cache.h"
|
||||
|
||||
LOG_MODULE_REGISTER(log_mgmt);
|
||||
|
||||
#ifndef CONFIG_LOG_DOMAIN_NAME_CACHE_ENTRY_SIZE
|
||||
#define CONFIG_LOG_DOMAIN_NAME_CACHE_ENTRY_SIZE 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_DOMAIN_NAME_CACHE_ENTRY_COUNT
|
||||
#define CONFIG_LOG_DOMAIN_NAME_CACHE_ENTRY_COUNT 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_SOURCE_NAME_CACHE_ENTRY_SIZE
|
||||
#define CONFIG_LOG_SOURCE_NAME_CACHE_ENTRY_SIZE 1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LOG_SOURCE_NAME_CACHE_ENTRY_COUNT
|
||||
#define CONFIG_LOG_SOURCE_NAME_CACHE_ENTRY_COUNT 1
|
||||
#endif
|
||||
|
||||
#define DCACHE_BUF_SIZE \
|
||||
(CONFIG_LOG_DOMAIN_NAME_CACHE_ENTRY_SIZE + sizeof(struct log_cache_entry)) * \
|
||||
CONFIG_LOG_DOMAIN_NAME_CACHE_ENTRY_COUNT
|
||||
|
||||
#define SCACHE_BUF_SIZE \
|
||||
(CONFIG_LOG_SOURCE_NAME_CACHE_ENTRY_SIZE + sizeof(struct log_cache_entry)) * \
|
||||
CONFIG_LOG_SOURCE_NAME_CACHE_ENTRY_COUNT
|
||||
|
||||
static uint8_t dname_cache_buffer[DCACHE_BUF_SIZE] __aligned(sizeof(uint32_t));
|
||||
static uint8_t sname_cache_buffer[SCACHE_BUF_SIZE] __aligned(sizeof(uint32_t));
|
||||
|
||||
static struct log_cache dname_cache;
|
||||
static struct log_cache sname_cache;
|
||||
|
||||
struct log_source_id {
|
||||
uint8_t domain_id;
|
||||
uint16_t source_id;
|
||||
};
|
||||
|
||||
union log_source_ids {
|
||||
struct log_source_id id;
|
||||
uintptr_t raw;
|
||||
};
|
||||
|
||||
static bool domain_id_cmp(uintptr_t id0, uintptr_t id1)
|
||||
{
|
||||
return id0 == id1;
|
||||
}
|
||||
|
||||
static bool source_id_cmp(uintptr_t id0, uintptr_t id1)
|
||||
{
|
||||
union log_source_ids s0 = { .raw = id0 };
|
||||
union log_source_ids s1 = { .raw = id1 };
|
||||
|
||||
return (s0.id.source_id == s1.id.source_id) &&
|
||||
(s0.id.domain_id == s1.id.domain_id);
|
||||
}
|
||||
|
||||
/* Implementation of functions related to controlling logging sources and backends:
|
||||
* - getting/setting source details like name, filtering
|
||||
* - controlling backends filtering
|
||||
*/
|
||||
|
||||
/** @brief Get compiled level of the log source.
|
||||
/** @brief Return link and relative domain id based on absolute domain id.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
* @return Level.
|
||||
* @param[in] domain_id Aboslute domain ID.
|
||||
* @param[out] rel_domain_id Domain ID elative to the link domain ID as output.
|
||||
*
|
||||
* @return Link to which given domain belongs. NULL if link was not found.
|
||||
*/
|
||||
static inline uint8_t log_compiled_level_get(uint32_t source_id)
|
||||
static const struct log_link *get_link_domain(uint8_t domain_id, uint8_t *rel_domain_id)
|
||||
{
|
||||
uint8_t domain_max;
|
||||
|
||||
STRUCT_SECTION_FOREACH(log_link, link) {
|
||||
domain_max = link->ctrl_blk->domain_offset +
|
||||
link->ctrl_blk->domain_cnt;
|
||||
if (domain_id < domain_max) {
|
||||
|
||||
*rel_domain_id = domain_id - link->ctrl_blk->domain_offset;
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
||||
*rel_domain_id = 0;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** @brief Get source offset used for getting runtime filter.
|
||||
*
|
||||
* Runtime filters for each link are dynamically allocated as an array of
|
||||
* filters for all domains in the link. In order to fetch link associated with
|
||||
* given source an index in the array must be retrieved.
|
||||
*/
|
||||
static uint32_t get_source_offset(const struct log_link *link,
|
||||
uint8_t rel_domain_id)
|
||||
{
|
||||
uint32_t offset = 0;
|
||||
|
||||
for (uint8_t i = 0; i < rel_domain_id; i++) {
|
||||
offset += log_link_sources_count(link, i);
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
uint32_t *z_log_link_get_dynamic_filter(uint8_t domain_id, uint32_t source_id)
|
||||
{
|
||||
uint8_t rel_domain_id;
|
||||
const struct log_link *link = get_link_domain(domain_id, &rel_domain_id);
|
||||
uint32_t source_offset = 0;
|
||||
|
||||
__ASSERT_NO_MSG(link != NULL);
|
||||
|
||||
source_offset = get_source_offset(link, rel_domain_id);
|
||||
|
||||
return &link->ctrl_blk->filters[source_offset + source_id];
|
||||
}
|
||||
|
||||
static int link_filters_init(const struct log_link *link)
|
||||
{
|
||||
uint32_t total_cnt = get_source_offset(link, link->ctrl_blk->domain_cnt);
|
||||
|
||||
link->ctrl_blk->filters = k_malloc(sizeof(uint32_t) * total_cnt);
|
||||
if (link->ctrl_blk->filters == NULL) {
|
||||
LOG_ERR("Failed to allocate buffer for runtime filtering.");
|
||||
__ASSERT(0, "Failed to allocate buffer.");
|
||||
}
|
||||
|
||||
memset(link->ctrl_blk->filters, 0, sizeof(uint32_t) * total_cnt);
|
||||
LOG_DBG("%s: heap used for filters:%d",
|
||||
link->name, (int)(total_cnt * sizeof(uint32_t)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cache_init(void)
|
||||
{
|
||||
int err;
|
||||
static const struct log_cache_config dname_cache_config = {
|
||||
.buf = dname_cache_buffer,
|
||||
.buf_len = sizeof(dname_cache_buffer),
|
||||
.item_size = CONFIG_LOG_DOMAIN_NAME_CACHE_ENTRY_SIZE,
|
||||
.cmp = domain_id_cmp
|
||||
};
|
||||
static const struct log_cache_config sname_cache_config = {
|
||||
.buf = sname_cache_buffer,
|
||||
.buf_len = sizeof(sname_cache_buffer),
|
||||
.item_size = CONFIG_LOG_SOURCE_NAME_CACHE_ENTRY_SIZE,
|
||||
.cmp = source_id_cmp
|
||||
};
|
||||
|
||||
err = log_cache_init(&dname_cache, &dname_cache_config);
|
||||
__ASSERT_NO_MSG(err == 0);
|
||||
|
||||
err = log_cache_init(&sname_cache, &sname_cache_config);
|
||||
__ASSERT_NO_MSG(err == 0);
|
||||
}
|
||||
|
||||
uint8_t z_log_ext_domain_count(void)
|
||||
{
|
||||
uint8_t cnt = 0;
|
||||
|
||||
STRUCT_SECTION_FOREACH(log_link, link) {
|
||||
cnt += log_link_domains_count(link);
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static uint16_t link_source_count(uint8_t domain_id)
|
||||
{
|
||||
uint8_t rel_domain_id;
|
||||
const struct log_link *link = get_link_domain(domain_id, &rel_domain_id);
|
||||
|
||||
__ASSERT_NO_MSG(link != NULL);
|
||||
|
||||
return log_link_sources_count(link, rel_domain_id);
|
||||
}
|
||||
|
||||
uint32_t log_src_cnt_get(uint32_t domain_id)
|
||||
{
|
||||
if (z_log_is_local_domain(domain_id)) {
|
||||
return log_const_source_id(__log_const_end);
|
||||
}
|
||||
|
||||
return link_source_count(domain_id);
|
||||
}
|
||||
|
||||
/* First check in cache if not there fetch from remote.
|
||||
* When fetched from remote put in cache.
|
||||
*
|
||||
* @note Execution time depends on whether entry is in cache.
|
||||
*/
|
||||
static const char *link_source_name_get(uint8_t domain_id, uint32_t source_id)
|
||||
{
|
||||
uint8_t *cached;
|
||||
size_t cache_size = sname_cache.item_size;
|
||||
union log_source_ids id = {
|
||||
.id = {
|
||||
.domain_id = domain_id,
|
||||
.source_id = source_id
|
||||
}
|
||||
};
|
||||
|
||||
/* If not in cache fetch from link and cache it. */
|
||||
if (!log_cache_get(&sname_cache, id.raw, &cached)) {
|
||||
uint8_t rel_domain_id;
|
||||
const struct log_link *link = get_link_domain(domain_id, &rel_domain_id);
|
||||
int err;
|
||||
|
||||
__ASSERT_NO_MSG(link != NULL);
|
||||
|
||||
err = log_link_get_source_name(link, rel_domain_id, source_id,
|
||||
cached, &cache_size);
|
||||
if (err < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
log_cache_put(&sname_cache, cached);
|
||||
}
|
||||
|
||||
return (const char *)cached;
|
||||
}
|
||||
|
||||
const char *log_source_name_get(uint32_t domain_id, uint32_t source_id)
|
||||
{
|
||||
if (z_log_is_local_domain(domain_id)) {
|
||||
if (source_id < log_src_cnt_get(domain_id)) {
|
||||
return __log_const_start[source_id].name;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return link_source_name_get(domain_id, source_id);
|
||||
}
|
||||
|
||||
/* First check in cache if not there fetch from remote.
|
||||
* When fetched from remote put in cache.
|
||||
*
|
||||
* @note Execution time depends on whether entry is in cache.
|
||||
*/
|
||||
static const char *link_domain_name_get(uint8_t domain_id)
|
||||
{
|
||||
uint8_t *cached;
|
||||
size_t cache_size = dname_cache.item_size;
|
||||
uintptr_t id = (uintptr_t)domain_id;
|
||||
static const char *invalid_domain = "invalid";
|
||||
|
||||
/* If not in cache fetch from link and cache it. */
|
||||
if (!log_cache_get(&dname_cache, id, &cached)) {
|
||||
uint8_t rel_domain_id;
|
||||
const struct log_link *link = get_link_domain(domain_id, &rel_domain_id);
|
||||
int err;
|
||||
|
||||
__ASSERT_NO_MSG(link != NULL);
|
||||
|
||||
err = log_link_get_domain_name(link, rel_domain_id, cached, &cache_size);
|
||||
if (err < 0) {
|
||||
log_cache_release(&dname_cache, cached);
|
||||
return invalid_domain;
|
||||
}
|
||||
|
||||
log_cache_put(&dname_cache, cached);
|
||||
}
|
||||
|
||||
return (const char *)cached;
|
||||
}
|
||||
|
||||
const char *log_domain_name_get(uint32_t domain_id)
|
||||
{
|
||||
if (z_log_is_local_domain(domain_id)) {
|
||||
return CONFIG_LOG_DOMAIN_NAME;
|
||||
}
|
||||
|
||||
return link_domain_name_get(domain_id);
|
||||
}
|
||||
|
||||
static uint8_t link_compiled_level_get(uint8_t domain_id, uint32_t source_id)
|
||||
{
|
||||
uint8_t rel_domain_id;
|
||||
const struct log_link *link = get_link_domain(domain_id, &rel_domain_id);
|
||||
uint8_t level;
|
||||
|
||||
__ASSERT_NO_MSG(link != NULL);
|
||||
|
||||
return !log_link_get_levels(link, rel_domain_id, source_id, &level, NULL) ?
|
||||
level : 0;
|
||||
}
|
||||
|
||||
uint8_t log_compiled_level_get(uint8_t domain_id, uint32_t source_id)
|
||||
{
|
||||
if (z_log_is_local_domain(domain_id)) {
|
||||
if (source_id < log_src_cnt_get(domain_id)) {
|
||||
return __log_const_start[source_id].level;
|
||||
} else {
|
||||
return LOG_LEVEL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
return link_compiled_level_get(domain_id, source_id);
|
||||
}
|
||||
|
||||
int z_log_link_set_runtime_level(uint8_t domain_id, uint16_t source_id, uint8_t level)
|
||||
{
|
||||
uint8_t rel_domain_id;
|
||||
const struct log_link *link = get_link_domain(domain_id, &rel_domain_id);
|
||||
|
||||
__ASSERT_NO_MSG(link != NULL);
|
||||
|
||||
return log_link_set_runtime_level(link, rel_domain_id, source_id, level);
|
||||
}
|
||||
|
||||
static uint32_t *get_dynamic_filter(uint8_t domain_id, uint32_t source_id)
|
||||
{
|
||||
if (z_log_is_local_domain(domain_id)) {
|
||||
return &__log_dynamic_start[source_id].filters;
|
||||
}
|
||||
|
||||
return z_log_link_get_dynamic_filter(domain_id, source_id);
|
||||
}
|
||||
|
||||
void z_log_runtime_filters_init(void)
|
||||
|
@ -35,7 +346,7 @@ void z_log_runtime_filters_init(void)
|
|||
*/
|
||||
for (int i = 0; i < z_log_sources_count(); i++) {
|
||||
uint32_t *filters = z_log_dynamic_filters_get(i);
|
||||
uint8_t level = log_compiled_level_get(i);
|
||||
uint8_t level = log_compiled_level_get(Z_LOG_LOCAL_DOMAIN_ID, i);
|
||||
|
||||
level = MAX(level, CONFIG_LOG_OVERRIDE_LEVEL);
|
||||
LOG_FILTER_SLOT_SET(filters,
|
||||
|
@ -44,30 +355,10 @@ void z_log_runtime_filters_init(void)
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t log_src_cnt_get(uint32_t domain_id)
|
||||
{
|
||||
return z_log_sources_count();
|
||||
}
|
||||
|
||||
/** @brief Get name of the log source.
|
||||
*
|
||||
* @param source_id Source ID.
|
||||
* @return Name.
|
||||
*/
|
||||
static inline const char *log_name_get(uint32_t source_id)
|
||||
{
|
||||
return __log_const_start[source_id].name;
|
||||
}
|
||||
|
||||
const char *log_source_name_get(uint32_t domain_id, uint32_t src_id)
|
||||
{
|
||||
return src_id < z_log_sources_count() ? log_name_get(src_id) : NULL;
|
||||
}
|
||||
|
||||
int log_source_id_get(const char *name)
|
||||
{
|
||||
for (int i = 0; i < log_src_cnt_get(CONFIG_LOG_DOMAIN_ID); i++) {
|
||||
if (strcmp(log_source_name_get(CONFIG_LOG_DOMAIN_ID, i),
|
||||
for (int i = 0; i < log_src_cnt_get(Z_LOG_LOCAL_DOMAIN_ID); i++) {
|
||||
if (strcmp(log_source_name_get(Z_LOG_LOCAL_DOMAIN_ID, i),
|
||||
name) == 0) {
|
||||
return i;
|
||||
}
|
||||
|
@ -92,50 +383,57 @@ static uint32_t max_filter_get(uint32_t filters)
|
|||
return max_filter;
|
||||
}
|
||||
|
||||
uint32_t z_impl_log_filter_set(struct log_backend const *const backend,
|
||||
uint32_t domain_id, int16_t source_id,
|
||||
uint32_t level)
|
||||
static void set_runtime_filter(uint8_t backend_id, uint8_t domain_id,
|
||||
uint32_t source_id, uint32_t level)
|
||||
{
|
||||
__ASSERT_NO_MSG(source_id < (int16_t)z_log_sources_count());
|
||||
uint32_t prev_max;
|
||||
uint32_t new_max;
|
||||
uint32_t *filters = get_dynamic_filter(domain_id, source_id);
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
||||
uint32_t new_aggr_filter;
|
||||
prev_max = LOG_FILTER_SLOT_GET(filters, LOG_FILTER_AGGR_SLOT_IDX);
|
||||
|
||||
uint32_t *filters = z_log_dynamic_filters_get(source_id);
|
||||
|
||||
if (backend == NULL) {
|
||||
uint32_t max = 0U;
|
||||
uint32_t current;
|
||||
|
||||
STRUCT_SECTION_FOREACH(log_backend, iter_backend) {
|
||||
current = log_filter_set(iter_backend,
|
||||
domain_id,
|
||||
source_id, level);
|
||||
max = MAX(current, max);
|
||||
}
|
||||
|
||||
level = max;
|
||||
} else {
|
||||
uint32_t max = log_filter_get(backend, domain_id,
|
||||
source_id, false);
|
||||
|
||||
level = MIN(level, MAX(max, CONFIG_LOG_OVERRIDE_LEVEL));
|
||||
|
||||
LOG_FILTER_SLOT_SET(filters,
|
||||
log_backend_id_get(backend),
|
||||
level);
|
||||
LOG_FILTER_SLOT_SET(filters, backend_id, level);
|
||||
|
||||
/* Once current backend filter is updated recalculate
|
||||
* aggregated maximal level
|
||||
*/
|
||||
new_aggr_filter = max_filter_get(*filters);
|
||||
new_max = max_filter_get(*filters);
|
||||
|
||||
LOG_FILTER_SLOT_SET(filters,
|
||||
LOG_FILTER_AGGR_SLOT_IDX,
|
||||
new_aggr_filter);
|
||||
LOG_FILTER_SLOT_SET(filters, LOG_FILTER_AGGR_SLOT_IDX, new_max);
|
||||
|
||||
if (!z_log_is_local_domain(domain_id) && (new_max != prev_max)) {
|
||||
(void)z_log_link_set_runtime_level(domain_id, source_id, level);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t z_impl_log_filter_set(struct log_backend const *const backend,
|
||||
uint32_t domain_id, int16_t source_id,
|
||||
uint32_t level)
|
||||
{
|
||||
if (!IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
||||
return level;
|
||||
}
|
||||
|
||||
__ASSERT_NO_MSG(source_id < log_src_cnt_get(domain_id));
|
||||
|
||||
|
||||
if (backend == NULL) {
|
||||
uint32_t max = 0U;
|
||||
|
||||
STRUCT_SECTION_FOREACH(log_backend, iter_backend) {
|
||||
uint32_t current = log_filter_set(iter_backend,
|
||||
domain_id, source_id, level);
|
||||
|
||||
max = MAX(current, max);
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
level = MIN(level, MAX(log_filter_get(backend, domain_id, source_id, false),
|
||||
CONFIG_LOG_OVERRIDE_LEVEL));
|
||||
set_runtime_filter(log_backend_id_get(backend), domain_id, source_id, level);
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
|
@ -147,9 +445,9 @@ uint32_t z_vrfy_log_filter_set(struct log_backend const *const backend,
|
|||
{
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(backend == NULL,
|
||||
"Setting per-backend filters from user mode is not supported"));
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(domain_id == CONFIG_LOG_DOMAIN_ID,
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(domain_id == Z_LOG_LOCAL_DOMAIN_ID,
|
||||
"Invalid log domain_id"));
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(src_id < (int16_t)z_log_sources_count(),
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(src_id < (int16_t)log_src_cnt_get(domain_id),
|
||||
"Invalid log source id"));
|
||||
Z_OOPS(Z_SYSCALL_VERIFY_MSG(
|
||||
(level <= LOG_LEVEL_DBG),
|
||||
|
@ -160,13 +458,40 @@ uint32_t z_vrfy_log_filter_set(struct log_backend const *const backend,
|
|||
#include <syscalls/log_filter_set_mrsh.c>
|
||||
#endif
|
||||
|
||||
static void link_filter_set(const struct log_link *link,
|
||||
struct log_backend const *const backend,
|
||||
uint32_t level)
|
||||
{
|
||||
if (log_link_is_active(link) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint8_t d = link->ctrl_blk->domain_offset;
|
||||
d < link->ctrl_blk->domain_offset + link->ctrl_blk->domain_cnt; d++) {
|
||||
for (uint16_t s = 0; s < log_src_cnt_get(d); s++) {
|
||||
log_filter_set(backend, d, s, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void backend_filter_set(struct log_backend const *const backend,
|
||||
uint32_t level)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
||||
for (int i = 0; i < z_log_sources_count(); i++) {
|
||||
log_filter_set(backend, CONFIG_LOG_DOMAIN_ID, i, level);
|
||||
if (!IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint16_t s = 0; s < log_src_cnt_get(0); s++) {
|
||||
log_filter_set(backend, 0, s, level);
|
||||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_LOG_MULTIDOMAIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set level in activated links. */
|
||||
STRUCT_SECTION_FOREACH(log_link, link) {
|
||||
link_filter_set(link, backend, level);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,6 +516,7 @@ void log_backend_enable(struct log_backend const *const backend,
|
|||
id += backend - log_backend_get(0);
|
||||
|
||||
log_backend_id_set(backend, id);
|
||||
backend->cb->level = level;
|
||||
backend_filter_set(backend, level);
|
||||
log_backend_activate(backend, ctx);
|
||||
|
||||
|
@ -199,25 +525,92 @@ void log_backend_enable(struct log_backend const *const backend,
|
|||
|
||||
void log_backend_disable(struct log_backend const *const backend)
|
||||
{
|
||||
log_backend_deactivate(backend);
|
||||
if (log_backend_is_active(backend)) {
|
||||
backend_filter_set(backend, LOG_LEVEL_NONE);
|
||||
}
|
||||
|
||||
log_backend_deactivate(backend);
|
||||
}
|
||||
|
||||
uint32_t log_filter_get(struct log_backend const *const backend,
|
||||
uint32_t domain_id, int16_t source_id, bool runtime)
|
||||
{
|
||||
__ASSERT_NO_MSG(source_id < (int16_t)z_log_sources_count());
|
||||
__ASSERT_NO_MSG(source_id < log_src_cnt_get(domain_id));
|
||||
|
||||
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && runtime) {
|
||||
if (source_id < 0) {
|
||||
return LOG_LEVEL_DBG;
|
||||
}
|
||||
|
||||
uint32_t *filters = z_log_dynamic_filters_get(source_id);
|
||||
|
||||
return LOG_FILTER_SLOT_GET(filters,
|
||||
return LOG_FILTER_SLOT_GET(get_dynamic_filter(domain_id, source_id),
|
||||
log_backend_id_get(backend));
|
||||
}
|
||||
|
||||
return log_compiled_level_get(source_id);
|
||||
return log_compiled_level_get(domain_id, source_id);
|
||||
}
|
||||
|
||||
void z_log_links_initiate(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
cache_init();
|
||||
|
||||
STRUCT_SECTION_FOREACH(log_link, link) {
|
||||
if (link->mpsc_pbuf) {
|
||||
mpsc_pbuf_init(link->mpsc_pbuf, link->mpsc_pbuf_config);
|
||||
}
|
||||
|
||||
err = log_link_initiate(link, NULL);
|
||||
__ASSERT(err == 0, "Failed to initialize link");
|
||||
}
|
||||
}
|
||||
|
||||
static void backends_link_init(const struct log_link *link)
|
||||
{
|
||||
for (int i = 0; i < log_backend_count_get(); i++) {
|
||||
const struct log_backend *backend = log_backend_get(i);
|
||||
|
||||
|
||||
if (!log_backend_is_active(backend)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
link_filter_set(link, backend, backend->cb->level);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t z_log_links_activate(uint32_t active_mask, uint8_t *offset)
|
||||
{
|
||||
uint32_t mask = 0x1;
|
||||
uint32_t out_mask = 0;
|
||||
|
||||
/* Initiate offset to 1. */
|
||||
if (*offset == 0) {
|
||||
*offset = 1;
|
||||
}
|
||||
|
||||
STRUCT_SECTION_FOREACH(log_link, link) {
|
||||
if (active_mask & mask) {
|
||||
int err = log_link_activate(link);
|
||||
|
||||
if (err == 0) {
|
||||
uint8_t domain_cnt = log_link_domains_count(link);
|
||||
|
||||
link->ctrl_blk->domain_offset = *offset;
|
||||
link->ctrl_blk->domain_cnt = domain_cnt;
|
||||
*offset += domain_cnt;
|
||||
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
||||
link_filters_init(link);
|
||||
backends_link_init(link);
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(err == -EINPROGRESS);
|
||||
out_mask |= mask;
|
||||
}
|
||||
}
|
||||
|
||||
mask <<= 1;
|
||||
}
|
||||
|
||||
return out_mask;
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ ZTEST(test_log_api, test_log_various_messages)
|
|||
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_DBG, str);
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
exp_timestamp++, str);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ ZTEST(test_log_api, test_log_various_messages)
|
|||
snprintk(str, sizeof(str), TEST_MSG_1, f, 100, d);
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, str);
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp++, str);
|
||||
|
||||
LOG_INF(TEST_MSG_1, f, 100, d);
|
||||
|
@ -199,12 +199,12 @@ ZTEST(test_log_api, test_log_various_messages)
|
|||
snprintk(str, sizeof(str), "wrn %s", dstr);
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_WRN, str);
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
exp_timestamp++, str);
|
||||
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_ERR, "err");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
exp_timestamp++, "err");
|
||||
|
||||
LOG_WRN("wrn %s", dstr);
|
||||
|
@ -247,20 +247,20 @@ ZTEST(test_log_api, test_log_backend_runtime_filtering)
|
|||
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_DBG, str);
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
exp_timestamp, str);
|
||||
mock_log_backend_record(&backend2, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
exp_timestamp, str);
|
||||
exp_timestamp++;
|
||||
}
|
||||
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, "test");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp, "test");
|
||||
mock_log_backend_record(&backend2, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp, "test");
|
||||
exp_timestamp++;
|
||||
|
||||
|
@ -271,7 +271,7 @@ ZTEST(test_log_api, test_log_backend_runtime_filtering)
|
|||
|
||||
|
||||
log_filter_set(&backend2,
|
||||
CONFIG_LOG_DOMAIN_ID,
|
||||
Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_CURRENT_MODULE_ID(),
|
||||
LOG_LEVEL_WRN);
|
||||
|
||||
|
@ -280,34 +280,34 @@ ZTEST(test_log_api, test_log_backend_runtime_filtering)
|
|||
/* INF logs expected only on backend1 */
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, "test");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp++, "test");
|
||||
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), CONFIG_LOG_DOMAIN_ID,
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_LEVEL_INF, "hexdump", data, sizeof(data));
|
||||
mock_log_backend_generic_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID,
|
||||
Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_LEVEL_INF,
|
||||
exp_timestamp++, "hexdump",
|
||||
data, sizeof(data));
|
||||
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_WRN, "test2");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
exp_timestamp, "test2");
|
||||
mock_log_backend_record(&backend2, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
exp_timestamp++, "test2");
|
||||
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), CONFIG_LOG_DOMAIN_ID,
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_LEVEL_WRN, "hexdump", data, sizeof(data));
|
||||
mock_log_backend_generic_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID,
|
||||
Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_LEVEL_WRN,
|
||||
exp_timestamp, "hexdump",
|
||||
data, sizeof(data));
|
||||
mock_log_backend_generic_record(&backend2, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID,
|
||||
Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_LEVEL_WRN,
|
||||
exp_timestamp++, "hexdump",
|
||||
data, sizeof(data));
|
||||
|
@ -388,15 +388,15 @@ ZTEST(test_log_api, test_log_overflow)
|
|||
/* expect first message to be dropped */
|
||||
exp_timestamp++;
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, "test 100 100");
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), CONFIG_LOG_DOMAIN_ID,
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_LEVEL_INF, "hexdump", data, hexdump_len);
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, "test2");
|
||||
mock_log_backend_generic_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp++, "hexdump",
|
||||
data, hexdump_len);
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp++, "test2");
|
||||
mock_log_backend_drop_record(&backend1, 1);
|
||||
|
||||
|
@ -415,13 +415,13 @@ ZTEST(test_log_api, test_log_overflow)
|
|||
mock_log_frontend_reset();
|
||||
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, "test");
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), CONFIG_LOG_DOMAIN_ID,
|
||||
mock_log_frontend_generic_record(LOG_CURRENT_MODULE_ID(), Z_LOG_LOCAL_DOMAIN_ID,
|
||||
LOG_LEVEL_INF, "test", data, hexdump_len + 1);
|
||||
/* Log2 allocation is not destructive if request exceeds the
|
||||
* capacity.
|
||||
*/
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp, "test");
|
||||
mock_log_backend_drop_record(&backend1, 1);
|
||||
|
||||
|
@ -440,7 +440,7 @@ ZTEST(test_log_api, test_log_overflow)
|
|||
*/
|
||||
#define MOCK_LOG_FRONT_BACKEND_RECORD(str) do { \
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(), \
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF, \
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF, \
|
||||
exp_timestamp++, str); \
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, str); \
|
||||
} while (0)
|
||||
|
@ -523,13 +523,13 @@ ZTEST(test_log_api, test_log_from_declared_module)
|
|||
|
||||
mock_log_frontend_record(test_source_id, LOG_LEVEL_DBG, str);
|
||||
mock_log_backend_record(&backend1, test_source_id,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
exp_timestamp++, str);
|
||||
}
|
||||
|
||||
mock_log_frontend_record(test_source_id, LOG_LEVEL_ERR, TEST_ERR_MSG);
|
||||
mock_log_backend_record(&backend1, test_source_id,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
exp_timestamp++, TEST_ERR_MSG);
|
||||
|
||||
test_func();
|
||||
|
@ -547,13 +547,13 @@ ZTEST(test_log_api, test_log_from_declared_module)
|
|||
|
||||
mock_log_frontend_record(test_source_id, LOG_LEVEL_DBG, str);
|
||||
mock_log_backend_record(&backend1, test_source_id,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
exp_timestamp++, str);
|
||||
}
|
||||
|
||||
mock_log_frontend_record(test_source_id, LOG_LEVEL_ERR, TEST_INLINE_ERR_MSG);
|
||||
mock_log_backend_record(&backend1, test_source_id,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
exp_timestamp, TEST_INLINE_ERR_MSG);
|
||||
|
||||
test_inline_func();
|
||||
|
@ -588,7 +588,7 @@ static void log_n_messages(uint32_t n_msg, uint32_t exp_dropped)
|
|||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, "dummy");
|
||||
if (i >= exp_dropped) {
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp, "dummy");
|
||||
}
|
||||
exp_timestamp++;
|
||||
|
@ -650,10 +650,10 @@ ZTEST(test_log_api, test_log_panic)
|
|||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_WRN, "test");
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_WRN, "test");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
exp_timestamp++, "test");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
exp_timestamp++, "test");
|
||||
LOG_WRN("test");
|
||||
LOG_WRN("test");
|
||||
|
@ -666,7 +666,7 @@ ZTEST(test_log_api, test_log_panic)
|
|||
/* messages processed where called */
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_WRN, "test");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_WRN,
|
||||
exp_timestamp++, "test");
|
||||
LOG_WRN("test");
|
||||
|
||||
|
@ -684,14 +684,14 @@ ZTEST(test_log_api, test_log_printk)
|
|||
log_setup(false);
|
||||
|
||||
mock_log_backend_record(&backend1, 0,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INTERNAL_RAW_STRING,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INTERNAL_RAW_STRING,
|
||||
exp_timestamp++, "test 100");
|
||||
printk("test %d", 100);
|
||||
|
||||
log_panic();
|
||||
|
||||
mock_log_backend_record(&backend1, 0,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INTERNAL_RAW_STRING,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INTERNAL_RAW_STRING,
|
||||
exp_timestamp++, "test 101");
|
||||
printk("test %d", 101);
|
||||
|
||||
|
@ -744,7 +744,7 @@ ZTEST(test_log_api, test_log_arg_evaluation)
|
|||
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_INF, "0 0");
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp++, "0 0");
|
||||
if (dbg_enabled()) {
|
||||
/* If prefix is enabled, add function name prefix */
|
||||
|
@ -756,7 +756,7 @@ ZTEST(test_log_api, test_log_arg_evaluation)
|
|||
}
|
||||
mock_log_frontend_record(LOG_CURRENT_MODULE_ID(), LOG_LEVEL_DBG, str);
|
||||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
exp_timestamp++, str);
|
||||
}
|
||||
/* Arguments used for logging shall be evaluated only once. They should
|
||||
|
@ -792,12 +792,12 @@ ZTEST(test_log_api, test_log_override_level)
|
|||
|
||||
mock_log_frontend_record(test2_source_id, LOG_LEVEL_DBG, str);
|
||||
mock_log_backend_record(&backend1, test2_source_id,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_DBG,
|
||||
exp_timestamp++, str);
|
||||
|
||||
mock_log_frontend_record(test2_source_id, LOG_LEVEL_ERR, TEST_ERR_MSG);
|
||||
mock_log_backend_record(&backend1, test2_source_id,
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, LOG_LEVEL_ERR,
|
||||
exp_timestamp++, TEST_ERR_MSG);
|
||||
} else if (CONFIG_LOG_OVERRIDE_LEVEL != 0) {
|
||||
zassert_true(false, "Unexpected configuration.");
|
||||
|
|
|
@ -71,7 +71,7 @@ static void process(const struct log_backend *const backend,
|
|||
}
|
||||
|
||||
if (cb->check_domain_id) {
|
||||
zassert_equal(log_msg_get_domain(&(msg->log)), CONFIG_LOG_DOMAIN_ID,
|
||||
zassert_equal(log_msg_get_domain(&(msg->log)), Z_LOG_LOCAL_DOMAIN_ID,
|
||||
"Unexpected domain id");
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ static bool log_test_process(void)
|
|||
* @brief Support multi-processor systems
|
||||
*
|
||||
* @details Logging system identify domain/processor by domain_id which is now
|
||||
* statically configured by CONFIG_LOG_DOMAIN_ID
|
||||
* statically configured by Z_LOG_LOCAL_DOMAIN_ID
|
||||
*
|
||||
* @addtogroup logging
|
||||
*/
|
||||
|
@ -461,7 +461,7 @@ ZTEST(test_log_core_additional, test_log_msg_create)
|
|||
sizeof(msg_data), NULL);
|
||||
|
||||
Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), mode,
|
||||
CONFIG_LOG_DOMAIN_ID, NULL,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, NULL,
|
||||
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, test_msg_usr);
|
||||
|
||||
while (log_test_process()) {
|
||||
|
@ -487,7 +487,7 @@ ZTEST_USER(test_log_core_additional, test_log_msg_create_user)
|
|||
sizeof(msg_data), test_msg_usr);
|
||||
|
||||
Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), mode,
|
||||
CONFIG_LOG_DOMAIN_ID, NULL,
|
||||
Z_LOG_LOCAL_DOMAIN_ID, NULL,
|
||||
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, test_msg_usr);
|
||||
|
||||
while (log_test_process()) {
|
||||
|
|
|
@ -69,7 +69,7 @@ ZTEST_USER(test_log_core_additional, test_log_generic_user)
|
|||
/* test log_filter_set from user space */
|
||||
ZTEST_USER(test_log_core_additional, test_log_filter_set)
|
||||
{
|
||||
log_filter_set(NULL, CONFIG_LOG_DOMAIN_ID, 0, LOG_LEVEL_WRN);
|
||||
log_filter_set(NULL, Z_LOG_LOCAL_DOMAIN_ID, 0, LOG_LEVEL_WRN);
|
||||
}
|
||||
|
||||
/* test log_panic() from user space */
|
||||
|
|
|
@ -158,19 +158,19 @@ void validate_base_message_set(const struct log_source_const_data *source,
|
|||
size_t len0, len1, len2;
|
||||
union log_msg_generic *msg0, *msg1, *msg2;
|
||||
|
||||
msg0 = z_log_msg_claim();
|
||||
msg0 = z_log_msg_claim(NULL);
|
||||
zassert_true(msg0, "Unexpected null message");
|
||||
len0 = log_msg_generic_get_wlen((union mpsc_pbuf_generic *)msg0);
|
||||
msg0 = msg_copy_and_free(msg0, buf0, sizeof(buf0));
|
||||
clear_pkg_flags(&msg0->log);
|
||||
|
||||
msg1 = z_log_msg_claim();
|
||||
msg1 = z_log_msg_claim(NULL);
|
||||
zassert_true(msg1, "Unexpected null message");
|
||||
len1 = log_msg_generic_get_wlen((union mpsc_pbuf_generic *)msg1);
|
||||
msg1 = msg_copy_and_free(msg1, buf1, sizeof(buf1));
|
||||
clear_pkg_flags(&msg1->log);
|
||||
|
||||
msg2 = z_log_msg_claim();
|
||||
msg2 = z_log_msg_claim(NULL);
|
||||
zassert_true(msg2, "Unexpected null message");
|
||||
len2 = log_msg_generic_get_wlen((union mpsc_pbuf_generic *)msg2);
|
||||
msg2 = msg_copy_and_free(msg2, buf2, sizeof(buf2));
|
||||
|
@ -357,7 +357,7 @@ static void get_msg_validate_length(uint32_t exp_len)
|
|||
uint32_t len;
|
||||
union log_msg_generic *msg;
|
||||
|
||||
msg = z_log_msg_claim();
|
||||
msg = z_log_msg_claim(NULL);
|
||||
len = log_msg_generic_get_wlen((union mpsc_pbuf_generic *)msg);
|
||||
|
||||
zassert_equal(len, exp_len, "Unexpected message length %d (exp:%d)",
|
||||
|
@ -571,12 +571,12 @@ ZTEST(log_msg, test_saturate)
|
|||
zassert_equal(z_log_dropped_read_and_clear(), 3, "No dropped messages.");
|
||||
|
||||
for (int i = 0; i < exp_capacity; i++) {
|
||||
msg = z_log_msg_claim();
|
||||
msg = z_log_msg_claim(NULL);
|
||||
zassert_equal(log_msg_get_timestamp(&msg->log), i,
|
||||
"Unexpected timestamp used for message id");
|
||||
}
|
||||
|
||||
msg = z_log_msg_claim();
|
||||
msg = z_log_msg_claim(NULL);
|
||||
zassert_equal(msg, NULL, "Expected no pending messages");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue