Skip to content

Conversation

@GUIDINGLI
Copy link
Contributor

Summary

os init_state: add new state OSINIT_IDLELOOP

This is for distinguish we are in init idle or idle loop.
Use for assertion for sem_trywait & sem_wait

In the previous PR:
#5577

There is a check error:
DEBUGASSERT(OSINIT_IDLELOOP() && !sched_idletask());
should be:
DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask());

And the last PR regression caused by lack of testing.
This time do the fully test.

Impact

idle take sem

Testing

Test in maix-bit:kostest, VELA

This is for distinguish we are in init idle or idle loop.
Use for assertion for sem_trywait & sem_wait

Signed-off-by: ligd <liguiding1@xiaomi.com>
@xiaoxiang781216
Copy link
Contributor

@masayuki2009 could you try this one?

@masayuki2009
Copy link
Contributor

@GUIDINGLI

Hmm, stm32f4discovery:kostest (DEBUG build) failed with assertion.
I've never seen this assertion before.

user_main: semaphore test
sem_test: Initializing semaphore to 0
sem_test: Starting waiter thread 1
sem_test: Set thread 1 priority to 191
waiter_func: Thread 1 Started
sem_test: Starting waiter thread 2
waiter_func: Thread 1 initial semaphore value = 0
sem_test: Set thread 2 priority to 128
waiter_func: Thread 1 waiting on semaphore
waiter_func: Thread 2 Started
sem_test: Starting poster thread 3
waiter_func: Thread 2 initial semaphore value = -1
sem_test: Set thread 3 priority to 64
waiter_func: Thread 2 waiting on semaphore
poster_func: Thread 3 started
poster_func: Thread 3 semaphore value = -2
poster_func: Thread 3 posting semaphore
waiter_func: Thread 1 awakened
poster_func: Thread 3 new semaphore value = -1
waiter_func: Thread 1 new semaphore value = -1
pup_assert: Assertion failed at file:armv7-m/arm_svcall.c line: 429 task: pt-0x8022711
arm_registerdump: R0: 20000004 R1: 00000000 R2: 40004400  R3: 00000000
arm_registerdump: R4: 20000004 R5: 00000031 R6: 00000000  FP: 00000068
arm_registerdump: R8: 00000001 SB: 2000000a SL: 00000000 R11: 00000001
arm_registerdump: IP: 08003eb7 SP: 20012358 LR: 08005353  PC: 0800ad9a
arm_registerdump: xPSR: 61000000 PRIMASK: 00000000 CONTROL: 00000000
arm_registerdump: EXC_RETURN: fffffff9
arm_dump_stack: User Stack:
arm_dump_stack: sp:     200122b0
arm_dump_stack:   base: 20011cf8
arm_dump_stack:   size: 00000800
arm_stackdump: 200122a0: 20011cf8 00000800 200122b0 08004d11 00000000 00000000 0800ad9a 00000001
arm_stackdump: 200122c0: 2001230c 1ffffffc 200003e4 00000068 00000001 08003ec7 00000001 08000c31
arm_stackdump: 200122e0: 00000000 200003e4 0000000b 0800203b 00000000 080008ad 2001230c 00000031
arm_stackdump: 20012300: 00000000 08000845 200022d0 20012358 00000000 20000004 00000031 00000000
arm_stackdump: 20012320: 00000068 00000001 2000000a 00000000 00000001 fffffff9 20000004 00000000
arm_stackdump: 20012340: 40004400 00000000 08003eb7 08005353 0800ad9a 61000000 00000001 00000000
arm_stackdump: 20012360: 20000004 0000001f 20010bab 00000001 00000011 20000010 00000068 0800b11b
arm_stackdump: 20012380: 0800b07f 20010b9c 0000001f 0000001f 00000001 200124b8 00000000 200124b8
arm_stackdump: 200123a0: 000000ed 08007073 00000001 200020f8 0000001f 00000000 00000001 08007083
arm_stackdump: 200123c0: 00000000 08000c0b 00000000 00000001 0000001f 08025e6d 00000014 20010b9c
arm_stackdump: 200123e0: 20010b7c 08025e6d 80000000 0000000a 20010b7c 00000000 00000000 08026929
arm_stackdump: 20012400: 0000000a 0a010b7c 080260ed 2001247c 0000000a 08026113 0000000a 2001247c
arm_stackdump: 20012420: 0000001f 0802640f 0802a85f 00000001 20002090 00000000 00000032 00000000
arm_stackdump: 20012440: 00000000 fffffffd 00000000 20010b84 00000000 20010b7c 0802a83f 200124b4
arm_stackdump: 20012460: 20002090 00000000 00000000 00000000 00000000 08025ef7 00000000 080260ed
arm_stackdump: 20012480: 20010b10 080260cd 0000001e 20010b7c 0802a83f 08025835 20002080 08025c1d
arm_stackdump: 200124a0: 0802a83f 200124b4 00000002 08022751 0802a83f 00000002 00000000 20002368
arm_stackdump: 200124c0: 00000002 ffffffff 00000000 08025847 00000002 08008a6d 00000080 08008a6d
arm_showtasks:    PID    PRI     STACK   COMMAND
arm_dump_task:      0      0      1000   Idle Task
arm_dump_task:      2    100      2024   ostest_main
arm_dump_task:      3    100      1992   ostest
arm_dump_task:     29    128      2048   pt-0x8022711
arm_dump_task:     30     64      2048   pt-0x8022669

@GUIDINGLI
Copy link
Contributor Author

@masayuki2009
Can you share the detail cmds ?

@GUIDINGLI
Copy link
Contributor Author

GUIDINGLI commented Feb 23, 2022

Can you revert this patch, and have a try ?


commit e0fabbfdd6a55510eae265472fd992aba1c0b588
Author: chao.an <anchao@xiaomi.com>
Date:   Tue Feb 22 15:25:56 2022 +0800

    arch/arm: replace SYS_syscall_return hardcode from syscall
    
    Signed-off-by: chao.an <anchao@xiaomi.com>

diff --git a/arch/arm/src/armv7-m/arm_svcall.c b/arch/arm/src/armv7-m/arm_svcall.c
index 6119ee6297..1330dc3a81 100644
--- a/arch/arm/src/armv7-m/arm_svcall.c
+++ b/arch/arm/src/armv7-m/arm_svcall.c
@@ -103,8 +103,9 @@ static void dispatch_syscall(void)
       " ldr r2, [sp, #16]\n"         /* Restore (orig_SP - new_SP) value */
       " add sp, sp, r2\n"            /* Restore SP */
       " mov r2, r0\n"                /* R2=Save return value in R2 */
-      " mov r0, #3\n"                /* R0=SYS_syscall_return */
-      " svc %0\n"::"i"(SYS_syscall)  /* Return from the SYSCALL */
+      " mov r0, %0\n"                /* R0=SYS_syscall_return */
+      " svc %1\n"::"i"(SYS_syscall_return),
+                   "i"(SYS_syscall)  /* Return from the SYSCALL */
     );
 }
 #endif

@masayuki2009
Copy link
Contributor

Can you share the detail cmds ?

@GUIDINGLI

$ st-flash --format ihex write ./nuttx_user.hex
$ st-flash --format ihex write ./nuttx.hex
$ st-flash reset

@GUIDINGLI
Copy link
Contributor Author

Can you share the detail cmds ?

@GUIDINGLI

$ st-flash --format ihex write ./nuttx_user.hex
$ st-flash --format ihex write ./nuttx.hex
$ st-flash reset

These cmds for real hardware board ?
Can this run on qemu ?

@masayuki2009
Copy link
Contributor

@GUIDINGLI

BTW, do you have the stm32f4discovery board?

@masayuki2009
Copy link
Contributor

@GUIDINGLI

These cmds for real hardware board ?

Yes.

Can this run on qemu ?

Unfortunately, no.

@GUIDINGLI
Copy link
Contributor Author

Then, without this patch, the ostest can run pass ?
Also, need open CONFIG_DEBUG_ASSERTIONS=y

@masayuki2009
Copy link
Contributor

Then, without this patch, the ostest can run pass ?
Also, need open CONFIG_DEBUG_ASSERTIONS=y

@GUIDINGLI

According to the latest upstream test logs, it passed with CONFIG_DEBUG_ASSERTIONS=y
However, I still suspect that my board has some issues.

I'm now preparing lm3s6965-ek:kostest with QEMU, so please wait.

@masayuki2009
Copy link
Contributor

I'm now preparing lm3s6965-ek:kostest with QEMU, so please wait.

@GUIDINGLI
See #5595
I confirmed that this PR works with the above lm3s6965-ek:qemu-kostest.

So let me merge this PR.

@masayuki2009 masayuki2009 merged commit 61a0453 into apache:master Feb 23, 2022
@masayuki2009
Copy link
Contributor

@GUIDINGLI

I found a new issue with sabre-6quad:netknsh which is not merged to the upstream.
Actually, if I run the getprime command, DEBUGASSERT happens when it exits.

The call stack is

(gdb) where                                                                                                                                                                                                                                                                                
#0  up_assert (filename=0x10856468 "semaphore/sem_wait.c", lineno=80) at common/arm_assert.c:478                                                                                                                                                                                           
#1  0x1080d38c in _assert (filename=0x10856468 "semaphore/sem_wait.c", linenum=80) at assert/lib_assert.c:36                                                                                                                                                                               
#2  0x10804354 in nxsem_wait (sem=0x1085ab34 <g_putc_lock>) at semaphore/sem_wait.c:80                                                                                                                                                                                                     
#3  0x10800e30 in up_putc (ch=91) at chip/imx_serial.c:1135                                                                                                                                                                                                                                
#4  0x10849344 in syslog_default_putc (channel=0x1085ac20 <g_default_channel>, ch=91) at syslog/syslog_channel.c:177                                                                                                                                                                       
#5  0x10848f70 in syslog_putc (ch=91) at syslog/syslog_putc.c:93                                                                                                                                                                                                                           
#6  0x10848e18 in syslogstream_putc (this=0x1086b9f4, ch=91) at syslog/syslog_stream.c:157                                                                                                                                                                                                 
#7  0x1080f780 in vsprintf_internal (stream=0x1086b9f4, arglist=0x0, numargs=0, fmt=0x1085a101 "%5jd.%06ld] ", ap=...) at stdio/lib_libvsprintf.c:236                                                                                                                                      
#8  0x10810da8 in lib_vsprintf (stream=0x1086b9f4, fmt=0x1085a100 "[%5jd.%06ld] ", ap=...) at stdio/lib_libvsprintf.c:1373                                                                                                                                                                 
#9  0x1084a590 in lib_sprintf (obj=0x1086b9f4, fmt=0x1085a100 "[%5jd.%06ld] ") at stdio/lib_libsprintf.c:45                                                                                                                                                                                
#10 0x10848db8 in nx_vsyslog (priority=6, fmt=0x108577ac "%s: tcb=%p\n", ap=0x1086ba24) at syslog/vsyslog.c:136                                                                                                                                                                            
#11 0x10813500 in vsyslog (priority=6, fmt=0x108577ac "%s: tcb=%p\n", ap=...) at syslog/lib_syslog.c:68                                                                                                                                                                                    
#12 0x10813538 in syslog (priority=6, fmt=0x108577ac "%s: tcb=%p\n") at syslog/lib_syslog.c:100                                                                                                                                                                                            
#13 0x10819b40 in up_addrenv_kstackfree (tcb=0x10865c40) at armv7-a/arm_addrenv_kstack.c:167                                                                                                                                                                                               
#14 0x108073e4 in nxsched_release_tcb (tcb=0x10865c40, ttype=1 '\001') at sched/sched_releasetcb.c:159                                                                                                                                                                                     
#15 0x10846cfc in nxtask_terminate (pid=6, nonblocking=1 '\001') at task/task_terminate.c:184                                                                                                                                                                                              
#16 0x108465fc in nxtask_exit () at task/task_exit.c:168                                                                                                                                                                                                                                   
#17 0x10816cd8 in up_exit (status=0) at common/arm_exit.c:125                                                                                                                                                                                                                              
#18 0x10805ffc in _exit (status=0) at task/exit.c:56                                                                                                                                                                                                                                       
#19 0x10842384 in nx_pthread_exit (exit_value=0x0) at pthread/pthread_exit.c:112                                                                                                                                                                                                           
#20 0x1080bec0 in STUB_nx_pthread_exit (nbr=107, parm1=0) at stubs/STUB_nx_pthread_exit.c:11                                                                                                                                                                                               
#21 0x10801f4c in dispatch_syscall () at armv7-a/arm_syscall.c:86        

And

(gdb) up                                                                                                                                                                                                                                                                                   
#1  0x1080d38c in _assert (filename=0x10856468 "semaphore/sem_wait.c", linenum=80) at assert/lib_assert.c:36                                                                                                                                                                               
36        up_assert(filename, linenum);                                                                                                                                                                                                                                                    
(gdb) up                                                                                                                                                                                                                                                                                   
#2  0x10804354 in nxsem_wait (sem=0x1085ab3c <g_putc_lock>) at semaphore/sem_wait.c:80                                                                                                                                                                                                     
80        DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask());                                                                                                                                                                                                                            
(gdb) p *rtcb                                                                                                                                                                                                                                                                              
$1 = {flink = 0x0, blink = 0x0, group = 0x10862b10, pid = 0, sched_priority = 0 '\000', init_priority = 0 '\000', start = 0x1080336c <nx_start>, entry = {pthread = 0x1080336c <nx_start>, main = 0x1080336c <nx_start>}, task_state = 2 '\002', flags = 6, lockcount = 1, errcode = 0, timeslice = 0, waitdog = {next = 0x0, func = 0x0, lag = 0, arg = 0}, adj_stack_size = 2024, stack_alloc_ptr = 0x1086115c, stack_base_ptr = 0x10861174, waitsem = 0x0, sigprocmask = 0, sigwaitmask = 0, sigpendactionq = {head = 0x0, tail = 0x0}, sigpostedq = {head = 0x0, tail = 0x0}, sigunbinfo = {si_signo = 0 '\000', si_code = 0 '\000', si_errno = 0 '\000', si_value = {sival_int = 0, sival_ptr = 0x0}}, msgwaitq = 0x0, mhead = 0x0, xcp = {sigdeliver = 0x0, saved_pc = 0, saved_cpsr = 0, sigreturn = 0, regs = {0, 277200652, 277230636, 0, 0, 9682944, 0, 0, 0, 0, 0, 277223732, 277223352, 277223732, 276839228, 276923088, 2147483987, 0 <repeats 33 times>}, nsyscalls = 0 '\000', syscall = {{cpsr = 0, sysreturn = 0}, {cpsr = 0, sysreturn = 0}}, ustkptr = 0x0, kstack = 0x0, kstkptr = 0x0}, name = "Idle Task", '\000' <repeats 22 times>}      

It seems that syslog flushes the internal buffers from the Idle task.

@masayuki2009
Copy link
Contributor

masayuki2009 commented Feb 24, 2022

It seems that syslog flushes the internal buffers from the Idle task.

@GUIDINGLI @xiaoxiang781216

Actual code is inside up_addrenv_kstackfre.
So do you mean that this PR does not permit such a debug log?
If so, this would be a big restriction for debugging.

int up_addrenv_kstackfree(FAR struct tcb_s *tcb)                                                                                                                                                                                                                                           
{                                                                                                                                                                                                                                                                                          
=>binfo("tcb=%p\n", tcb);                                                                                                                                                                                                                                                                  
  DEBUGASSERT(tcb);   

@masayuki2009
Copy link
Contributor

So do you mean that this PR does not permit such a debug log?
If so, this would be a big restriction for debugging.

@GUIDINGLI @xiaoxiang781216

I found that up_putc() in imx_serial.c uses sem_wait().
I fixed the issue in #5633

@xiaoxiang781216
Copy link
Contributor

It's good to know that this patch could catch the potential issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants