Commit Graph

2205 Commits

Author SHA1 Message Date
chao an
dff2192c75 misc/assert: remove const string from assert expression
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 15:08:47 +08:00
chao an
4c8d244fae sched/getpid: replace syscall getpid/tid/ppid() to kernel version
NuttX kernel should not use the syscall functions, especially after
enabling CONFIG_SCHED_INSTRUMENTATION_SYSCALL, all system functions
will be traced to backend, which will impact system performance.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 10:33:01 +08:00
chao an
c24dc389e4 sched/task: add kernel interface nxsched_* gettid/getpid/getppid
add new interface to implement getpid()/gettid()/getppid() for kernel version.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-02 10:33:01 +08:00
Gustavo Henrique Nihei
e6b204f438 nuttx: Use MIN/MAX definitions from "sys/param.h"
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-02-01 23:47:44 +08:00
Ville Juven
8306e0d175 sched/group: Implement group_drop()
Implement a function for dropping references to the group structure and
finally freeing the allocated memory, if the group has been marked for
destruction
2023-02-01 09:49:09 -03:00
chao an
cdfca12ab6 sched/waitpid: rename nx_waitpid() to nxsched_waitpid()
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-01 20:40:41 +08:00
Xiang Xiao
631a8da1e2 sched: Map SCHED_OTHER to SCHED_FIFO or SCHED_RR
this behaviour is explicitly specified here:
https://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_08.html
and map SCHED_NORMAL to SCHED_OTHER like Linux:
https://man7.org/linux/man-pages/man7/sched.7.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-30 03:01:03 +02:00
chao an
2ad0a02182 sched/pthread: set default pthread name to parent's name
Align ps behavior with linux:

linux:

  $ ps -e -T | grep hello
  3758130 3758130 pts/10   00:00:00 hello
  3758130 3758131 pts/10   00:00:00 hello

nuttx:

  nsh> ps
    PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK   STACK COMMAND
  ...
      4     4 100 FIFO     Task    --- Waiting  Signal    00000000 067504 hello
      5     4 100 FIFO     pthread --- Waiting  Signal    00000000 067536 hello 0x561cef0dfc53 0x1

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-30 02:59:17 +02:00
chao an
45e4bc5f33 sched/semaphore: correct the return value of sem_post()
sem_post() should return EOVERFLOW if maximum allowable value for
a semaphore would be exceeded.

Reference:
https://man7.org/linux/man-pages/man3/sem_post.3.html

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-28 21:45:10 +09:00
chao an
b9d70365a1 sched/wqueue: semaphore count should be consistent with the number of work entries.
The number of work entries will be inconsistent with semaphore count
if the work is canceled, in extreme case, semaphore count will overflow
and fallback to 0 the workqueue will stop scheduling the enqueue work.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-28 21:45:10 +09:00
yintao
beec3e4d80 fix run ltp_interfaces_sched_setscheduler_17_1 fail
The policy has changed when sched_setscheduler called invalid args.

Signed-off-by: yintao <yintao@xiaomi.com>
2023-01-28 09:10:23 +02:00
Xiang Xiao
69da13c86d sched/signal: Fix typo error in Kconfig(SIG_SEGA->SIG_SEGV)
Made by https://github.com/apache/nuttx/pull/8286

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-28 09:07:23 +02:00
yintao
739be67744 sched: Add SIGFPE, SIGILL and SIGSEGV definition
Signed-off-by: yintao <yintao@xiaomi.com>
2023-01-27 13:21:49 -03:00
Ville Juven
1c84fc9cd9 Revert "sched/release_tcb: Do not release stack for user processes here"
This reverts commit 1a67dc7c68.
2023-01-26 21:15:25 +08:00
Ville Juven
29eaf95ced Revert "sched/sched_releasetcb: Fix code style issue from prior patch"
This reverts commit 920956b20f.
2023-01-26 21:15:25 +08:00
Xiang Xiao
819fbd22cc sched: Implement tkill/tgkill
https://linux.die.net/man/2/tgkill

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-26 08:11:56 +02:00
Petro Karashchenko
e5dbc3328c sched/misc/assert: remove extra indentations
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-01-26 10:26:09 +08:00
Xiang Xiao
1280a2a8f9 Launch the initial task through task_spawn instead of nxtask_create
to share the code with the code path of posix_spawn

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-25 23:34:52 +02:00
Xiang Xiao
99e89809d7 board: Pass the assertion expression to board_crashdump too
continue the follow work:
commit 43e7b13697
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date:   Sun Jan 22 19:31:32 2023 +0800

    assert: Log the assertion expression in case of fail

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-25 16:00:48 -03:00
Petro Karashchenko
5f55290e41 sched/pthread: restore C89 compliance in pthread_create
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-01-26 01:26:11 +08:00
Xiang Xiao
43e7b13697 assert: Log the assertion expression in case of fail
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-24 15:00:19 -03:00
ligd
0a88799bab sched: fix task_delete crash in SMP case
A testcase as following:

child_task()
{
  sleep(3);
}

main_task()
{
  while (1)
    {
      ret = task_create("child_task", child_task, );
      sleep(1);

      task_delete(ret);
    }
}

Root casuse:
task_delete hasn's cover the condition that the deleted-task
is justing running on the other CPU.

Fix:
Let the nxsched_remove_readytorun() do the real work

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 14:11:18 +09:00
zhangyuan21
acd108a5ed pthread: fixed pthread_cancel and pthread_exit crash in SMP mode
1. When pthread exit, set the default cancellability state to NONCANCELABLE state.
2. Make sure modify tcb->flags is atomic operations.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-18 11:57:40 +08:00
zhangyuan21
9fd30c7f63 sched/pthread: check pthread group and flags before join
Prevent users from using the wrong pid and causing system crash.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-18 11:57:40 +08:00
Ville Juven
6a026382f0 group_leave: Don't instantiate address environment prior to destroying it
This is just unnecessary, a process cannot be destroyed by another
process in any case, every time this is executed the active address
environment is the process getting destroyed.

Even in the hypothetical case this was possible, the system would
crash at once if a context switch happens between "select()" and
"restore()", which is possible as the granule allocator is protected by
a semaphore (which is a synchronization point).
2023-01-18 11:02:19 +08:00
ligd
c0aaaa94e1 assert: used %p to logout the pointer
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 09:46:40 -03:00
ligd
19f87e88b9 assert: fix build break.
misc/assert.c: In function 'show_tasks':
Error: misc/assert.c:411:10: error: format '%p' expects argument of type 'void *', but argument 3 has type 'uintptr_t' {aka 'long unsigned int'} [-Werror=format=]
  411 |   _alert("  ----   ---"
      |          ^~~~~~~~~~~~~~
......
  424 |          , up_get_intstackbase()
      |            ~~~~~~~~~~~~~~~~~~~~~
      |            |
      |            uintptr_t {aka long unsigned int}

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 09:46:40 -03:00
ligd
c821088734 pthread: fix pthread exit error when set DETACHED
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 11:09:36 +08:00
ligd
940de60892 assert: add stackbase dump
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 11:04:12 +08:00
ligd
4de9317373 assert: add uname info to assert message
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 11:04:12 +08:00
Gustavo Henrique Nihei
a3e253b4a3 mm: Enable a dedicated kernel heap on BUILD_FLAT via MM_KERNEL_HEAP
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-01-17 10:30:00 +08:00
zhangyuan21
63039b80e1 sched/wqueue: do work_cancel when worker is not null
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-16 13:37:00 +08:00
Jukka Laitinen
a2a10c87e3 mm/shm: Switch to use process' common virtual memory region allocator
- Also remove the nuttx private shm.h file nuttx/mm/shm.h, which became redundant
- Also remove the gran allocator initialization/release in binfmt since common
  vpage allocator is initialized in group_create/group_leave

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-13 02:20:13 +08:00
Jukka Laitinen
2236facca9 mm/map: Add a common virtual memory region allocator
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-13 02:20:13 +08:00
Xiang Xiao
ef65d443ad sem: Remove PRIOINHERIT_FLAGS_ENABLE and use SEM_PRIO_INHERIT instead
and refine the code to prepare the support of new flags

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-11 17:35:28 +02:00
chao an
fdc3c44cc4 sched/group: fix task info heap-use-after-free
tg_info is still in use after task_uninit_info(), unifies
lib_stream_* with life cycle of task info to avoid this issue.

| ==1940861==ERROR: AddressSanitizer: heap-use-after-free on address 0xf47032e0 at pc 0x5676dc4f bp 0xf2f38c68 sp 0xf2f38c58
|
|#10 0xf7abec89 in __asan::__asan_report_load2 (addr=4100993760) at ../../../../src/libsanitizer/asan/asan_rtl.cpp:119
|#11 0x5677356a in nxsem_destroy (sem=0xf47032e0) at semaphore/sem_destroy.c:73
|#12 0x56773695 in sem_destroy (sem=0xf47032e0) at semaphore/sem_destroy.c:120
|#13 0x5676faa2 in nxmutex_destroy (mutex=0xf47032e0) at include/nuttx/mutex.h:126
|#14 0x567a3430 in lib_stream_release (group=0xf4901ba0) at stdio/lib_libstream.c:98
|#15 0x5676da75 in group_release (group=0xf4901ba0) at group/group_leave.c:162
|#16 0x5676e51c in group_leave (tcb=0xf5377740) at group/group_leave.c:360
|#17 0x569fe79b in nxtask_exithook (tcb=0xf5377740, status=0) at task/task_exithook.c:455
|#18 0x569f90b9 in _exit (status=0) at task/exit.c:82
|#19 0x56742680 in exit (status=0) at stdlib/lib_exit.c:61
|#20 0x56a69c78 in iperf_showusage (progname=0xf2f28838 "iperf", exitcode=0) at iperf_main.c:91
|#21 0x56a6a6ec in iperf_main (argc=1, argv=0xf2f28830) at iperf_main.c:140
|#22 0x5679c148 in nxtask_startup (entrypt=0x56a69c78 <iperf_main>, argc=1, argv=0xf2f28830) at sched/task_startup.c:70
|#23 0x56767f58 in nxtask_start () at task/task_start.c:134

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-11 01:53:59 +08:00
Jukka Laitinen
7f8bec7070 Add mm/mm_map virtual memory mapping list
The task_group specific list can be used to store information about
mmappings.

For a driver or filesystem performing mmap can also enable munmap by
adding an item to this list using mm_map_add(). The item is then
returned in the corresponding munmap call.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-10 18:34:25 +08:00
anjiahao
9a32cf7a1a assert:add a last type to call notifier
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-05 22:58:00 +08:00
Xiang Xiao
98ab55ef68 drivers/note: Replace the scritical section with spin_xxx_wo_note
to avoid to generate the unexpected schedule information

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-04 00:21:18 +02:00
yinshengkai
81448b5021 sched/irq: add spin_unlock_irqsave/irqrestore_wo_note
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-01-02 22:29:01 +08:00
yinshengkai
ca5fcc58c2 sched: move SCHED_INSTRUMENTATION_xxx to note Kconfig
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-12-30 15:50:30 -03:00
田昕
96a45e2c75 sched/misc:add linux-like reboot notifier list
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2022-12-29 19:18:42 +08:00
Xiang Xiao
d5f729ed25 sched/assert: Dump the global state only when it's a fatal error
and merge assert_end into _assert

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-29 11:50:31 +09:00
Xiang Xiao
d1497a8d08 sched/assert: Don't call up_check_tcbstack for the kernel stack
since up_check_tcbstack only check the userspace stack color

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-29 11:50:31 +09:00
Xiang Xiao
5f99e482b5 sched/assert: Don't call running_task more than once
and fix some minor style issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-29 11:50:31 +09:00
Masayuki Ishikawa
6992a8f4cc sched: group: Fix memory corruption in group_leave.c
Summary:
- I noticed that nxplayer (HTTP audio streaming) + command execution
  via telnet sometimes causes memory corruption.
  See https://github.com/apache/nuttx/pull/7947 for the detail.
- This commit fixes this issue by calling lib_stream_release() before
  lib_stream_release() in group_leave.c

Impact:
- Should be none

Testing:
- Tested with spresense:wifi_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-12-29 10:33:47 +08:00
Xiang Xiao
2e59d832fc sched/misc: Rename panic.c to panic_notifier.c
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-28 21:42:38 +02:00
dongjiuzhu1
9244b5a737 signal: Support sigaction:sa_user, siginfo_t:si_user with user info
When the signal sent by the sender is blocked in the target task,
if the target task has an action registered with sa_flags SA_KENELHAND,
it will directly respond to the action in the context of the sender.
When the action is executed, it will have the parameters set by the
target task with sigaction:sa_user.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-12-28 23:05:58 +08:00
dongjiuzhu1
3927d878e4 signal/nxsig_pengingset: move nxsig_pendingset to common header
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-12-28 23:05:58 +08:00
zhangyuan21
45394eb6dc arch: save user context in assert common code
This is the work continue with #7875

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-24 13:02:56 +08:00