Commit Graph

2413 Commits

Author SHA1 Message Date
dongjiuzhu1
18819b6b24 sched/task: close file descriptor with O_CLOEXEC before active task or exec
VELAPLATFO-18473

refs:
https://man7.org/linux/man-pages/man2/fcntl.2.html
If the FD_CLOEXEC bit is set, the file descriptor will automatically
be closed during a successful execve(2).
(If the execve(2) fails, the file descriptor is left open.)

modify:
1. Ensure that the child task copies all fds of the parent task,
   including those with O_CLOEXE.
2. Make sure spawn_file_action is executed under fd with O_CLOEXEC,
   otherwise it will fail.
3. When a new task is activated or exec is called, close all fds
   with O_CLOEXEC flags.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 21:15:07 +08:00
dongjiuzhu1
db13ff2dd5 libs/libc: fix compile warning about modlib_depend when CONFIG_MODLIB_MAXDEPEND = 0
modlib/modlib_symbols.c: In function ‘modlib_symcallback’:
modlib/modlib_symbols.c:215:13: warning: implicit declaration of function ‘modlib_depend’; did you mean ‘modlib_read’? [-Wimplicit-function-declaration]
  215 |       ret = modlib_depend(exportinfo->modp, modp);
      |             ^~~~~~~~~~~~~
      |             modlib_read

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-26 01:53:38 +08:00
dongjiuzhu1
e88a36fa92 libs/modlib: Adding architecture-specific memory allocator for dynamic data loading
Arch can specific the memory allocator for data to optimize access speed.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-26 01:53:38 +08:00
dongjiuzhu1
968e89303f env_dup: fix issue about USE_AFTER_FREE
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-26 00:11:14 +08:00
Ville Juven
ab78e3817a sched/task_[posix]spawn: Simplify how spawn attributes are handled
Handle task spawn attributes as task spawn file actions are handled.

Why? This removes the need for sched_lock() when the task is being
spawned. When loading the new task from a file the scheduler can be
locked for a VERY LONG time, in the order of hundreds of milliseconds!

This is unacceptable for real time operation.

Also fixes a latent bug in exec_module, spawn_file_actions is executed
at a bad location; when CONFIG_ARCH_ADDRENV=y actions will point to the
new process's address environment (as it is temporarily instantiated at
that point). Fix this by moving it to after addrenv_restore.
2023-10-25 11:55:44 -03:00
chao an
87d6084f31 sched: fix the minor style issue
and remove the unused return value

Signed-off-by: chao an <anchao@xiaomi.com>
2023-10-25 15:46:45 +08:00
chao an
50b17fb3fc group/killchildren: replace syscall(2) to kernel api
syscall(2) cannot be called from kernel space

Signed-off-by: chao an <anchao@xiaomi.com>
2023-10-25 15:46:45 +08:00
chao an
cdec5c80c2 sched/pthread/barrierwait: replace syscall(2) to kernel api
syscall(2) cannot be called from kernel space

Signed-off-by: chao an <anchao@xiaomi.com>
2023-10-25 09:18:55 +08:00
TaiJuWu
51eaa59cc0 Replace enter_critical_section with spin_irqsave
Base on discusion: https://github.com/apache/nuttx/issues/10981

Signed-off-by: TaiJuWu <tjwu1217@gmail.com>
2023-10-21 11:00:07 +08:00
Michal Lenc
0a107ca6d9 libc: add support for custom streams with fopencookie()
This commit adds support for custom stream via fopencookie function.
The function allows the programmer the create his own custom stream
for IO operations and hook his custom functions to it.

This is a non POSIX interface defined in Standard C library and implemented
according to it. The only difference is in usage of off_t instead of
off64_t. Programmer can use 64 bits offset if CONFIG_FS_LARGEFILE is
enabled. In that case off_t is defined as int64_t (int32_t otherwise).

Field fs_fd is removed from file_struct and fs_cookie is used instead
as a shared variable for file descriptor or user defined cookie.

The interface will be useful for future fmemopen implementation.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2023-10-18 21:13:01 +08:00
zhangyuan21
083c87b39a sched: Exit immediately when cpuset change to 0.
Exit immediately when finished processing the current CPU
if there are no other CPUs to be processed.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-10-18 21:12:35 +08:00
zhangyuan21
34412349e9 sched: add smp function call
Support smp function call, calling smp_call_function allows
a specific core to execute a function. It should be noted
that there should be no waiting operations in the executed
function.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-10-18 09:57:50 +08:00
Xiang Xiao
a34be7f7c2 sched: Remove the unused tcb argument from group_setupidlefiles
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 17:23:05 +03:00
Xiang Xiao
62c2b1abba stdio: Initialize stdin, stdout and stderr directly
and then remove group_setupstreams

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
Xiang Xiao
b0d197534f stdio: Move lib_stream_[initialize|release] from libc/stdio to sched/tls
both functions aren't suitable to be put into libc,
because they call the kernel internal functions directly.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-17 13:34:00 +08:00
Bowen Wang
77306e5029 assert: move the backtrace dump after the stack dump
Execute the simple logic first to avoid rarely crash information
when crash in backtrace again.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-10-16 16:07:44 +08:00
TaiJu Wu
e28fcbd777 fix: Mac sim-02 compiler issue
This path just for modify Mac sim-02 issue.
The compiler require the firt paramter of atomic_compare_exchange_strong
is atomic type and second parameter is int type.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
2023-10-16 08:55:01 +08:00
TaiJu Wu
68a4d3df7e spinlock: implement read writer spinlock
spinlock.c:
Implement read write spinlock.
Readers can take lock simultaneously but only one writer can take lock.

irq_spinlock.c:
Align g_irq_spin_count.
If the lock is NULL, the caller will get global lock (e.g. g_irq_spin) and spin_lock_irqsave() support nest on the same CPU.
If the CPU can write lock, it can call write_lock_irqsave() again (e.g. support nest).

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>

Co-authored-by: David Sidrane <David.Sidrane@Nscdg.com>
2023-10-16 08:55:01 +08:00
Ville Juven
d72de58aa8 sched/assert.c: Print process name in assert dump
In addition to printing out the thread name (task name in flat mode),
print the parent process's name as well.

It is quite useful to know which process is the parent of a faulting
thread, although this information can be read from the assert dump, in
some cases the dump might be incomplete (due to e.g. stack corruption,
which causes another exception and PANIC().)
2023-10-09 21:30:33 +08:00
Xiang Xiao
dfa0283d83 spinlock: Rename spin_islocked to spin_is_locked
align with Linux naming style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-06 20:03:19 -04:00
TaiJu Wu
ffba0d15a5 Feature: implement ticket spinlock
test config: ./tools/configure.sh -l qemu-armv8a:nsh_smp

Pass ostest

No matter big-endian or little-endian, ticket spinlock only check the
next and the owner is equal or not.

If they are equal, it means there is a task hold the lock or lock is
free.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>

Co-authored-by: Xiang Xiao <xiaoxiang781216@gmail.com>
2023-10-07 01:38:37 +08:00
yinshengkai
ddb87d3b86 clock: replace all up_perf_xx with perf_xx
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-02 16:11:43 +02:00
yinshengkai
b99820744c timer: handle perf count overflow
clock_getcycle always returns an incremented cycle value
If the hardware does not support perf event it will use arch_alarm's up_perf_gettime

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-10-02 16:11:43 +02:00
Petteri Aimonen
0611f39cdc adjtime(): Improve configuration and math
1) Previously adjustments less than 1 microsecond per tick would be
   completely ignored. Now they are applied over a shorter period at
   a rate of 1 us per tick.

2) Previously CLOCK_ADJTIME_PERIOD was in units of 1/100th of second.
   Change to milliseconds to be more generally useful unit.
   Change setting name to CLOCK_ADJTIME_PERIOD_MS to make the unit change
   easier to notice.

3) Previously CLOCK_ADJTIME_SLEWLIMIT was in percentage.
   Most clock crystals have better accuracy than 1%, so the minimum slew
   rate was excessive. Change to CLOCK_ADJTIME_SLEWLIMIT_PPM with setting
   value in parts per million.

4) No need to use floating point math in clock_adjtime.c.
2023-09-29 13:03:10 +08:00
Petteri Aimonen
a2da12a67e Fix dependencies of CONFIG_SCHED_CPULOAD_ settings
CONFIG_SCHED_CPULOAD_EXTCLK doesn't actually require tickless mode.
As long as the platform provides external call to nxsched_process_cpuload(),
it will work in either tickless or ticking mode.
Removed Kconfig dependency.

Instead, CONFIG_SCHED_CPULOAD_SYSCLK does require ticking mode to work,
as documented in CONFIG_SCHED_CPULOAD help text.
Added the dependency to Kconfig also.
2023-09-26 22:13:37 +08:00
Xiang Xiao
2acd975435 assert: Skip to include arch/board/board.h if CONFIG_ARCH_LEDS=n
follow up the change: https://github.com/apache/nuttx/pull/10553

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-09-26 15:41:35 +08:00
zhuanglin
13ee3f8117 sched/clock Add special handling for TCB null pointer cases
Adding a judgment in the code that null return values are not referenced for dereference

Signed-off-by: zhuanglin <zhuanglin@xiaomi.com>
2023-09-22 08:46:50 +08:00
ThomasNS
a2c806027f fix led panic feature 2023-09-21 00:35:12 +08:00
Neale Ferguson
5d7f2fdf16 Fix loading of ET_DYN type of shared objects
* build-globals.sh
  - Only look in the nuttx for external symbols used when loading
    dynamic shared objects

* include/elf64.h
  - Correct the type of fields in the Elf64_Phdr structure

* libs/libc/dlfcn/lib_dlclose.c
  - Distinguish between ET_DYN and other objects as the former
    has both text and data in a single allocation to reserve
    GOT offsets

* libs/libc/dlfcn/lib_dlopen.c
  - Code formatting

* libs/libc/modlib/modlib_bind.c
  - Distinguish between relocation entry sizes by section type
  - Handle RELA style relocations

* libs/libc/modlib/modlib_globals.S
  - Formatting fixes
  - Symbols should not be weak - they exist or they don't

* include/nuttx/lib/modlib.h
  - Add an inidcator to module_s to distinguish between ET_DYN and other

* libs/libc/modlib/modlib_load.c
  - ET_DYN objects need to keep the relative displacement between the text
    and data sections due to GOT references from the former to the latter.
    This also implies that linking may require modification from the default
    for the shared objects being produced. For example, default alignment may
    mean nearly 64K of wasted space.

* libs/libc/modlib/modlib_unload.c
  sched/module/mod_rmmod.c
  - Distingusih between freeing of ET_DYN storage and other as the former
    is a single allocation.

* libs/libc/modlib/mod_insmod.c
  - Cater for ET_DYN objects having init and preinit sections
2023-09-20 09:35:28 -04:00
Xu Xingliang
3cd5e20f74 sched: return 0 from clock_systime_ticks if failed
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2023-09-19 16:17:08 +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
ligd
61ef7eb3dc wqueue: add work_cancel_sync() support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 15:52:48 +08:00
yangguangcai
fe30f0fa82 sched/wdog:change g_wdtickbase update situation.
In the 'wd_timer',the callback function executed by 'wd_expiration' could call wd_start,and g_wdtickbase might be updated.Subsequently, g_wdtickbase is incremented by the value of ticks, causing g_wdtickbase to be greater than the actual passage of time.

Signed-off-by: yangguangcai <yangguangcai@xiaomi.com>
2023-09-19 11:41:50 +08:00
guoshichao
e0ec88e738 timer/timer_getoverrun: adjust the default errno from ENOSYS to EINVAL
modify the default errno from ENOSYS to EINVAL can pass the ltp
case: ltp_timer_getoverrun_speculative_6_1,
ltp_timer_getoverrun_speculative_6_2, ltp_timer_getoverrun_speculative_6_3

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-09-19 09:35:27 +08:00
Petro Karashchenko
440be65010 spinlock: use spinlock API instead of direct asignment/compare
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-16 14:17:47 +08:00
fangxinyong
a73f5f86dc sched: do not crash for priority multi-boost
aio client will queue asynchronous io requests to the worker threads.
if PRIORITY_INHERITANCE is enabled, client thread's priority will be
set to worker threads. There will be multi-boost/restore of worker
threads' priority and assert the system.

No need priority multi-boot/restore to worker thread because client
thread's priority is alway the same.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-09-12 23:02:10 +03: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
yangyalei
fd776e8cee fix wait after vfork return error
vfork use waitpid hang father process,
but waitpid release child processs information by default.
So when user call wait, it return errno 10.

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-09-08 00:53:56 +03:00
yangyalei
eba2f163ed Revert "fix wait after vfork return error"
This reverts commit 50428979d0.
2023-09-08 00:53:56 +03:00
Petro Karashchenko
47627c5fbd sched/misc: optimize collect_deadlock implementation
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-09-07 00:50:30 +08: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
chenxiaoyi
cc690f1d21 move task tls destruct to before _exit
Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2023-08-29 12:05:57 +08:00
anjiahao
48c153db25 vfs:add nxsched_foreach to sched_lock avoid crash
If scheduling occurs in file_fsync,
fl_lock may be released, and an error may
occur when calling nxmutex_unlock

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-29 10:36:21 +08:00
SPRESENSE
57d9083844 assert: Fix the printing alignment of interrupt stack during assert
Fix the printing alignment of interrupt stack during assert.
2023-08-29 02:59:38 +08:00
Xiang Xiao
47faeeb360 tls: Move task_tls_alloc and task_tls_destruct to libc
so task_tls_destruct can be called from usrspace, which is required by:
https://github.com/apache/nuttx/pull/10288

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-28 11:02:18 +03:00
Xiang Xiao
cb8df39207 binfmt/elf: Fix the minor style issue
and remove the unused macros and unnecessary cast

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-27 18:46:40 -03: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
zhangyuan21
7737efd995 SMP: fix repeat entry timer_start
If we are running on a single CPU architecture, then we know interrupts
are disabled and there is no need to explicitly call enter_critical_section().
However, in the SMP case, enter_critical_section() is required prevent
multiple cpu to enter timer_start.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-21 13:20:56 +08:00
zhangyuan21
fb12e7530d sched/smp: flush dcache before start other cpus
core0 may write the data used by other cpu, this will cause cache inconsistency.
so need fulsh dcache before start other cpus.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-21 12:02: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