I decided to run some tests ... I wrote a task that simply eats CPU in a loop and tells me how long it takes to process that loop. I ran 1 instance of the task and took a measurement, then 2 instances and then 3 instances and so on. The resulting graph is shown here:
What I am not understanding are the first two entries. It takes 338 msecs to run a loop instance with 1 task running and 678 msecs to run a loop with 2 tasks running. What I am being a dummy on ... is why doesn't it "also" take 338 msecs to complete BOTH loops with 2 tasks running when we have two cores? Naively I am imagining one task running on one core and a second task running on the second core and BOTH tasks each taking 338 msecs to complete the loop.
Here is my sample code ... and I am running with unmodified from defaults "make menuconfig":
Code: Select all
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "c_timeutils.h"
#include "sdkconfig.h"
static char tag[] = "tasks";
static void test1(void *param) {
char *id = (char *)param;
ESP_LOGD(tag, ">> %s", id);
int i;
while(1) {
struct timeval start;
gettimeofday(&start, NULL);
int j=0;
for (i=0; i<9000000; i++) {
j=j+1;
}
ESP_LOGD(tag, "%s - tick: %d", id, timeval_durationBeforeNow(&start));
}
vTaskDelete(NULL);
}
void task_tests(void *ignore) {
xTaskCreate(&test1, "task1", 2048, "Task1", 5, NULL);
xTaskCreate(&test1, "task2", 2048, "Task2", 5, NULL);
xTaskCreate(&test1, "task3", 2048, "Task3", 5, NULL);
xTaskCreate(&test1, "task4", 2048, "Task4", 5, NULL);
xTaskCreate(&test1, "task5", 2048, "Task5", 5, NULL);
xTaskCreate(&test1, "task6", 2048, "Task6", 5, NULL);
vTaskDelete(NULL);
}