Skip to content

Refine the implementation of TLS#6337

Merged
pkarashchenko merged 5 commits into
apache:masterfrom
xiaoxiang781216:tls
Jun 3, 2022
Merged

Refine the implementation of TLS#6337
pkarashchenko merged 5 commits into
apache:masterfrom
xiaoxiang781216:tls

Conversation

@xiaoxiang781216

@xiaoxiang781216 xiaoxiang781216 commented May 27, 2022

Copy link
Copy Markdown
Contributor

Summary

  1. tls: Merge tls_xxx into pthread_keyxxx
  2. libc/tls: Make tls_get_info as the pulibc function instead up_tls_info
  3. sched/tls: Add tls_init_info and tls_dup_info
  4. sched/tls: Add task_init_info and task_uninit_info

Impact

Code refactor

Testing

ostest

Comment thread libs/libc/tls/Make.defs
@pkarashchenko

Copy link
Copy Markdown
Contributor

Please rebase your changes

Comment thread libs/libc/pthread/pthread_keycreate.c Outdated
Comment thread libs/libc/pthread/pthread_keydelete.c Outdated
@xiaoxiang781216 xiaoxiang781216 force-pushed the tls branch 2 times, most recently from 2983ae1 to f096fcc Compare May 27, 2022 14:48
@xiaoxiang781216 xiaoxiang781216 force-pushed the tls branch 2 times, most recently from 300b045 to 37ef8f9 Compare May 27, 2022 18:19
@pkarashchenko pkarashchenko self-requested a review May 27, 2022 19:05
Comment thread libs/libc/pthread/pthread_setspecific.c Outdated
@pkarashchenko pkarashchenko self-requested a review May 28, 2022 14:15
@xiaoxiang781216 xiaoxiang781216 force-pushed the tls branch 2 times, most recently from 962cfe5 to a10c4dd Compare May 28, 2022 15:54
@xiaoxiang781216 xiaoxiang781216 changed the title tls: Merge tls_xxx into pthread_keyxxx Refine the implementation of TLS May 28, 2022
@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

depend on: apache/nuttx-apps#1173

@davids5

davids5 commented May 29, 2022

Copy link
Copy Markdown
Contributor

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216 are the comments

https://github.com/apache/incubator-nuttx/blob/a10c4dde56134f54974c4bf7f57c49e3cd1eeadb/libs/libc/tls/Kconfig#L19

still valid?

Yes, it's here:
https://github.com/apache/incubator-nuttx/pull/6337/files#diff-2c833ffaa18374fab0d57499dc593937167b198a630cb4e9068f654aaebdc42dR308
I just mov the same code from include/nuttx/arch.h to include/nuttx/tls.h

Comment thread libs/libc/pthread/pthread_keycreate.c
Comment thread libs/libc/pthread/pthread_keycreate.c
Comment thread libs/libc/pthread/pthread_keydelete.c
Comment thread libs/libc/pthread/pthread_keycreate.c
it's always better to provide the standard api directly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
it isn't good to change the stack size passed by caller

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
@pkarashchenko pkarashchenko merged commit 01c8beb into apache:master Jun 3, 2022
@masayuki2009

Copy link
Copy Markdown
Contributor

@xiaoxiang781216

I noticed that rv-virt:knsh64 failed.

$ qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt -bios none -kernel ./nuttx/nuttx
ABC[    0.000000] up_assert: Assertion failed at file:init/nx_bringup.c line: 297 task: Idle Task
[    0.000000] up_assert: Assertion failed at file:common/riscv_swint.c line: 189 task: Idle Task
[    0.000000] riscv_registerdump: EPC: 00000000800071de
[    0.000000] riscv_registerdump: A0: 0000000000000000 A1: 0000000000000000 A2: 0000000010000000 A3: 0000000000000001
[    0.000000] riscv_registerdump: A4: 0000000000000001 A5: 0000000000000000 A6: 0000000000000074 A7: 000000000000006a
[    0.000000] riscv_registerdump: T0: 00000000000001ff T1: 000000000000006c T2: 000000000000002d T3: 0000000000000068
[    0.000000] riscv_registerdump: T4: 0000000000000009 T5: 000000000000002a T6: 000000000000002e
[    0.000000] riscv_registerdump: S0: 0000000080200928 S1: 0000000080206b30 S2: 0000000080200928 S3: 0000000080200918
[    0.000000] riscv_registerdump: S4: 0000000080201050 S5: 0000000000000000 S6: 0000000000000000 S7: 0000000000000000
[    0.000000] riscv_registerdump: S8: 0000000000000000 S9: 0000000000000000 S10: 0000000000000000 S11: 0000000000000000
[    0.000000] riscv_registerdump: SP: 0000000080206b20 FP: 0000000080200928 TP: 0000000000000000 RA: 00000000800071de
[    0.000000] riscv_dumpstate: sp:     0000000080200850
[    0.000000] riscv_dumpstate: IRQ stack:
[    0.000000] riscv_dumpstate:   base: 00000000802000f0
[    0.000000] riscv_dumpstate:   size: 0000000000000800
[    0.000000] riscv_stackdump: 0000000080200840: 802000f0 00000000 80006cbc 00000000 000000bd 00000000 80015138 00000000
[    0.000000] riscv_stackdump: 0000000080200860: deadbeef deadbeef 00000000 00000000 80201050 00000000 80200918 00000000
[    0.000000] riscv_stackdump: 0000000080200880: 80201050 00000000 80206a18 00000000 80206a18 00000000 800043ac 00000000
[    0.000000] riscv_stackdump: 00000000802008a0: deadbeef deadbeef 800015f6 00000000 80200928 00000000 80201050 00000000
[    0.000000] riscv_stackdump: 00000000802008c0: 80206a18 00000000 80001812 00000000 deadbeef deadbeef 00000100 00000000
[    0.000000] riscv_dumpstate: sp:     0000000080206b20
[    0.000000] riscv_dumpstate: User stack:
[    0.000000] riscv_dumpstate:   base: 0000000080206030
[    0.000000] riscv_dumpstate:   size: 0000000000000bd0
[    0.000000] riscv_dumpstate: User Stack
[    0.000000] riscv_stackdump: 0000000080206b20: 00000000 00000000 80006e50 00000000 00000129 00000000 80015280 00000000
[    0.000000] riscv_stackdump: 0000000080206b40: 00000000 00000000 00000000 00000000 00000000 00000000 80200918 00000000
[    0.000000] riscv_stackdump: 0000000080206b60: 80201064 00000000 80201068 00000000 80200928 00000000 800043ac 00000000
[    0.000000] riscv_stackdump: 0000000080206b80: 80200928 00000000 80001b48 00000000 80200928 00000000 80016400 00000000
[    0.000000] riscv_stackdump: 0000000080206ba0: 80200928 00000000 80001a94 00000000 80400000 00000000 00400000 00000000
[    0.000000] riscv_stackdump: 0000000080206bc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    0.000000] riscv_stackdump: 0000000080206be0: 00000000 00000000 80000d72 00000000 00000000 00000000 80000046 00000000
[    0.000000] riscv_showtasks:    PID    PRI      USED     STACK   FILLED    COMMAND
[    0.000000] riscv_showtasks:   ----   ----       744      2048    36.3%    irq
[    0.000000] riscv_dump_task:      0      0      1184      3024    39.1%    Idle Task

@xiaoxiang781216 xiaoxiang781216 deleted the tls branch June 4, 2022 06:21
@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216

I noticed that rv-virt:knsh64 failed.

$ qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt -bios none -kernel ./nuttx/nuttx
ABC[    0.000000] up_assert: Assertion failed at file:init/nx_bringup.c line: 297 task: Idle Task
[    0.000000] up_assert: Assertion failed at file:common/riscv_swint.c line: 189 task: Idle Task
[    0.000000] riscv_registerdump: EPC: 00000000800071de
[    0.000000] riscv_registerdump: A0: 0000000000000000 A1: 0000000000000000 A2: 0000000010000000 A3: 0000000000000001
[    0.000000] riscv_registerdump: A4: 0000000000000001 A5: 0000000000000000 A6: 0000000000000074 A7: 000000000000006a
[    0.000000] riscv_registerdump: T0: 00000000000001ff T1: 000000000000006c T2: 000000000000002d T3: 0000000000000068
[    0.000000] riscv_registerdump: T4: 0000000000000009 T5: 000000000000002a T6: 000000000000002e
[    0.000000] riscv_registerdump: S0: 0000000080200928 S1: 0000000080206b30 S2: 0000000080200928 S3: 0000000080200918
[    0.000000] riscv_registerdump: S4: 0000000080201050 S5: 0000000000000000 S6: 0000000000000000 S7: 0000000000000000
[    0.000000] riscv_registerdump: S8: 0000000000000000 S9: 0000000000000000 S10: 0000000000000000 S11: 0000000000000000
[    0.000000] riscv_registerdump: SP: 0000000080206b20 FP: 0000000080200928 TP: 0000000000000000 RA: 00000000800071de
[    0.000000] riscv_dumpstate: sp:     0000000080200850
[    0.000000] riscv_dumpstate: IRQ stack:
[    0.000000] riscv_dumpstate:   base: 00000000802000f0
[    0.000000] riscv_dumpstate:   size: 0000000000000800
[    0.000000] riscv_stackdump: 0000000080200840: 802000f0 00000000 80006cbc 00000000 000000bd 00000000 80015138 00000000
[    0.000000] riscv_stackdump: 0000000080200860: deadbeef deadbeef 00000000 00000000 80201050 00000000 80200918 00000000
[    0.000000] riscv_stackdump: 0000000080200880: 80201050 00000000 80206a18 00000000 80206a18 00000000 800043ac 00000000
[    0.000000] riscv_stackdump: 00000000802008a0: deadbeef deadbeef 800015f6 00000000 80200928 00000000 80201050 00000000
[    0.000000] riscv_stackdump: 00000000802008c0: 80206a18 00000000 80001812 00000000 deadbeef deadbeef 00000100 00000000
[    0.000000] riscv_dumpstate: sp:     0000000080206b20
[    0.000000] riscv_dumpstate: User stack:
[    0.000000] riscv_dumpstate:   base: 0000000080206030
[    0.000000] riscv_dumpstate:   size: 0000000000000bd0
[    0.000000] riscv_dumpstate: User Stack
[    0.000000] riscv_stackdump: 0000000080206b20: 00000000 00000000 80006e50 00000000 00000129 00000000 80015280 00000000
[    0.000000] riscv_stackdump: 0000000080206b40: 00000000 00000000 00000000 00000000 00000000 00000000 80200918 00000000
[    0.000000] riscv_stackdump: 0000000080206b60: 80201064 00000000 80201068 00000000 80200928 00000000 800043ac 00000000
[    0.000000] riscv_stackdump: 0000000080206b80: 80200928 00000000 80001b48 00000000 80200928 00000000 80016400 00000000
[    0.000000] riscv_stackdump: 0000000080206ba0: 80200928 00000000 80001a94 00000000 80400000 00000000 00400000 00000000
[    0.000000] riscv_stackdump: 0000000080206bc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    0.000000] riscv_stackdump: 0000000080206be0: 00000000 00000000 80000d72 00000000 00000000 00000000 80000046 00000000
[    0.000000] riscv_showtasks:    PID    PRI      USED     STACK   FILLED    COMMAND
[    0.000000] riscv_showtasks:   ----   ----       744      2048    36.3%    irq
[    0.000000] riscv_dump_task:      0      0      1184      3024    39.1%    Idle Task

let me try it.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@masayuki2009 the assertion happen here:

  ret = exec_spawn(CONFIG_INIT_FILEPATH, argv, NULL,
                   CONFIG_INIT_SYMTAB, CONFIG_INIT_NEXPORTS, &attr);
  DEBUGASSERT(ret >= 0);

But I can't find init in my apps/bin/ folder. Could you point me the setup document of knsh64?

@masayuki2009

Copy link
Copy Markdown
Contributor

@xiaoxiang781216

But I can't find init in my apps/bin/ folder. Could you point me the setup document of knsh64?

The crash messages were incorrect.

$ qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt -bios none -kernel ./nuttx
ABC
NuttShell (NSH) NuttX-10.3.0
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: 0000000080005c3c
[    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: 000000008000399c 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: 0000000080005b60
[    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 80006cbc 00000000 00000059 00000000 80014ee8 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 800043ac 00000000
[    0.000000] riscv_stackdump: 0000000080200880: 00000009 00000000 80001464 00000000 00000000 00000000 80201050 00000000
[    0.000000] riscv_stackdump: 00000000802008a0: 80209c88 00000000 80001bca 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: 00000000000007b0
[    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 80007a52 00000000 00000000 00000000 00000000 00000000
[    0.000000] riscv_stackdump: 0000000080209dc0: 802090c2 00000000 80208f00 00000000 802090a0 00000000 800127e4 00000000
[    0.000000] riscv_stackdump: 0000000080209de0: 80207ec0 00000000 80010c8e 00000000 802090c2 00000000 802090a0 00000000
[    0.000000] riscv_stackdump: 0000000080209e00: 80208f00 00000000 80011982 00000000 00000000 00000000 00000000 00000000
[    0.000000] riscv_stackdump: 0000000080209e20: 00000000 00000000 80011c54 00000000 00000000 00000000 800039a8 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      1952      1952   100.0%!   /system/bin/init
[    0.000000] riscv_dump_task:      2    100       536      1968    27.2%    hello

It seems that the init task consumes more stack than before.
Actually, it consumed less memory before merging this PR.

qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt -bios none -kernel ./nuttx
ABC
NuttShell (NSH) NuttX-10.3.0
nsh> hello
Hello, World!!
nsh> ps
  PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK   STACK   USED  FILLED COMMAND
    0     0   0 FIFO     Kthread N-- Ready              00000000 003024 001328  43.9%  Idle Task
    1     1 100 RR       Task    --- Running            00000000 002000 001736  86.8%! /system/bin/init
nsh> 

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@masayuki2009 it is made by 48a0a2e. Could you try #6365?

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.

5 participants