Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby Fuzzyzilla » Mon Nov 20, 2017 9:01 pm

Hello!

I have just started freeRTOS and I wanted to do some debugging of my tasks. I wrote a function to display all task states using "uxTaskGetSystemState()" but any attempt to use this function results in the following error:

C:\Users\...\AppData\Local\Temp\arduino_modified_sketch_317958/sketch_nov20a.ino:3: undefined reference to `uxTaskGetSystemState'

This happens on all computers I've tried it on. All other freeRTOS functions I've tried work fine, just not this one.

What can I do to fix this?

Thanks!

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby chegewara » Mon Nov 20, 2017 10:58 pm

This function requires configUSE_TRACE_FACILITY=1. You have to check this option in menuconfig:

Code: Select all

menuconfig->Component config->FreeRTOS->Enable FreeRTOS trace facility

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby kolban » Mon Nov 20, 2017 10:59 pm

If we visit the Github for the ESP-IDF and do a search for uxTaskGetSystemState() we eventually find this source:

https://github.com/espressif/esp-idf/bl ... ks.c#L2287

If we look at the source, we see that it only gets compiled in if the configUSE_TRACE_FACILITY is set to 1.

We can set this in the "make menuconfig" within FreeRTOS > Enable FreeRTOS trace facility.

Image

Switch this on and recompile. If that doesn't help, please post back and we'll try something else.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby Fuzzyzilla » Mon Nov 20, 2017 11:25 pm

Thank you both for your answers. Do I have to install ESPIDF to access these options?

Edit: I tried changing the config file manually, that didn't help.
(tried setting CONFIG_FREERTOS_USE_TRACE_FACILITY to 'y' , '1', and 'true' and then recompiling in arduino.)

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby chegewara » Tue Nov 21, 2017 12:36 am

Im not sure but maybe try to change this option in sdkconfig.h
It is in sdk/include/config folder

Or change this file and set default value to y
https://github.com/espressif/esp-idf/bl ... onfig#L288

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby Fuzzyzilla » Tue Nov 21, 2017 12:55 am

Yeah, I've scanned through the different files changing them to 1, it still doesn't work...

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby kolban » Tue Nov 21, 2017 3:38 am

Ahh just noticed that you are using Arduino. It may be that the ESP-IDF distributed with the Arduino version you are using pre-dates the latest ESP-IDF into which this option was recently added. You'd want to check the ESP-IDF commit history and find out what this option was added and then compare that against the ESP-IDF distributed by Arduino. If Arduino ESP-IDF distribution pre-dates that then this suggestion won't work as described and you would either have to find a new solution or wait for the Arduino ESP-IDF distibution to catch up.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

NickJames
Posts: 7
Joined: Sun May 26, 2019 5:53 am

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby NickJames » Sun May 26, 2019 9:24 am

I managed to make this work with the following steps:

[*]run git log in arduino-esp32 to find the latest tagged IDF (3.1 in my case)
[*]checkout that tag in esp-idf
[*]copy sdkconfig from arduino-esp32/tools/sdk/sdkconfig to esp-idf/examples/get-started/blink/sdkconfig
[*]run make menuconfig in esp-idf/examples/get-started/blink, turn on the options mentioned above
[*]make
[*]copy build/freertos/libfreertos.a to Arduino/hardware/expressif/esp32/tools/sdk/lib/
[*]copy build/esp32/libesp32.a to Arduino/hardware/expressif/esp32/tools/sdk/lib/

After doing these steps, I was able to compile this example: https://www.freertos.org/uxTaskGetSystemState.html
with the following changes
[*]use uxTaskGetNumberOfTasks() instead of uxCurrentNumberOfTasks()
[*]hack the task status data out of memory. I've still messed something up because sizeof(TaskStatus_t) evaluates to 36, but the actual struct size in memory was 40. I offset the pointers manually. Please do pardon my language.
  1. void print_shit(void)
  2. {
  3.     char *str = (char *)malloc(sizeof(char) * 2000);
  4.     memset(str, 0, 2000);
  5.     char *pcWriteBuffer = str;
  6.  
  7.     TaskStatus_t *pxTaskStatusArray;
  8.  
  9.     volatile UBaseType_t uxArraySize, x;
  10.     unsigned long ulStatsAsPercentage;
  11.     uint32_t ulTotalRunTime;
  12.  
  13.    /* Make sure the write buffer does not contain a string. */
  14.    *pcWriteBuffer = 0x00;
  15.  
  16.    /* Take a snapshot of the number of tasks in case it changes while this
  17.    function is executing. */
  18.    uxArraySize = uxTaskGetNumberOfTasks();
  19.  
  20.    /* Allocate a TaskStatus_t structure for each task.  An array could be
  21.    allocated statically at compile time. */
  22.    Serial.printf("sizeof TaskStatus_t: %d\n", sizeof(TaskStatus_t));
  23.    pxTaskStatusArray = (TaskStatus_t*)pvPortMalloc( uxArraySize * sizeof(TaskStatus_t));
  24.    memset(pxTaskStatusArray, 0, uxArraySize * sizeof(TaskStatus_t));
  25.  
  26.    if( pxTaskStatusArray != NULL )
  27.    {
  28.       /* Generate raw status information about each task. */
  29.       Serial.printf("Array size before: %d\n", uxArraySize);
  30.       uxArraySize = uxTaskGetSystemState( pxTaskStatusArray,
  31.                                  uxArraySize,
  32.                                  &ulTotalRunTime );
  33.       Serial.printf("Array size after: %d\n", uxArraySize);
  34.       Serial.printf("Total runtime: %d\n", ulTotalRunTime);
  35.  
  36.       /* For percentage calculations. */
  37.       ulTotalRunTime /= 100UL;
  38.  
  39.       /* Avoid divide by zero errors. */
  40.       if( ulTotalRunTime > 0 )
  41.       {
  42.          /* For each populated position in the pxTaskStatusArray array,
  43.          format the raw data as human readable ASCII data. */
  44.          Serial.printf("  name        runtime      pct     core         prio\n");
  45.          for( int x = 0; x < uxArraySize; x++ )
  46.          {
  47.             TaskStatus_t *fuckit;
  48.             void *tmp = &pxTaskStatusArray[x];
  49.             void *hmm = tmp + (4 * x);
  50.             fuckit = (TaskStatus_t*)hmm;
  51.  
  52.                 // Serial.printf("Name: %.5s, ulRunTimeCounter: %d\n", fuckit->pcTaskName , fuckit->ulRunTimeCounter);
  53.             /* What percentage of the total run time has the task used?
  54.             This will always be rounded down to the nearest integer.
  55.             ulTotalRunTimeDiv100 has already been divided by 100. */
  56.             ulStatsAsPercentage =
  57.                   fuckit->ulRunTimeCounter / ulTotalRunTime;
  58.  
  59.             if( ulStatsAsPercentage > 0UL )
  60.             {
  61.                sprintf( pcWriteBuffer, "%30s %10lu %10lu%% %5d %5d\n",
  62.                                  fuckit->pcTaskName,
  63.                                  fuckit->ulRunTimeCounter,
  64.                                  ulStatsAsPercentage,
  65.                                 *((int *)(&fuckit->usStackHighWaterMark)+1),
  66.                                 fuckit->uxBasePriority);
  67.             }
  68.             else
  69.             {
  70.                /* If the percentage is zero here then the task has
  71.                consumed less than 1% of the total run time. */
  72.                sprintf( pcWriteBuffer, "%30s %10lu %10s  %5d %5d\n",
  73.                                  fuckit->pcTaskName,
  74.                                  fuckit->ulRunTimeCounter,
  75.                                  "<1%",
  76.                                  *((uint32_t *)(&fuckit->usStackHighWaterMark)+1),
  77.                                  fuckit->uxBasePriority);
  78.             }
  79.  
  80.             pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
  81.             // Serial.printf("len: %d, idx: %d\n", pcWriteBuffer - str, x);
  82.          }
  83.          Serial.print(str);
  84.       }
  85.  
  86.       /* The array is no longer needed, free the memory it consumes. */
  87.     //   vPortFree( pxTaskStatusArray );
  88.     //   free(str);
  89.    }
  90. }
  1.         Name        runtime        pct    core  prio
  2.         loopTask    8361337         89%     1     1
  3.            IDLE0    9270465         99%     0     0
  4.            IDLE1      14782        <1%      1     0
  5.        CAN_RX_25     218240          2%     1    24
  6.  100Hz_CAN_send_     144393          1%     1     3
  7.              tiT      11428        <1%      0    18  
  8.  10Hz_CAN_send_t      19815        <1%      1     1
  9.      LED blinker       2382        <1%      0     0
  10.        CAN_WD_BI       4471        <1%      1    10
  11.  1Hz_CAN_send_ta      75161        <1%      1     1
  12.        CAN_RX_24     195768          2%     1    24
  13.          Tmr Svc         36        <1%      0     1
  14.             ipc0       3502        <1%      0    24
  15.    network_event         18        <1%      1    19
  16.        eventTask         23        <1%      0    20
  17.           CAN_RX         27        <1%  2147483647    15
  18.         CAN_LORX         20        <1%      1    19
  19.             mdns        141        <1%      0     1
  20.        esptimer       4469        <1%      0    22
  21.  ACAN2517Handler      60268        <1%  2147483647    24
  22.  ACAN2517Handler     215147          2% 2147483647    24
  23.             ipc1      22592        <1%      1    24
This forum is fine, but BBcode is an awful impediment. Good Night.

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby boarchuz » Sun May 26, 2019 2:16 pm

Looks familiar :lol:

I wonder if this is any help to tie up that loose end:
https://github.com/espressif/esp-idf/bl ... ask.h#L176

Possibly CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is different between the relevant precompiled file and the sdkconfig that Arduino uses?

NickJames
Posts: 7
Joined: Sun May 26, 2019 5:53 am

Re: Undefined Reference to "uxTaskGetSystemState" Upon Any Attempt to Use.

Postby NickJames » Sat Jun 01, 2019 3:34 am

Thanks @boarchuz, adding `-DCONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID` to the `build.extra_flags` in platform.txt was all I needed.

While this approach has provided some very useful information on tasks, it has also unfortunately broken part of the WiFi stack.

Who is online

Users browsing this forum: No registered users and 78 guests