arch/risc-v64: Add lazy FPU stacking and QEMU functional tests for GNU port - #549
arch/risc-v64: Add lazy FPU stacking and QEMU functional tests for GNU port#549Winstonllllai wants to merge 3 commits into
Conversation
Save mstatus/sstatus to stack slot 29 and skip floating-point register save/restore when FS is Off (bits 14:13). This avoids unnecessary FP context work for threads that do not use the FPU. - context_save: check FS in nested and first-level interrupt paths - context_restore: gate FP restore on nested, no-preempt, and preempt paths - use sstatus when TX_RISCV_SMODE is defined, otherwise mstatus
Wire the QEMU virt demo into the CMake build system and add a Python/GDB functional test runner, mirroring the risc-v32/gnu port. - Add qemu_virt/CMakeLists.txt to build kernel.elf and register the check-functional-riscv64 target (requires Python3; skipped if absent) - Link kernel.elf with --whole-archive so all ThreadX symbols resolve - Pin _start at 0x80000000 via .text.boot in entry.s and KEEP(*(.text.boot)) in link.lds - Extend demo_threadx.c with fpu_test_val and shorten thread_0 sleep for GDB-driven FPU, timer, and preemption checks - Add test/azrtos_test_tx_gnu_riscv64_qemu.py; verified passing on QEMU virt (FPU, timer interrupt, preemption)
|
Hi @Winstonllllai. Thank you for this contribution. @akifejaz and I will review it. |
|
Hi @fdesbiens and @akifejaz , |
|
Hi @Winstonllllai please see comments below |
akifejaz
left a comment
There was a problem hiding this comment.
Hi @Winstonllllai I see multiple issue at first glance some of those I already pointed in your previous PR : #513
and
- i see no significance for test/ dir & *.py script you can keep it for local testing. -- please also remove from RV32 port (PR : #513)
- the "TX_RISCV_SMODE" is obviously from some other PR, seems like merging issue, you should not be adding these changes
- There are multiple new empty asm symbols in there, I'm not sure why you've added those if you chose to keep them empty.
- also please change the comments carefully, I see you updated the comments wrongly, the earlier versions were fine.
- the file name is
entry.Sbut your cmake calls it `entry.s' (small s), it should give build fails, please double check changes when submit PR
Also AI generated code should be marked properly. @fdesbiens when you get time, please also share the AI coding guidelines (if we have any) to him.
4c8dcd2 to
6943895
Compare
Revert accidental RV64 qemu_virt test/CMake integration changes and keep this branch focused on lazy FPU context handling only. Also remove unintended TX_RISCV_SMODE-based mstatus/sstatus save path and align comments/logic to mstatus-only behavior.
|
Hi @akifejaz . Thanks for the review — I've addressed the points below:
The PR is now scoped to lazy FPU context save/restore only. |
|
For the RV32 cleanup requested in review, I opened a separate follow-up PR: #552. It removes the local-only QEMU test script and related CMake/test-only changes from the RV32 port. |
|
Thank you for the cleanup — the scope now matches the title, and I can see every one of @akifejaz's points addressed:
I checked the mechanism rather than reading it. The One thing to fix before this can go inSlot 29 is read uninitialised on the first restore of every newly created thread. The frame map at the top of and the builder skips it accordingly — it writes slot 28 and slot 30 and nothing in between, because until now nothing read slot 29. This PR reads it. Since One line alongside the existing initialisers fixes it: li t1, 0x2000 // mstatus.FS = Initial
sd t1, 29*8(t0) // Initial mstatusAny non-zero Please also add a test that a thread created after another thread has used floating point starts with clean FP state — that is the case this bug breaks, and it is the one a reviewer cannot see by reading. |
|
@akifejaz — good catch, and yes, we do have guidelines. The authority is the Eclipse Foundation rather than anything we invent per project:
The short version for contributors: you may use these tools, the contribution still has to pass the same IP due diligence as anything else, and the committer merging it remains responsible for its correctness and provenance. Disclosure is expected rather than optional. Concretely, here is what that looks like in code already on A new file carries the disclosure in its header. From #!/bin/bash
##############################################################################
# Copyright (c) 2026 Eclipse ThreadX contributors
#
# This program and the accompanying materials are made available under the
# terms of the MIT License which is available at
# https://opensource.org/licenses/MIT.
#
# AI Disclosure: This file was largely AI-generated by Claude Code (Opus 5).
# The AI-generated portions may be considered public domain (CC0-1.0)
# and not subject to the project's licence. The human contributor has
# reviewed and verified that the code is correct.
#
# SPDX-License-Identifier: MIT and CC0-1.0
##############################################################################Note the An edit to an existing file keeps that file's licence header and adds one line just below it, plus the Eclipse copyright if it is not already there. From /***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
// Some portions generated by Codex (GPT-5).Name the actual tool and version rather than a generic label — the tree currently has files naming Claude Code, Codex and Gemini, for example @Winstonllllai — nothing to redo retroactively here; if any of this PR was AI-assisted, please add the appropriate marking to the two files you touched. You are right that this is hard to find today: |
This PR adds functional enhancements for the ThreadX RISC-V 64-bit (RV64) GNU port, mirroring the improvements delivered for RV32 in #513.
Lazy FPU Stacking:
_tx_thread_context_saveand_tx_thread_context_restoreto savemstatus/sstatusand skip FP register save/restore when the FS field (bits 14:13) is Off.TX_RISCV_SMODE(readssstatusvsmstatusas appropriate).Automated Testing Framework:
azrtos_test_tx_gnu_riscv64_qemu.py).qemu_virt/CMakeLists.txtand registered thecheck-functional-riscv64target.demo_threadx.cwithfpu_test_valand adjusted thread timing for GDB-driven verification.QEMU Boot & Link Fixes:
_startin a.text.bootsection and addedKEEP(*(.text.boot))tolink.ldsso the entry point is pinned at0x80000000(QEMU virt reset PC).kernel.elfwith--whole-archiveto ensure all ThreadX symbols resolve on RV64.How to Run Tests
cmake -B build_qemu -DCMAKE_TOOLCHAIN_FILE=cmake/riscv64_gnu.cmake cd build_qemu make check-functional-riscv64Tested on QEMU virt machine (rv64gc).
Please let me know if there is anything I should improve or if I missed anything.