openocd rtos integration

Report here problems in any of ChibiOS components. This forum is NOT for support.
dflogeras
Posts: 212
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 7 times
Been thanked: 19 times

openocd rtos integration

Postby dflogeras » Fri Oct 22, 2021 1:58 pm

See also:

viewtopic.php?f=24&t=5893

I think there may be a problem with the openocd -rtos addition and ChibiOS 21. I've compiled the demos/STM32/RT-STM32L152-DISCOVERY application from ChibiOS_19.1.3 and the thread view works fine from gdb.

When I repeated the same process with the same demo from ChibiOS_21.6.0, it fails when I ask for 'info threads' and openocd prints the following:

Code: Select all

Error: ChibiOS registry integrity check failed, double linked list violation
Info : Only showing current execution because of a broken ChibiOS thread registry.


while gdb says:

Code: Select all

(gdb) info thread
  Id   Target Id                                          Frame
* 5    Thread 1 (Name: Current Execution, No RTOS thread) __idle_thread (p=0x0)

This is all with openocd-0.10.0, but I also tried 0.11.0 and the same results (note that they changed the plugin name from -rtos ChibiOS to -rtos chibios). Is it possible the data structure it is looking for in Chibi has changed?

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: openocd rtos integration

Postby Giovanni » Fri Oct 22, 2021 2:08 pm

Hi,

RT7 has differences because it introduced SMP support, OpenOCD will need some patches.

Giovanni

casrya
Posts: 3
Joined: Fri Jun 30, 2023 6:04 am
Been thanked: 1 time

Re: openocd rtos integration

Postby casrya » Fri Jun 30, 2023 6:18 am

Hi Giovanni,

I came across this issue recently (via ArduPilot on an H743 with a STLINKV2 clone) so investigated further and found the specific cause of the problem and a quick fix.

The first issue is that the “ch” variable is now “ch0” so this is an easy enough fix for a single CPU system so that is not a problem.

However the more significant issue is that the way openocd uses the off_newer/off_older offsets in ch_debug to traverse the threads is no longer working as expected.

Specifically line 91-92 in chregistry.c (below) gives the rqueue offsets for next/prev which does not work with openocd. However, if you change these lines to use hdr.pqueue.next/prev it will work as expected however I do not know if this is correct for other client code using ch_debug?

Code: Select all

  .off_newer = (uint8_t)__CH_OFFSETOF(thread_t, rqueue.next),
  .off_older = (uint8_t)__CH_OFFSETOF(thread_t, rqueue.prev),


So my main question is whether the current rqueue behaviour in chregistry.c is actually correct and thus is it possible to traverse the thread list in external code such as openocd using only ch_debug and the existing rqueue offsets? (I could not work out how to do this easily).

In the short term, rather than modify chibios to provide the pqueue offsets, my current quick fix was to just modify the offsets directly in openocd so it uses pqueue instead. As such I have my local version of openocd working now. However, if I can clarify the expected behaviour I might be able to do a better fix which I can then share since it does not look like it is going to get fixed on the openocd side any time soon :)

P.S Thanks for all your hard work on ChibiOS which has made a big contribution to projects like ArduPilot!

Cheers,

casrya

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: openocd rtos integration

Postby Giovanni » Fri Jun 30, 2023 10:21 am

Hi,

Field "pqueue" is the list element of the "ready list", not all threads are in that list. The list element "rqueue" is the item in the registry list, not sure why it is not working in your case.

Fnctions chRegFirstThread() and chRegNextThread() use the rqueue list, you need to mimic their behavior in the OOCD code, note the "__CH_OFFSETOF" thing, list pointers do not point directly to thread_t structures, there is an offset.

Giovanni

casrya
Posts: 3
Joined: Fri Jun 30, 2023 6:04 am
Been thanked: 1 time

Re: openocd rtos integration

Postby casrya » Sat Jul 01, 2023 12:16 am

Thanks for the advice, I had a quick look at the code/functions you suggested and I think I know how to proceed now using the reglist.queue to get the first thread (which I can get from ch_debug.off_inst_reglist via ch0) and then applying the offset according to __CH_OFFSETOF to get the actual thread_t. Once I have that I should be able to get the rest of them using ch_debug.off_newer which gives rqueue.next (again applying the __CH_OFFSETOF each time to get the next thread_t).

BTW this is quite different to the existing openocd approach so it is not surprising that it does not work anymore!

Anyway, I will have a proper go at it next week and if you have any further tips based on what I wrote above (or if I have misunderstood something?) that would be appreciated :)

Also, is locking/concurrency likely to be an issue during traversal since I am not sure I can control this from openocd?

Cheers,

casrya

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: openocd rtos integration

Postby Giovanni » Sat Jul 01, 2023 6:07 am

Hi,

Concurrency should not be a problem, OOCD should do that scan while the program is halted. It is true that the list could be transiently in a non-correct state (halted while inserting/deleting elements), it is advisable to check for the list integrity while scanning but an error would be a very rare occurrence.

Giovanni

casrya
Posts: 3
Joined: Fri Jun 30, 2023 6:04 am
Been thanked: 1 time

Re: openocd rtos integration

Postby casrya » Mon Jul 03, 2023 3:25 pm

Thanks for the help, I got it working based on your suggestions and by following the chibios source code 8-)

I have made a fork at https://github.com/casrya/openocd/commits/ChibiosRT7 in case it is useful for others.

Cheers,

casrya


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 28 guests