From 0567f161d8f59ea429ea344f11e1c23f18471df8 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 21 May 2019 14:10:15 -0400 Subject: [PATCH] log facility: make its arguments 64-bit compatible Log arguments were hardcoded to u32_t values. On 64-bit systems, this is rather restrictive. To make things clear, arguments now have their own type, log_arg_t, which now can be adjusted in only one location if need be. It is currently defined as unsigned long whose effective width is equivalent to u32_t on 32-bit systems, and u64_t on 64-bit systems. Signed-off-by: Nicolas Pitre --- include/logging/log_core.h | 30 +++++++++---------- include/logging/log_msg.h | 28 ++++++++++------- subsys/logging/log_core.c | 18 +++++------ subsys/logging/log_msg.c | 16 +++++----- .../subsys/logging/log_msg/src/log_msg_test.c | 2 +- 5 files changed, 50 insertions(+), 44 deletions(-) diff --git a/include/logging/log_core.h b/include/logging/log_core.h index 6837776955b..a6b81cee146 100644 --- a/include/logging/log_core.h +++ b/include/logging/log_core.h @@ -179,22 +179,22 @@ extern "C" { log_0(_str, _src_level) #define _LOG_INTERNAL_1(_src_level, _str, _arg0) \ - log_1(_str, (u32_t)(_arg0), _src_level) + log_1(_str, (log_arg_t)(_arg0), _src_level) #define _LOG_INTERNAL_2(_src_level, _str, _arg0, _arg1) \ - log_2(_str, (u32_t)(_arg0), (u32_t)(_arg1), _src_level) + log_2(_str, (log_arg_t)(_arg0), (log_arg_t)(_arg1), _src_level) #define _LOG_INTERNAL_3(_src_level, _str, _arg0, _arg1, _arg2) \ - log_3(_str, (u32_t)(_arg0), (u32_t)(_arg1), (u32_t)(_arg2), _src_level) + log_3(_str, (log_arg_t)(_arg0), (log_arg_t)(_arg1), (log_arg_t)(_arg2), _src_level) -#define __LOG_ARG_CAST(_x) (u32_t)(_x), +#define __LOG_ARG_CAST(_x) (log_arg_t)(_x), #define __LOG_ARGUMENTS(...) MACRO_MAP(__LOG_ARG_CAST, __VA_ARGS__) -#define _LOG_INTERNAL_LONG(_src_level, _str, ...) \ - do { \ - u32_t args[] = {__LOG_ARGUMENTS(__VA_ARGS__)}; \ - log_n(_str, args, ARRAY_SIZE(args), _src_level); \ +#define _LOG_INTERNAL_LONG(_src_level, _str, ...) \ + do { \ + log_arg_t args[] = {__LOG_ARGUMENTS(__VA_ARGS__)};\ + log_n(_str, args, ARRAY_SIZE(args), _src_level); \ } while (false) #define Z_LOG_LEVEL_CHECK(_level, _check_level, _default_level) \ @@ -442,7 +442,7 @@ void log_0(const char *str, struct log_msg_ids src_level); * @param src_level Log identification. */ void log_1(const char *str, - u32_t arg1, + log_arg_t arg1, struct log_msg_ids src_level); /** @brief Standard log with two arguments. @@ -453,8 +453,8 @@ void log_1(const char *str, * @param src_level Log identification. */ void log_2(const char *str, - u32_t arg1, - u32_t arg2, + log_arg_t arg1, + log_arg_t arg2, struct log_msg_ids src_level); /** @brief Standard log with three arguments. @@ -466,9 +466,9 @@ void log_2(const char *str, * @param src_level Log identification. */ void log_3(const char *str, - u32_t arg1, - u32_t arg2, - u32_t arg3, + log_arg_t arg1, + log_arg_t arg2, + log_arg_t arg3, struct log_msg_ids src_level); /** @brief Standard log with arguments list. @@ -479,7 +479,7 @@ void log_3(const char *str, * @param src_level Log identification. */ void log_n(const char *str, - u32_t *args, + log_arg_t *args, u32_t narg, struct log_msg_ids src_level); diff --git a/include/logging/log_msg.h b/include/logging/log_msg.h index 7dee2e9cad7..d9b2c3e4d80 100644 --- a/include/logging/log_msg.h +++ b/include/logging/log_msg.h @@ -22,6 +22,12 @@ extern "C" { * @{ */ +/** @brief Log argument type. + * + * Should preferably be equivalent to a native word size. + */ +typedef unsigned long log_arg_t; + /** @brief Maximum number of arguments in the standard log entry. * * It is limited by 4 bit nargs field in the log message. @@ -123,7 +129,7 @@ struct log_msg_hdr { /** @brief Data part of log message. */ union log_msg_head_data { - u32_t args[LOG_MSG_NARGS_SINGLE_CHUNK]; + log_arg_t args[LOG_MSG_NARGS_SINGLE_CHUNK]; u8_t bytes[LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK]; }; @@ -131,7 +137,7 @@ union log_msg_head_data { struct log_msg_ext_head_data { struct log_msg_cont *next; union log_msg_ext_head_data_data { - u32_t args[LOG_MSG_NARGS_HEAD_CHUNK]; + log_arg_t args[LOG_MSG_NARGS_HEAD_CHUNK]; u8_t bytes[LOG_MSG_HEXDUMP_BYTES_HEAD_CHUNK]; } data; }; @@ -155,7 +161,7 @@ BUILD_ASSERT_MSG((sizeof(union log_msg_head_data) == struct log_msg_cont { struct log_msg_cont *next; /*!< Pointer to the next chunk. */ union log_msg_cont_data { - u32_t args[ARGS_CONT_MSG]; + log_arg_t args[ARGS_CONT_MSG]; u8_t bytes[HEXDUMP_BYTES_CONT_MSG]; } payload; }; @@ -261,7 +267,7 @@ u32_t log_msg_nargs_get(struct log_msg *msg); * @return Argument value or 0 if arg_idx exceeds number of arguments in the * message. */ -u32_t log_msg_arg_get(struct log_msg *msg, u32_t arg_idx); +log_arg_t log_msg_arg_get(struct log_msg *msg, u32_t arg_idx); /** @brief Gets pointer to the unformatted string from standard log message. @@ -379,7 +385,7 @@ static inline struct log_msg *log_msg_create_0(const char *str) * @return Pointer to allocated head of the message or NULL. */ static inline struct log_msg *log_msg_create_1(const char *str, - u32_t arg1) + log_arg_t arg1) { struct log_msg *msg = z_log_msg_std_alloc(); @@ -407,8 +413,8 @@ static inline struct log_msg *log_msg_create_1(const char *str, * @return Pointer to allocated head of the message or NULL. */ static inline struct log_msg *log_msg_create_2(const char *str, - u32_t arg1, - u32_t arg2) + log_arg_t arg1, + log_arg_t arg2) { struct log_msg *msg = z_log_msg_std_alloc(); @@ -438,9 +444,9 @@ static inline struct log_msg *log_msg_create_2(const char *str, * @return Pointer to allocated head of the message or NULL. */ static inline struct log_msg *log_msg_create_3(const char *str, - u32_t arg1, - u32_t arg2, - u32_t arg3) + log_arg_t arg1, + log_arg_t arg2, + log_arg_t arg3) { struct log_msg *msg = z_log_msg_std_alloc(); @@ -470,7 +476,7 @@ static inline struct log_msg *log_msg_create_3(const char *str, * @return Pointer to allocated head of the message or NULL. */ struct log_msg *log_msg_create_n(const char *str, - u32_t *args, + log_arg_t *args, u32_t nargs); /** diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index d864852f92d..35819f6a614 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -225,7 +225,7 @@ void log_0(const char *str, struct log_msg_ids src_level) } void log_1(const char *str, - u32_t arg0, + log_arg_t arg0, struct log_msg_ids src_level) { struct log_msg *msg = log_msg_create_1(str, arg0); @@ -237,8 +237,8 @@ void log_1(const char *str, } void log_2(const char *str, - u32_t arg0, - u32_t arg1, + log_arg_t arg0, + log_arg_t arg1, struct log_msg_ids src_level) { struct log_msg *msg = log_msg_create_2(str, arg0, arg1); @@ -251,9 +251,9 @@ void log_2(const char *str, } void log_3(const char *str, - u32_t arg0, - u32_t arg1, - u32_t arg2, + log_arg_t arg0, + log_arg_t arg1, + log_arg_t arg2, struct log_msg_ids src_level) { struct log_msg *msg = log_msg_create_3(str, arg0, arg1, arg2); @@ -266,7 +266,7 @@ void log_3(const char *str, } void log_n(const char *str, - u32_t *args, + log_arg_t *args, u32_t narg, struct log_msg_ids src_level) { @@ -362,11 +362,11 @@ void log_generic(struct log_msg_ids src_level, const char *fmt, va_list ap) } } } else { - u32_t args[LOG_MAX_NARGS]; + log_arg_t args[LOG_MAX_NARGS]; u32_t nargs = count_args(fmt); for (int i = 0; i < nargs; i++) { - args[i] = va_arg(ap, u32_t); + args[i] = va_arg(ap, log_arg_t); } log_n(fmt, args, nargs, src_level); diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 0884e2c976b..1210d0644dd 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -99,7 +99,7 @@ u32_t log_msg_nargs_get(struct log_msg *msg) return msg->hdr.params.std.nargs; } -static u32_t cont_arg_get(struct log_msg *msg, u32_t arg_idx) +static log_arg_t cont_arg_get(struct log_msg *msg, u32_t arg_idx) { struct log_msg_cont *cont; @@ -119,9 +119,9 @@ static u32_t cont_arg_get(struct log_msg *msg, u32_t arg_idx) return cont->payload.args[arg_idx]; } -u32_t log_msg_arg_get(struct log_msg *msg, u32_t arg_idx) +log_arg_t log_msg_arg_get(struct log_msg *msg, u32_t arg_idx) { - u32_t arg; + log_arg_t arg; /* Return early if requested argument not present in the message. */ if (arg_idx >= msg->hdr.params.std.nargs) { @@ -186,18 +186,18 @@ static struct log_msg *msg_alloc(u32_t nargs) return msg; } -static void copy_args_to_msg(struct log_msg *msg, u32_t *args, u32_t nargs) +static void copy_args_to_msg(struct log_msg *msg, log_arg_t *args, u32_t nargs) { struct log_msg_cont *cont = msg->payload.ext.next; if (nargs > LOG_MSG_NARGS_SINGLE_CHUNK) { (void)memcpy(msg->payload.ext.data.args, args, - LOG_MSG_NARGS_HEAD_CHUNK * sizeof(u32_t)); + LOG_MSG_NARGS_HEAD_CHUNK * sizeof(log_arg_t)); nargs -= LOG_MSG_NARGS_HEAD_CHUNK; args += LOG_MSG_NARGS_HEAD_CHUNK; } else { (void)memcpy(msg->payload.single.args, args, - nargs * sizeof(u32_t)); + nargs * sizeof(log_arg_t)); nargs = 0U; } @@ -205,14 +205,14 @@ static void copy_args_to_msg(struct log_msg *msg, u32_t *args, u32_t nargs) u32_t cpy_args = MIN(nargs, ARGS_CONT_MSG); (void)memcpy(cont->payload.args, args, - cpy_args * sizeof(u32_t)); + cpy_args * sizeof(log_arg_t)); nargs -= cpy_args; args += cpy_args; cont = cont->next; } } -struct log_msg *log_msg_create_n(const char *str, u32_t *args, u32_t nargs) +struct log_msg *log_msg_create_n(const char *str, log_arg_t *args, u32_t nargs) { __ASSERT_NO_MSG(nargs < LOG_MAX_NARGS); diff --git a/tests/subsys/logging/log_msg/src/log_msg_test.c b/tests/subsys/logging/log_msg/src/log_msg_test.c index feba421b55f..0180add1fe0 100644 --- a/tests/subsys/logging/log_msg/src/log_msg_test.c +++ b/tests/subsys/logging/log_msg/src/log_msg_test.c @@ -24,7 +24,7 @@ void test_log_std_msg(void) "test assumes following setting"); u32_t used_slabs = k_mem_slab_num_used_get(&log_msg_pool); - u32_t args[] = {1, 2, 3, 4, 5, 6}; + log_arg_t args[] = {1, 2, 3, 4, 5, 6}; struct log_msg *msg; /* allocation of 0 argument fits in single buffer */