Skip to content

Commit 03165c9

Browse files
nordic-krchcfriedt
authored andcommitted
logging: Cleanup in the internal headers
Added log_internal.h for internal APIs. Move functions out of log_core.h. Log_core.h shall have only macros and functions related to logging message creation. Log_core.h is included by log.h thus number of dependencies in that headers must be limited to minimum to allow including without risk of circular dependencies. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 8d20e8d commit 03165c9

File tree

12 files changed

+161
-169
lines changed

12 files changed

+161
-169
lines changed

include/logging/log_core.h

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
#define ZEPHYR_INCLUDE_LOGGING_LOG_CORE_H_
88

99
#include <logging/log_msg.h>
10-
#include <logging/log_core2.h>
10+
#include <logging/log_msg2.h>
1111
#include <logging/log_instance.h>
1212
#include <stdbool.h>
1313
#include <stdint.h>
1414
#include <stdarg.h>
1515
#include <syscall.h>
1616
#include <sys/util.h>
1717

18+
/* This header file keeps all macros and functions needed for creating logging
19+
* messages (macros like @ref LOG_ERR).
20+
*/
1821
#define LOG_LEVEL_NONE 0U
1922
#define LOG_LEVEL_ERR 1U
2023
#define LOG_LEVEL_WRN 2U
@@ -481,27 +484,6 @@ enum log_strdup_action {
481484
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
482485
} while (0)
483486

484-
485-
/** @brief Get name of the log source.
486-
*
487-
* @param source_id Source ID.
488-
* @return Name.
489-
*/
490-
static inline const char *log_name_get(uint32_t source_id)
491-
{
492-
return __log_const_start[source_id].name;
493-
}
494-
495-
/** @brief Get compiled level of the log source.
496-
*
497-
* @param source_id Source ID.
498-
* @return Level.
499-
*/
500-
static inline uint8_t log_compiled_level_get(uint32_t source_id)
501-
{
502-
return __log_const_start[source_id].level;
503-
}
504-
505487
/** @brief Get index of the log source based on the address of the constant data
506488
* associated with the source.
507489
*
@@ -516,12 +498,6 @@ static inline uint32_t log_const_source_id(
516498
sizeof(struct log_source_const_data);
517499
}
518500

519-
/** @brief Get number of registered sources. */
520-
static inline uint32_t log_sources_count(void)
521-
{
522-
return log_const_source_id(__log_const_end);
523-
}
524-
525501
extern struct log_source_dynamic_data __log_dynamic_start[];
526502
extern struct log_source_dynamic_data __log_dynamic_end[];
527503

@@ -534,17 +510,6 @@ extern struct log_source_dynamic_data __log_dynamic_end[];
534510
#define LOG_INSTANCE_DYNAMIC_DATA(_module_name, _inst) \
535511
LOG_ITEM_DYNAMIC_DATA(LOG_INSTANCE_FULL_NAME(_module_name, _inst))
536512

537-
/** @brief Get pointer to the filter set of the log source.
538-
*
539-
* @param source_id Source ID.
540-
*
541-
* @return Pointer to the filter set.
542-
*/
543-
static inline uint32_t *log_dynamic_filters_get(uint32_t source_id)
544-
{
545-
return &__log_dynamic_start[source_id].filters;
546-
}
547-
548513
/** @brief Get index of the log source based on the address of the dynamic data
549514
* associated with the source.
550515
*
@@ -558,12 +523,6 @@ static inline uint32_t log_dynamic_source_id(struct log_source_dynamic_data *dat
558523
sizeof(struct log_source_dynamic_data);
559524
}
560525

561-
/* Initialize runtime filters */
562-
void z_log_runtime_filters_init(void);
563-
564-
/* Notify log_core that a backend was enabled. */
565-
void z_log_notify_backend_enabled(void);
566-
567526
/** @brief Dummy function to trigger log messages arguments type checking. */
568527
static inline __printf_like(1, 2)
569528
void z_log_printf_arg_checker(const char *fmt, ...)
@@ -710,49 +669,6 @@ void log_generic_from_user(struct log_msg_ids src_level,
710669
*/
711670
bool log_is_strdup(const void *buf);
712671

713-
/** @brief Free allocated buffer.
714-
*
715-
* @param buf Buffer.
716-
*/
717-
void log_free(void *buf);
718-
719-
/**
720-
* @brief Get current number of allocated buffers for string duplicates.
721-
*/
722-
uint32_t log_get_strdup_pool_current_utilization(void);
723-
724-
/**
725-
* @brief Get maximal number of simultaneously allocated buffers for string
726-
* duplicates.
727-
*
728-
* Value can be used to determine pool size.
729-
*/
730-
uint32_t log_get_strdup_pool_utilization(void);
731-
732-
/**
733-
* @brief Get length of the longest string duplicated.
734-
*
735-
* Value can be used to determine buffer size in the string duplicates pool.
736-
*/
737-
uint32_t log_get_strdup_longest_string(void);
738-
739-
/** @brief Indicate to the log core that one log message has been dropped.
740-
*/
741-
void z_log_dropped(void);
742-
743-
/** @brief Read and clear current drop indications counter.
744-
*
745-
* @return Dropped count.
746-
*/
747-
uint32_t z_log_dropped_read_and_clear(void);
748-
749-
/** @brief Check if there are any pending drop notifications.
750-
*
751-
* @retval true Pending unreported drop indications.
752-
* @retval false No pending unreported drop indications.
753-
*/
754-
bool z_log_dropped_pending(void);
755-
756672
/** @brief Log a message from user mode context.
757673
*
758674
* @note This function is intended to be used internally

include/logging/log_core2.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

include/logging/log_ctrl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ void log_backend_enable(struct log_backend const *const backend,
169169
*/
170170
void log_backend_disable(struct log_backend const *const backend);
171171

172+
/**
173+
* @brief Get current number of allocated buffers for string duplicates.
174+
*/
175+
uint32_t log_get_strdup_pool_current_utilization(void);
176+
177+
/**
178+
* @brief Get maximal number of simultaneously allocated buffers for string
179+
* duplicates.
180+
*
181+
* Value can be used to determine pool size.
182+
*/
183+
uint32_t log_get_strdup_pool_utilization(void);
184+
185+
/**
186+
* @brief Get length of the longest string duplicated.
187+
*
188+
* Value can be used to determine buffer size in the string duplicates pool.
189+
*/
190+
uint32_t log_get_strdup_longest_string(void);
191+
172192
#if defined(CONFIG_LOG) && !defined(CONFIG_LOG_MINIMAL)
173193
#define LOG_CORE_INIT() log_core_init()
174194
#define LOG_INIT() log_init()

include/logging/log_internal.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_INTERNAL_H_
7+
#define ZEPHYR_INCLUDE_LOGGING_LOG_INTERNAL_H_
8+
9+
#include <zephyr/types.h>
10+
#include <sys/__assert.h>
11+
#include <logging/log_core.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/* Header contains declarations of functions used internally in the logging,
18+
* shared between various portions of logging subsystem. Functions are internal
19+
* not intended to be used outside, including logging backends.
20+
*/
21+
22+
/** @brief Indicate to the log core that one log message has been dropped.
23+
*/
24+
void z_log_dropped(void);
25+
26+
/** @brief Read and clear current drop indications counter.
27+
*
28+
* @return Dropped count.
29+
*/
30+
uint32_t z_log_dropped_read_and_clear(void);
31+
32+
/** @brief Check if there are any pending drop notifications.
33+
*
34+
* @retval true Pending unreported drop indications.
35+
* @retval false No pending unreported drop indications.
36+
*/
37+
bool z_log_dropped_pending(void);
38+
39+
/** @brief Free allocated buffer.
40+
*
41+
* @param buf Buffer.
42+
*/
43+
void log_free(void *buf);
44+
45+
/* Initialize runtime filters */
46+
void z_log_runtime_filters_init(void);
47+
48+
/* Notify log_core that a backend was enabled. */
49+
void z_log_notify_backend_enabled(void);
50+
51+
/** @brief Get pointer to the filter set of the log source.
52+
*
53+
* @param source_id Source ID.
54+
*
55+
* @return Pointer to the filter set.
56+
*/
57+
static inline uint32_t *log_dynamic_filters_get(uint32_t source_id)
58+
{
59+
return &__log_dynamic_start[source_id].filters;
60+
}
61+
62+
/** @brief Get number of registered sources. */
63+
static inline uint32_t log_sources_count(void)
64+
{
65+
return log_const_source_id(__log_const_end);
66+
}
67+
68+
/** @brief Initialize module for handling logging message. */
69+
void z_log_msg2_init(void);
70+
71+
/** @brief Commit log message.
72+
*
73+
* @param msg Message.
74+
*/
75+
void z_log_msg2_commit(struct log_msg2 *msg);
76+
77+
/** @brief Get pending log message.
78+
*
79+
* @param[out] len Message length in bytes is written is @p len is not null.
80+
*
81+
* @param Message or null if no pending messages.
82+
*/
83+
union log_msg2_generic *z_log_msg2_claim(void);
84+
85+
/** @brief Free message.
86+
*
87+
* @param msg Message.
88+
*/
89+
void z_log_msg2_free(union log_msg2_generic *msg);
90+
91+
/** @brief Check if there are any message pending.
92+
*
93+
* @retval true if at least one message is pending.
94+
* @retval false if no message is pending.
95+
*/
96+
bool z_log_msg2_pending(void);
97+
98+
#ifdef __cplusplus
99+
}
100+
#endif
101+
102+
#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_INTERNAL_H_ */

include/logging/log_msg2.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ do { \
434434
} \
435435
}
436436

437+
/** @brief Allocate log message.
438+
*
439+
* @param wlen Length in 32 bit words.
440+
*
441+
* @return allocated space or null if cannot be allocated.
442+
*/
443+
struct log_msg2 *z_log_msg2_alloc(uint32_t wlen);
444+
437445
/** @brief Finalize message.
438446
*
439447
* Finalization includes setting source, copying data and timestamp in the

subsys/logging/log_cmds.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <shell/shell.h>
88
#include <logging/log_ctrl.h>
99
#include <logging/log.h>
10+
#include <logging/log_internal.h>
1011
#include <string.h>
1112

1213
typedef int (*log_backend_cmd_t)(const struct shell *shell,

subsys/logging/log_core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include <logging/log_backend.h>
1010
#include <logging/log_ctrl.h>
1111
#include <logging/log_output.h>
12-
#include <logging/log_msg2.h>
13-
#include <logging/log_core2.h>
12+
#include <logging/log_internal.h>
1413
#include <sys/mpsc_pbuf.h>
1514
#include <sys/printk.h>
1615
#include <sys_clock.h>

0 commit comments

Comments
 (0)