From 6987937582adcfa51200505a09566373c6f64ef4 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 21 May 2019 14:27:47 -0400 Subject: [PATCH] log facility: make its records 64-bit compatible Log records may store either data or pointers to more records. In both cases they must have the same size. With 64-bit pointers, the amount of data that can occupy the same space as a pointer has to be adjusted. And storage alignment has to accommodate actual pointers not u32_t. Signed-off-by: Nicolas Pitre --- include/logging/log_core.h | 4 ---- include/logging/log_msg.h | 11 +++++++--- subsys/logging/log_core.c | 2 +- subsys/logging/log_msg.c | 2 +- .../subsys/logging/log_msg/src/log_msg_test.c | 22 +++++++++++++++++++ 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/logging/log_core.h b/include/logging/log_core.h index a6b81cee146..64be59ef462 100644 --- a/include/logging/log_core.h +++ b/include/logging/log_core.h @@ -16,10 +16,6 @@ extern "C" { #endif -#if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFUL -#error "Logger does not support 64 bit architecture." -#endif - #ifndef CONFIG_LOG #define CONFIG_LOG_DEFAULT_LEVEL 0 #define CONFIG_LOG_DOMAIN_ID 0 diff --git a/include/logging/log_msg.h b/include/logging/log_msg.h index d9b2c3e4d80..9ea31e639f3 100644 --- a/include/logging/log_msg.h +++ b/include/logging/log_msg.h @@ -35,15 +35,20 @@ typedef unsigned long log_arg_t; #define LOG_MAX_NARGS 15 /** @brief Number of arguments in the log entry which fits in one chunk.*/ +#ifdef CONFIG_64BIT +#define LOG_MSG_NARGS_SINGLE_CHUNK 4 +#else #define LOG_MSG_NARGS_SINGLE_CHUNK 3 +#endif /** @brief Number of arguments in the head of extended standard log message..*/ -#define LOG_MSG_NARGS_HEAD_CHUNK (LOG_MSG_NARGS_SINGLE_CHUNK - 1) +#define LOG_MSG_NARGS_HEAD_CHUNK \ + (LOG_MSG_NARGS_SINGLE_CHUNK - (sizeof(void *)/sizeof(log_arg_t))) /** @brief Maximal amount of bytes in the hexdump entry which fits in one chunk. */ #define LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK \ - (LOG_MSG_NARGS_SINGLE_CHUNK * sizeof(u32_t)) + (LOG_MSG_NARGS_SINGLE_CHUNK * sizeof(log_arg_t)) /** @brief Number of bytes in the first chunk of hexdump message if message * consists of more than one chunk. @@ -57,7 +62,7 @@ typedef unsigned long log_arg_t; #define HEXDUMP_BYTES_CONT_MSG \ (sizeof(struct log_msg) - sizeof(void *)) -#define ARGS_CONT_MSG (HEXDUMP_BYTES_CONT_MSG / sizeof(u32_t)) +#define ARGS_CONT_MSG (HEXDUMP_BYTES_CONT_MSG / sizeof(log_arg_t)) /** @brief Flag indicating standard log message. */ #define LOG_MSG_TYPE_STD 0 diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index 35819f6a614..09bef2dd5ba 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -51,7 +51,7 @@ struct log_strdup_buf { static const char *log_strdup_fail_msg = ""; struct k_mem_slab log_strdup_pool; -static u8_t __noinit __aligned(sizeof(u32_t)) +static u8_t __noinit __aligned(sizeof(void *)) log_strdup_pool_buf[LOG_STRDUP_POOL_BUFFER_SIZE]; static struct log_list_t list; diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 1210d0644dd..155d736f8de 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -17,7 +17,7 @@ #define NUM_OF_MSGS (CONFIG_LOG_BUFFER_SIZE / MSG_SIZE) struct k_mem_slab log_msg_pool; -static u8_t __noinit __aligned(sizeof(u32_t)) +static u8_t __noinit __aligned(sizeof(void *)) log_msg_pool_buf[CONFIG_LOG_BUFFER_SIZE]; void log_msg_pool_init(void) 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 0180add1fe0..5f8bc3bfd41 100644 --- a/tests/subsys/logging/log_msg/src/log_msg_test.c +++ b/tests/subsys/logging/log_msg/src/log_msg_test.c @@ -20,8 +20,13 @@ extern struct k_mem_slab log_msg_pool; static const char my_string[] = "test_string"; void test_log_std_msg(void) { +#ifdef CONFIG_64BIT + zassert_true(LOG_MSG_NARGS_SINGLE_CHUNK == 4, + "test assumes following setting"); +#else zassert_true(LOG_MSG_NARGS_SINGLE_CHUNK == 3, "test assumes following setting"); +#endif u32_t used_slabs = k_mem_slab_num_used_get(&log_msg_pool); log_arg_t args[] = {1, 2, 3, 4, 5, 6}; @@ -85,6 +90,22 @@ void test_log_std_msg(void) "Expected mem slab allocation."); used_slabs--; +#ifdef CONFIG_64BIT + /* allocation of 4 argument fits in single buffer */ + msg = log_msg_create_n(my_string, args, 4); + + zassert_equal((used_slabs + 1), + k_mem_slab_num_used_get(&log_msg_pool), + "Expected mem slab allocation."); + used_slabs++; + + log_msg_put(msg); + + zassert_equal((used_slabs - 1), + k_mem_slab_num_used_get(&log_msg_pool), + "Expected mem slab allocation."); + used_slabs--; +#else /* allocation of 4 argument fits in 2 buffers */ msg = log_msg_create_n(my_string, args, 4); @@ -99,6 +120,7 @@ void test_log_std_msg(void) k_mem_slab_num_used_get(&log_msg_pool), "Expected mem slab allocation."); used_slabs -= 2U; +#endif /* allocation of 5 argument fits in 2 buffers */ msg = log_msg_create_n(my_string, args, 5);