Test upstream RISC-V SMP candidates on HERE VP
Build the SMP library and Moonlight board support against a selectable ThreadX source tree. Keep the pinned regression matrix and add RV32GC and RV64GC context tests. Adapt the direct timeout fixture to the RV64 timer extension and give timing-sensitive cases more phase coverage on HERE VP.
This commit is contained in:
1 parent
f3dc14193c
commit
054251f810
12 files changed
+363
-251
No files matched your search
+33
-1
@@ -24,7 +24,10 @@ if(NOT THREADX_TEST_SIMULATOR)
|
||||
"THREADX_TEST_SIMULATOR is not set. Configure with -DTHREADX_TEST_SIMULATOR=/path/to/riscv-vp")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "risc-v32")
|
||||
if(ARCH_FLAGS MATCHES "-march=(rv(32|64)gc)")
|
||||
set(THREADX_TEST_ISA "${CMAKE_MATCH_1}_m")
|
||||
set(THREADX_TEST_FP_CONTEXT ON)
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "risc-v32")
|
||||
set(THREADX_TEST_ISA "rv32imac_m")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "risc-v64")
|
||||
set(THREADX_TEST_ISA "rv64imac_m")
|
||||
@@ -216,6 +219,18 @@ add_library(threadx_smp_regression_weak_defaults OBJECT
|
||||
function(add_threadx_regression_test TEST_SOURCE)
|
||||
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
||||
|
||||
if(TEST_NAME STREQUAL "threadx_thread_basic_execution_test")
|
||||
# This fixture calls _tx_thread_timeout directly. Use its existing pointer
|
||||
# setup on ports where ULONG cannot carry a thread pointer.
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${TEST_SOURCE}")
|
||||
file(READ "${TEST_SOURCE}" test_source_text)
|
||||
string(REPLACE "#if defined(_WIN64)\n {\n TX_TIMER_INTERNAL timeout_timer;"
|
||||
"#if defined(_WIN64) || defined(TX_TIMER_EXTENSION_PTR_DEFINED)\n {\n TX_TIMER_INTERNAL timeout_timer;"
|
||||
test_source_text "${test_source_text}")
|
||||
set(TEST_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.c")
|
||||
file(GENERATE OUTPUT "${TEST_SOURCE}" CONTENT "${test_source_text}")
|
||||
endif()
|
||||
|
||||
if(TEST_NAME STREQUAL "threadx_initialize_kernel_setup_test")
|
||||
set(test_libraries threadx_smp)
|
||||
else()
|
||||
@@ -249,6 +264,10 @@ function(add_threadx_regression_test TEST_SOURCE)
|
||||
-p tb.top.num_cores=4
|
||||
)
|
||||
set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 60)
|
||||
if(TEST_NAME STREQUAL "threadx_byte_memory_thread_contention_test")
|
||||
# The four-hart VP has to simulate more than 1,280 ticks of active work.
|
||||
set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 120)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
foreach(test_case ${TX_REGRESSION_CASES})
|
||||
@@ -259,3 +278,16 @@ add_custom_target(
|
||||
threadx_smp_regression_build
|
||||
DEPENDS ${TX_REGRESSION_TARGETS}
|
||||
)
|
||||
|
||||
if(THREADX_TEST_FP_CONTEXT)
|
||||
setup_target(vp_smp_context
|
||||
SOURCES vp_smp_context.c vp_smp_context_fp.S
|
||||
LIBRARIES threadx_smp_regression_weak_defaults threadx_smp)
|
||||
target_include_directories(vp_smp_context PRIVATE ${THREADX4TGFS_ROOT}/port/moonlight/inc)
|
||||
add_test(NAME vp_smp_context COMMAND ${THREADX_TEST_SIMULATOR}
|
||||
--isa=${THREADX_TEST_ISA}
|
||||
-f $<TARGET_FILE:vp_smp_context>
|
||||
-m 60s
|
||||
-p tb.top.num_cores=4)
|
||||
set_tests_properties(vp_smp_context PROPERTIES TIMEOUT 60)
|
||||
endif()
|
||||
@@ -59,6 +59,22 @@
|
||||
"CMAKE_BUILD_TYPE": "MinSizeRel",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Context32",
|
||||
"inherits": "Debug32",
|
||||
"binaryDir": "${sourceDir}/../../build/${presetName}/test/smp",
|
||||
"cacheVariables": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/../../cmake/rv32gc_gnu.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Context64",
|
||||
"inherits": "Debug",
|
||||
"binaryDir": "${sourceDir}/../../build/${presetName}/test/smp",
|
||||
"cacheVariables": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/../../cmake/rv64gc_gnu.cmake"
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
@@ -67,6 +83,8 @@
|
||||
{ "name": "Release", "configurePreset": "Release" },
|
||||
{ "name": "Release32", "configurePreset": "Release32" },
|
||||
{ "name": "MinSizeRel", "configurePreset": "MinSizeRel" },
|
||||
{ "name": "MinSizeRel32", "configurePreset": "MinSizeRel32" }
|
||||
{ "name": "MinSizeRel32", "configurePreset": "MinSizeRel32" },
|
||||
{ "name": "Context32", "configurePreset": "Context32", "targets": ["vp_smp_context"] },
|
||||
{ "name": "Context64", "configurePreset": "Context64", "targets": ["vp_smp_context"] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "aclint_ipi.h"
|
||||
#include "board.h"
|
||||
#include "riscv-csr.h"
|
||||
#include "riscv-traps.h"
|
||||
#include "tx_api.h"
|
||||
#include "tx_thread.h"
|
||||
|
||||
static TX_THREAD controller;
|
||||
static TX_THREAD worker;
|
||||
static ULONG controller_stack[1024];
|
||||
static ULONG worker_stack[1024];
|
||||
static TX_SEMAPHORE worker_finished;
|
||||
static volatile UINT worker_waiting_on_hart_1;
|
||||
static volatile UINT request_nested_irq;
|
||||
static volatile UINT observed_nested_irq;
|
||||
|
||||
/* Disable fault injection in the regression-configured kernel. */
|
||||
TEST_FLAG test_initialize_flag;
|
||||
#ifndef TX_TIMER_PROCESS_IN_ISR
|
||||
TEST_FLAG threadx_delete_timer_thread;
|
||||
|
||||
void delete_timer_thread(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
UINT vp_fp_context_sleep(void);
|
||||
UINT vp_fp_context_migrate(volatile UINT *waiting);
|
||||
|
||||
static void check(UINT pass, const char *message)
|
||||
{
|
||||
if (!pass) {
|
||||
puts(message);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void check_software_interrupt(void)
|
||||
{
|
||||
UINT hart = tx_thread_smp_core_get();
|
||||
set_aclint_msip(aclint, hart, 0);
|
||||
|
||||
if (hart == 0 && request_nested_irq) {
|
||||
observed_nested_irq = _tx_thread_smp_current_state_get() == 2;
|
||||
request_nested_irq = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Called by the board timer ISR after it has acknowledged the timer. */
|
||||
void test_interrupt_dispatch(void)
|
||||
{
|
||||
if (tx_thread_smp_core_get() == 0 && request_nested_irq) {
|
||||
send_ipi(0);
|
||||
csr_set_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||
while (request_nested_irq) {
|
||||
}
|
||||
csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
static void run_worker(ULONG input)
|
||||
{
|
||||
(void)input;
|
||||
check(tx_thread_smp_core_get() == 1, "Worker did not start on hart 1");
|
||||
check(vp_fp_context_migrate(&worker_waiting_on_hart_1) == TX_SUCCESS,
|
||||
"FP context was corrupted during interrupt-driven migration");
|
||||
check(tx_thread_smp_core_get() == 2, "Worker did not migrate to hart 2");
|
||||
check(tx_semaphore_put(&worker_finished) == TX_SUCCESS, "Worker completion signal failed");
|
||||
}
|
||||
|
||||
static void run_controller(ULONG input)
|
||||
{
|
||||
(void)input;
|
||||
request_nested_irq = 1;
|
||||
check(vp_fp_context_sleep() == TX_SUCCESS, "Sleep failed or corrupted the solicited FP context");
|
||||
check(observed_nested_irq, "Software interrupt did not nest inside the timer interrupt");
|
||||
|
||||
check(tx_thread_resume(&worker) == TX_SUCCESS, "Unable to start worker");
|
||||
for (UINT tick = 0; tick < 50 && !worker_waiting_on_hart_1; ++tick) {
|
||||
check(tx_thread_sleep(1) == TX_SUCCESS, "Sleep while waiting for worker failed");
|
||||
}
|
||||
check(worker_waiting_on_hart_1, "Worker never started on hart 1");
|
||||
check(tx_thread_smp_core_exclude(&worker, TX_THREAD_SMP_CORE_MASK & ~(1UL << 2)) == TX_SUCCESS,
|
||||
"Unable to migrate worker to hart 2");
|
||||
check(tx_semaphore_get(&worker_finished, 50) == TX_SUCCESS, "Worker did not finish after migration");
|
||||
puts("SMP context test passed");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void tx_application_define(void *memory)
|
||||
{
|
||||
(void)memory;
|
||||
check(register_irq_handler(RISCV_INT_MSI, check_software_interrupt), "Unable to install software IRQ handler");
|
||||
check(tx_semaphore_create(&worker_finished, "worker finished", 0) == TX_SUCCESS,
|
||||
"Unable to create worker completion semaphore");
|
||||
check(tx_thread_create(&worker, "worker", run_worker, 0, worker_stack, sizeof(worker_stack),
|
||||
5, 5, TX_NO_TIME_SLICE, TX_DONT_START) == TX_SUCCESS, "Unable to create worker");
|
||||
check(tx_thread_smp_core_exclude(&worker, TX_THREAD_SMP_CORE_MASK & ~(1UL << 1)) == TX_SUCCESS,
|
||||
"Unable to assign worker to hart 1");
|
||||
check(tx_thread_create(&controller, "controller", run_controller, 0, controller_stack, sizeof(controller_stack),
|
||||
5, 5, TX_NO_TIME_SLICE, TX_AUTO_START) == TX_SUCCESS, "Unable to create controller");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
tx_kernel_enter();
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
|
||||
.section .text
|
||||
.balign 4
|
||||
|
||||
.global vp_fp_context_sleep
|
||||
.type vp_fp_context_sleep, @function
|
||||
vp_fp_context_sleep:
|
||||
li a1, 0
|
||||
j .Lcheck_context
|
||||
|
||||
.global vp_fp_context_migrate
|
||||
.type vp_fp_context_migrate, @function
|
||||
vp_fp_context_migrate:
|
||||
li a1, 1
|
||||
|
||||
.Lcheck_context:
|
||||
addi sp, sp, -48
|
||||
#if __riscv_xlen == 64
|
||||
sd ra, 40(sp)
|
||||
#else
|
||||
sw ra, 40(sp)
|
||||
#endif
|
||||
fsd fs0, 16(sp)
|
||||
fsd fs11, 24(sp)
|
||||
frcsr t0
|
||||
sw t0, 32(sp)
|
||||
|
||||
la t0, .Lpatterns
|
||||
fld fs0, 0(t0)
|
||||
fld fs11, 8(t0)
|
||||
fld ft0, 16(t0)
|
||||
fld ft11, 24(t0)
|
||||
li t0, 0x65
|
||||
fscsr t0
|
||||
bnez a1, .Linterrupt_switch
|
||||
|
||||
li a0, 2
|
||||
call _tx_thread_sleep
|
||||
bnez a0, .Lreturn
|
||||
j .Lcheck_preserved
|
||||
|
||||
.Linterrupt_switch:
|
||||
fence rw, w
|
||||
sw a1, 0(a0)
|
||||
.Lwait_for_migration:
|
||||
csrr t0, mhartid
|
||||
li t1, 2
|
||||
bne t0, t1, .Lwait_for_migration
|
||||
|
||||
fsd ft0, 0(sp)
|
||||
fsd ft11, 8(sp)
|
||||
la t0, .Lpatterns
|
||||
addi t0, t0, 16
|
||||
mv t1, sp
|
||||
li t2, 4
|
||||
jal t3, .Lcompare_words
|
||||
|
||||
.Lcheck_preserved:
|
||||
frcsr t0
|
||||
li t1, 0x65
|
||||
bne t0, t1, .Lbad_context
|
||||
fsd fs0, 0(sp)
|
||||
fsd fs11, 8(sp)
|
||||
la t0, .Lpatterns
|
||||
mv t1, sp
|
||||
li t2, 4
|
||||
jal t3, .Lcompare_words
|
||||
li a0, 0
|
||||
j .Lreturn
|
||||
|
||||
.Lcompare_words:
|
||||
lw t4, 0(t0)
|
||||
lw t5, 0(t1)
|
||||
bne t4, t5, .Lbad_context
|
||||
addi t0, t0, 4
|
||||
addi t1, t1, 4
|
||||
addi t2, t2, -1
|
||||
bnez t2, .Lcompare_words
|
||||
jr t3
|
||||
|
||||
.Lbad_context:
|
||||
li a0, 1
|
||||
.Lreturn:
|
||||
fld fs0, 16(sp)
|
||||
fld fs11, 24(sp)
|
||||
lw t0, 32(sp)
|
||||
fscsr t0
|
||||
#if __riscv_xlen == 64
|
||||
ld ra, 40(sp)
|
||||
#else
|
||||
lw ra, 40(sp)
|
||||
#endif
|
||||
addi sp, sp, 48
|
||||
ret
|
||||
|
||||
.section .rodata
|
||||
.balign 8
|
||||
.Lpatterns:
|
||||
.dword 0x3ff0123456789abc, 0x40023456789abcde
|
||||
.dword 0x401456789abcdef0, 0x4026789abcdef012
|
||||
Reference in new issue
Block a user