6#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_MSG2_H_
7#define ZEPHYR_INCLUDE_LOGGING_LOG_MSG2_H_
18#define alloca __builtin_alloca
28#define LOG_MSG2_DEBUG 0
29#define LOG_MSG2_DBG(...) IF_ENABLED(LOG_MSG2_DEBUG, (printk(__VA_ARGS__)))
31#if CONFIG_LOG_TIMESTAMP_64BIT
44#define Z_LOG_MSG2_LOG 0
45#define Z_LOG_MSG2_TRACE 1
47#define LOG_MSG2_GENERIC_HDR \
63#if CONFIG_LOG_TRACE_SHORT_TIMESTAMP
81#if (INTPTR_MAX > INT32_MAX) && !CONFIG_LOG_TIMESTAMP_64BIT
88#if defined(__xtensa__) && !defined(CONFIG_LOG_TIMESTAMP_64BIT)
126enum z_log_msg2_mode {
130 Z_LOG_MSG2_MODE_RUNTIME,
135 Z_LOG_MSG2_MODE_FROM_STACK,
141 Z_LOG_MSG2_MODE_ZERO_COPY,
147#define Z_LOG_MSG_DESC_INITIALIZER(_domain_id, _level, _plen, _dlen) \
151 .type = Z_LOG_MSG2_LOG, \
152 .domain = _domain_id, \
154 .package_len = _plen, \
160#define Z_LOG_MSG2_ALIGNMENT CBPRINTF_PACKAGE_ALIGNMENT
162#if CONFIG_LOG2_USE_VLA
163#define Z_LOG_MSG2_ON_STACK_ALLOC(ptr, len) \
164 long long _ll_buf[ceiling_fraction(len, sizeof(long long))]; \
165 long double _ld_buf[ceiling_fraction(len, sizeof(long double))]; \
166 ptr = (sizeof(long double) == Z_LOG_MSG2_ALIGNMENT) ? \
167 (struct log_msg2 *)_ld_buf : (struct log_msg2 *)_ll_buf; \
168 if (IS_ENABLED(CONFIG_LOG_TEST_CLEAR_MESSAGE_SPACE)) { \
170 memset(ptr, 0, len); \
178#define Z_LOG_MSG2_ON_STACK_ALLOC(ptr, len) \
179 long long _ll_buf32[32 / sizeof(long long)]; \
180 long long _ll_buf48[48 / sizeof(long long)]; \
181 long long _ll_buf64[64 / sizeof(long long)]; \
182 long long _ll_buf128[128 / sizeof(long long)]; \
183 long long _ll_buf256[256 / sizeof(long long)]; \
184 long double _ld_buf32[32 / sizeof(long double)]; \
185 long double _ld_buf48[48 / sizeof(long double)]; \
186 long double _ld_buf64[64 / sizeof(long double)]; \
187 long double _ld_buf128[128 / sizeof(long double)]; \
188 long double _ld_buf256[256 / sizeof(long double)]; \
189 if (sizeof(long double) == Z_LOG_MSG2_ALIGNMENT) { \
190 ptr = (len > 128) ? (struct log_msg2 *)_ld_buf256 : \
191 ((len > 64) ? (struct log_msg2 *)_ld_buf128 : \
192 ((len > 48) ? (struct log_msg2 *)_ld_buf64 : \
193 ((len > 32) ? (struct log_msg2 *)_ld_buf48 : \
194 (struct log_msg2 *)_ld_buf32)));\
196 ptr = (len > 128) ? (struct log_msg2 *)_ll_buf256 : \
197 ((len > 64) ? (struct log_msg2 *)_ll_buf128 : \
198 ((len > 48) ? (struct log_msg2 *)_ll_buf64 : \
199 ((len > 32) ? (struct log_msg2 *)_ll_buf48 : \
200 (struct log_msg2 *)_ll_buf32)));\
202 if (IS_ENABLED(CONFIG_LOG_TEST_CLEAR_MESSAGE_SPACE)) { \
204 memset(ptr, 0, len); \
208#define Z_LOG_MSG2_ALIGN_OFFSET \
209 sizeof(struct log_msg2_hdr)
211#define Z_LOG_MSG2_LEN(pkg_len, data_len) \
212 (sizeof(struct log_msg2_hdr) + pkg_len + (data_len))
214#define Z_LOG_MSG2_ALIGNED_WLEN(pkg_len, data_len) \
215 ceiling_fraction(ROUND_UP(Z_LOG_MSG2_LEN(pkg_len, data_len), \
216 Z_LOG_MSG2_ALIGNMENT), \
219#define Z_LOG_MSG2_SYNC(_domain_id, _source, _level, _data, _dlen, ...) do { \
221 CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG2_ALIGN_OFFSET, \
223 struct log_msg2 *_msg; \
224 Z_LOG_MSG2_ON_STACK_ALLOC(_msg, Z_LOG_MSG2_LEN(_plen, _dlen)); \
226 CBPRINTF_STATIC_PACKAGE(_msg->data, _plen, _plen, \
227 Z_LOG_MSG2_ALIGN_OFFSET, \
230 struct log_msg2_desc _desc = \
231 Z_LOG_MSG_DESC_INITIALIZER(_domain_id, _level, \
232 (uint32_t)_plen, _dlen); \
233 z_log_msg2_finalize(_msg, _source, _desc, _data); \
236#define Z_LOG_MSG2_STACK_CREATE(_domain_id, _source, _level, _data, _dlen, ...)\
239 if (GET_ARG_N(1, __VA_ARGS__) == NULL) { \
242 CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG2_ALIGN_OFFSET, \
245 struct log_msg2 *_msg; \
246 Z_LOG_MSG2_ON_STACK_ALLOC(_msg, Z_LOG_MSG2_LEN(_plen, 0)); \
248 CBPRINTF_STATIC_PACKAGE(_msg->data, _plen, \
249 _plen, Z_LOG_MSG2_ALIGN_OFFSET, \
252 struct log_msg2_desc _desc = \
253 Z_LOG_MSG_DESC_INITIALIZER(_domain_id, _level, \
254 (uint32_t)_plen, _dlen); \
255 LOG_MSG2_DBG("creating message on stack: package len: %d, data len: %d\n", \
256 _plen, (int)(_dlen)); \
257 z_log_msg2_static_create((void *)_source, _desc, _msg->data, _data); \
261#define Z_LOG_MSG2_SIMPLE_CREATE(_domain_id, _source, _level, ...) do { \
263 CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG2_ALIGN_OFFSET, \
265 size_t _msg_wlen = Z_LOG_MSG2_ALIGNED_WLEN(_plen, 0); \
266 struct log_msg2 *_msg = z_log_msg2_alloc(_msg_wlen); \
267 struct log_msg2_desc _desc = \
268 Z_LOG_MSG_DESC_INITIALIZER(_domain_id, _level, (uint32_t)_plen, 0); \
269 LOG_MSG2_DBG("creating message zero copy: package len: %d, msg: %p\n", \
272 CBPRINTF_STATIC_PACKAGE(_msg->data, _plen, _plen, \
273 Z_LOG_MSG2_ALIGN_OFFSET, \
276 z_log_msg2_finalize(_msg, (void *)_source, _desc, NULL); \
282#define Z_LOG_MSG2_SIMPLE_CREATE(...)
288#define Z_LOG_FMT_ARGS_2(_name, ...) \
289 COND_CODE_1(CONFIG_LOG2_FMT_SECTION, \
290 (COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), \
291 (_name), (_name, GET_ARGS_LESS_N(1, __VA_ARGS__)))), \
303#define Z_LOG_FMT_ARGS(_name, ...) \
304 COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \
306 (Z_LOG_FMT_ARGS_2(_name, ##__VA_ARGS__)))
311#define Z_LOG_MSG2_STR_VAR_IN_SECTION(_name, ...) \
312 COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \
314 (static const char _name[] \
315 __attribute__((__section__(".log_strings"))) = \
316 GET_ARG_N(1, __VA_ARGS__);))
325#define Z_LOG_MSG2_STR_VAR(_name, ...) \
326 IF_ENABLED(CONFIG_LOG2_FMT_SECTION, \
327 (Z_LOG_MSG2_STR_VAR_IN_SECTION(_name, ##__VA_ARGS__)))
368#if CONFIG_LOG2_ALWAYS_RUNTIME
369#define Z_LOG_MSG2_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\
370 _level, _data, _dlen, ...) \
372 Z_LOG_MSG2_STR_VAR(_fmt, ##__VA_ARGS__) \
373 z_log_msg2_runtime_create(_domain_id, (void *)_source, \
374 _level, (uint8_t *)_data, _dlen,\
375 Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__));\
376 _mode = Z_LOG_MSG2_MODE_RUNTIME; \
378#elif CONFIG_LOG2_MODE_IMMEDIATE
379#define Z_LOG_MSG2_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\
380 _level, _data, _dlen, ...) \
382 Z_LOG_MSG2_STR_VAR(_fmt, ##__VA_ARGS__); \
383 if (CBPRINTF_MUST_RUNTIME_PACKAGE(_cstr_cnt, __VA_ARGS__)) { \
384 LOG_MSG2_DBG("create runtime message\n");\
385 z_log_msg2_runtime_create(_domain_id, (void *)_source, \
386 _level, (uint8_t *)_data, _dlen,\
387 Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__));\
388 _mode = Z_LOG_MSG2_MODE_RUNTIME; \
390 Z_LOG_MSG2_SYNC(_domain_id, _source, _level, \
391 _data, _dlen, Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__)); \
392 _mode = Z_LOG_MSG2_MODE_SYNC; \
396#define Z_LOG_MSG2_CREATE2(_try_0cpy, _mode, _cstr_cnt, _domain_id, _source,\
397 _level, _data, _dlen, ...) \
399 Z_LOG_MSG2_STR_VAR(_fmt, ##__VA_ARGS__); \
400 if (CBPRINTF_MUST_RUNTIME_PACKAGE(_cstr_cnt, __VA_ARGS__)) { \
401 LOG_MSG2_DBG("create runtime message\n");\
402 z_log_msg2_runtime_create(_domain_id, (void *)_source, \
403 _level, (uint8_t *)_data, _dlen,\
404 Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__));\
405 _mode = Z_LOG_MSG2_MODE_RUNTIME; \
406 } else if (IS_ENABLED(CONFIG_LOG_SPEED) && _try_0cpy && ((_dlen) == 0)) {\
407 LOG_MSG2_DBG("create zero-copy message\n");\
408 Z_LOG_MSG2_SIMPLE_CREATE(_domain_id, _source, \
409 _level, Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__)); \
410 _mode = Z_LOG_MSG2_MODE_ZERO_COPY; \
412 LOG_MSG2_DBG("create on stack message\n");\
413 Z_LOG_MSG2_STACK_CREATE(_domain_id, _source, _level, _data, \
414 _dlen, Z_LOG_FMT_ARGS(_fmt, ##__VA_ARGS__)); \
415 _mode = Z_LOG_MSG2_MODE_FROM_STACK; \
421#define Z_LOG_MSG2_CREATE(_try_0cpy, _mode, _domain_id, _source,\
422 _level, _data, _dlen, ...) \
423 Z_LOG_MSG2_CREATE2(_try_0cpy, _mode, UTIL_CAT(Z_LOG_FUNC_PREFIX_, _level), \
424 _domain_id, _source, _level, _data, _dlen, \
425 Z_LOG_STR(_level, __VA_ARGS__))
427#define Z_TRACING_LOG_HDR_INIT(name, id) \
428 struct log_msg2_trace name = { \
430 .type = Z_LOG_MSG2_TRACE, \
450void z_log_msg2_finalize(
struct log_msg2 *msg,
const void *source,
463__syscall
void z_log_msg2_static_create(
const void *source,
486__syscall
void z_log_msg2_runtime_vcreate(
uint8_t domain_id,
const void *source,
488 size_t dlen,
const char *fmt,
510static inline void z_log_msg2_runtime_create(
uint8_t domain_id,
513 size_t dlen,
const char *fmt, ...)
518 z_log_msg2_runtime_vcreate(domain_id, source, level,
519 data, dlen, fmt, ap);
549 if (z_log_item_is_msg(generic_msg)) {
static const void * log_msg2_get_source(struct log_msg2 *msg)
Get message source data.
Definition: log_msg2.h:587
static uint8_t log_msg2_get_level(struct log_msg2 *msg)
Get log message level.
Definition: log_msg2.h:576
static log_timestamp_t log_msg2_get_timestamp(struct log_msg2 *msg)
Get timestamp.
Definition: log_msg2.h:598
#define LOG_MSG2_GENERIC_HDR
Definition: log_msg2.h:47
static uint8_t * log_msg2_get_package(struct log_msg2 *msg, size_t *len)
Get string package.
Definition: log_msg2.h:626
static uint32_t log_msg2_generic_get_wlen(union mpsc_pbuf_generic *item)
Get length of the log item.
Definition: log_msg2.h:545
static uint8_t * log_msg2_get_data(struct log_msg2 *msg, size_t *len)
Get data buffer.
Definition: log_msg2.h:611
static uint8_t log_msg2_get_domain(struct log_msg2 *msg)
Get log message domain ID.
Definition: log_msg2.h:565
static uint32_t log_msg2_get_total_wlen(const struct log_msg2_desc desc)
Get total length (in 32 bit words) of a log message.
Definition: log_msg2.h:534
uint32_t log_timestamp_t
Definition: log_msg2.h:34
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Definition: log_msg2.h:51
uint32_t reserved
Definition: log_msg2.h:57
uint32_t domain
Definition: log_msg2.h:53
uint32_t level
Definition: log_msg2.h:54
uint32_t data_len
Definition: log_msg2.h:56
uint32_t package_len
Definition: log_msg2.h:55
Definition: log_msg2.h:110
uint32_t type
Definition: log_msg2.h:111
Definition: log_msg2.h:76
log_timestamp_t timestamp
Definition: log_msg2.h:86
struct log_msg2_desc desc
Definition: log_msg2.h:77
const void * source
Definition: log_msg2.h:85
Definition: log_msg2.h:60
uint32_t evt_id
Definition: log_msg2.h:62
log_timestamp_t timestamp
Definition: log_msg2.h:66
Definition: log_msg2.h:100
void * ptr
Definition: log_msg2.h:102
struct log_msg2_trace_hdr hdr
Definition: log_msg2.h:101
Definition: log_msg2.h:96
struct log_msg2_trace_hdr hdr
Definition: log_msg2.h:97
Definition: log_msg2.h:105
struct log_msg2_hdr hdr
Definition: log_msg2.h:106
uint8_t data[]
Definition: log_msg2.h:107
Constant data associated with the source of log messages.
Definition: log_instance.h:16
Dynamic data associated with the source of log messages.
Definition: log_instance.h:29
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Definition: log_msg2.h:114
struct log_msg2_trace_ptr trace_ptr
Definition: log_msg2.h:118
struct log_msg2_trace trace
Definition: log_msg2.h:117
struct log_msg2_generic_hdr generic
Definition: log_msg2.h:116
union mpsc_pbuf_generic buf
Definition: log_msg2.h:115
struct log_msg2 log
Definition: log_msg2.h:119
Definition: log_msg2.h:70
struct log_source_dynamic_data * dynamic
Definition: log_msg2.h:72
const struct log_source_const_data * fixed
Definition: log_msg2.h:71
void * raw
Definition: log_msg2.h:73
Generic packet header.
Definition: mpsc_packet.h:49