How to make the list of all treads in ChibiOS 21?

Discussions and support about ChibiOS/RT, the free embedded RTOS.
alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

How to make the list of all treads in ChibiOS 21?

Postby alexblack » Wed Jun 23, 2021 6:23 pm

Hi.
For the debug purposes I need to make a list of all threads in the system. In previous versions I used this code:

Code: Select all

  thread_t *ctp;
  /* Scanning registry.*/
  ctp = ch.rlist.newer;
  do {
    /* Exclude IDLE THREAD from list */
    if (ctp->hdr.pqueue.prio != IDLEPRIO)   {
      /* Fill elements with current task information */
      Info.TaskID     = (uint32_t) ctp;
      Info.sName      = ctp->name;
      Info.Prio       = ctp->hdr.pqueue.prio;
      Info.StackBase  = (uint32_t) ctp->wabase;
      Info.StackSize  = (uint32_t) 0;
    }
   
    /* search next thread */
    sts = chSysGetStatusAndLockX();
    ctp = ctp->newer;
    if (ctp == (thread_t *)&ch.rlist) {
      ctp = NULL;
    }
    chSysRestoreStatusX(sts);
  } while (ctp != NULL);

Now it does not compiling because all structures was changed.
Please help to make this.

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

Re: How to make the list of all treads in ChibiOS 21?

Postby Giovanni » Wed Jun 23, 2021 7:21 pm

Hi,

In order to scan the registry you need to use chRegFirstThread() and chRegNextThread() functions, it is not appropriate to use the pointers directly.

If you need an example then look at the "threads" shell command in /os/various/shell/shell_cmd.c

Giovanni

alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: How to make the list of all treads in ChibiOS 21?

Postby alexblack » Thu Jun 24, 2021 7:01 am

Thank you.

方悠然
Posts: 4
Joined: Mon Nov 14, 2022 2:43 am
Has thanked: 2 times

Re: How to make the list of all treads in ChibiOS 21?

Postby 方悠然 » Wed Dec 28, 2022 12:13 pm

I've seen /os/various/shell/shell_cmd.c, I want to increase the unused ratio of the thread stack in the "threads" shell.
It seems that using chRegFirstThread() and chRegNextThread() does not get "wsp". I can only add the "wsp" parameter manually.
//my program:

#if CH_DBG_FILL_THREADS
float GetThdFreeStack(void *wsp, uint32_t size) {
uint32_t stack_unused = 0;
uint8_t *startp = (uint8_t *)wsp; //The start address of the thread stack
uint8_t *endp = (uint8_t *)wsp + size; //The address at the end of the thread stack
while (startp < endp)
if(*startp++ == CH_DBG_STACK_FILL_VALUE) ++stack_unused; //Unused thread stack space
return ((float)stack_unused - sizeof(thread_t))/((float)size - sizeof(thread_t)); //The ratio of unused stacks to the thread's total stack space
}
#endif
......
chThdCreateStatic(motor_test_thread_wa, sizeof(motor_test_thread_wa), NORMALPRIO-1, motor_test_thread, NULL);
......
float unused_thread1 = GetThdFreeStack(motor_test_thread_wa, sizeof(motor_test_thread_wa));
float unused_thread2 = GetThdFreeStack(......);
......

Is there any way to get the "wsp" list, or to add thread usage to the "threads" shell? Appreciate.

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

Re: How to make the list of all treads in ChibiOS 21?

Postby Giovanni » Wed Dec 28, 2022 1:56 pm

Hi,

The "wabase" field of the thread structure is the base of the working area, that is your "wsp".

Giovanni

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 10 guests