ESP32-C3 RDCYCLE

fabianpedd
Posts: 2
Joined: Tue Feb 22, 2022 8:12 am

ESP32-C3 RDCYCLE

Postby fabianpedd » Tue Feb 22, 2022 8:17 am

How do I access the RISC-V performance counters, namely CYCLE, TIME, and INSTRET on the ESP32-C3 (see Chapter 10 RISC-V spec)? I am running the ESP-IDF.

Running

Code: Select all

__asm__ volatile("rdcycle %0" : "=r"(cycles));
or

Code: Select all

__asm__ volatile("csrrs %0, cycle, x0" : "=r"(cycles));
results in illegal instruction exceptions. However, they work on other platforms.

Thanks in advance

EDIT: It seems like Espressif decided to implement their own perf counter instead of using the one(s) specified by the RISC-V standard. If you are looking for a register that returns the cycle count, just like

Code: Select all

CYCLE
,

Code: Select all

MPCCR
is probably what you are looking for. It is located at

Code: Select all

0x7E2
in the CSRs address space and documented under "Performance Counter CSRs (Custom)" in the technical reference manual. There seems to be a C function (not documented in the ESP-IDF for whatever reason) that can be used to read it conveniently from C applications:

Code: Select all

esp_cpu_ccount_t esp_cpu_get_ccount(void)
(see here https://github.com/espressif/esp-idf/bl ... _cpu.h#L61).
Last edited by fabianpedd on Tue Mar 08, 2022 8:40 pm, edited 1 time in total.

fabianpedd
Posts: 2
Joined: Tue Feb 22, 2022 8:12 am

Re: ESP32-C3 RDCYCLE

Postby fabianpedd » Tue Mar 08, 2022 7:27 pm

Does anyone have any idea?

Who is online

Users browsing this forum: No registered users and 228 guests