feat: 增加mutex trace功能

Close: #I5YJOZ

Signed-off-by: zhangdengyu <zhangdengyu2@huawei.com>
Change-Id: Id36ed4f4d23b9aa59ae9ee8cdb17c06d7e3c151b
This commit is contained in:
zhangdengyu 2022-10-28 16:02:12 +08:00
parent 3f54fdc898
commit a940dda69a
6 changed files with 82 additions and 5 deletions

10
Kconfig
View File

@ -521,6 +521,14 @@ config DEBUG_QUEUE
help
Answer Y to enable debug queue.
config MUTEX_CREATE_TRACE
bool "Enable Mutex Trace Debugging"
default n
depends on ARCH_ARM
depends on DEBUG_KERNEL
help
Answer Y to enable debug mutex trace.
config DEBUG_DEADLOCK
bool "Enable Mutex Deadlock Debugging"
default n
@ -609,7 +617,7 @@ config VM_OVERLAP_CHECK
depends on DEBUG_VERSION && MEM_DEBUG
help
Answer Y to enable vm overlap check.
config TASK_MEM_USED
bool "Enable show task mem used or not"
default n

View File

@ -62,6 +62,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
__asm("mrs %0, msp" : "=r" (msp));
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm("mov %0, lr" : "=r" (lr));
return lr;
}
#elif defined(__CLANG_ARM) || defined(__GNUC__)
STATIC INLINE UINTPTR ArchSpGet(VOID)
{
@ -83,6 +90,13 @@ STATIC INLINE UINTPTR ArchMspGet(VOID)
__asm volatile("mrs %0, msp" : "=r" (msp));
return msp;
}
STATIC INLINE UINTPTR ArchLRGet(VOID)
{
UINTPTR lr;
__asm volatile("mov %0, lr" : "=r" (lr));
return lr;
}
#else
/* Other platforms to be improved */
#endif

View File

@ -42,6 +42,9 @@
#include "los_task.h"
#include "los_timer.h"
#include "los_debug.h"
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
#include "los_arch.h"
#endif
#include "string.h"
#include "securec.h"
@ -1002,6 +1005,10 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
UINT32 ret;
UINT32 muxId;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
UINTPTR regLR = ArchLRGet();
#endif
UNUSED(attr);
if (OS_INT_ACTIVE) {
@ -1010,6 +1017,9 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
ret = LOS_MuxCreate(&muxId);
if (ret == LOS_OK) {
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
OsSetMutexCreateInfo(GET_MUX(muxId), regLR);
#endif
return (osMutexId_t)(GET_MUX(muxId));
} else {
return (osMutexId_t)NULL;

View File

@ -38,6 +38,9 @@
#include "los_debug.h"
#include "los_hook.h"
#include "los_sched.h"
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
#include "los_arch.h"
#endif
#define MUTEXATTR_TYPE_MASK 0x0FU
#define OS_SYS_NS_PER_MSECOND 1000000
@ -130,6 +133,10 @@ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexA
UINT32 muxHandle;
UINT32 ret;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
UINTPTR regLR = ArchLRGet();
#endif
if (mutex == NULL) {
return EINVAL;
}
@ -148,6 +155,9 @@ int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexA
mutex->stAttr = useAttr;
mutex->magic = _MUX_MAGIC;
mutex->handle = muxHandle;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
OsSetMutexCreateInfo(GET_MUX(mutex->handle), regLR);
#endif
return 0;
}
@ -324,6 +334,10 @@ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *absTi
struct timespec curTime = {0};
LosMuxCB *muxPended = NULL;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
UINTPTR regLR = ArchLRGet();
#endif
ret = MuxPreCheck(mutex, OS_TCB_FROM_TID(LOS_CurTaskIDGet()));
if (ret != 0) {
return (INT32)ret;
@ -337,6 +351,9 @@ int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *absTi
if (ret != LOS_OK) {
return MapError(ret);
}
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
OsSetMutexCreateInfo(GET_MUX(mutex->handle), regLR);
#endif
} else {
muxPended = GET_MUX(mutex->handle);
if ((mutex->stAttr.type == PTHREAD_MUTEX_ERRORCHECK) &&
@ -364,6 +381,11 @@ int pthread_mutex_lock(pthread_mutex_t *mutex)
{
UINT32 ret;
LosMuxCB *muxPended = NULL;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
UINTPTR regLR = ArchLRGet();
#endif
LosTaskCB *runTask = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
ret = MuxPreCheck(mutex, runTask);
@ -376,6 +398,9 @@ int pthread_mutex_lock(pthread_mutex_t *mutex)
if (ret != LOS_OK) {
return MapError(ret);
}
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
OsSetMutexCreateInfo(GET_MUX(mutex->handle), regLR);
#endif
} else {
muxPended = GET_MUX(mutex->handle);
if ((mutex->stAttr.type == PTHREAD_MUTEX_ERRORCHECK) &&
@ -394,6 +419,10 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex)
UINT32 ret;
LosMuxCB *muxPended = NULL;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
UINTPTR regLR = ArchLRGet();
#endif
ret = MuxPreCheck(mutex, OS_TCB_FROM_TID(LOS_CurTaskIDGet()));
if (ret != 0) {
return (INT32)ret;
@ -404,6 +433,9 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex)
if (ret != LOS_OK) {
return MapError(ret);
}
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
OsSetMutexCreateInfo(GET_MUX(mutex->handle), regLR);
#endif
} else {
muxPended = GET_MUX(mutex->handle);
if ((mutex->stAttr.type != PTHREAD_MUTEX_RECURSIVE) && (muxPended->muxCount != 0)) {

View File

@ -39,7 +39,6 @@
#include "los_task.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
@ -302,6 +301,9 @@ typedef struct {
UINT32 muxID; /**< Handle ID */
LOS_DL_LIST muxList; /**< Mutex linked list */
LosTaskCB *owner; /**< The current thread that is locking a mutex */
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
UINTPTR createInfo; /**< Return address of the caller */
#endif
UINT16 priority; /**< Priority of the thread that is locking a mutex */
} LosMuxCB;
@ -351,6 +353,13 @@ extern UINT32 OsMuxInit(VOID);
*/
#define GET_MUX_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosMuxCB, muxList)
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
STATIC INLINE VOID OsSetMutexCreateInfo(LosMuxCB *mux, UINTPTR val)
{
mux->createInfo = val;
}
#endif /* LOSCFG_MUTEX_CREATE_TRACE == 1 */
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -37,7 +37,6 @@
#include "los_memory.h"
#include "los_sched.h"
#if (LOSCFG_BASE_IPC_MUX == 1)
LITE_OS_SEC_BSS LosMuxCB* g_allMux = NULL;
@ -71,6 +70,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsMuxInit(VOID)
muxNode->muxID = index;
muxNode->owner = (LosTaskCB *)NULL;
muxNode->muxStat = OS_MUX_UNUSED;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
muxNode->createInfo = 0;
#endif
LOS_ListTailInsert(&g_unusedMuxList, &muxNode->muxList);
}
return LOS_OK;
@ -149,7 +151,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 muxHandle)
LOS_ListAdd(&g_unusedMuxList, &muxDeleted->muxList);
muxDeleted->muxStat = OS_MUX_UNUSED;
#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
muxDeleted->createInfo = 0;
#endif
LOS_IntRestore(intSave);
OsHookCall(LOS_HOOK_TYPE_MUX_DELETE, muxDeleted);
@ -320,5 +324,5 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 muxHandle)
return LOS_OK;
}
#endif /* (LOSCFG_BASE_IPC_MUX == 1) */
#endif /* (LOSCFG_BASE_IPC_MUX == 1) */