Commit Graph

252 Commits

Author SHA1 Message Date
hujun5 e13d255345 sched: add nxsched_remove_self
reason:
1In the scenario of active waiting, context switching is inevitable, and we can eliminate redundant judgments.

code size
before
hujun5@hujun5-OptiPlex-7070:~/downloads1/vela_sim/nuttx$ size nuttx
   text    data     bss     dec     hex filename
 262848   49985   63893  376726   5bf96 nuttx

after
hujun5@hujun5-OptiPlex-7070:~/downloads1/vela_sim/nuttx$ size nuttx
   text    data     bss     dec     hex filename
 263324   49985   63893  377202   5c172 nuttx

reduce code size by  -476

Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
   -machine virt,virtualization=on,gic-version=3 \
   -net none -chardev stdio,id=con,mux=on -serial chardev:con \
   -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-24 22:07:00 +08:00
ouyangxiangzhen db88754822 sched/signal: Simplify the implementation of SIGEV_THREAD_TID.
This commit simplified thread ID dispatching logic by integrating it into the `nxsig_dispatch` function.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-23 12:29:36 +08:00
ouyangxiangzhen 0373ba0fab sched/signal: Simplified Implementation for SIGEV_THREAD_TID.
This commit simplified the implementation for SIGEV_THREAD_TID.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-23 12:29:36 +08:00
ouyangxiangzhen 9f36509c0b signal: Add siginfo initializer
This patch is to make Coverity happy.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-09-23 12:29:36 +08:00
ouyangxiangzhen 213d5538fc signal: Add support for SIGEV_THREAD_ID and sigev_notify_thread_id
This patch added support for SIGEV_THREAD_ID and sigev_notify_thread_id.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-17 12:15:14 +08:00
ligd f0d3c8ab2b usleep: use div_const to optimize the usleep
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
ligd 6a2c03732f clock: Replace all ts and tick conversion functions
Using the ts/tick conversion functions provided in clock.h

Do this caused we want speed up the time calculation, so change:
clock_time2ticks, clock_ticks2time, clock_timespec_add,
clock_timespec_compare, clock_timespec_subtract... to MACRO

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
Alin Jerpelea eb9030c891 sched: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-12 01:10:14 +08:00
yinshengkai 7b02d788ef sched/signal: fix pthread_kill use after free
When a low-priority thread sends a kill signal to a high-priority thread,
the high-priority thread will exit and release tcb. When the thread returns
to the low-priority thread, it will access the released stcb.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-23 20:02:46 +08:00
xuxin19 b3f1871bc3 sched:fix windows sim build error
nuttx\sched\signal\sig_timedwait.c(253,13): error C2059: syntax error:'<parameter-list>'
nuttx\sched\signal\sig_timedwait.c(321,44): error C2182: '$S1': illegal use of type 'void'
nuttx\sched\signal\sig_timedwait.c(321,50): error C2059: syntax error:':'

nuttx\sched\tls\tls_initinfo.c(68,39): error C2036: 'void *': unknown size
nuttx\sched\sched\sched_get_tls.c(76,44): error C2036: 'void *': unkown size

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-14 22:36:57 +08:00
hujun5 a4fece3450 spin_lock: inline spin_lock
test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx
2024-07-15 02:29:30 +08:00
hujun5 ddf1410312 sched/signal: There is no need to use sched_[un]lock
purpose:
1 sched_lock is very time-consuming, and reducing its invocations can improve performance.
2 sched_lock is prone to misuse, and narrowing its scope of use is to prevent people from referencing incorrect code and using it

test:
We can use qemu for testing.
compiling
make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20
running
qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx

We have also tested this patch on other ARM hardware platforms.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-06-27 11:51:16 +08:00
Yanfeng Liu 2827703b0c sched/signal: reclaim dynamic sigactions
This adds pre-allocation and dynamic allocations for sigactions.
Current behavior can be acheived by setting SIG_ALLOC_ACTIONS to
a number larger than 1.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-06-21 22:45:52 +08:00
chao an 58ad896281 sched/signal: move signal structures pool to bss
Decoupling with memory allocator

Signed-off-by: chao an <anchao@lixiang.com>
2024-06-04 14:26:55 +08:00
chao an a8de85de0b sched/signal: add sanity check for siginfo
add sanity check for siginfo to ensure whether there is really a
consumer waiting for the signal, since the task state will not be
changed appropriately if in cancel/killed case

Test Case:
https://github.com/linux-test-project/ltp/blob/master/testcases/open_posix_testsuite/conformance/interfaces/sigpause/1-1.c#L63

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-26 20:55:04 +08:00
chao an 63a0a544be sched/signal: merge allocate of signal pool
1. merge allocate of signal pool
2. remove unnecessary static variables

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-22 21:40:56 +08:00
chao an 306c1c0b7d sched/tasklist: replace task status list with macro definition
replace to macro will help to extend the scheduling implementation

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-21 11:23:46 +09:00
chao an 2b4002d9ad sched/signal: move unblock signal info to stack
struct tcb_s will reduce by 24 bytes

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-15 01:10:55 +08:00
chao an 7cb1f3b3c0 sched/group: replace group_findbypid to task_getgroup
Task group could find from process id, replace group_findbypid to
task_getgroup to simplify the search logic

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-05 22:24:52 +08:00
Petteri Aimonen 0648a61668 sigaction: Expand si_user for non-kernel signals
Commit 9244b5a737 added support
for non-standard field si_user that is useful for passing context
pointers to signal handlers.

This commits makes it work for all signals, not just SA_KERNELHAND.
Previously si_user for normal signals was uninitialized garbage.
2023-11-22 08:00:43 -08:00
Huang Qi 0995e17927 sched: Check for zero sleep time and yield CPU if
necessary

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-11-07 18:26:54 +08:00
ligd 415fe60695 signal: use work_cancel_sync() to fix used after free
bug:

user thread:                             hpwork:
timer_create() with SIGEV_THREAD
timer_settime()
    irq -> work_queue()                  add nxsig_notification_worker to Q
timer_delete()
    nxsig_cancel_notification()
                                         call nxsig_notification_worker()
    work_cancel()
    timer_free()
                                         nxsig_notification_worker() used after free

root cause:
work_cancel() can't cancel work completely, the worker may alreay be running.

resolve:
use work_cancel_sync() API to cancel the work completely

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 15:52:48 +08:00
xuxin19 d93d377257 cmake:complete missing changes during cmake reforming for sched
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-08 21:20:16 +03:00
chao an 664927c86e mm/alloc: remove all unnecessary cast for alloc
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 14:34:20 +08:00
xinhaiteng dbefe37a3a sigqueue: add signal type judgment logic
To determine whether a signal is real-time signal or standard signal, the POSIX standard https://www.man7.org/linux/man-pages/man7/signal.7.html defines a real-time signal between SIGRTMIN  and SIGRTMAX , which can store multiple copies, otherwise only one can be retained.

Signed-off-by: xinhaiteng <xinhaiteng@xiaomi.com>
2023-08-21 15:35:45 +08:00
yinshengkai 8fa4f2d61d add the startup process tracepoint
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-19 21:50:08 +08:00
Petro Karashchenko d113722eb2 style: fix indentation issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
zhangyuan21 671c5dc3d8 sched/pthread: Don't do cancel when it is already in the exit process
When the task is already in the exit process,
do not execute pthread cancel and return ESRCH.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-03 03:12:36 -07:00
guanyi 55a727b1ce ltp: sigprocmask fix
1. change signal/sig_procmask.c and pthread/pthread_sigmask.c together
2. clear signals unconditionally

Signed-off-by: guanyi <guanyi@xiaomi.com>
2023-07-31 22:29:31 -07:00
guoshichao 0092b3e30f sched/signal/sig_nanosleep: fix the clock_nanosleep posix case
1. make the clock_nanosleep can pass
ltp/open_posix_testsuite/clock_nanosleep 13-1, 10-1, 9-1 cases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-23 22:02:03 -07:00
fangxinyong 7462b199bb signal: SIGCONT can be caught
pass ltp sigaction case 19-5.c, 23-5,c and 28-5.c.
When SIGCONT is dispatched, resume all members of the task group.
So there is nothing do in default action.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-07-12 21:27:06 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
fangxinyong dc7f8f136c signal: correct to const pointer for sigorset and sigandset
the two GNU functions, should use const input pointer parameter.

https://refspecs.linuxfoundation.org/LSB_1.3.0/gLSB/gLSB/baselib-sigorset.html
https://refspecs.linuxfoundation.org/LSB_1.3.0/gLSB/gLSB/baselib-sigandset.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-07-05 16:26:18 +08:00
Petro Karashchenko 1b801a5bbc style: remove extra spaces and align parameters
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-06-11 12:55:29 +08:00
chao an fb9b41221d semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00
Petro Karashchenko 764f8ef9be sched/signal: fix typo in comments
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Gregory Nutt 8cca30b44c Signal must be masked when it is delivered to a signal handler
Signal must be masked when it is delivered to a signal handler per:

https://pubs.opengroup.org/onlinepubs/007904875/functions/sigaction.html:

When a signal is caught by a signal-catching function installed by sigaction(), a new signal mask is calculated and installed for the duration of the signal-catching function (or until a call to either sigprocmask() or sigsuspend() is made). This mask is formed by taking the union of the current signal mask and the value of the sa_mask for the signal being delivered [XSI] [Option Start] unless SA_NODEFER or SA_RESETHAND is set, [Option End] and then including the signal being delivered. If and when the user's signal handler returns normally, the original signal mask is restored.

Any action queued for that signal while the signal is masked should be deferred. It should go into the group pending signal list and should not be processed until until the signal is unmasked (which should occur when the signal handler returns).
2023-05-18 01:19:12 +08:00
anjiahao 1e22163b57 sig_timewait:remove useless assert
use sclock_t repalce int64 and int32

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-05-04 18:04:45 +03:00
anjiahao 78bff8e9c5 sig_timewait:changes the macro for waitticks
use SYSTEM_TIME64 inside of LONG LONG better

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-04-30 00:41:06 +08:00
Petro Karashchenko a8f4a89221 signal: add SIGSYS
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-03-28 11:24:35 -06:00
Gregory Nutt 717bb04cb7 Increase the number of real time signals. Two is not enough.
Refer to issue #8867 for details and rational.

Convert sigset_t to an array type so that more than 32 signals can be supported.

Why not use a uin64_t?
- Using a uin32_t is more flexible if we decide to increase the number of signals beyound 64.
- 64-bit accesses are not atomic, at least not on 32-bit ARMv7-M and similar
- Keeping the base type as uint32_t does not introduce additional overhead due to padding to achieve 64-bit alignment of uin64_t
- Some architectures still supported by NuttX do not support uin64_t
  types,

Increased the number of signals to 64. This matches Linux. This will support all xsignals defined by Linux and also 32 real time signals (also like Linux).

This is is a work in progress; a draft PR that you are encouraged to comment on.
2023-03-27 16:59:04 +03:00
Ville Juven 776e2d774f signal/sig_dispatch: Add signal action, if task is in system call
The _unmasked_ signal action was never added if the task is in system call
and waiting for (a different) signal.

This fixes deliver especially for default signal actions / unmaskable
signals, like SIGTERM.
2023-03-14 11:16:52 +09:00
Ville Juven 47ce89f757 Revert "signal/sig_dispatch: Signal action was not performed if TCB_FLAG_SYSCALL is set"
This reverts commit 0e44666828.
2023-03-08 10:13:26 +01:00
Ville Juven 3f529b4882 Revert "signal/sig_dispatch: Fix case where signal action is sent twice"
This reverts commit be0cb4cbe3.
2023-03-08 10:13:26 +01:00
chenrun1 e6227e1943 include/signal.h:Expanding SIGNAL to be consistent with Linux 2023-02-24 04:07:10 +08:00
Ville Juven be0cb4cbe3 signal/sig_dispatch: Fix case where signal action is sent twice
As far as I can interpret how signal delivery should work when the signal
is blocked, it should still be sent to the pending queue even if the signal
is masked. When the sigmask changes it will be delivered.

The original implementation did not add the pending signal action, if
stcb->task_state == TSTATE_WAIT_SIG is true.

An attempt to patch this was made in #8563 but it is insufficient as it
creates an issue when the task is not waiting for a signal, but is in
syscall, in this case the signal is incorrectly queued twice.
2023-02-22 01:29:06 +08:00
Ville Juven df1d7dd480 libc/exit: Purge calls to userspace API exit() from kernel
Remove calls to the userspace API exit() from the kernel. The problem
with doing such calls is that the exit functions are called with kernel
mode privileges which is a big security no-no.
2023-02-17 23:07:17 +08:00
Ville Juven 0e44666828 signal/sig_dispatch: Signal action was not performed if TCB_FLAG_SYSCALL is set
For some reason the signal action was never performed if the receiveing
task was within a system call, the pending queue inser was simply missing.

This fixes the issue.
2023-02-17 22:54:55 +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
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