Commit Graph

2441 Commits

Author SHA1 Message Date
Bowen Wang 3bac449286 assert: fix flags type, should be irqstate_t
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-04 22:16:54 -08:00
yinshengkai 9852428953 fs: procfs add poll support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-12-26 19:23:13 -08:00
Xiang Xiao 50e2269642 sched: Stop the sched timer when possible to save the power in tickless mode
Remove KEEP_ALIVE_HACK to avoid waking up the device periodly.
The workaround it's added by:
    commit 6546fa39c7
    Author: Gregory Nutt <gnutt@nuttx.org>
    Date:   Tue Aug 12 11:12:00 2014 -0600

    Tickless Stuff:  Back out the risky timer operations when the ready-to-run
    list is modified. That is unsafe.  An ugly workaround is just to keep an
    interval timer going all of the time with a minimum duration equal to the
    timeslice interval.
But look like it doesn't needed anymore.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-12-17 08:25:11 -06:00
simbit18 c494ce4a96 Update kconfig2html.c
Fix nuttx coding style
2023-12-14 20:02:52 -08:00
anjiahao 94d449e722 arch:Mark key functions to prohibit instrumentation to prevent recursive calls
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-11 02:06:51 -08:00
anjiahao d932e0af2a sched/procfs:use instrument to statistics run time max stack
Usage:
1. CONFIG_FS_PROCFS_MAX_STACK_RECORD > 0, such as 32,
2. add '-finstrument-functions' to CFLAGS for What you want to check
   stack.
3. mount porcfs
4. cat /proc/<pid>/stack will print backtace & size

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-11 02:06:51 -08:00
anjiahao 35051dd715 coredump: support coredump save to block device when crash
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-10 07:02:03 -08:00
anjiahao c3fd7f84ad assert/stack_dump: Output some more information on the premise that sp has it.
gdb may need more information when doing backtrace

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-08 19:55:32 -08:00
anjiahao 7fd172d9ff stack_dump:change Conditions for stack dump
If the gap between sp and stack_top is too small,
then the stack will not be output,
modify the conditional loop condition, and fix this problem

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-08 19:55:32 -08:00
chenrun1 a6dc4412ba misc/rwlock:Implementing read/write locks.
A new locking mechanism: read/write locks
When there is a writer it is not possible to put on a read lock or a write lock; when there is a reader it is possible to reenter the read lock but not the write lock.
Writers are exclusive locks, readers are shared locks.
At the same time through the waiter count to determine whether there is currently a blocked task, if there is then in the unlock time to wake up all the waiter, through the priority of the competition to complete the blocked lock execution.
For example:
When we have a reader blocking two waiter writers, when the reader is unlocked it wakes up both writers. The writer with higher priority wakes up and checks for a successful condition and locks the lock, the second writer wakes up and fails to check for a condition and continues to block the lock.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2023-12-02 19:43:19 -08:00
Ville Juven c9bdadd541 sched/semaphore: Move cancel point and errno handling to libc / user-space
This moves all the public POSIX semaphore functions into libc and with
this most of the user-space logic is also moved; namely cancel point and
errno handling.

This also removes the need for the _SEM_XX macros used to differentiate
which API is used per user-/kernel mode. Such macros are henceforth
unnecessary.
2023-11-27 04:52:54 -08:00
ligd 00121f9812 sched: delete check when pick nexttcb in readytorun list
CPU0                     CPU1
1. feed0 thread             feed1 thread
   (prio 1 affinity)        (prio 1 affinity)
2. nsh_main
   sched_lock()
3. waitpid()                hello_main
4. ------                   hello exit()
5. ------                   exit()->exit_wakeup()->wakeup nsh ->
                            add_readytorun()->
                            nsh at schedlock state set g_cpu_schedlock
6. -----                    exit()->nxtask_exit()->remove_readytorun()
                            -> check g_cpu_schedlock -> pick idle1
7. waitpid() return         idle thread
8. sched_unlock             idle thread

The error is in step 6:
pick a idle thread to execute not feed1 thread.

resolve:
remove the schedlocked-check in remove_readytorun()

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-11-24 12:43:54 +09:00
Ville Juven 57de6484e9 task/pthread_cancelpt: Fix task_delete from another task group
PR #11165 causes an unnecessary regression; task_delete no longer works,
if the deleted task is from another group.

The logic that prevents this comes from:

nxnotify_cancellation() ->
tls_get_info_pid() ->
nxsched_get_stackinfo()

Which checks for permissions, which does not make sense in this case since
it is the kernel asking for the stack information.

Fix this by partially reverting 11165 and implementing a direct path for
the kernel to query for any tasks TLS.
2023-11-22 08:05:58 -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
Xiang Xiao b2f75c2f3d spinlock: Move the inclusion of stdatomic.h to source file
to make rwlock work with c++ source code

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-11-19 20:22:50 +01:00
chao an 42427e9e29 sched/taskfiles: skip unnecessary file open/close operations to improve performance
The task files should consult the "spawn action" and "O_CLOEXEC flags"
to determine further whether the file should be duplicated.

This PR will further optimize file list duplicating to avoid the performance
regression caused by additional file operations.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-11-16 07:30:36 -08:00
chao an 342a6bb676 sched/task: ignore return value of nxspawn_close()
Closing an invalid file descriptor will not cause the action fail.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-11-16 07:30:36 -08:00
Ville Juven 0dedbcd4ae task/pthread_cancelpt: Move cancel point handling to libc, data to TLS
This moves task / thread cancel point logic from the NuttX kernel into
libc, while the data needed by the cancel point logic is moved to TLS.

The change is an enabler to move user-space APIs to libc as well, for
a coherent user/kernel separation.
2023-11-15 08:52:04 -08:00
chao an 64cf63475c arch/dumponexit: unify dump on exit to common code
remove arch implement and move to common code

Signed-off-by: chao an <anchao@xiaomi.com>
2023-11-15 08:28:25 -08:00
chao an 61aa2c36b6 misc/assert: restore assertion registers to array of last registers
Some assertions in extreme cases will cause syslog to be unable to
output logs normally, so this PR will restore the input registers
into the array of last registers to ensure that we can also obtain
some important informations.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-11-15 15:49:27 +01:00
Ville Juven b7b0a17682 sched/sem_holder.c: When accessing SEM_WAITLIST, use holder's addrenv
If the semaphore is shared, the holder has put its own mmapped address
to pholder->sem. This means we must switch to the holder's address
environment when going through the held semaphores list.

A better option would be to get the kernel mapped address for the
semaphore's physical page, but that mechanism is not functional yet.

This fixes a full system crash when CONFIG_PRIORITY_INHERITANCE=y and
CONFIG_BUILD_KERNEL=y and user makes shared semaphore via:

int semfd  = shm_open("sem", O_CREAT | O_RDWR, 0666);
sem_t *sem = mmap(0, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED, semfd, 0);
2023-11-15 03:45:15 -08:00
Petteri Aimonen 1825f9534c adjtime: Rewrite implementation to work for RTC and tickless kernel
Previous adjtime() implementation was limited to adjusting system
timer tick period. This commit reimplements the internals to use
a kernel watchdog timer. Platform-independent part of the code now
works also for adjusting hires RTC and tickless timer rate.

User code facing API is unchanged. Architecture code API has changed:
up_adj_timer_period() is replaced by up_adjtime().

Other improvements:

- Support query of remaining adjustment by passing NULL to first
  argument of adjtime(). This matches Linux behavior.

- Improve resolution available for architecture driver, previously
  limited to 1 microsecond per tick. Now 1 nanosecond per second.
2023-11-14 19:47:40 -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
raiden00pl ffc5434a8c sched/Kconfig: RW_SPINLOCK depends on SPINLOCK 2023-11-05 12:11:28 +08:00
raiden00pl 34476b497f sched/semaphore/spinlock.c: cosmetics 2023-11-05 12:11:28 +08:00
yinshengkai d0a5489ac5 sched: explicitly select the cpuload clock source configuration
Different configurations require different dependencies.
Explicitly select dependencies to avoid automatically selecting inappropriate configurations.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-11-01 09:27:56 +08:00
Ville Juven e935bc53bb task/task_spawnparms.c: Set the new process's signal mask
Set the newly spawned process's signal mask, if the caller has instructed
to do so by setting POSIX_SPAWN_SETSIGMASK.

This is called after the task has been created but has NOT been started
yet.
2023-10-30 22:30:03 +08:00
Ville Juven 6e9e215943 sched/task: Remove spawn_proxyattrs as obsolete implementation
Like the name implies, it is supposed to set the spawn attributes for
the NuttX specific "spawn proxy task" which was historically used as
a proxy to spawn new tasks. The proxy handled file actions and the signal
mask which are inherited from the parent.

The proxy task does not exist anymore, thus the proxy task attributes
do not need to be set anymore either.

Also, the function is currently still used, but the signal mask is set
for the spawning process, not the proxy process, and this is most
DEFINITELY an error (as the spawning process's signal mask changes
unexpectedly).

Setting the signal mask for the newly spawned process is simple, just
set it directly, if instructed to do so. This will be done in a later
patch!
2023-10-30 22:30:03 +08:00
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