Commit Graph

612 Commits

Author SHA1 Message Date
GuEe-GUI d8db49c17a [COMPILER/FEATURE] Support rt_packed
__ARMCC_VERSION:         https://smtp.keil.com/support/man/docs/armcc/armcc_chr1359124980173.htm
__IAR_SYSTEMS_ICC__:     <Not Found>
__GNUC__:                https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute
__ADSPBLACKFIN__:        <Not Found>
_MSC_VER:                https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-170
__TI_COMPILER_VERSION__: https://software-dl.ti.com/codegen/docs/tiarmclang/rel1_3_0_LTS/migration_guide/migrating_c_and_cpp_source/pragmas_and_attributes.html
__TASKING__:             https://resources.tasking.com/sites/default/files/2021-02/TASKING_Alignment%20Requirements%20Restrictions_WEB.pdf

Usage:
```c
rt_packed(struct object1
{
    int dword;
    char byte;
});
typedef struct object1 object1;

rt_packed(struct object2
{
    int dword;
    char byte;
});
```

Signed-off-by: GuEe-GUI <2991707448@qq.com>
2024-11-04 10:10:15 +08:00
Shell 2f6d98bfcb feat: smp_call: added signaling call_req
This patch introduces `rt_smp_call_request` API to handle queued
requests across cores with user provided data buffer, which provides a
way to request IPI through a non-blocking pattern.

It also resolved several issues in the old implementation:
- Multiple requests from different cores can not be queued in the work
  object of the target core.
- Data racing on `rt_smp_work` of same core. If multiple requests came
  in turns, or if the call is used by the target cpu, while a new
  request is coming, the value will be overwrite.
- Memory vulnerability. The rt_smp_event is allocated on stack, though
  the caller may not wait until the call is done.
- API naming problem. Actually we don't provide a way to issue an IPI to
  ANY core in mask. What the API do is aligned to MANY pattern.
- FUNC_IPI registering to PIC.

Changes:
- Declared and configured the new `RT_SMP_CALL_IPI` to support
  functional IPIs for task requests across cores.
- Replaced the single `rt_smp_work` array with `call_req_cores` to
  manage per-core call requests safely.
- Added `_call_req_take` and `_call_req_release` functions for atomic
  handling of request lifetimes, preventing data race conditions.
- Replaced single event handling with a queue-based approach
  (`call_queue`) for efficient multi-request processing per core.
- Introduced `rt_smp_call_ipi_handler` to process queued requests,
  reducing IPI contention by only sending new requests when needed.
- Implemented `_smp_call_remote_request` to handle remote requests
  with specific flags, enabling more flexible core-to-core task
  signaling.
- Refined `rt_smp_call_req_init` to initialize and track requests
  with atomic usage flags, mitigating potential memory vulnerabilities.

Signed-off-by: Shell <smokewood@qq.com>
2024-11-03 10:08:45 +08:00
Shell 285fee9d4c feat: rtatomic: lockless single linked list
Signed-off-by: Shell <smokewood@qq.com>
2024-11-03 10:08:45 +08:00
Shell 40cd8cce99 feat: Added rt_interrupt_context* family for nested interrupt handling
These changes introduce the rt_interrupt_context family, providing a
mechanism for managing nested interrupts. The context management
ensures proper storage and retrieval of interrupt states, improving
reliability in nested interrupt scenarios by enabling context tracking
across different interrupt levels. This enhancement is essential for
platforms where nested interrupt handling is crucial, such as in real-
time or multi-threaded applications.

Changes:
- Defined rt_interrupt_context structure with context and node fields
  in `rtdef.h` to support nested interrupts.
- Added rt_slist_pop function in `rtservice.h` for simplified node
  removal in singly linked lists.
- Declared rt_interrupt_context_push, rt_interrupt_context_pop, and
  rt_interrupt_context_get functions in `rtthread.h` to manage the
  interrupt/exception stack.
- Modified AArch64 CPU support in `cpuport.h` to include
  rt_hw_show_register for debugging registers.
- Refactored `_rt_hw_trap_irq` in `trap.c` for context-aware IRQ
  handling, with stack push/pop logic to handle nested contexts.
- Implemented interrupt context push, pop, and retrieval logic in
  `irq.c` to manage context at the CPU level.

Signed-off-by: Shell <smokewood@qq.com>
2024-11-03 10:08:45 +08:00
KunYi Chen 6b7f1177de fix: suppress unused warnings when DEBUG disabled
When RT_USING_DEBUG is disabled, variables used only in RT_ASSERT
statements become unused, triggering -Wunused-but-set-variable compiler
warnings. These variables are essential for runtime assertions in debug
builds but appear unused in release builds.

Example:
- Variables used in RT_ASSERT(var != RT_NULL) checks
- Affects multiple drivers and components using RT_ASSERT

This is a general cleanup to improve code compilation without affecting
functionality.
2024-10-25 22:22:09 -04:00
heyuanjie87 1045bcb9df 给使用独立的defunct线程添加限制条件 2024-10-21 13:05:08 +08:00
heyuanjie87 2351981e83 分离defunct 2024-10-21 13:05:08 +08:00
Shell 645b3c6015 feat: remove RT_USING_SCHED_THREAD_CTX
Prepare for the next release by removing the compatible codes for v5.1.0
and before.

Changes:

- Remove the compatible macros and Kconfig options for the old struct
  rt_thread layout.

Signed-off-by: Shell <smokewood@qq.com>
2024-10-19 15:19:41 -04:00
Shell 588611d314 feat: includes: included kerrno.h in rtdef.h
Those definitions are presented in rtdef.h until PR #9461 moved them to
kerrno.h, which introduced unknown definition error for project building

Changes:

- Added includes of kerrno.h

Signed-off-by: Shell <smokewood@qq.com>
2024-09-25 21:03:48 -04:00
zhujiale 244cf61af6 SMP 2024-09-24 09:56:30 +08:00
zhujiale 512dae84be smp_ipi 2024-09-24 09:56:30 +08:00
Meco Man ee5014d32f [klibc] add kerrno.h 2024-09-23 21:30:37 +08:00
GuEe-GUI 802a6ed2ca [DM] Extended drivers MISC interface
1. RT_FIELD_PREP: prepare a bitfield element.
2. RT_FIELD_GET: extract a bitfield element.
3. rt_offsetof: member offset of a struct
4. rt_upper_32_bits: high 32 bits of value.
5. rt_lower_32_bits: lower 32 bits of value.
6. rt_upper_16_bits: high 16 bits of value.
7. rt_lower_16_bits: lower 16 bits of value.
8. rt_max_t: fix type of max(...).
9. rt_ilog2: integer logarithm base 2.

Signed-off-by: GuEe-GUI <2991707448@qq.com>
2024-09-06 17:45:03 -04:00
Shell dfd8ccf262 feat: kernel/libcpu: fit into ilp32d 2024-09-01 15:12:34 -04:00
Shell e9b683d0b3 feat: set RT_USING_STDC_ATOMIC to first priority
RT_USING_STDC_ATOMIC is a user selected option on current config system.
While the RT_USING_HW_ATOMIC is a forced option selected by Kconfig
under libcpu. And the RT_USING_STDC_ATOMIC will be meaningless if we set
RT_USING_HW_ATOMIC to first priority if the arch has hw-atomic.

Changes:
- set RT_USING_STDC_ATOMIC to first priority on rttypes.h

Signed-off-by: Shell <smokewood@qq.com>
2024-08-13 04:13:51 -04:00
zhao maosheng f543160ead fix rt_atomic_dec_and_test 2024-08-09 12:54:10 +08:00
wdfk-prog 8d3ad68caf [src][tick]rt_tick setting arbitrary value function is added to support low-power wake-up tick compensation 2024-07-19 11:51:39 +08:00
supperthomas b79d5013ff [doc][doxygen] Fix hook struct error.
Signed-off-by: supperthomas <78900636@qq.com>
2024-06-27 23:05:12 +08:00
supperthomas 14e4c45408 [doc][doxygen] Fix doxygen struct error.
Signed-off-by: supperthomas <78900636@qq.com>
2024-06-26 20:22:43 +08:00
zms123456 59193dfeeb
[timer]add all soft timer config (#9048)
* add all soft timer

* update wq

* add timer test

* shield LOG_D
2024-06-20 04:20:38 +08:00
Shell e5b7f3fdd8
[kservice] Enhance support for backtrace service (#9037)
[feat] Enhance support for backtrace service

rt_backtrace_formatted_print() and rt_backtrace_to_buffer() to help
debug routines.

Also, following modification are included:
- make rt_backtrace_frame patchable with weak attr
- replace lwp backtrace with sync output

Signed-off-by: Shell <smokewood@qq.com>
2024-06-13 08:55:53 +08:00
Shell 6ca327d8ce
[smart] add CPU/thread usage tracing config (#8947)
* [smart] add CPU usage tracing config

This patch introduces following features:

- Added CPU usage tracing functionality, enabled by default, for
  applications like 'top'
- update time as smart independent

Signed-off-by: Shell <smokewood@qq.com>

* fixup: add ump idle thread

---------

Signed-off-by: Shell <smokewood@qq.com>
2024-06-04 00:06:41 +08:00
GUI e7cddf3a52
[Feature] Support simple power domain API (#9005)
* [Feature] Power domain for device

1.Support device power on/off.
2.Support attach/detach device.
3.Support power domain driver api.

Signed-off-by: GuEe-GUI <2991707448@qq.com>

* [DM/platform] Enhanced platform bus

1.Add power domain for device.
2.Support `remove` and `shutdown` bus interface.

Signed-off-by: GuEe-GUI <2991707448@qq.com>

---------

Signed-off-by: GuEe-GUI <2991707448@qq.com>
2024-05-30 15:30:40 +08:00
Shell f17f994f8c
[arm64] add hw thread self (#8942)
* [libcpu] arm64: Add hardware thread_self support

This patch introduces hardware-based thread self-identification
for the AArch64 architecture. It optimizes thread management by
using hardware registers to store and access the current thread's
pointer, reducing overhead and improving overall performance.

Changes include:
- Added `ARCH_USING_HW_THREAD_SELF` configuration option.
- Modified `rtdef.h`, `rtsched.h` to conditionally include
  `critical_switch_flag` based on the new config.
- Updated context management in `context_gcc.S`, `cpuport.h`
  to support hardware-based thread self.
- Enhanced `scheduler_mp.c` and `thread.c` to leverage the new
  hardware thread self feature.

These modifications ensure better scheduling and thread handling,
particularly in multi-core environments, by minimizing the
software overhead associated with thread management.

Signed-off-by: Shell <smokewood@qq.com>

* fixup: address suggestion

* fixup: rt_current_thread as global

* scheduler: add cpu object for UP scheduler

Also, maintain the rt_current_thread in cpu object on UP scheduler.

---------

Signed-off-by: Shell <smokewood@qq.com>
2024-05-28 14:27:55 +08:00
Shell f2d6325b43
[smart] select console device dynamically (#8949)
* [smart] select console device dynamically

- Fixed compiler warning on terminal subsystem for
  `components/lwp/terminal/terminal.h`
- Updated default console setup to dynamically select an appropriate tty
  device based on the configured console device name.

Signed-off-by: Shell <smokewood@qq.com>

* fixup: remove useless codes

---------

Signed-off-by: Shell <smokewood@qq.com>
2024-05-17 13:19:00 +08:00
Yang Xijing f55187f830 [include/rtthread.h] rt_thread_close函数声明应当与RT_USING_HEAP无关 2024-05-11 13:42:27 -04:00
Shell 48bd0e49f2
[ipc] support of lockless rt_completion (#8887)
* [ipc] lockless rt_completion implementation

The new rt_completion implemented by lockless algorithm can improve timer resolution for up to ~12%, compare to sem IPC.

Signed-off-by: Shell <smokewood@qq.com>

* fixup: error

* remove useless changes

---------

Signed-off-by: Shell <smokewood@qq.com>
2024-05-08 09:25:57 +08:00
Shell 6977cf9101
[src] add rt_hw_cpu_id() wrapper API (#8894)
* [src] add rt_hw_cpu_id() wrapper API

rt_hw_cpu_id() is an unsafe API which should not be used by most codes
directly. It's error-prone because it must be used in proper context,
otherwise it can lead to errors and unpredictable behavior.

This patch adds a wrapper API for rt_hw_cpu_id() to address this risk.
It includes the context-checking functionality and provides a safer
alternative for obtaining CPU IDs, ensuring that it is used correctly
within the appropriate context.

Signed-off-by: Shell <smokewood@qq.com>

* fixup UMP

* update API & comment

* ci: cpp_check

---------

Signed-off-by: Shell <smokewood@qq.com>
2024-05-08 09:22:09 +08:00
zms123456 9112dffec8
[src][Kconfig]make RT_ASSERT independent of RT_USING_DEUBG 2024-05-06 20:40:30 -04:00
Shell 2c9b7c10b9
[kernel] add rt_thread_close()
* [thread] Add rt_thread_close()

This patch introduces a new function `rt_thread_close()` to enhances the
usability and maintainability by providing a dedicated mechanism for
closing threads.

- A new function `rt_thread_close()` is added to the API, providing a
  standardized approach for closing threads.
- The `rt_thread_close()` function removes a thread from the thread
  queue, updates its status to indicate closure, and performs the thread
  timer detaching which is a embedded timer in thread object.
- Additionally, the `rt_thread_detach()` function is modified to utilize
  `rt_thread_close()` internally, streamlining the thread detachment
  process.

Signed-off-by: Shell <smokewood@qq.com>
2024-05-01 00:49:09 -04:00
sp-cai 554632f1ee
[ipc] [dataqueue] 修复队列 pop 挂起的线程 push 无法恢复运行的错误 (#8839)
队列在 push 后查找挂起列表时使用了错误的挂起列表。
2024-04-22 20:20:35 +08:00
Meco Man d68e47eb25 [klibc] organize and renmae macros, and add CI check 2024-04-20 21:52:49 -04:00
Meco Man 792c3c0603 [kernel] move errno functions into klibc 2024-04-20 00:57:17 -04:00
Shell d1bb01621b fixup: add Kconfig option 2024-04-19 21:30:12 -04:00
Shell 8c4db32d04 fixup: debug 2024-04-19 21:30:12 -04:00
Shell 451ac03965 add cpu up 2024-04-19 21:30:12 -04:00
Shell 2aacba2c86 [src] Fixup UP irq_spinlock
Use scheduler lock in up irq_spinlock to avoid scheduling during spinlock.

Signed-off-by: Shell <smokewood@qq.com>
2024-04-19 21:30:12 -04:00
xiao-mang 84e6b3c393 fix for art-pi smart 2024-04-19 18:17:20 +08:00
xiao-mang 4de96450be fix for art-pi smart 2024-04-19 18:17:20 +08:00
zhao maosheng 24373e1ec3 add rt_hw_interrupt_uninstall declare in rthw 2024-04-18 22:08:08 -04:00
Meco Man a0735dcb11 upgrade RT-Thread version to v5.2.0 2024-04-16 23:04:24 -04:00
zms123456 6ad0b2bd09
[components][drivers]fix workqueue bug
fix workqueue bug
2024-04-15 23:15:37 -04:00
Shell ad9c20950f
[include] using signed atomic types 2024-04-11 18:48:54 -04:00
geniusgogo 48f83a5416
add subsys early init level (#8756)
Signed-off-by: geniusgogo <xpxyr@sina.com>
2024-04-10 23:55:58 +08:00
Shell 4b0f42c24a
[drivers/serial] Introduce hooker for TTY (#8733)
In this patch, a hook list has been introduced to address the concerns
regarding coupling issues arising from modifications to the serial code
for integrating TTY logic.

Signed-off-by: Shell <smokewood@qq.com>
2024-04-09 21:36:16 +08:00
Shell 83e95bdff4
sync smart & dfs (#8672)
Signed-off-by: xqyjlj <xqyjlj@126.com>
Signed-off-by: Shell <smokewood@qq.com>
Co-authored-by: xqyjlj <xqyjlj@126.com>
2024-03-28 23:42:56 +08:00
Shell f143ea2b31
[kernel] remove redundant _scheduler_stack_check 2024-03-20 22:26:41 -04:00
Meco Man e81978c5dc [kernel] move std libc related to rtklibc.h 2024-03-20 22:26:11 -04:00
Yuqiang Wang c0e632e56f Fixed an issue in mdk where macro definitions are not supported in the C99 specification 2024-03-20 22:43:55 +08:00
Meco Man e3a14a97a9
[kernel] fix warning of rt_thread_t struct (#8584) 2024-03-06 16:57:19 +08:00