322322 #error "Nano newlib formatting must not be enabled for benchmark"
323323 #endif
324324 #endif
325+ #if ESP_IDF_VERSION_MAJOR >= 5
326+ #define TFMT "%lu"
327+ #else
328+ #define TFMT "%d"
329+ #endif
325330
326331 #ifdef configTICK_RATE_HZ
327332 /* Define CPU clock cycles per tick of FreeRTOS clock
337342 #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
338343 #endif
339344 #endif
345+ #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
346+ /* This section is for pre-v5 ESP-IDF */
347+ #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
348+ #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
349+ CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
350+ #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
351+ #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
352+ CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
353+ #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
354+ #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
355+ CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
356+ #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
357+ #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
358+ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
359+ #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
360+ #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
361+ CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
362+ #else
363+ /* TODO unsupported */
364+ #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
365+ #endif
340366 #define CPU_TICK_CYCLES ( \
341367 (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
342368 / configTICK_RATE_HZ \
354380 #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
355381 defined(CONFIG_IDF_TARGET_ESP32C6)
356382 #include <esp_cpu.h>
357- #include "driver/gptimer.h"
383+ #if ESP_IDF_VERSION_MAJOR >= 5
384+ #include <driver/gptimer.h>
385+ #endif
358386 #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
359387 #define RESOLUTION_SCALE 100
388+ /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
360389 static gptimer_handle_t esp_gptimer = NULL;
361390 static gptimer_config_t esp_timer_config = {
362391 .clk_src = GPTIMER_CLK_SRC_DEFAULT,
375404 #elif defined(CONFIG_IDF_TARGET_ESP8266)
376405 /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
377406 #include <FreeRTOS.h>
407+ #include <esp_system.h>
408+ #include <esp_timer.h>
409+ #include <xtensa/hal.h>
378410 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
379411 /* TODO add ESP32-H2 benchmark support */
380412 #else
@@ -1446,10 +1478,16 @@ static const char* bench_result_words3[][5] = {
14461478 thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
14471479 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
14481480
1449- thisVal = esp_cpu_get_cycle_count();
1481+ #if ESP_IDF_VERSION_MAJOR >= 5
1482+ thisVal = esp_cpu_get_cycle_count();
1483+ #else
1484+ thisVal = cpu_hal_get_cycle_count();
1485+ #endif
14501486
14511487 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
14521488 thisVal = esp_cpu_get_cycle_count();
1489+ #elif defined(CONFIG_IDF_TARGET_ESP8266)
1490+ thisVal = esp_timer_get_time();
14531491 #else
14541492 /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
14551493 * Calling current_time(1) to reset time causes thisVal overflow,
@@ -1478,7 +1516,7 @@ static const char* bench_result_words3[][5] = {
14781516 expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
14791517 ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
14801518 ESP_LOGV(TAG, "tickCount = %llu", tickCount);
1481- ESP_LOGV(TAG, "last_tickCount = %u", last_tickCount);
1519+ ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
14821520 ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
14831521 ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
14841522 }
@@ -1514,9 +1552,16 @@ static const char* bench_result_words3[][5] = {
15141552
15151553 /* double check expected diff calc */
15161554 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
1517- expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
1518- * tickDiff / configTICK_RATE_HZ;
1519- ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
1555+ #if defined(CONFIG_IDF_TARGET_ESP8266)
1556+ expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
1557+ * MILLION_VALUE)
1558+ * tickDiff / configTICK_RATE_HZ;
1559+ #else
1560+ expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
1561+ * tickDiff / configTICK_RATE_HZ;
1562+
1563+ #endif
1564+ ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
15201565 #endif
15211566 if (expected_diff > UINT_MAX) {
15221567 /* The number of cycles expected from FreeRTOS ticks is
@@ -1540,7 +1585,7 @@ static const char* bench_result_words3[][5] = {
15401585 ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
15411586 ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
15421587
1543- ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
1588+ ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
15441589 }
15451590 #endif
15461591 }
@@ -1593,7 +1638,13 @@ static const char* bench_result_words3[][5] = {
15931638 ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
15941639 ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
15951640 #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
1596- _esp_cpu_count_last = esp_cpu_get_cycle_count();
1641+
1642+ #if ESP_IDF_VERSION_MAJOR >= 5
1643+ _esp_cpu_count_last = esp_cpu_get_cycle_count();
1644+ #else
1645+ _esp_cpu_count_last = cpu_hal_get_cycle_count();
1646+ #endif
1647+
15971648 ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
15981649 }
15991650 #elif defined(CONFIG_IDF_TARGET_ESP32H2)
@@ -2243,8 +2294,9 @@ static WC_INLINE void bench_stats_start(int* count, double* start)
22432294
22442295#ifdef WOLFSSL_ESPIDF
22452296 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
2246- ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu, start=" FLT_FMT,
2247- total_cycles, FLT_FMT_ARGS(*start) );
2297+ ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
2298+ ", start=" FLT_FMT,
2299+ total_cycles, FLT_FMT_ARGS(*start) );
22482300 #endif
22492301 BEGIN_ESP_CYCLES
22502302#else
@@ -2264,12 +2316,14 @@ static WC_INLINE void bench_stats_start(int* count, double* start)
22642316static WC_INLINE int bench_stats_check(double start)
22652317{
22662318 int ret = 0;
2267- double this_current_time;
2319+ double this_current_time = 0.0 ;
22682320 this_current_time = current_time(0); /* get the timestamp, no reset */
22692321
22702322#if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
2271- ESP_LOGV(TAG, "bench_stats_check: Current time %f, start %f",
2272- this_current_time, start );
2323+ #if defined(WOLFSSL_ESPIDF)
2324+ ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
2325+ this_current_time, start );
2326+ #endif
22732327#endif
22742328
22752329 ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
@@ -14179,8 +14233,13 @@ void bench_sphincsKeySign(byte level, byte optim)
1417914233 #ifdef __XTENSA__
1418014234 _esp_cpu_count_last = xthal_get_ccount();
1418114235 #else
14182- esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
14183- _esp_cpu_count_last = esp_cpu_get_cycle_count();
14236+ #if ESP_IDF_VERSION_MAJOR >= 5
14237+ esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
14238+ _esp_cpu_count_last = esp_cpu_get_cycle_count();
14239+ #else
14240+ cpu_hal_set_cycle_count((uint32_t)0);
14241+ _esp_cpu_count_last = cpu_hal_get_cycle_count();
14242+ #endif
1418414243 #endif
1418514244 }
1418614245 #endif
@@ -14191,9 +14250,9 @@ void bench_sphincsKeySign(byte level, byte optim)
1419114250 typiclly in app_startup.c */
1419214251
1419314252 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
14194- ESP_LOGV(TAG, "tickCount = %d" , tickCount);
14253+ ESP_LOGV(TAG, "tickCount = " TFMT , tickCount);
1419514254 if (tickCount == last_tickCount) {
14196- ESP_LOGW(TAG, "last_tickCount unchanged? %d" , tickCount);
14255+ ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT , tickCount);
1419714256
1419814257 }
1419914258 if (tickCount < last_tickCount) {
@@ -14203,13 +14262,13 @@ void bench_sphincsKeySign(byte level, byte optim)
1420314262
1420414263 if (reset) {
1420514264 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
14206- ESP_LOGW(TAG, "Assign last_tickCount = %d" , tickCount);
14265+ ESP_LOGW(TAG, "Assign last_tickCount = " TFMT , tickCount);
1420714266 #endif
1420814267 last_tickCount = tickCount;
1420914268 }
1421014269 else {
1421114270 #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
14212- ESP_LOGV(TAG, "No Reset last_tickCount = %d" , tickCount);
14271+ ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT , tickCount);
1421314272 #endif
1421414273 }
1421514274
0 commit comments