mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00
FreeRTOS/make Queue Registry and Run Time Stats configurable
This commit makes the configQUEUE_REGISTRY_SIZE and configGENERATE_RUN_TIME_STATS configurable in menuconfig. - configQUEUE_REGISTRY_SIZE can now be set in menuconfig. - The functions vQueueAddToRegistry() and vQueueUnregisterQueue() were made SMP compatbile - pcQueueGetName() was backported from FreeRTOS v9.0.0 - Added test case for Queue Registry functions - configGENERATE_RUN_TIME_STATS can now be enabled in menuconfig. CCOUNT or esp_timer can be selected as the FreeRTOS run time clock in menuconfig as well, although CCOUNT will overflow quickly. - Run time stats collection (in vTaskSwitchContext) and generation (in uxTaskGetSystemState) have been made SMP compatible. Therefore vTaskGetRunTimeStats() now displays the run time usage of each task as a percentage of total runtime of both CPUs Squash
This commit is contained in:
100
components/freertos/test/test_freertos_debug_functions.c
Normal file
100
components/freertos/test/test_freertos_debug_functions.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Test FreeRTOS debug functions and utilities.
|
||||
* - Queue registry functions vQueueAddToRegistry(), vQueueUnregisterQueue(),
|
||||
* and pcQueueGetName(backported)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "unity.h"
|
||||
|
||||
#if (CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE > 0)
|
||||
#define NO_OF_QUEUES_PER_CORE ((int)((CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE - 3)/portNUM_PROCESSORS)) //Save space for some preallocated tasks
|
||||
#define NO_OF_QUEUES_TOTAL (NO_OF_QUEUES_PER_CORE * portNUM_PROCESSORS)
|
||||
#define QUEUE_NAME_MAX_LENGTH 10
|
||||
|
||||
static SemaphoreHandle_t start_sem = NULL;
|
||||
static SemaphoreHandle_t done_sem = NULL;
|
||||
static char *names[NO_OF_QUEUES_TOTAL];
|
||||
static QueueHandle_t handles[NO_OF_QUEUES_TOTAL];
|
||||
|
||||
void test_queue_registry_task(void *arg)
|
||||
{
|
||||
int core = xPortGetCoreID();
|
||||
int offset = core * NO_OF_QUEUES_PER_CORE;
|
||||
//Create queues and accompanying queue names
|
||||
for(int i = 0; i < NO_OF_QUEUES_PER_CORE; i++){
|
||||
handles[i + offset] = xQueueCreate(1,1); //Create queues
|
||||
names[i + offset] = calloc(QUEUE_NAME_MAX_LENGTH, sizeof(char));
|
||||
sprintf(names[i + offset], "Queue%d%d", core, i);
|
||||
}
|
||||
|
||||
xSemaphoreTake(start_sem, portMAX_DELAY); //Wait for start vQueueAddToRegistry()
|
||||
for(int i = 0; i < NO_OF_QUEUES_PER_CORE; i++){
|
||||
vQueueAddToRegistry(handles[i + offset] , names[i + offset]); //Register queues to queue registry
|
||||
}
|
||||
xSemaphoreGive(done_sem); //Signal that vQueueAddToRegistry() has completed
|
||||
|
||||
vTaskDelay(1);
|
||||
|
||||
xSemaphoreTake(start_sem, portMAX_DELAY); //Wait to start vQueueUnregisterQueue()
|
||||
for(int i = 0; i < NO_OF_QUEUES_PER_CORE; i++){
|
||||
vQueueDelete(handles[i + offset]); //Internally calls vQueueUnregisterQueue
|
||||
}
|
||||
xSemaphoreGive(done_sem); //Signal done
|
||||
|
||||
vTaskDelete(NULL); //Delete self
|
||||
}
|
||||
|
||||
TEST_CASE("Test FreeRTOS Queue Registry", "[freertos]")
|
||||
{
|
||||
//Create synchronization semaphores
|
||||
start_sem = xSemaphoreCreateCounting(portNUM_PROCESSORS, 0);
|
||||
done_sem = xSemaphoreCreateCounting(portNUM_PROCESSORS, 0);
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++){ //Create tasks to test queue registry
|
||||
xTaskCreatePinnedToCore(test_queue_registry_task, "testing task", 4096, NULL, UNITY_FREERTOS_PRIORITY+1, NULL, i);
|
||||
}
|
||||
|
||||
portDISABLE_INTERRUPTS();
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++){
|
||||
xSemaphoreGive(start_sem); //Trigger start
|
||||
}
|
||||
portENABLE_INTERRUPTS();
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++){
|
||||
xSemaphoreTake(done_sem, portMAX_DELAY); //Wait for tasks to complete vQueueAddToRegistry
|
||||
}
|
||||
for(int i = 0; i < NO_OF_QUEUES_TOTAL; i++){
|
||||
const char *addr = pcQueueGetName(handles[i]);
|
||||
TEST_ASSERT(addr == names[i]) //Check vQueueAddToRegistry was successful
|
||||
}
|
||||
|
||||
portDISABLE_INTERRUPTS();
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++){
|
||||
xSemaphoreGive(start_sem); //Trigger start
|
||||
}
|
||||
portENABLE_INTERRUPTS();
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++){
|
||||
xSemaphoreTake(done_sem, portMAX_DELAY); //Wait for tasks to complete vQueueUnregisterQueue
|
||||
}
|
||||
for(int i = 0; i < NO_OF_QUEUES_TOTAL; i++){
|
||||
const char *addr = pcQueueGetName(handles[i]);
|
||||
TEST_ASSERT(addr == NULL) //Check vQueueUnregisterQueue was successful
|
||||
handles[i] = NULL;
|
||||
}
|
||||
|
||||
//Cleanup
|
||||
for(int i = 0; i < NO_OF_QUEUES_TOTAL; i++){
|
||||
free(names[i]);
|
||||
names[i] = NULL;
|
||||
}
|
||||
vSemaphoreDelete(start_sem);
|
||||
start_sem = NULL;
|
||||
vSemaphoreDelete(done_sem);
|
||||
done_sem = NULL;
|
||||
}
|
||||
#endif //(CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE > 0)
|
Reference in New Issue
Block a user