Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions ports_smp/risc-v-common/readme_threadx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Eclipse ThreadX SMP on RISC-V GNU

RISC-V SMP contributions by
Eyck-Alexander Jentzsch, MINRES Technologies GmbH

Use THREADX_SMP=ON with THREADX_ARCH=risc-v32 or risc-v64 and
THREADX_TOOLCHAIN=gnu. The ports run in machine mode and require the A and
Zicsr extensions. RV32 supports ILP32 without hardware FP and ILP32D. RV64
supports LP64 without hardware FP, LP64F, and LP64D. The ports use a 32-bit
ULONG on both architectures and preserve native-width pointers.

Place kernel data and thread and system stacks in shared, coherent memory
that supports word atomic operations. An SMP debug build
(TX_THREAD_SMP_DEBUG_ENABLE) also needs a working rdtime instruction.

The context sources derive from the corresponding single-core GNU ports.
SMP adds per-hart kernel state, context publication and claiming, and
software interrupt wakeups.

Board integration
-----------------

The port uses mhartid directly as the ThreadX core index. It requires exactly
TX_THREAD_SMP_MAX_CORES participating harts, numbered consecutively from 0,
with hart 0 as the primary. Keep all other harts out of ThreadX. A missing
participating hart can stall initialization. Set the core count consistently
in the kernel and BSP builds.

Provide a separate, 16-byte-aligned system stack for each participating hart.
Hart 0 calls tx_kernel_enter(). Secondary harts call
_tx_thread_smp_initialize_wait() after the BSP has made C runtime initialization
visible to them.

Provide _tx_initialize_low_level() to initialize hart 0 and set
_tx_initialize_unused_memory and _tx_thread_system_stack_ptr[0]. Provide
_tx_riscv_smp_hart_initialize() to initialize local trap and interrupt handling
on secondary harts. The port calls it before scheduling begins with global
machine interrupts masked. Leave them masked on return.

Reuse the corresponding single-core GNU machine-mode trap entry. Take the
interrupt frame size from TX_RISCV_TRAP_FRAME_SIZE in the selected port's
tx_port.h.

Timer and interprocessor interrupts
-----------------------------------

On hart 0, acknowledge or rearm the timer and call _tx_timer_interrupt() at
TX_TIMER_TICKS_PER_SECOND. This advances the global tick and updates time
slices for all cores.

Provide _tx_thread_smp_core_preempt(UINT core) to send a reschedule interrupt
to the target hart. Ensure scheduler updates are visible before delivering the
interrupt. The target must acknowledge the interrupt before checking scheduler
state during context restore. With TX_ENABLE_WFI, the interrupt must wake an
idle hart.

The ready-token offset in each tx_port.h is a byte displacement for an
assembly atomic operation. After changing the control block, preceding
members, or thread and timer extensions, remeasure with the target compiler.
The port's C99 offset checks are built with the kernel and reject a mismatch.
32 changes: 32 additions & 0 deletions ports_smp/risc-v-common/tx_port_offset_check.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2026 Eclipse ThreadX contributors
* RISC-V SMP contributions by
* Eyck-Alexander Jentzsch, MINRES Technologies GmbH
* Portions of this file were generated with AI assistance.
* SPDX-License-Identifier: MIT
*/

#include <stddef.h>

#include "tx_api.h"

/* Keep hard-coded assembly displacements tied to the actual target C layout. */
typedef char tx_port_assert_ready_token_offset[
offsetof(TX_THREAD, tx_thread_smp_core_control) == TX_THREAD_SMP_LOCK_READY_BIT_OFFSET ? 1 : -1];
typedef char tx_port_assert_ready_token_atomic_width_and_alignment[
sizeof(((TX_THREAD *) 0)->tx_thread_smp_core_control) == 4 &&
TX_THREAD_SMP_LOCK_READY_BIT_OFFSET % 4 == 0 ? 1 : -1];
typedef char tx_port_assert_stack_ptr_offset[
offsetof(TX_THREAD, tx_thread_stack_ptr) == TX_RISCV_TCB_STACK_PTR ? 1 : -1];
typedef char tx_port_assert_stack_end_offset[
offsetof(TX_THREAD, tx_thread_stack_end) == TX_RISCV_TCB_STACK_END ? 1 : -1];
typedef char tx_port_assert_run_count_offset[
offsetof(TX_THREAD, tx_thread_run_count) == TX_RISCV_TCB_RUN_COUNT ? 1 : -1];
typedef char tx_port_assert_time_slice_offset[
offsetof(TX_THREAD, tx_thread_time_slice) == TX_RISCV_TCB_TIME_SLICE ? 1 : -1];
typedef char tx_port_assert_smp_protection_layout[
offsetof(TX_THREAD_SMP_PROTECT, tx_thread_smp_protect_in_force) == TX_RISCV_SMP_PROTECT_IN_FORCE &&
offsetof(TX_THREAD_SMP_PROTECT, tx_thread_smp_protect_core) == TX_RISCV_SMP_PROTECT_CORE &&
offsetof(TX_THREAD_SMP_PROTECT, tx_thread_smp_protect_count) == TX_RISCV_SMP_PROTECT_COUNT ? 1 : -1];
typedef char tx_port_assert_array_strides[
sizeof(ULONG) == 4 && sizeof(UINT) == 4 && sizeof(VOID *) == __riscv_xlen / 8 ? 1 : -1];
Loading