20
20
#include "esp_log.h"
21
21
#include "driver/spi_common.h"
22
22
#include "soc/soc_caps.h"
23
+ #include "ccomp_timer.h"
23
24
24
25
#if defined(SOC_SDMMC_HOST_SUPPORTED ) && defined(SOC_SDIO_SLAVE_SUPPORTED )
25
26
#include "driver/sdio_slave.h"
@@ -352,17 +353,16 @@ static void log_performance_tohost(uint32_t speed, const sdio_test_config_t* con
352
353
if (!config -> check_data ) {
353
354
switch (config -> sdio_mode ) {
354
355
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 );
356
357
break ;
357
358
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 );
359
360
break ;
360
361
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 );
362
363
break ;
363
364
}
364
365
}
365
- ESP_LOGI (MASTER_TAG , "Throughput: %.2lf MB/s" , speed /1000. );
366
366
}
367
367
368
368
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
377
377
int remain_length = expected_length ;
378
378
int offset = 0 ;
379
379
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 );
380
385
// though the flow is the same, the check of config->check_data influences the throughput much, put it outside
381
- uint32_t pre = xTaskGetTickCount ();
382
386
if (config -> check_data ) {
383
387
do {
384
388
size_t rcv_len ;
@@ -416,11 +420,15 @@ static void test_tp_tohost_master(essl_handle_t handle, const sdio_test_config_t
416
420
remain_length -= rcv_len ;
417
421
} while (remain_length > 0 );
418
422
}
419
- uint32_t end = xTaskGetTickCount ();
423
+ int64_t c_time_ms = ccomp_timer_stop ()/1000 ;
424
+ int64_t end_us = esp_timer_get_time ();
420
425
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. ));
424
432
log_performance_tohost (throughput_byte_per_ms , config );
425
433
426
434
send_finish_test (handle );
@@ -431,17 +439,16 @@ static void log_performance_frhost(uint32_t speed, const sdio_test_config_t* con
431
439
if (!config -> check_data ) {
432
440
switch (config -> sdio_mode ) {
433
441
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 );
435
443
break ;
436
444
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 );
438
446
break ;
439
447
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 );
441
449
break ;
442
450
}
443
451
}
444
- ESP_LOGI (MASTER_TAG , "Throughput: %.2lf MB/s" , speed /1000. );
445
452
}
446
453
447
454
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
454
461
455
462
int remain_length = expected_length ;
456
463
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 );
458
470
do {
459
471
int send_len ;
460
472
uint8_t * send_start ;
@@ -468,11 +480,15 @@ static void test_tp_frhost_master(essl_handle_t handle, const sdio_test_config_t
468
480
offset += send_len ;
469
481
} while (remain_length > 0 );
470
482
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 );
472
488
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. ) );
476
492
log_performance_frhost (throughput_byte_per_ms , config );
477
493
478
494
send_finish_test (handle );
0 commit comments