feat(freertos): Introduced new Kconfig option CONFIG_FREERTOS_NUMBER_OF_CORES

This commit replaces the use of portNUM_PROCESSORS and configNUM_CORES
macros in all of ESP-IDF. These macros are needed to realize an SMP
scenario by fetching the number of active cores FreeRTOS is running on.
Instead, a new Kconfig option, CONFIG_FREERTOS_NUMBER_OF_CORES, has been
added as a proxy for the FreeRTOS config option, configNUMBER_OF_CORES.
This new commit is now used to realize an SMP scenario in various places
in ESP-IDF.

[Sudeep Mohanty: Added new Kconfig option CONFIG_FREERTOS_NUMBER_OF_CORES]

Signed-off-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
This commit is contained in:
fl0wl0w
2023-12-13 16:32:53 -06:00
committed by Sudeep Mohanty
parent b8abf75a11
commit 90d1dcfd76
91 changed files with 361 additions and 307 deletions

View File

@@ -59,17 +59,17 @@ static void tlsp_task(void *arg)
TEST_CASE("Test TLSP deletion callbacks", "[freertos]")
{
TaskHandle_t tasks[portNUM_PROCESSORS];
int tlsps[portNUM_PROCESSORS][NUM_TLSP];
TaskHandle_t tasks[configNUM_CORES];
int tlsps[configNUM_CORES][NUM_TLSP];
for (int i = 0; i < portNUM_PROCESSORS; i++) {
for (int i = 0; i < configNUM_CORES; i++) {
TEST_ASSERT_EQUAL(pdPASS, xTaskCreatePinnedToCore(tlsp_task, "tlsp_tsk", configMINIMAL_STACK_SIZE * 2, (void *)&tlsps[i], CONFIG_UNITY_FREERTOS_PRIORITY - 1, &tasks[i], i));
}
// Significant delay to let tasks run and delete themselves
vTaskDelay(pdMS_TO_TICKS(100));
// Check the values of the TLSPs to see if the del cb have ran
for (int i = 0; i < portNUM_PROCESSORS; i++) {
for (int i = 0; i < configNUM_CORES; i++) {
for (int index = 0; index < NUM_TLSP; index++) {
// Del cb should have set the TLSP to a negative value
TEST_ASSERT_EQUAL(-index, tlsps[i][index]);

View File

@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
@@ -138,16 +139,16 @@ static void send_func(void *arg)
TEST_CASE("Test queue sets multi-core", "[freertos]")
{
// Create done semaphore
done_sem = xSemaphoreCreateCounting(portNUM_PROCESSORS - 1, 0);
done_sem = xSemaphoreCreateCounting(configNUM_CORES - 1, 0);
TEST_ASSERT_NOT_EQUAL(NULL, done_sem);
// Create queues and queue set
QueueHandle_t queues[portNUM_PROCESSORS];
QueueHandle_t queues[configNUM_CORES];
QueueSetHandle_t queue_set;
allocate_resources(portNUM_PROCESSORS, QUEUE_LEN, queues, &queue_set);
allocate_resources(configNUM_CORES, QUEUE_LEN, queues, &queue_set);
// Create tasks of the same priority for all cores except for core 0
for (int i = 1; i < portNUM_PROCESSORS; i++) {
for (int i = 1; i < configNUM_CORES; i++) {
TEST_ASSERT_EQUAL(pdTRUE, xTaskCreatePinnedToCore(send_func, "send", 2048, (void *)queues[i], CONFIG_UNITY_FREERTOS_PRIORITY, NULL, i));
}
@@ -155,30 +156,30 @@ TEST_CASE("Test queue sets multi-core", "[freertos]")
send_func((void *)queues[0]);
// Wait for all other cores to be done
for (int i = 1; i < portNUM_PROCESSORS; i++) {
for (int i = 1; i < configNUM_CORES; i++) {
xSemaphoreTake(done_sem, portMAX_DELAY);
}
// Read queues from the queue set, then read an item from the queue
uint32_t queues_check_count[portNUM_PROCESSORS] = {0};
uint32_t queues_check_count[configNUM_CORES] = {0};
QueueSetMemberHandle_t member = xQueueSelectFromSet(queue_set, 0);
while (member != NULL) {
// Read the core ID from the queue, check that core ID is sane
BaseType_t core_id;
TEST_ASSERT_EQUAL(pdTRUE, xQueueReceive(member, &core_id, 0));
TEST_ASSERT_LESS_THAN(portNUM_PROCESSORS, core_id);
TEST_ASSERT_LESS_THAN(configNUM_CORES, core_id);
queues_check_count[core_id]++;
// Get next member
member = xQueueSelectFromSet(queue_set, 0);
}
// Check that all items from all queues have been read
for (int i = 0; i < portNUM_PROCESSORS; i++) {
for (int i = 0; i < configNUM_CORES; i++) {
TEST_ASSERT_EQUAL(QUEUE_LEN, queues_check_count[i]);
}
// Cleanup queues and queue set
free_resources(portNUM_PROCESSORS, queues, queue_set);
free_resources(configNUM_CORES, queues, queue_set);
// Cleanup done sem
vSemaphoreDelete(done_sem);
done_sem = NULL;

View File

@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity.h"
@@ -48,13 +49,13 @@ static void loop_task(void *arg)
TEST_CASE("Test eTaskGetState", "[freertos]")
{
TaskHandle_t blocked_tasks[portNUM_PROCESSORS];
TaskHandle_t suspended_tasks[portNUM_PROCESSORS];
TaskHandle_t ready_tasks[portNUM_PROCESSORS];
TaskHandle_t running_tasks[portNUM_PROCESSORS];
TaskHandle_t blocked_tasks[configNUM_CORES];
TaskHandle_t suspended_tasks[configNUM_CORES];
TaskHandle_t ready_tasks[configNUM_CORES];
TaskHandle_t running_tasks[configNUM_CORES];
// Create tasks of each state on each core
for (int i = 0; i < portNUM_PROCESSORS; i++) {
for (int i = 0; i < configNUM_CORES; i++) {
TEST_ASSERT_EQUAL(pdPASS, xTaskCreatePinnedToCore(blocked_task, "blkd", configMINIMAL_STACK_SIZE * 2, NULL, CONFIG_UNITY_FREERTOS_PRIORITY - 1, &blocked_tasks[i], i));
TEST_ASSERT_EQUAL(pdPASS, xTaskCreatePinnedToCore(suspended_task, "susp", configMINIMAL_STACK_SIZE * 2, NULL, CONFIG_UNITY_FREERTOS_PRIORITY - 1, &suspended_tasks[i], i));
TEST_ASSERT_EQUAL(pdPASS, xTaskCreatePinnedToCore(loop_task, "rdy", configMINIMAL_STACK_SIZE * 2, NULL, CONFIG_UNITY_FREERTOS_PRIORITY - 1, &ready_tasks[i], i));
@@ -69,7 +70,7 @@ TEST_CASE("Test eTaskGetState", "[freertos]")
vTaskDelay(10);
// Check the state of the created tasks
for (int i = 0; i < portNUM_PROCESSORS; i++) {
for (int i = 0; i < configNUM_CORES; i++) {
TEST_ASSERT_EQUAL(eBlocked, eTaskGetState(blocked_tasks[i]));
TEST_ASSERT_EQUAL(eSuspended, eTaskGetState(suspended_tasks[i]));
TEST_ASSERT_EQUAL(eReady, eTaskGetState(ready_tasks[i]));
@@ -77,7 +78,7 @@ TEST_CASE("Test eTaskGetState", "[freertos]")
}
// Clean up created tasks
for (int i = 0; i < portNUM_PROCESSORS; i++) {
for (int i = 0; i < configNUM_CORES; i++) {
vTaskDelete(blocked_tasks[i]);
vTaskDelete(suspended_tasks[i]);
vTaskDelete(ready_tasks[i]);

View File

@@ -17,7 +17,7 @@
* deletion callbacks will still be carried out by the Idle Task.
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
@@ -62,8 +62,8 @@ static void tsk_blocks_frequently(void *param)
TEST_CASE("FreeRTOS Delete Blocked Tasks", "[freertos][ignore]") // TODO: esp_rom_delay_us is interrupted by signal
{
TaskHandle_t blocking_tasks[portNUM_PROCESSORS + 1]; // one per CPU, plus one unpinned task
tsk_blocks_param_t params[portNUM_PROCESSORS + 1] = { 0 };
TaskHandle_t blocking_tasks[configNUM_CORES + 1]; // one per CPU, plus one unpinned task
tsk_blocks_param_t params[configNUM_CORES + 1] = { 0 };
esp_rom_delay_us(100);
@@ -79,19 +79,19 @@ TEST_CASE("FreeRTOS Delete Blocked Tasks", "[freertos][ignore]") // TODO: esp_ro
for(unsigned iter = 0; iter < 1000; iter++) {
// Create everything
SemaphoreHandle_t sem = xSemaphoreCreateMutex();
for(unsigned i = 0; i < portNUM_PROCESSORS + 1; i++) {
for(unsigned i = 0; i < configNUM_CORES + 1; i++) {
params[i].deleted = false;
params[i].sem = sem;
TEST_ASSERT_EQUAL(pdTRUE,
xTaskCreatePinnedToCore(tsk_blocks_frequently, "tsk_block", 4096, &params[i],
CONFIG_UNITY_FREERTOS_PRIORITY - 1, &blocking_tasks[i],
i < portNUM_PROCESSORS ? i : tskNO_AFFINITY));
i < configNUM_CORES ? i : tskNO_AFFINITY));
}
vTaskDelay(5); // Let the tasks juggle the mutex for a bit
for(unsigned i = 0; i < portNUM_PROCESSORS + 1; i++) {
for(unsigned i = 0; i < configNUM_CORES + 1; i++) {
vTaskDelete(blocking_tasks[i]);
params[i].deleted = true;
}

View File

@@ -11,7 +11,7 @@
#include <esp_types.h>
#include <stdio.h>
#include <strings.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity.h"
@@ -29,20 +29,20 @@ static void counter_task(void *param)
TEST_CASE("Get/Set Priorities", "[freertos]")
{
/* Two tasks per processor */
TaskHandle_t tasks[portNUM_PROCESSORS][2] = { 0 };
unsigned volatile counters[portNUM_PROCESSORS][2] = { 0 };
TaskHandle_t tasks[configNUM_CORES][2] = { 0 };
unsigned volatile counters[configNUM_CORES][2] = { 0 };
TEST_ASSERT_EQUAL(CONFIG_UNITY_FREERTOS_PRIORITY, uxTaskPriorityGet(NULL));
/* create a matrix of counter tasks on each core */
for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for (int cpu = 0; cpu < configNUM_CORES; cpu++) {
for (int task = 0; task < 2; task++) {
xTaskCreatePinnedToCore(counter_task, "count", 2048, (void *)&(counters[cpu][task]), CONFIG_UNITY_FREERTOS_PRIORITY - task, &(tasks[cpu][task]), cpu);
}
}
/* check they were created with the expected priorities */
for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for (int cpu = 0; cpu < configNUM_CORES; cpu++) {
for (int task = 0; task < 2; task++) {
TEST_ASSERT_EQUAL(CONFIG_UNITY_FREERTOS_PRIORITY - task, uxTaskPriorityGet(tasks[cpu][task]));
}
@@ -51,25 +51,25 @@ TEST_CASE("Get/Set Priorities", "[freertos]")
vTaskDelay(10);
/* at this point, only the higher priority tasks (first index) should be counting */
for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for (int cpu = 0; cpu < configNUM_CORES; cpu++) {
TEST_ASSERT_NOT_EQUAL(0, counters[cpu][0]);
TEST_ASSERT_EQUAL(0, counters[cpu][1]);
}
/* swap priorities! */
for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for (int cpu = 0; cpu < configNUM_CORES; cpu++) {
vTaskPrioritySet(tasks[cpu][0], CONFIG_UNITY_FREERTOS_PRIORITY - 1);
vTaskPrioritySet(tasks[cpu][1], CONFIG_UNITY_FREERTOS_PRIORITY);
}
/* check priorities have swapped... */
for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for (int cpu = 0; cpu < configNUM_CORES; cpu++) {
TEST_ASSERT_EQUAL(CONFIG_UNITY_FREERTOS_PRIORITY -1, uxTaskPriorityGet(tasks[cpu][0]));
TEST_ASSERT_EQUAL(CONFIG_UNITY_FREERTOS_PRIORITY, uxTaskPriorityGet(tasks[cpu][1]));
}
/* check the tasks which are counting have also swapped now... */
for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for (int cpu = 0; cpu < configNUM_CORES; cpu++) {
unsigned old_counters[2];
old_counters[0] = counters[cpu][0];
old_counters[1] = counters[cpu][1];
@@ -79,7 +79,7 @@ TEST_CASE("Get/Set Priorities", "[freertos]")
}
/* clean up */
for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
for (int cpu = 0; cpu < configNUM_CORES; cpu++) {
for (int task = 0; task < 2; task++) {
vTaskDelete(tasks[cpu][task]);
}

View File

@@ -8,6 +8,7 @@
* Unit tests for FreeRTOS task yielding
*/
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
@@ -444,7 +445,7 @@ TEST_CASE("Task yield must happed when a task raises the priority of another pri
TEST_ASSERT_EQUAL(2, task_yield_sequence[idx++]);
}
#if (portNUM_PROCESSORS > 1) && !(CONFIG_FREERTOS_UNICORE)
#if (configNUM_CORES > 1) && !(CONFIG_FREERTOS_UNICORE)
/*
* Test yielding behavior when a task on one core forces an yield on the other core
*
@@ -654,4 +655,4 @@ TEST_CASE("Task yield on other core must not happen when scheduler is suspended"
TEST_ASSERT_EQUAL(2, task_yield_sequence[idx1++]);
}
#endif // !CONFIG_FREERTOS_SMP
#endif // (portNUM_PROCESSORS > 1) && !(CONFIG_FREERTOS_UNICORE)
#endif // (configNUM_CORES > 1) && !(CONFIG_FREERTOS_UNICORE)