From 94b17f7a4fc2838dc88907200265b209fc0a240a Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Sat, 17 Dec 2022 08:51:20 +0800 Subject: [PATCH] Garbled Console Output --- README.md | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 601591e..c6412b7 100644 --- a/README.md +++ b/README.md @@ -4716,13 +4716,13 @@ funlockfile: 0x40a5cc78, ret=0 funlockfile: 0x40a5cc78, ret=0 ``` -`nxrmutex_lock` calls [`nxsem_wait`](https://github.com/apache/nuttx/blob/master/sched/semaphore/sem_wait.c#L42-L210), which calls [`up_switch_context`](https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_switchcontext.c#L41-L103) +[`nxrmutex_lock`](https://github.com/apache/nuttx/blob/master/include/nuttx/mutex.h#L335-L377) calls [`nxmutex_lock`](https://github.com/apache/nuttx/blob/master/include/nuttx/mutex.h#L135-L179), which calls [`nxsem_wait`](https://github.com/apache/nuttx/blob/master/sched/semaphore/sem_wait.c#L42-L210), which calls [`up_switch_context`](https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_switchcontext.c#L41-L103) -Is there an issue with [`up_switch_context`](https://github.com/apache/nuttx/blob/master/arch/arm64/src/common/arm64_switchcontext.c#L41-L103)? +_Maybe it's caused by Multiple CPU Cores calling the same code?_ -Checking that CPU ID is 0... +Let's check that CPU ID is 0... -``` +```c #include "../arch/arm64/src/common/arm64_arch.h" //// _info("%p, ret=%d, up_cpu_index=%d\n", stream, ret, MPIDR_TO_CORE(GET_MPIDR())); //// // Shows: `flockfile: 0x40a5cc78, ret=0, up_cpu_index=0` @@ -4731,6 +4731,35 @@ _info("%p, ret=%d, mpidr_el1=%p\n", stream, ret, read_sysreg(mpidr_el1)); //// // Shows `flockfile: 0x40a5cc78, ret=0, mpidr_el1=0x80000000` ``` +Yep CPU ID is always 0. + +Let's print the Thread ID and Mutex Count... + +```text +void flockfile(FAR struct file_struct *stream) +{ + nxrmutex_lock(&stream->fs_lock); + _info("%p, thread=%d, mutex.count=%d\n", stream, gettid(), stream->fs_lock.count); //// +} + +void funlockfile(FAR struct file_struct *stream) +{ + _info("%p, thread=%d, mutex.count=%d\n", stream, gettid(), stream->fs_lock.count); //// + nxrmutex_unlock(&stream->fs_lock); +} +``` + +Thread ID is always the same. Mutex Count goes from 1 to 3 and drops to 2... + +```text +lib_cxx_initialize: _sinit: 0x400e9000 _einit: 0x400e9000 +flockfile: 0x40a5cc78, thread=2, mutex.count=1 +flockfile: 0x40a5cc78, thread=2, mutex.count=2 +flockfile: 0x40a5cc78, thread=2, mutex.count=3 +funlockfile: 0x40a5cc78, thread=2, mutex.count=3 +funlockfile: 0x40a5cc78, thread=2, mutex.count=2 +``` + TODO # Add Display Engine Driver to NuttX Kernel