debug: kernel's object tracing api
Restructure the kernel's object tracing implementation to provide a public API that allows debug tools to use the debug hooks easier and allows kernel developers to extend the kernel's object tracing scope and include new kernel objects easier. The API provides the trace list abstraction to keep track of different types of kernel objects. The API contains a simple single-linked list implementation that allows to save space and simplifies the access to the data for debug tools such as gdb. Change-Id: Ic4d393d584576f67f2c5b706e61bae08869debba Signed-off-by: Juan Manuel Cruz <juan.m.cruz.alcaraz@intel.com>
This commit is contained in:
parent
f206d86c10
commit
caa17577ef
10 changed files with 179 additions and 82 deletions
|
@ -114,7 +114,7 @@ struct _k_mbox_struct {
|
|||
struct k_args *readers;
|
||||
int count;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct _k_mbox_struct *next;
|
||||
struct _k_mbox_struct *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -127,7 +127,7 @@ struct _k_mutex_struct {
|
|||
int count;
|
||||
int num_conflicts;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct _k_mutex_struct *next;
|
||||
struct _k_mutex_struct *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -140,7 +140,7 @@ struct _k_sem_struct {
|
|||
int level;
|
||||
int count;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct _k_sem_struct *next;
|
||||
struct _k_sem_struct *__next;
|
||||
#endif
|
||||
} __aligned(4);
|
||||
|
||||
|
@ -156,7 +156,7 @@ struct _k_fifo_struct {
|
|||
int high_watermark;
|
||||
int count;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct _k_fifo_struct *next;
|
||||
struct _k_fifo_struct *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -220,7 +220,7 @@ struct _k_pipe_struct {
|
|||
struct _k_pipe_desc desc;
|
||||
int count;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct _k_pipe_struct *next;
|
||||
struct _k_pipe_struct *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -236,7 +236,7 @@ struct _k_mem_map_struct {
|
|||
int high_watermark;
|
||||
int count;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct _k_mem_map_struct *next;
|
||||
struct _k_mem_map_struct *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -251,20 +251,6 @@ struct _k_event_struct {
|
|||
int count;
|
||||
} __aligned(4);
|
||||
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct _k_mbox_struct *_track_list_micro_mbox;
|
||||
|
||||
struct _k_mutex_struct *_track_list_micro_mutex;
|
||||
|
||||
struct _k_sem_struct *_track_list_micro_sem;
|
||||
|
||||
struct _k_fifo_struct *_track_list_micro_fifo;
|
||||
|
||||
struct _k_pipe_struct *_track_list_micro_pipe;
|
||||
|
||||
struct _k_mem_map_struct *_track_list_micro_mem_map;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
|
@ -275,7 +261,6 @@ typedef enum {
|
|||
_ALL_N = 0x00000004
|
||||
} K_PIPE_OPTION;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
70
include/misc/debug/object_tracing.h
Normal file
70
include/misc/debug/object_tracing.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Kernel object tracing support.
|
||||
*/
|
||||
|
||||
#ifndef _OBJECT_TRACING_H_
|
||||
#define _OBJECT_TRACING_H_
|
||||
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
#include <nanokernel.h>
|
||||
extern struct nano_fifo *_trace_list_nano_fifo;
|
||||
extern struct nano_lifo *_trace_list_nano_lifo;
|
||||
extern struct nano_sem *_trace_list_nano_sem;
|
||||
extern struct nano_timer *_trace_list_nano_timer;
|
||||
|
||||
#ifdef CONFIG_MICROKERNEL
|
||||
#include <microkernel/base_api.h>
|
||||
extern struct _k_mbox_struct *_trace_list_micro_mbox;
|
||||
extern struct _k_mutex_struct *_trace_list_micro_mutex;
|
||||
extern struct _k_sem_struct *_trace_list_micro_sem;
|
||||
extern struct _k_fifo_struct *_trace_list_micro_fifo;
|
||||
extern struct _k_pipe_struct *_trace_list_micro_pipe;
|
||||
extern struct pool_struct *_trace_list_micro_mem_pool;
|
||||
extern struct _k_mem_map_struct *_trace_list_micro_mem_map;
|
||||
#endif /*CONFIG_MICROKERNEL*/
|
||||
|
||||
/**
|
||||
* @def SYS_TRACING_HEAD
|
||||
*
|
||||
* @brief Head element of a trace list.
|
||||
*
|
||||
* @details Access the head element of a given trace list.
|
||||
*
|
||||
* @param type Data type of the trace list to get the head from.
|
||||
* @param name Name of the trace list to get the head from.
|
||||
*/
|
||||
#define SYS_TRACING_HEAD(type, name) ((type *) _CONCAT(_trace_list_, name))
|
||||
|
||||
/**
|
||||
* @def SYS_TRACING_NEXT
|
||||
*
|
||||
* @brief Gets a node's next element.
|
||||
*
|
||||
* @details Given a node in a trace list, gets the next element
|
||||
* in the list.
|
||||
*
|
||||
* @param type Data type of the trace list
|
||||
* @param name Name of the trace list to get the head from.
|
||||
* @param obj Object to get next element from.
|
||||
*/
|
||||
#define SYS_TRACING_NEXT(type, name, obj) (((type *)obj)->__next)
|
||||
|
||||
#endif /*CONFIG_DEBUG_TRACING_KERNEL_OBJECTS*/
|
||||
#endif /*_OBJECT_TRACING_H_*/
|
76
include/misc/debug/object_tracing_common.h
Normal file
76
include/misc/debug/object_tracing_common.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Kernel object tracing common structures.
|
||||
*/
|
||||
|
||||
#ifndef _OBJECT_TRACING_COMMON_H_
|
||||
#define _OBJECT_TRACING_COMMON_H_
|
||||
|
||||
#ifndef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
|
||||
#define SYS_TRACING_OBJ_INIT(name, obj) do { } while ((0))
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* @def SYS_TRACING_OBJ_INIT
|
||||
*
|
||||
* @brief Adds a new object into the trace list
|
||||
*
|
||||
* @details The object is added for tracing into
|
||||
* a trace list. This is usually called at the
|
||||
* moment of object initialization.
|
||||
*
|
||||
* @param name Name of the trace list.
|
||||
* @param obj Object to be added in the trace list.
|
||||
*/
|
||||
#define SYS_TRACING_OBJ_INIT(name, obj) \
|
||||
do { \
|
||||
unsigned int key; \
|
||||
\
|
||||
key = irq_lock(); \
|
||||
(obj)->__next = _trace_list_##name;\
|
||||
_trace_list_##name = obj; \
|
||||
irq_unlock(key); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/*
|
||||
* Lists for object tracing.
|
||||
*/
|
||||
#include <nanokernel.h>
|
||||
struct nano_fifo *_trace_list_nano_fifo;
|
||||
struct nano_lifo *_trace_list_nano_lifo;
|
||||
struct nano_sem *_trace_list_nano_sem;
|
||||
struct nano_timer *_trace_list_nano_timer;
|
||||
|
||||
#ifdef CONFIG_MICROKERNEL
|
||||
#include <microkernel/base_api.h>
|
||||
struct _k_mbox_struct *_trace_list_micro_mbox;
|
||||
struct _k_mutex_struct *_trace_list_micro_mutex;
|
||||
struct _k_sem_struct *_trace_list_micro_sem;
|
||||
struct _k_fifo_struct *_trace_list_micro_fifo;
|
||||
struct _k_pipe_struct *_trace_list_micro_pipe;
|
||||
struct pool_struct *_trace_list_micro_mem_pool;
|
||||
struct _k_mem_map_struct *_trace_list_micro_mem_map;
|
||||
#endif /*CONFIG_MICROKERNEL*/
|
||||
|
||||
|
||||
#endif /*CONFIG_DEBUG_TRACING_KERNEL_OBJECTS*/
|
||||
#endif /*_OBJECT_TRACING_COMMON_H_*/
|
|
@ -410,7 +410,7 @@ struct nano_fifo {
|
|||
};
|
||||
int stat;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct nano_fifo *next;
|
||||
struct nano_fifo *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -621,7 +621,7 @@ struct nano_lifo {
|
|||
struct _nano_queue wait_q;
|
||||
void *list;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct nano_lifo *next;
|
||||
struct nano_lifo *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -808,7 +808,7 @@ struct nano_sem {
|
|||
struct _nano_queue wait_q;
|
||||
int nsig;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct nano_sem *next;
|
||||
struct nano_sem *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -1192,7 +1192,7 @@ struct nano_timer {
|
|||
struct nano_lifo lifo;
|
||||
void *userData;
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct nano_timer *next;
|
||||
struct nano_timer *__next;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -1472,41 +1472,6 @@ extern int64_t sys_tick_delta(int64_t *reftime);
|
|||
*/
|
||||
extern uint32_t sys_tick_delta_32(int64_t *reftime);
|
||||
|
||||
|
||||
/*
|
||||
* Lists for object tracing.
|
||||
*/
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
|
||||
struct nano_sem *_track_list_nano_sem;
|
||||
|
||||
struct nano_fifo *_track_list_nano_fifo;
|
||||
|
||||
struct nano_lifo *_track_list_nano_lifo;
|
||||
|
||||
struct nano_timer *_track_list_nano_timer;
|
||||
|
||||
#define DEBUG_TRACING_OBJ_INIT(type, obj, list) { \
|
||||
obj->next = NULL; \
|
||||
if (list == NULL) { \
|
||||
list = obj; \
|
||||
} \
|
||||
else { \
|
||||
if (list != obj) { \
|
||||
type link = list; \
|
||||
while ((link->next != NULL) && (link->next != obj)) { \
|
||||
link = link->next; \
|
||||
} \
|
||||
if (link->next == NULL) { \
|
||||
link->next = obj; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define DEBUG_TRACING_OBJ_INIT(type, obj, list) do { } while ((0))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @} nanokernel services
|
||||
|
|
|
@ -402,10 +402,6 @@ struct pool_struct {
|
|||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
|
||||
struct pool_struct *_track_list_micro_mem_pool;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
*/
|
||||
|
||||
#include <nano_private.h>
|
||||
#include <misc/debug/object_tracing_common.h>
|
||||
#include <toolchain.h>
|
||||
#include <sections.h>
|
||||
#include <wait_q.h>
|
||||
|
@ -66,7 +67,7 @@ void nano_fifo_init(struct nano_fifo *fifo)
|
|||
|
||||
fifo->stat = 0;
|
||||
|
||||
DEBUG_TRACING_OBJ_INIT(struct nano_fifo *, fifo, _track_list_nano_fifo);
|
||||
SYS_TRACING_OBJ_INIT(nano_fifo, fifo);
|
||||
}
|
||||
|
||||
FUNC_ALIAS(_fifo_put_non_preemptible, nano_isr_fifo_put, void);
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
*/
|
||||
|
||||
#include <nano_private.h>
|
||||
#include <misc/debug/object_tracing_common.h>
|
||||
#include <toolchain.h>
|
||||
#include <sections.h>
|
||||
#include <wait_q.h>
|
||||
|
@ -48,7 +49,7 @@ void nano_lifo_init(struct nano_lifo *lifo)
|
|||
{
|
||||
lifo->list = (void *) 0;
|
||||
_nano_wait_q_init(&lifo->wait_q);
|
||||
DEBUG_TRACING_OBJ_INIT(struct nano_lifo *, lifo, _track_list_nano_lifo);
|
||||
SYS_TRACING_OBJ_INIT(nano_lifo, lifo);
|
||||
}
|
||||
|
||||
FUNC_ALIAS(_lifo_put_non_preemptible, nano_isr_lifo_put, void);
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
*/
|
||||
|
||||
#include <nano_private.h>
|
||||
#include <misc/debug/object_tracing_common.h>
|
||||
#include <toolchain.h>
|
||||
#include <sections.h>
|
||||
#include <wait_q.h>
|
||||
|
@ -55,7 +56,7 @@ void nano_sem_init(struct nano_sem *sem)
|
|||
{
|
||||
sem->nsig = 0;
|
||||
_nano_wait_q_init(&sem->wait_q);
|
||||
DEBUG_TRACING_OBJ_INIT(struct nano_sem *, sem, _track_list_nano_sem);
|
||||
SYS_TRACING_OBJ_INIT(nano_sem, sem);
|
||||
}
|
||||
|
||||
FUNC_ALIAS(_sem_give_non_preemptible, nano_isr_sem_give, void);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <nano_private.h>
|
||||
#include <misc/debug/object_tracing_common.h>
|
||||
|
||||
struct nano_timer *_nano_timer_list;
|
||||
|
||||
|
@ -25,7 +26,7 @@ void nano_timer_init(struct nano_timer *timer, void *data)
|
|||
{
|
||||
nano_lifo_init(&timer->lifo);
|
||||
timer->userData = data;
|
||||
DEBUG_TRACING_OBJ_INIT(struct nano_timer *, timer, _track_list_nano_timer);
|
||||
SYS_TRACING_OBJ_INIT(nano_timer, timer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -254,6 +254,7 @@ def kernel_main_c_header():
|
|||
do_not_edit_warning +
|
||||
"\n" +
|
||||
"#include <sysgen.h>\n" +
|
||||
"#include <misc/debug/object_tracing_common.h>\n" +
|
||||
"#include <micro_private_types.h>\n" +
|
||||
"#include <kernel_main.h>\n" +
|
||||
"#include <toolchain.h>\n" +
|
||||
|
@ -716,39 +717,39 @@ def kernel_main_c_node_init():
|
|||
# mutex object ids
|
||||
for mutex in mutex_list:
|
||||
name = mutex[0]
|
||||
kernel_main_c_out("\tDEBUG_TRACING_OBJ_INIT(struct _k_mutex_struct *, " +
|
||||
"(&_k_mutex_obj_%s), _track_list_micro_mutex);\n" % (name))
|
||||
kernel_main_c_out("\tSYS_TRACING_OBJ_INIT(micro_mutex, " +
|
||||
"&_k_mutex_obj_%s);\n" % (name))
|
||||
# semaphore object ids
|
||||
for semaphore in sema_list:
|
||||
name = semaphore[0]
|
||||
kernel_main_c_out("\tDEBUG_TRACING_OBJ_INIT(struct _k_sem_struct *, " +
|
||||
"(&_k_sem_obj_%s), _track_list_micro_sem);\n" % (name))
|
||||
kernel_main_c_out("\tSYS_TRACING_OBJ_INIT(micro_sem, " +
|
||||
"&_k_sem_obj_%s);\n" % (name))
|
||||
# fifo object ids
|
||||
for fifo in fifo_list:
|
||||
name = fifo[0]
|
||||
kernel_main_c_out("\tDEBUG_TRACING_OBJ_INIT(struct _k_fifo_struct *, " +
|
||||
"(&_k_fifo_obj_%s), _track_list_micro_fifo);\n" % (name))
|
||||
kernel_main_c_out("\tSYS_TRACING_OBJ_INIT(micro_fifo, " +
|
||||
"&_k_fifo_obj_%s);\n" % (name))
|
||||
# mailbox object ids
|
||||
for mbx in mbx_list:
|
||||
name = mbx[0]
|
||||
kernel_main_c_out("\tDEBUG_TRACING_OBJ_INIT(struct _k_mbox_struct *, " +
|
||||
"(&_k_mbox_obj_%s), _track_list_micro_mbox);\n" % (name))
|
||||
kernel_main_c_out("\tSYS_TRACING_OBJ_INIT(micro_mbox, " +
|
||||
"&_k_mbox_obj_%s);\n" % (name))
|
||||
# pipe object id
|
||||
for pipe in pipe_list:
|
||||
name = pipe[0];
|
||||
kernel_main_c_out("\tDEBUG_TRACING_OBJ_INIT(struct _k_pipe_struct *, " +
|
||||
"(&_k_pipe_obj_%s), _track_list_micro_pipe);\n" % (name))
|
||||
kernel_main_c_out("\tSYS_TRACING_OBJ_INIT(micro_pipe, " +
|
||||
"&_k_pipe_obj_%s);\n" % (name))
|
||||
# memory map object id
|
||||
for map in map_list:
|
||||
name = map[0];
|
||||
kernel_main_c_out("\tDEBUG_TRACING_OBJ_INIT(struct _k_mem_map_struct *, " +
|
||||
"(&_k_mem_map_obj_%s), _track_list_micro_mem_map);\n" % (name))
|
||||
kernel_main_c_out("\tSYS_TRACING_OBJ_INIT(micro_mem_map, " +
|
||||
"&_k_mem_map_obj_%s);\n" % (name))
|
||||
# memory pool object id
|
||||
pool_count = 0;
|
||||
total_pools = len(pool_list);
|
||||
while (pool_count < total_pools):
|
||||
kernel_main_c_out("\tDEBUG_TRACING_OBJ_INIT(struct pool_struct *, " +
|
||||
"(&(_k_mem_pool_list[%d])), _track_list_micro_mem_pool);\n" % (pool_count))
|
||||
kernel_main_c_out("\tSYS_TRACING_OBJ_INIT(micro_mem_pool, " +
|
||||
"&(_k_mem_pool_list[%d]));\n" % (pool_count))
|
||||
pool_count = pool_count + 1;
|
||||
kernel_main_c_out("#endif\n")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue