关于esp32双核调用及性能问题

wencaitian
Posts: 2
Joined: Fri Apr 09, 2021 6:35 am

关于esp32双核调用及性能问题

Postby wencaitian » Fri Apr 09, 2021 6:45 am

我用arduino写了一个测试程序,共有8个进程,让它们单独在一个核心上运行和分布在两个核心上运行,效果为啥是一样的,性能没有改变。单核心运行所有进程每个任务耗时460微秒。所有任务分布到两个核心上还是460微秒。

volatile int item;
volatile long item1;
volatile int itm;
volatile long itm1;
volatile int it;
volatile long it1;
volatile int t;
volatile long t1;
volatile int z;
volatile long z1;
volatile int x;
volatile long x1;
volatile int c;
volatile long c1;
volatile int g;
volatile long g1;

extern "C"
{
uint8_t temprature_sens_read();
}
uint8_t temprature_sens_read();

void task_1( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
item = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
item1 = item1 + 1;
}
item = micros() - item;
Serial.println(String("p1:") + String(item));
Serial.println(item1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (item1 > 9000000000) {
item1 = 1;

}
vTaskDelay(1);
}
}

void task_2( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
itm = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
itm1 = itm1 + 2;
}
itm = micros() - itm;
Serial.println(String("p2:") + String(itm));
Serial.println(itm1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (itm1 > 9000000000) {
itm1 = 1;

}
vTaskDelay(1);
}
}

void task_3( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
it = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
it1 = it1 + 3;
}
it = micros() - it;
Serial.println(String("p3:") + String(it));
Serial.println(it1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (it1 > 9000000000) {
it1 = 1;

}
vTaskDelay(1);
}
}

void task_4( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
t = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
t1 = t1 + 4;
}
t = micros() - t;
Serial.println(String("p4:") + String(t));
Serial.println(t1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (t1 > 9000000000) {
t1 = 1;

}
vTaskDelay(1);
}
}

void task_5( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
z = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
z1 = z1 + 5;
}
z = micros() - z;
Serial.println(String("p5:") + String(z));
Serial.println(z1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (z1 > 9000000000) {
z1 = 1;

}
vTaskDelay(1);
}
}

void task_6( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
x = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
x1 = x1 + 6;
}
x = micros() - x;
Serial.println(String("p6:") + String(x));
Serial.println(x1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (x1 > 9000000000) {
x1 = 1;

}
vTaskDelay(1);
}
}

void task_7( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
c = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
c1 = c1 + 6;
}
c = micros() - c;
Serial.println(String("p7:") + String(c));
Serial.println(c1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (c1 > 9000000000) {
c1 = 1;

}
vTaskDelay(1);
}
}

void task_8( void * pvParameters ){
for(;;){
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
g = micros();
for (int i = 1; i <= 10000; i = i + (1)) {
g1 = g1 + 6;
}
g = micros() - g;
Serial.println(String("p8:") + String(g));
Serial.println(g1);
Serial.println((temprature_sens_read() - 32) / 1.8);
if (g1 > 9000000000) {
g1 = 1;

}
vTaskDelay(1);
}
}

void setup(){
item = 0;
item1 = 1;
pinMode(2, OUTPUT);
Serial.begin(9600);

xTaskCreatePinnedToCore(task_1,"task_1",4096,NULL,2,NULL,0);

itm = 0;
itm1 = 1;

xTaskCreatePinnedToCore(task_2,"task_2",4096,NULL,2,NULL,0);

it = 0;
it1 = 1;

xTaskCreatePinnedToCore(task_3,"task_3",4096,NULL,2,NULL,0);

t = 0;
t1 = 1;

xTaskCreatePinnedToCore(task_4,"task_4",4096,NULL,2,NULL,0);

z = 0;
z1 = 1;

xTaskCreatePinnedToCore(task_5,"task_5",4096,NULL,2,NULL,1);

x = 0;
x1 = 1;

xTaskCreatePinnedToCore(task_6,"task_6",4096,NULL,2,NULL,1);

c = 0;
c1 = 1;

xTaskCreatePinnedToCore(task_7,"task_7",4096,NULL,2,NULL,1);

g = 0;
g1 = 1;

xTaskCreatePinnedToCore(task_8,"task_8",4096,NULL,2,NULL,1);

}

void loop(){
vTaskDelay(1);

vTaskDelay(1);

vTaskDelay(1);

vTaskDelay(1);

vTaskDelay(1);

vTaskDelay(1);

vTaskDelay(1);

vTaskDelay(1);

}
Attachments
esp多任务测试.txt
(4.76 KiB) Downloaded 660 times

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: 关于esp32双核调用及性能问题

Postby ESP_Gargamel » Fri Apr 09, 2021 10:39 am

你可以认为 2 个核还是各跑各的任务,每个任务还是需要原来一样多的时间。并不是说一个任务,因为有 2 个核了,就会快。但现在有 2 个核,你所有的任务跑完,耗费的时间,会比 1 个核少。

wencaitian
Posts: 2
Joined: Fri Apr 09, 2021 6:35 am

Re: 关于esp32双核调用及性能问题

Postby wencaitian » Sat Apr 10, 2021 12:52 am

谢谢,现在清楚了。

Who is online

Users browsing this forum: No registered users and 122 guests