Page 1 of 1

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

Posted: Wed Jun 23, 2021 6:23 pm
by alexblack
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.

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

Posted: Wed Jun 23, 2021 7:21 pm
by Giovanni
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

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

Posted: Thu Jun 24, 2021 7:01 am
by alexblack
Thank you.

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

Posted: Wed Dec 28, 2022 12:13 pm
by 方悠然
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.

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

Posted: Wed Dec 28, 2022 1:56 pm
by Giovanni
Hi,

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

Giovanni

Giovanni