Skip to content

Commit 437a8fa

Browse files
committed
Merge branch 'test/sdio_ut_performance_time' into 'master'
sdio: fix random unit test performance failure See merge request espressif/esp-idf!8665
2 parents ad9e514 + f10a721 commit 437a8fa

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

components/driver/test/test_sdio.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "esp_log.h"
2121
#include "driver/spi_common.h"
2222
#include "soc/soc_caps.h"
23+
#include "ccomp_timer.h"
2324

2425
#if defined(SOC_SDMMC_HOST_SUPPORTED) && defined(SOC_SDIO_SLAVE_SUPPORTED)
2526
#include "driver/sdio_slave.h"
@@ -352,17 +353,16 @@ static void log_performance_tohost(uint32_t speed, const sdio_test_config_t* con
352353
if (!config->check_data) {
353354
switch (config->sdio_mode) {
354355
case SDIO_4BIT:
355-
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_MBSEC_TOHOST_4BIT, "%d", speed);
356+
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_KBSEC_TOHOST_4BIT, "%d", speed);
356357
break;
357358
case SDIO_1BIT:
358-
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_MBSEC_TOHOST_1BIT, "%d", speed);
359+
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_KBSEC_TOHOST_1BIT, "%d", speed);
359360
break;
360361
case SDIO_SPI:
361-
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_MBSEC_TOHOST_SPI, "%d", speed);
362+
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_KBSEC_TOHOST_SPI, "%d", speed);
362363
break;
363364
}
364365
}
365-
ESP_LOGI(MASTER_TAG, "Throughput: %.2lf MB/s", speed/1000.);
366366
}
367367

368368
static void test_tp_tohost_master(essl_handle_t handle, const sdio_test_config_t* config)
@@ -377,8 +377,12 @@ static void test_tp_tohost_master(essl_handle_t handle, const sdio_test_config_t
377377
int remain_length = expected_length;
378378
int offset = 0;
379379

380+
// Two counters are used. The `esp_timer_get_time()` is for the typical time, and the
381+
// `ccomp_timer` is for performance test to reduce influence caused by cache miss.
382+
int64_t pre_us = esp_timer_get_time();
383+
err = ccomp_timer_start();
384+
assert(err == ESP_OK);
380385
// though the flow is the same, the check of config->check_data influences the throughput much, put it outside
381-
uint32_t pre = xTaskGetTickCount();
382386
if (config->check_data) {
383387
do {
384388
size_t rcv_len;
@@ -416,11 +420,15 @@ static void test_tp_tohost_master(essl_handle_t handle, const sdio_test_config_t
416420
remain_length -= rcv_len;
417421
} while (remain_length > 0);
418422
}
419-
uint32_t end = xTaskGetTickCount();
423+
int64_t c_time_ms = ccomp_timer_stop()/1000;
424+
int64_t end_us = esp_timer_get_time();
420425

421-
uint32_t total_time_ms = (end-pre)*portTICK_PERIOD_MS;
422-
uint32_t throughput_byte_per_ms = expected_length / total_time_ms;
423-
ESP_LOGI(MASTER_TAG, "test done, total time: %d ms, bytes transferred: %d", total_time_ms, expected_length);
426+
uint32_t total_time_ms = (end_us - pre_us)/1000;
427+
ESP_LOGI(MASTER_TAG, "test done, total time: %d ms (%d ms compensated), bytes transferred: %d", total_time_ms, (int)c_time_ms, expected_length);
428+
429+
uint32_t throughput_byte_per_ms = expected_length / c_time_ms;
430+
ESP_LOGI(MASTER_TAG, "Throughput: compensated %.2lf MB/s, typical %.2lf MB/s",
431+
throughput_byte_per_ms/1000., expected_length/(total_time_ms*1000.));
424432
log_performance_tohost(throughput_byte_per_ms, config);
425433

426434
send_finish_test(handle);
@@ -431,17 +439,16 @@ static void log_performance_frhost(uint32_t speed, const sdio_test_config_t* con
431439
if (!config->check_data) {
432440
switch (config->sdio_mode) {
433441
case SDIO_4BIT:
434-
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_MBSEC_FRHOST_4BIT, "%d", speed);
442+
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_KBSEC_FRHOST_4BIT, "%d", speed);
435443
break;
436444
case SDIO_1BIT:
437-
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_MBSEC_FRHOST_1BIT, "%d", speed);
445+
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_KBSEC_FRHOST_1BIT, "%d", speed);
438446
break;
439447
case SDIO_SPI:
440-
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_MBSEC_FRHOST_SPI, "%d", speed);
448+
TEST_PERFORMANCE_GREATER_THAN(SDIO_THROUGHPUT_KBSEC_FRHOST_SPI, "%d", speed);
441449
break;
442450
}
443451
}
444-
ESP_LOGI(MASTER_TAG, "Throughput: %.2lf MB/s", speed/1000.);
445452
}
446453

447454
static void test_tp_frhost_master(essl_handle_t handle, const sdio_test_config_t* config)
@@ -454,7 +461,12 @@ static void test_tp_frhost_master(essl_handle_t handle, const sdio_test_config_t
454461

455462
int remain_length = expected_length;
456463
int offset = 0;
457-
uint32_t pre = xTaskGetTickCount();
464+
465+
// Two counters are used. The `esp_timer_get_time()` is for the typical time, and the
466+
// `ccomp_timer` is for performance test to reduce influence caused by cache miss.
467+
int64_t pre_us = esp_timer_get_time();
468+
err = ccomp_timer_start();
469+
assert(err == ESP_OK);
458470
do {
459471
int send_len;
460472
uint8_t* send_start;
@@ -468,11 +480,15 @@ static void test_tp_frhost_master(essl_handle_t handle, const sdio_test_config_t
468480
offset += send_len;
469481
} while (remain_length > 0);
470482

471-
uint32_t end = xTaskGetTickCount();
483+
int64_t c_time_ms = ccomp_timer_stop()/1000;
484+
int64_t end_us = esp_timer_get_time();
485+
486+
uint32_t total_time_ms = (end_us - pre_us)/1000;
487+
ESP_LOGI(MASTER_TAG, "test done, total time: %d ms (%d ms compensated), bytes transferred: %d", total_time_ms, (int)c_time_ms, expected_length);
472488

473-
uint32_t total_time_ms = (end-pre)*portTICK_PERIOD_MS;
474-
uint32_t throughput_byte_per_ms = expected_length / total_time_ms;
475-
ESP_LOGI(MASTER_TAG, "test done, total time: %d ms, bytes transferred: %d", total_time_ms, expected_length);
489+
uint32_t throughput_byte_per_ms = expected_length / c_time_ms;
490+
ESP_LOGI(MASTER_TAG, "Throughput: compensated %.2lf MB/s, typical %.2lf MB/s",
491+
throughput_byte_per_ms/1000., expected_length/(total_time_ms*1000.));
476492
log_performance_frhost(throughput_byte_per_ms, config);
477493

478494
send_finish_test(handle);

components/idf_test/include/idf_performance.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@
7171
#define IDF_PERFORMANCE_MAX_ISR_EXIT_CYCLES 565
7272
#endif
7373

74-
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_TOHOST_4BIT
75-
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_TOHOST_4BIT 12200
74+
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_TOHOST_4BIT
75+
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_TOHOST_4BIT 12200
7676
#endif
77-
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_FRHOST_4BIT
78-
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_FRHOST_4BIT 12200
77+
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_FRHOST_4BIT
78+
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_FRHOST_4BIT 12200
7979
#endif
80-
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_TOHOST_1BIT
81-
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_TOHOST_1BIT 4000
80+
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_TOHOST_1BIT
81+
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_TOHOST_1BIT 4000
8282
#endif
83-
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_FRHOST_1BIT
84-
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_FRHOST_1BIT 4000
83+
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_FRHOST_1BIT
84+
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_FRHOST_1BIT 4000
8585
#endif
86-
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_TOHOST_SPI
87-
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_TOHOST_SPI 1000
86+
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_TOHOST_SPI
87+
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_TOHOST_SPI 1000
8888
#endif
89-
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_FRHOST_SPI
90-
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_MBSEC_FRHOST_SPI 1000
89+
#ifndef IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_FRHOST_SPI
90+
#define IDF_PERFORMANCE_MIN_SDIO_THROUGHPUT_KBSEC_FRHOST_SPI 1000
9191
#endif
9292

9393
//time to perform the task selection plus context switch (from task)

0 commit comments

Comments
 (0)