2207 Commits

Author SHA1 Message Date
Jukka Laitinen
156469f158 Clean up the nxmutex library
- Remove the redundant holder, as nxsem now manages hoder TID
- Remove DEBUGASSERTIONS which are managed in nxsem
- Remove the "reset" handling logic, as it is now managed in nxsem
- Inline the simplest functions

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-05-08 16:00:05 +08:00
Jukka Laitinen
ffb49a25fb Enable mutex fast path for sem_wait and nxsem_wait also when priority inheritance is enabled
This enables the mutex fast path for nxsem_wait, nxsem_trywait and nxsem_post also when
the priority inheritance is enabled.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-05-08 16:00:05 +08:00
Jukka Laitinen
b6f2729730 Integrate nxmutex support fully into nxsem
This puts the mutex support fully inside nxsem, allowing
locking the mutex and setting the holder with single atomic
operation.

This enables fast mutex locking from userspace, avoiding taking
critical_sections, which may be heavy in SMP and cleanup
of nxmutex library in the future.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-05-08 16:00:05 +08:00
ouyangxiangzhen
fb592064cb sched: Improved the wdog and wq list insertion.
For the watchdog list and the workqueue list, we wonder whether the list head has changed after the insertion. In the original implementation, we have to access the list->next field and compare the result to the currently inserted node. In this commit, we mark the list head before the insertion and comparing the current traversed node with the list head we marked, which can avoid accessing the list->next and is more cache-friendly.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-07 02:02:10 +08:00
ouyangxiangzhen
6f72f5481d sched/wqueue: Refactor delayed and periodical workqueue.
This commit refactors the logic of workqueue processing delayed and periodic work, and changes the timer to be set in `work_thread`. The improvements of this change are as follows:
- Fixed the memory reuse problem of the original periodic workqueue implementation.
- By removing the `wdog_s` structure in the `work_s` structure, the memory overhead of each `work_s` structure is reduced by about 30 bytes.
- Set the timer for each workqueue instead of each work, which improves system performance.
- Simplified the workqueue cancel logic.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-07 02:02:10 +08:00
ouyangxiangzhen
9dbb9b49c6 sched/wqueue: Change dq to list.
In NuttX, the dq and the list are two different implementations of the double-linked list. Comparing to the dq, the list implementation has less branch conditions such as checking whether the head or tail is NULL. In theory and practice, the list is more friendly to the CPU pipeline. This commit changed the dq to the list in the wqueue implementation.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-07 02:02:10 +08:00
ouyangxiangzhen
900b1c19dd wqueue: improve the robustness of the work
struct work_s
{
  union
  {
    struct
    {
      struct dq_entry_s dq;      /* Implements a double linked list */
      clock_t qtime;             /* Time work queued */
    } s;
    struct wdog_s timer;         /* Delay expiry timer */
    struct wdog_period_s ptimer; /* Period expiry timer */
  } u;
  worker_t  worker;              /* Work callback */
  FAR void *arg;                 /* Callback argument */
  FAR struct kwork_wqueue_s *wq; /* Work queue */
};

work_cancel() should determine whether the current work is
in the timer or has already entered the queue.
This judgment is indispensable because the structure is a union.
Whether it is interpreted as a timer or as a dq needs to be determined.

But this judgment seriously depends on the order of struct wdog_s and
struct dq_entry_s, once someone change the order of any, there is a bug.
So we decide remove the union, to improve the robustness.

For the work_s structure size will grow bigger, then we will provide a
another optimization patch

Signed-off-by: ligd <liguiding1@xiaomi.com>
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-07 02:02:10 +08:00
Lars Kruse
bacc6bec37 fix(locale): misspelled "February" string (nl_langinfo) 2025-05-05 09:32:31 +08:00
rongbaichuan
ee3e2401e7 libc/backtrace: Fix compilation error when set LIBC_BACKTRACE_BUFFSIZE
When compiling lib_backtrace.c after set CONFIG_LIBC_BACKTRACE_BUFFSIZE,
there will be compilation error warnings. This is because spin_unlock_irqrestore
incorrectly used pool->lock during unlocking, which has been corrected to bp->lock.

Signed-off-by: Baichuan Rong <rongbaichuan1027@163.com>
2025-05-05 09:29:26 +08:00
Michal Lenc
eeb4a0de83 setlogmask: fix setlogmask behavior according to POSIX standard
POSIX states "If the maskpri argument is 0, the current log mask is
not modified." The current implementation in NuttX doesn't
respect this and thus is in a clear violation with a strict POSIX
compliance rule in The Inviolable Principles of NuttX.

This commit therefore changes the behavior to the expected one. Passing
argument 0 doesn't change the current log mask, but just returns the
old one. Completely disabling logging at runtime is thus not possible,
but you may set the highest priority LOG_EMERG only to disable most of
the messages. Default can still be set to no logging with
CONFIG_SYSLOG_DEFAULT_MASK configuration option.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2025-05-02 16:29:08 +02:00
Tiago Medicci Serrano
40c6af6dec Revert "libs/libc/semaphore: Fix DEBUGASSERTS"
This reverts commit 300992203ac0a14602c8cf744ec87d5525fe4dfb to
fix a problem with `esp32-devkitc:blewifi`, which fails to boot up
if `CONFIG_DEBUG_ASSERTIONS=y`.

Introduced by https://github.com/apache/nuttx/pull/16176 with the
following description:

> The DEBUGASSERTS in nxsem_wait and nxsem_trywait are
non-functional, they don't check anything. These were broken in
previous commits.

The above statements are not valid. Originally, there was no
problem calling `nxsem_trywait` from the interrupt and the
`DEBUGASSERT` simply checked a corner case: if ran from the
interrupt context, the current (interrupted) task may be the idle
task. This case is allowed only if called from an interrupt and
that's what the original commit checks with:

```
  DEBUGASSERT(!OSINIT_IDLELOOP() || !sched_idletask() ||
              up_interrupt_context());
```
2025-04-16 10:10:56 +08:00
Jukka Laitinen
300992203a libs/libc/semaphore: Fix DEBUGASSERTS
The DEBUGASSERTS in nxsem_wait and nxsem_trywait were non-functional, they
didn't check anything.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-04-11 16:13:06 +08:00
chao an
52482219c8 libc/elf: rename modlib to libelf
Renaming "modlib" to "libelf" is more in line with the implementation content,
which makes it easier for individual developers to understand the capabilities of this module.

CONFIG_LIBC_MODLIB -> CONFIG_LIBC_ELF

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-11 09:43:22 +08:00
chao an
59da455fea libs/libc/crc16: Separate implementation of crc16xmodem from crc16
keep default crc16 catalogue for CRC-16/XMODEM

Mapping crc16 implement to crc16xmodem

crc16     -> crc16xmodem
crc16part -> crc16xmodempart

- CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM
poly: 0x1021 initial seed: 0x0000, xor output: 0x0000

: width=16
: poly=0x1021
: init=0x0000
: refin=false
: refout=false
: xorout=0x0000
: check=0x31c3
: residue=0x0000
: name="CRC-16/XMODEM"

https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-xmodem

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-10 16:47:28 +08:00
anjiahao
297a1cb1fe armv7a:need initialize constructor and destructor on crt0
The C++ constructor and destructor need to be executed in crt0

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-04-09 23:07:29 +08:00
Ville Juven
04e760b1c2 sched/gettid: Move thread ID to TLS
There is no need for a gettid() syscall, as the thread ID is stable through
the life of the process. It is safe to put a copy of TID to TLS. This way
a user processes can access TID quickly via its own stack, instead of
having to use an expensive syscall.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
2025-04-08 22:53:10 +08:00
Jukka Laitinen
84cb21791f libc/semaphore: Read semaphore value by using NXSEM_COUNT macro
We should not access semaphore internals directly outside sched/semaphore.

Just read it via the NXSEM_COUNT macro provided.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-04-08 16:12:17 +08:00
chao an
53836fc18a libs/libc/crc16: add support of CRC-16/ANSI(aka CRC-16/IBM)
Compatible CRC16 with Linux Kernel:
https://github.com/torvalds/linux/blob/master/lib/crc16.c

- CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/KERMIT
poly: 0x8005 (0xA001) initial seed: 0x0000, xor output: 0x0000

: width=16
: poly=0x8005
: init=0x0000
: refin=true
: refout=true
: xorout=0x0000
: check=0xbb3d
: residue=0x0000
: name="CRC-16/ARC"

https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-arc

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-07 12:10:05 +08:00
chao an
921ffc7319 libs/libc/crc16: move crc16 table to rodata
move crc16 table from data to rodata

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-07 09:02:01 +08:00
chao an
4e2f6eabb3 libs/libc/crc16: add some comments for crc16ccitt
The search table of ccitt should describe more algorithm details:

- CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-16/KERMIT
initial seed: 0x0000, xor output: 0x0000

: width=16
: poly=0x1021
: init=0x0000
: refin=true
: refout=true
: xorout=0x0000
: check=0x2189
: residue=0x0000
: name="CRC-16/KERMIT"

https://reveng.sourceforge.io/crc-catalogue/16.htm#crc.cat.crc-16-kermit

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-07 09:02:01 +08:00
Jinliang Li
d5db7d1cee libc/arm: optimize crc32/crc32c for arm
Optimize crc32 standard(poly:0x04C11DB7) and crc32
castagnoli(poly:0x1EDC6F41) with arm crc32 extension instructions.

For example, crc32 standard caculates(lookup crc32 table) 1812 bytes data,
reduced the time from 118 us to 14 us through optimization.

Performance improved ~700%

Signed-off-by: Jinliang Li <lijinliang1@lixiang.com>
2025-04-04 09:51:50 -03:00
chao an
0d6de4c0a7 sched/mutex: add ticked lock version for mutex/rmutex
Added ticked lock version for mutex to reduce time calculation overhead

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-03 20:13:55 +08:00
ouyangxiangzhen
9f01e5c972 libc/stream: Support lowsyslog.
This commit added support for lowsyslog.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-04-02 12:01:46 +08:00
Jukka Laitinen
19a8e2403f libc/semaphore: Move fast mutex wait/post paths to libc
This avoids unnecessary syscalls in memory protected builds, when mutex
lock/unlock can be done with only atomic counter access

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-04-01 20:37:23 +08:00
raiden00pl
c4f142e45c syslog: add an option to completely disable syslog logic
Add an option to completely disable syslog() and replace it with an empty functions.
This option can be useful for small systems when we don't have any logging support,
but compiler is not able to remove useless code.

This way the final image also won't contain the strings that are present in
syslog() calls when compiler optimization is enabled (for example from /boards
where syslog is often used instead of debug macros).

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-03-30 11:36:19 +08:00
simbit18
35a793ed17 [nxstyle] fix Relative files path
fix Relative file path does not match actual file.

Signed-off-by: simbit18 <simbit18@gmail.com>
2025-02-21 15:36:05 +01:00
chao an
ff1dc9583f libc/libcxx: fix failures with GCC 14
CXX:  libcxx/libcxx/src/random.cpp In file included from nuttx/include/libcxx/__filesystem/filesystem_error.h:15,
                 from nuttx/include/libcxx/__filesystem/directory_entry.h:20,
                 from nuttx/include/libcxx/filesystem:539,
                 from nuttx/include/libcxx/fstream:192,
                 from libcxx/libcxx/src/ios.instantiations.cpp:10:
nuttx/include/libcxx/__filesystem/path.h: In instantiation of 'std::__1::__fs::filesystem::path::_EnableIfPathable<_Source> std::__1::__fs::filesystem::path::append(const _Source&) [with _Source = std::__1::basic_string<char>]':
nuttx/include/libcxx/__filesystem/path.h:623:30: error: use of built-in trait '__remove_pointer(typename std::__1::decay<_Tp>::type)' in function signature; use library traits instead
  623 |   _EnableIfPathable<_Source> append(const _Source& __src) {
      |                              ^~~~~~

Pick the change from llvm-project:

https://github.com/llvm/llvm-project/pull/92663

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-02-20 08:46:25 +01:00
chao an
1d383a243f libs/libnx: do not generate resource if CONFIG_NX is not enabled
To avoid generate resource if CONFIG_NX is disabled:
| $ make -j12
| Create version.h
| CPP:  nxfonts_convert.c-> nxfonts_convert_8bpp.i
| CPP:  nxfonts_convert.c-> nxfonts_convert_24bpp.i

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-02-20 08:45:05 +01:00
Jukka Laitinen
18c3e76c55 libs/libc/modlib/modlib_bind.c: Fix system crash if modlib_bind fails
Addrenv is changed to the newly created process' one in the beginning of
modlib_bind, and needs to be changed always when returning from the function;
also in error cases.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-02-14 09:39:56 +08:00
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
cuiziwei
b57f3bb840 Fix macOS build error.
1. fix https://github.com/apache/nuttx/issues/14774.
Change the defconfig of libcxxtest and select libcxxabi by default to
fix sim:libcxxtest build in macOS CI can't find cxxabi.h.

2. fix https://github.com/apache/nuttx/issues/15491.
libcxxabi cannot be used with uclibc, so when compiling macos sim, libcxxabi cannot be selected by default in Kconfig.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2025-02-12 15:24:02 -03:00
Neo Xu
28cf56ce4f gdbstub: fix memory binary upload on latest GDB
GDB release 16.2 recently to fix the incompatibility issue with LLDB.
For us, the only change is stub must report it support feature 'binary-upload' before GDB will use this feature.
For more information, find bug report and discussion in https://sourceware.org/bugzilla/show_bug.cgi?id=32593

Use GDB 16.2, now it works with binary upload.
```
  [remote] Sending packet: $x39c,4#a7
  [remote] Received Ack
  [remote] Packet received: b\000\203
```

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2025-02-09 11:45:43 +08:00
Tiago Medicci Serrano
fdc0b608b5 libc/wcsrtombs: Fix the wcsrtombs() according to the POSIX standard
According to https://pubs.opengroup.org/onlinepubs/9799919799/, the
expected behavior for the wcstombs() function is that it should
convert the wide-character codes stoping conversion either when a
character sequence exceeds the limit of n total bytes or if a null
byte is stored. In the first case, the null-terminated value should
not be appended to the dst buffer.

Currently, no null-terminator is appended to the dst buffer, even
when it's expected to be appended, generating erroneous output.
2025-02-06 10:24:55 +01: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
Yanfeng Liu
944f6ceeec libc/modlib: guard modname field usage
This guards `.modname` field usage with same condition as header
definitions.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-01-22 20:29:07 +08:00
Neo Xu
ec9b079c04 arch/x86-64: fix cmake compile error
-- Configuring done
CMake Error at cmake/nuttx_add_library.cmake:142 (add_library):
  Cannot find source file:

    /vela/nuttx/libs/libc/machine/x86_64/arch_elf.c
Call Stack (most recent call first):
  libs/libc/CMakeLists.txt:22 (nuttx_add_kernel_library)

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2025-01-22 16:35:32 +08:00
xuxingliang
dc3ab55e6d libc/gdbstub: avoid RLE decoding special characters
Read/write special data like 0x2a2a2a2a will trigger this issue.
The current GDB implementation has this flaw. GDB processes the RLE
decoding before espaping the data, make it impossible to repeate special
characters.

The details can be seen in GDB source code remote.c
remote_target::read_frame function.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-01-21 18:26:42 +08:00
xuxingliang
03765a6a1e libc/gdbstub: add memory binary read support
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-01-21 18:26:42 +08:00
xuxingliang
b1d0b5a4d6 libc/gdbstub: support binary data sent from stub
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-01-21 18:26:42 +08:00
Tim Kan(SSS)
4dd042d00b fix(libc): lib_strftime %F month number off-by-one
Corrects the month number output for the %F format specifier in lib_strftime.
2025-01-21 18:24:35 +08:00
xuxingliang
e5a7f55d9f libc/gdbstub: use rawsyslog for debug log
To avoid new line for every character.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-01-21 01:59:35 +08:00
xuxingliang
ef27bcb34f libc/gdbstub: fix typos
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-01-21 01:59:35 +08:00
Ville Juven
1a9241ca1c pthread_barrier_destroy: Fix return value, if sem_getvalue fails
sem_getvalue returns ERROR and sets errno if it fails, we don't want to
return OK in this case, we want to return the non-negated error number.
2025-01-20 23:55:26 +08:00
Ville Juven
516d1c069a pthread_conddestroy: Fix return value, if sem_getvalue fails
sem_getvalue returns ERROR and sets errno if it fails, we don't want to
return OK in this case, we want to return the non-negated error number.
2025-01-20 23:55:26 +08:00
Xiang Xiao
92e884bee2 libc: Rename LIBC_STRING_OPTIMIZE to LIBC_NEWLIB_OPTSPEED
and correct the dependence

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-01-20 22:27:19 +08:00
lipengfei28
d3e3993682 arch/riscv: use UP_DSB, UP_DMB, UP_ISB as barrier standard API
Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
2025-01-20 20:13:07 +08:00
lipengfei28
2d1af01d44 mem barrier: use UP_DMP UP_DSP as barriers standard API
Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
2025-01-20 20:13:07 +08:00
Neo Xu
afe90db5c4 gdbstub: change send buffer to const char
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2025-01-20 20:07:13 +08:00
Yanfeng Liu
1b369544ca modlib/gnu-elf.ld.in: fix regression with armv7a
As armv7-a addrenv layout is not in line with other archs, we need
align it with others by defining ARCH_DATA_RESERVE_SIZE as same as
MM_PGSIZE for now to keep gnu-elf.ld.in unified.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-01-17 23:16:26 +08:00
Huang Qi
bac2df6bc8 risc-v: replace fence.i with __ISB for instruction sync
Summary:
- Replace direct use of `fence.i` instruction with `__ISB()` macro for instruction synchronization
- This change improves portability while maintaining the same functionality

Impact:
- No functional changes - both `fence.i` and `__ISB()` ensure instruction
synchronization on RISC-V
- Makes the code more maintainable by using the architecture abstraction
layer

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-17 09:04:45 +08:00