Skip to content

Conversation

@Jer6y
Copy link
Contributor

@Jer6y Jer6y commented Oct 25, 2024

Hi , I port threadx to qemu-riscv64-virt and run the demo

I also add toolchain cmake scripts , so we can use cmake like arm to generated libthreadx.a

To Test it

First , Maksure riscv64-unknown-elf- binutils and make is installed , and qemu-system-riscv64 is also required

cd into example_build work

cd ports/risc-v64/gnu/example_build/qemu_virt

use make to compile the demo (make clean can clean the output)

make

If done successfully, we will find A ELF FILE kernel.elf , use qemu to load it

qemu-system-riscv64 -nographic -smp 1 -bios none -m 128M -machine virt -kernel kernel.elf

If success , you will get different thread output the message like this

[UART0] : Uart Init Done, this is Test output!
[Thread] : thread_0_entry is here!
[Thread] : thread_5_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_1_entry is here!
[Thread] : thread_2_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_0_entry is here!
[Thread] : thread_5_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_0_entry is here!
[Thread] : thread_5_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!
[Thread] : thread_3_and_4_entry is here!
[Thread] : thread_6_and_7_entry is here!

PR checklist

  • add riscv qemu virt support , add cmake toolchain script to generate libthreadx.a
  • fix riscv64 contex_resotre bug (when f/d isa is enable)
  • use weak symbol to invalidate _tx_initialize_low_level function

@fdesbiens
Copy link
Contributor

Hi @Jer6y.

Thank you for your contribution! I am the new Eclipse ThreadX project lead. I am still ramping up, so I couldn't comment right away. I appreciate your patience.

I lack the knowledge and experience to review the code thoroughly myself, so I will do my best to get someone else to look at it in the upcoming weeks. In the meantime, I am curious about the history of this contribution. What led you to write this port? Feel free to contact me privately if you cannot share those details publicly.

@fdesbiens
Copy link
Contributor

@eclipse-threadx/iot-threadx-committers, I need a volunteer with porting expertise to review this contribution.

@Jer6y
Copy link
Contributor Author

Jer6y commented Dec 6, 2024

Hi @Jer6y.

Thank you for your contribution! I am the new Eclipse ThreadX project lead. I am still ramping up, so I couldn't comment right away. I appreciate your patience.

I lack the knowledge and experience to review the code thoroughly myself, so I will do my best to get someone else to look at it in the upcoming weeks. In the meantime, I am curious about the history of this contribution. What led you to write this port? Feel free to contact me privately if you cannot share those details publicly.

Hi,
I am working on this porting task because I found that I can't directly use the ThreadX project on RISC-V. There are some issues with the code in terms of architecture code, and I can't find the way to run ThreadX on qemu-system-riscv64 for verification and learning.

@fdesbiens
Copy link
Contributor

@rahmanih I think you mentioned you have feedback for the author of this pull request. Can you please share it with them here?

@rahmanih
Copy link
Contributor

@rahmanih I think you mentioned you have feedback for the author of this pull request. Can you please share it with them here?

Hi,
I misunderstood some points, but it is clear now, LGTM, if no more comments, these can be merged.
regards
Haithem.

@fdesbiens fdesbiens changed the base branch from master to dev January 28, 2025 21:25
@fdesbiens
Copy link
Contributor

@eclipse-threadx/iot-threadx-committers

@rahmanih Reviewed this contribution and determined it meets our quality standards.

I would like all the others to explicitly approve (+1) or reject (-1) this contribution. Please express your opinion by Tuesday, February 11, 2025. I will not vote myself unless there is a tie.

If the vote is positive, I will merge the code and this feature will ship with our next release.

@billlamiework
Copy link

+1

@fdesbiens
Copy link
Contributor

This contribution is approved. Thanks for submitting this PR, @Jer6y!

@fdesbiens fdesbiens merged commit e657568 into eclipse-threadx:dev Feb 13, 2025
1 check passed
@fdesbiens
Copy link
Contributor

This feature will ship in ThreadX v6.4.2. We expect to release it by the end of February 2025.

@akifejaz
Copy link

akifejaz commented Jan 2, 2026

Hi @fdesbiens, there seems to be a problem with this. I'was testing this and I found a bug, please see the details below.

The task 1,2 which are using tx_queue_send()/tx_queue_receive() are not working as expected they are failing and exiting as soon as the task enters. It is because tx_queue_create failed with status code TX_PTR_ERROR = 0x3.

see logs:

(gdb) c
Continuing.

Breakpoint 1, main () at demo_threadx.c:62
62          tx_kernel_enter();
(gdb) b demo_threadx.c:147
Breakpoint 2 at 0x80000b02: file demo_threadx.c, line 147.
(gdb) c
Continuing.

Breakpoint 2, tx_application_define (first_unused_memory=0x8000e000) at demo_threadx.c:147
147         tx_byte_allocate(&byte_pool_0, (VOID **) &pointer, DEMO_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT);
(gdb) info reg ra
ra             0x80000b02       0x80000b02 <tx_application_define+682>
(gdb) print $ra
$1 = (void (*)()) 0x80000b02 <tx_application_define+682>
(gdb) n
150         tx_queue_create(&queue_0, "queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG));
(gdb) s
_txe_queue_create (queue_ptr=0x80009320 <queue_0>, name_ptr=0x80008130 "queue 0", message_size=1, queue_start=0x0, queue_size=800, queue_control_block_size=104)
    at /home/akif-10xe/projects/threadx-work/threadx/common/src/txe_queue_create.c:97
97          status =  TX_SUCCESS;
(gdb) info local
interrupt_save = 0
status = 0
i = 2147540936
next_queue = 0x320
thread_ptr = 0x8000285a <_txe_byte_allocate+264>
(gdb) n
100         if (queue_ptr == TX_NULL)
(gdb) 
108         else if (queue_control_block_size != (sizeof(TX_QUEUE)))
(gdb) l
103             /* Queue pointer is invalid, return appropriate error code.  */
104             status =  TX_QUEUE_ERROR;
105         }
106
107         /* Now check for a valid control block size.  */
108         else if (queue_control_block_size != (sizeof(TX_QUEUE)))
109         {
110
111             /* Queue pointer is invalid, return appropriate error code.  */
112             status =  TX_QUEUE_ERROR;
(gdb) n
118             TX_DISABLE
(gdb) b txe_queue_create.c:235
Breakpoint 3 at 0x800031ea: file /home/akif-10xe/projects/threadx-work/threadx/common/src/txe_queue_create.c, line 237.
(gdb) c
Continuing.

Breakpoint 3, _txe_queue_create (queue_ptr=0x80009320 <queue_0>, name_ptr=0x80008130 "queue 0", message_size=1, queue_start=0x0, queue_size=800, queue_control_block_size=104)
    at /home/akif-10xe/projects/threadx-work/threadx/common/src/txe_queue_create.c:237
237         return(status);
(gdb) info local
interrupt_save = 9223372079804479616
status = 3
i = 0
next_queue = 0x0
thread_ptr = 0x8000285a <_txe_byte_allocate+264>
(gdb) n
238     }
(gdb) 
tx_application_define (first_unused_memory=0x8000e000) at demo_threadx.c:153
153         tx_semaphore_create(&semaphore_0, "semaphore 0", 1);

See the return value in _txe_queue_create.

Moreover, as per the logs we can also see the thread 1,2 only came ones which means they got exited in first iter as this condition if (status != TX_SUCCESS) break in thread 1 entry.

(gdb) b thread_1_entry
Breakpoint 1 at 0x80000c58: file demo_threadx.c, line 213.
(gdb) c
Continuing.

Breakpoint 1, thread_1_entry (thread_input=1) at demo_threadx.c:213
warning: Source file is more recent than executable.
213             puts("[Thread] : thread_1_entry is here!");
(gdb) info local
status = 0
(gdb) n
215             thread_1_counter++;
(gdb) 
218             status =  tx_queue_send(&queue_0, &thread_1_messages_sent, TX_WAIT_FOREVER);
(gdb) 
221             if (status != TX_SUCCESS)
(gdb) info local
status = 9
(gdb) l
216
217             /* Send message to queue 0.  */
218             status =  tx_queue_send(&queue_0, &thread_1_messages_sent, TX_WAIT_FOREVER);
219
220             /* Check completion status.  */
221             if (status != TX_SUCCESS)
222                 break;
223
224             /* Increment the message sent.  */
225             thread_1_messages_sent++;
(gdb) s
222                 break;
(gdb) s
227     }

let me know if someone is interested to debug this further or please assign this to me I'll look into this.

PS: I think the expected output should be like this #492

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants