Commit graph

2853 commits

Author SHA1 Message Date
hujun5
f22b93b337 sched/spin_lock: rename raw_spin_lock to spin_lock_notrace
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-02-13 20:48:15 +08:00
hujun5
ac26f9c690 Revert "sched/wqueue: some minor improve to reduce sched_lock range"
This reverts commit 2779989add.
2025-02-13 20:48:15 +08:00
Xiang Xiao
45422e2ad9 Revert "No need to call sched_lock explicitly after call spin_lock_irqsave, since it will be called in func spin_lock_irqsave."
This reverts commit 8f3a2a6f76.
2025-02-13 14:15:43 +08:00
Michal Lenc
0ae633cc08 clock/clock_adjtime.c: fix compile errors
The missing <nuttx/spinlock.h> header caused following compile errors:

CC:  clock/clock_adjtime.c clock/clock_adjtime.c: In function 'adjtime_wdog_callback':
clock/clock_adjtime.c:67:11: error: implicit declaration of function 'spin_lock_irqsave' [-Wimplicit-function-declaration]
   67 |   flags = spin_lock_irqsave(&g_adjtime_lock);
      |           ^~~~~~~~~~~~~~~~~
clock/clock_adjtime.c:78:3: error: implicit declaration of function 'spin_unlock_irqrestore' [-Wimplicit-function-declaration]
   78 |   spin_unlock_irqrestore(&g_adjtime_lock, flags);

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2025-02-06 09:22:44 +08:00
wangzhi16
8f3a2a6f76 No need to call sched_lock explicitly after call spin_lock_irqsave, since it will be called in func spin_lock_irqsave.
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
2025-01-24 17:27:50 +08:00
Neo Xu
1ab1a6eaf3 arch: select LIBC_ARCH_ELF when using COREDUMP
Coredump doens't need CONFIG_ELF to be enabled, but need elf.h to include correct elf32.h or elf64.h.
Select LIBC_ARCH_ELF in COREDUMP to allow LIBC_ARCH_ELF_64BIT to be
defined correctly.

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2025-01-24 09:37:58 +08:00
wanggang26
f6b9a8f577 coredump: fix issue that nvic region overlapped by board memory region
Firstly call arm_coredump_add_region in up_initialize to add nvic region, then call
coredump_set_memory_region to add board mem region, at this moment, an overlap occurs.

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2025-01-24 09:15:56 +08:00
xuxingliang
ba18502b93 misc/coredump: move coredump info to note
Add a custom note for NuttX information including magic and coredump
file data size, so when system reboots, we can check if the block device
contains valid coredump file, and save it to file system.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-01-24 09:12:59 +08:00
hujun5
914ae532e6 sched: remove csection and reduce the interrupt disabling time in sched_[un]lock
reason:
1 Accelerated the implementation of sched_lock, remove enter_critical_section in sched_lock and
only enter_critical_section when task scheduling is required.
2 we add sched_lock_wo_note/sched_unlock_wo_note and it does not perform instrumentation logic

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-23 19:58:49 +08:00
hujun5
b49f4286fb spinlock: Due to semantic inconsistency, remove/rename some functions with the _wo_note suffix.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-23 19:58:49 +08:00
liwenxiang1
7eccf4493a arch/x86_64:Adapt coredump
Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
2025-01-22 16:35:32 +08:00
Ville Juven
bb85ad849e pthread_cond_wait: Use atomic_t to protect the waiter count
The load/compare and RMW to wait_count need protection. Using atomic
operations should resolve both issues.

NOTE:
The assumption that the user will call pthread_cond_signal /
pthread_cond_broadcast with the mutex given to pthread_cond_wait held is
simply not true. It MAY hold it, but it is not forced. Thus, using the
user space lock for protecting the wait counter as well is not valid!

The pthread_cond_signal() or pthread_cond_broadcast() functions may be called by a thread whether or not it currently owns the mutex that threads calling pthread_cond_wait() or pthread_cond_timedwait() have associated with the condition variable during their waits; however, if predictable scheduling behaviour is required, then that mutex is locked by the thread calling pthread_cond_signal() or pthread_cond_broadcast().

[1] https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_signal.html
2025-01-20 23:55:26 +08:00
wanggang26
1fd21bbd69 coredump: fix crash dump failed when items of pr_regs not equal with regs_num
elf_emit_tcb_note: nitems(status.pr_regs) is 18, g_tcbinfo.regs_num is 17, then g_tcbinfo.reg_off.p[17] has been out of bounds

Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2025-01-19 19:43:53 +08:00
hujun5
3193457dd0 sched/timer: remove critical section in setitimer
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-19 17:08:32 +08:00
hujun5
fcfc300f7a group: use tg_mutex to replace tg_joinlock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-19 17:08:32 +08:00
hujun5
544da3c64c sched/timer: remove critical section in timer_deleteall
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-19 17:08:32 +08:00
chao an
2779989add sched/wqueue: some minor improve to reduce sched_lock range
Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-17 23:33:23 +08:00
raiden00pl
d4a0abec82 sched/mqueue/CMakeLists.txt: fix compilation for CONFIG_DISABLE_MQUEUE_SYSV=n
fix compilation for CONFIG_DISABLE_MQUEUE_SYSV=n in cmake
2025-01-17 23:14:39 +08:00
hujun5
b8660fc39c sim: fix regression from https://github.com/apache/nuttx/pull/14623
reason:
work_timer_expiry may be called in thread context

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-17 18:59:29 +08:00
chao an
67582acc14 sched/wqueue: fix potential deadlock
sched_unlock() should called after spin_unlock

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-17 09:05:37 +08:00
chao an
8877366c0e sched/wdog: remove wd_cancel_irq() implement
we do not need this implement after change the lock from csec to spin_lock

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-17 09:05:11 +08:00
chao an
dedb57cb2d libc/unistd: move NAME_MAX/LINE_MAX/PATH_MAX define to unistd
These options are unistd-specific and should not be filesystem dependent,
and also not suitable for define in the sched directory.

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-15 23:17:51 +08:00
hujun5
61f0c97193 wqueue: wqueue remove csection
reason:
We decouple semcount from business logic
by using an independent counting variable,
which allows us to remove critical sections in many cases.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-15 17:26:07 +08:00
hujun5
9dad781d07 sched/wdog: use small lock to protect g_wdactivelist
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-14 12:29:29 +08:00
hujun5
684ddc6ada irq: enter_critical_section_wo_note/leave_critical_section_wo_note
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-14 12:29:29 +08:00
chao an
5dedc0119f sched/clock: remove unlock logic to avoid relock
get time spec before protect g_basetime

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-13 19:11:49 -03:00
hujun5
daebf4c8b7 Revert "sched: misc: Remove sched_lock in _assert()"
reason:
This reverts commit d0820acbbb
assert will call syslog

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-14 00:52:10 +08:00
hujun5
699b23fa19 sched_processtimer: use atomic to protect g_timer_interval and g_timer_tick
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-14 00:27:13 +08:00
hujun5
5f4a15b690 pthread: remove enter_critical_section in pthread_mutex
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 22:30:35 +08:00
hujun5
19bca74c7c clock_adjtime: use small lock to protect g_adjtime_ppb g_adjtime_wdog
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 22:07:15 +08:00
hujun5
a2d4d74af7 clock_timekeeping: remove enter_critical_section in sched/clock/clock_timekeeping.c
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 16:51:40 +08:00
wangmingrong1
2149d89336 macro/align: Use ALIGN_UP and ALIGN_DOWN uniformly
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-12 16:48:35 +08:00
hujun5
4bd8d9eac7 sched: remove spin_lock_irqsave(NULL) support
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-10 22:35:14 +08:00
Huang Qi
cfd0cc0d1a Remove duplicate includes across multiple files
This commit cleans up redundant header file includes throughout the codebase.
 The changes include:

 - Removing duplicate #include directives that were present in the same file
 - Consolidating includes that were split across multiple lines unnecessarily
 - Removing unused includes that were no longer needed
 - Fixing some formatting issues with includes

 The changes improve code organization and maintainability by:
 - Reducing unnecessary dependencies
 - Making include dependencies more explicit
 - Following consistent include patterns
 - Removing dead code

 No functional changes are made - this is purely a code cleanup commit.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-09 23:30:23 +08:00
hujun5
57e54b399b sched: remove all spin_lock_irqsave(NULL)
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-06 23:11:44 +08:00
hujun5
4d63921f0a use atomic operation for g_system_ticks
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-05 12:01:16 +08:00
wangzhi16
893c5e92c2 Reduce the size of tcb by four bytes.
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
2025-01-02 23:18:42 +08:00
chao an
27a03b8278 sched/semaphore: tick wait 0 timeout should be safe in interrupt context
1. remove up_interrupt_context() check, which should be safe in interrupt context
2. remove sem instance check will be handle in nxsem_trywait()

Signed-off-by: chao an <anchao@lixiang.com>
2024-12-30 12:02:34 +08:00
Ville Juven
e19e1a8532 nxsem_destroyholder: Use critical section when destroying holder(s)
Otherwise the free holder list will leak, causing either a crash due to
holder->htcb = NULL, or the free holder list becomes (erroneously) empty
even though most of the holder entries are free.
2024-12-27 00:28:34 +08:00
chao an
54e85075c4 sched/event: init deleted node to avoid null pointer reference
nxevent_tickwait() will remove the node in failure case(EINTR). If the node
has been deleted in the nxevent_post(), NULL pointer reference will
be triggered after semaphore wait.

Signed-off-by: chao an <anchao@lixiang.com>
2024-12-26 23:28:37 +08:00
zhangshoukui
f8377f8666 Add LINE_MAX configuration
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-12-26 13:25:19 +08:00
Ville Juven
ea020a4eae sem_holder.c: Replace addrenv_select with kmm_map for holder sem access
The holder list can be modified via interrupt so using addrenv_select is
not safe. Access the semaphore by mapping it into kernel virtual memory
instead.
2024-12-18 08:57:01 +08:00
Ville Juven
510d9659b4 sem_waitirq: Use kmap interface to access the semaphore
The temporary mappings via addrenv_select() and addrenv_restore() simply
do not work from interrupt, so remove its usage and replace with kmap
which is safe.
2024-12-18 08:57:01 +08:00
hujun5
f301524cb9 sem: remove the additional assignment.
reason:
running tcb->waitobj should be NULL

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-12 22:01:50 +08:00
chao an
cafdcb1eb0 sched/clock: cleanup g_system_ticks reference if arch timer is enabled
continue work of: https://github.com/apache/nuttx/pull/15139

Signed-off-by: chao an <anchao@lixiang.com>
2024-12-12 09:52:07 +01:00
ligd
4a51c21afc sched/clock: call up_timer_gettime() to get higher resolution
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-12-12 14:47:02 +08:00
zhangyuan29
b74a50775f sem: change sem wait to atomic operation
Add sem_wait fast operations, use atomic to ensure
atomicity of semcount operations, and do not depend
on critical section.

Test with robot:
before modify:
nxmutex_lock cost: 78 ns
nxmutex_unlock cost: 82 ns

after modify:
nxmutex_lock cost: 28 ns
nxmutex_unlock cost: 14 ns

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-12-10 22:00:42 +08:00
hujun5
bc844509e2 addrenv: Ensure that the transmission parameter of addrenv_switch is not NULL
reason:
avoid obtaining this_task multiple times.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-04 14:20:12 +08:00
wangmingrong1
2aaf6641a2 Fix compile error
'ret' may be used uninitialized

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-12-02 11:32:48 +08:00
buxiasen
7a4fac0df6 coredump: add BOARD_CRASHDUMP_CUSTOM support
For only board specific crashdump and no syslog/blk/mtd coredump

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-11-30 03:08:35 +08:00