Skip to content

sched/tls: Wrap up_info_size into tls_info_size #6365

Merged
masayuki2009 merged 2 commits into
apache:masterfrom
xiaoxiang781216:tls
Jun 8, 2022
Merged

sched/tls: Wrap up_info_size into tls_info_size #6365
masayuki2009 merged 2 commits into
apache:masterfrom
xiaoxiang781216:tls

Conversation

@xiaoxiang781216

@xiaoxiang781216 xiaoxiang781216 commented Jun 5, 2022

Copy link
Copy Markdown
Contributor

Summary

and Initialize the idle thread local storage by tls_init_info

Impact

code refactor

Testing

rv-virt:knsh64

@masayuki2009

Copy link
Copy Markdown
Contributor

In file included from pthread/pthread_create.c:39:
pthread/pthread_create.c: In function 'nx_pthread_create':
Error: pthread/pthread_create.c:294:29: error: invalid application of 'sizeof' to incomplete type 'struct tls_info_s'
  294 |                             up_tls_size() + attr->stacksize,
      |                             ^~~~~~~~~~~
make[1]: *** [Makefile:58: pthread_create.o] Error 1
In file included from task/task_init.c:34:
task/task_init.c: In function 'nxtask_init':
Error: task/task_init.c:134:29: error: invalid application of 'sizeof' to incomplete type 'struct tls_info_s'
  134 |                             up_tls_size() + stack_size,
      |                             ^~~~~~~~~~~
make[1]: *** [Makefile:58: task_init.o] Error 1
make[1]: Target 'libsched.a' not remade because of errors.
make: *** [tools/LibTargets.mk:59: sched/libsched.a] Error 2
make: Target 'all' not remade because of errors.

@xiaoxiang781216 xiaoxiang781216 changed the title Revert "sched/tls: Don't compensate the tls size to the stack size" sched/tls: Compensate the tls size to the stack size Jun 5, 2022
@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@masayuki2009 fixed, please try again.

@xiaoxiang781216 xiaoxiang781216 force-pushed the tls branch 2 times, most recently from 08ddce0 to 3e4e5e0 Compare June 5, 2022 18:01
@masayuki2009

Copy link
Copy Markdown
Contributor

@masayuki2009 fixed, please try again.

@xiaoxiang781216
Hmm, the issue still happens.

$ qemu-6.2/build/riscv64-softmmu/qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt -bios none -kernel ./nuttx
ABC
NuttShell (NSH) NuttX-3.6.1
nsh> uname -a
NuttX 3.6.1 3e4e5e0b82-dirty Jun  6 2022 08:11:36 risc-v rv-virt
nsh> hello
Hello, World!!
[    0.000000] riscv_exception: EXCEPTION: Store/AMO access fault. MCAUSE: 0000000000000007
[    0.000000] riscv_exception: PANIC!!! Exception = 0000000000000007
[    0.000000] up_assert: Assertion failed at file:common/riscv_exception.c line: 89 task: hello
[    0.000000] riscv_registerdump: EPC: 0000000080005c66
[    0.000000] riscv_registerdump: A0: 0000000000000001 A1: 0000000080208038 A2: 0000000000000019 A3: 0000000080206c38
[    0.000000] riscv_registerdump: A4: 0000000080208018 A5: 0000000080208058 A6: 0000000000000101 A7: 0000000000000000
[    0.000000] riscv_registerdump: T0: 00000000800039c6 T1: 0000000000000000 T2: 0000000000000000 T3: 0000000000000000
[    0.000000] riscv_registerdump: T4: 0000000000000000 T5: 0000000000000000 T6: 0000000000000000
[    0.000000] riscv_registerdump: S0: 0000000080208040 S1: 0000000080206c00 S2: ffffffffffffffe0 S3: fffffffffffffff8
[    0.000000] riscv_registerdump: S4: ffffffffffffffe0 S5: 0000000000000000 S6: 0000000000000000 S7: 0000000000000000
[    0.000000] riscv_registerdump: S8: 0000000000000000 S9: 0000000000000000 S10: 0000000000000000 S11: 0000000000000000
[    0.000000] riscv_registerdump: SP: 0000000080209d90 FP: 0000000080208040 TP: 0000000000000000 RA: 0000000080005b8a
[    0.000000] riscv_dumpstate: sp:     0000000080200830
[    0.000000] riscv_dumpstate: IRQ stack:
[    0.000000] riscv_dumpstate:   base: 00000000802000f0
[    0.000000] riscv_dumpstate:   size: 0000000000000800
[    0.000000] riscv_stackdump: 0000000080200820: 802000f0 00000000 80006ce6 00000000 00000059 00000000 80014ed8 00000000
[    0.000000] riscv_stackdump: 0000000080200840: deadbeef deadbeef 00000000 00000000 ffffffe0 ffffffff fffffff8 ffffffff
[    0.000000] riscv_stackdump: 0000000080200860: ffffffe0 ffffffff 80209c88 00000000 00000007 00000000 800043d6 00000000
[    0.000000] riscv_stackdump: 0000000080200880: 00000009 00000000 80001464 00000000 00000000 00000000 80201050 00000000
[    0.000000] riscv_stackdump: 00000000802008a0: 80209c88 00000000 80001bb8 00000000 c0003200 00000000 80000f98 00000000
[    0.000000] riscv_stackdump: 00000000802008c0: 80209d58 00000000 80206c00 00000000 00000007 00000000 80000dfe 00000000
[    0.000000] riscv_dumpstate: sp:     0000000080209d90
[    0.000000] riscv_dumpstate: User stack:
[    0.000000] riscv_dumpstate:   base: 00000000c0004050
[    0.000000] riscv_dumpstate:   size: 00000000000007e0
[    0.000000] riscv_dumpstate: Kernel stack:
[    0.000000] riscv_dumpstate:   base: 0000000080209260
[    0.000000] riscv_dumpstate:   size: 0000000000000c00
[    0.000000] riscv_dumpstate: Kernel Stack
[    0.000000] riscv_stackdump: 0000000080209d80: 00000000 00000000 00040120 00000000 fffffff8 ffffffff 80209120 00000000
[    0.000000] riscv_stackdump: 0000000080209da0: fffffff8 ffffffff 80007a7c 00000000 00000000 00000000 00000000 00000000
[    0.000000] riscv_stackdump: 0000000080209dc0: 802090c2 00000000 80208f00 00000000 802090a0 00000000 800127d8 00000000
[    0.000000] riscv_stackdump: 0000000080209de0: 80207ec0 00000000 80010cba 00000000 802090c2 00000000 802090a0 00000000
[    0.000000] riscv_stackdump: 0000000080209e00: 80208f00 00000000 800119b2 00000000 00000000 00000000 00000000 00000000
[    0.000000] riscv_stackdump: 0000000080209e20: 00000000 00000000 80011c84 00000000 00000000 00000000 800039d2 00000000
[    0.000000] riscv_stackdump: 0000000080209e40: 00000000 00000000 800015bc 00000000 c00014de 00000000 00040020 00000000
[    0.000000] riscv_showtasks:    PID    PRI      USED     STACK   FILLED    COMMAND
[    0.000000] riscv_showtasks:   ----   ----       776      2048    37.8%    irq
[    0.000000] riscv_dump_task:      0      0      1328      3024    43.9%    Idle Task
[    0.000000] riscv_dump_task:      1    100      2000      2000   100.0%!   /system/bin/init
[    0.000000] riscv_dump_task:      2    100       536      2016    26.5%    hello

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@masayuki2009 fixed, please try again.

@xiaoxiang781216 Hmm, the issue still happens.

$ qemu-6.2/build/riscv64-softmmu/qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt -bios none -kernel ./nuttx
ABC
NuttShell (NSH) NuttX-3.6.1
nsh> uname -a
NuttX 3.6.1 3e4e5e0b82-dirty Jun  6 2022 08:11:36 risc-v rv-virt
nsh> hello
Hello, World!!
[    0.000000] riscv_stackdump: 0000000080209e40: 00000000 00000000 800015bc 00000000 c00014de 00000000 00040020 00000000
[    0.000000] riscv_showtasks:    PID    PRI      USED     STACK   FILLED    COMMAND
[    0.000000] riscv_showtasks:   ----   ----       776      2048    37.8%    irq
[    0.000000] riscv_dump_task:      0      0      1328      3024    43.9%    Idle Task
[    0.000000] riscv_dump_task:      1    100      2000      2000   100.0%!   /system/bin/init
[    0.000000] riscv_dump_task:      2    100       536      2016    26.5%    hello

init task restore the stack to the original size(2000), but the consumption is still higher than the capacity.
All patch in PR #6337 is the code refactor and the stack consumption should be same as before except:
48a0a2e

@masayuki2009 the follow command look like just generate the kernel binary:

./tools/configure.sh rv-virt:knsh64
make -j8

Could you tell me how to generate hello and init elf in the kernel mode?
BTW, is it right to set CONFIG_SYSTEM_NSH=y here?
https://github.com/apache/incubator-nuttx/blob/master/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig#L93

@masayuki2009

Copy link
Copy Markdown
Contributor

Could you tell me how to generate hello and init elf in the kernel mode?

Please try the following commands.

$ cd nuttx                                                                                                                                                                                                                               
$ ./tools/configure.sh rv-virt:knsh64
$ make V=1 -j7                                                                                                                                                                                                                           
$ make export V=1                                                                                                                                                                                                                        
$ cd ../apps                                                                                                                                                                                                                             
$ ./tools/mkimport.sh -x ../nuttx/nuttx-export-*.zip                                                                                                                                                                                     
$ make import V=1                                                                                                                                                                                                                        
$ cd ../nuttx
$ qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt -bios none -kernel ./nuttx

BTW, is it right to set CONFIG_SYSTEM_NSH=y here?

Yes.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

Ok, I will repo locally later.

@xiaoxiang781216

xiaoxiang781216 commented Jun 7, 2022

Copy link
Copy Markdown
Contributor Author

@masayuki2009 the crash is made by: 11313e1
but the change only contain the code refactor, I will compare the generated code to find the real difference.

@xiaoxiang781216 xiaoxiang781216 changed the title sched/tls: Compensate the tls size to the stack size sched/tls: Wrap up_info_size into tls_info_size Jun 7, 2022
@xiaoxiang781216

xiaoxiang781216 commented Jun 7, 2022

Copy link
Copy Markdown
Contributor Author

@masayuki2009 Fix is here: #6377
I retitle this PR to refactor tls code during the review. Please try both.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@masayuki2009 how about this patch?

@masayuki2009

Copy link
Copy Markdown
Contributor

@masayuki2009 how about this patch?

Could you rebase this PR to the latest master?

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

Done.

@masayuki2009 masayuki2009 merged commit 11c8f31 into apache:master Jun 8, 2022
@xiaoxiang781216 xiaoxiang781216 deleted the tls branch July 31, 2022 14:21
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.

4 participants