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 <npitre@baylibre.com>
This commit is contained in:
parent
0567f161d8
commit
6987937582
5 changed files with 32 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -51,7 +51,7 @@ struct log_strdup_buf {
|
|||
|
||||
static const char *log_strdup_fail_msg = "<log_strdup alloc failed>";
|
||||
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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue