Function for reading cycle count of CPU clock
- Vader_Mester
- Posts: 300
- Joined: Tue Dec 05, 2017 8:28 pm
- Location: Hungary
- Contact:
Function for reading cycle count of CPU clock
Hey Guys,
Is there an function in ESP-IDF to return the number of cycles?
I came across a function somewhere named "_getcyclescount()", but I'm not sure where, and I'm not really sure which header file should I look for.
Thanks in advance
Vader[BEN]
Is there an function in ESP-IDF to return the number of cycles?
I came across a function somewhere named "_getcyclescount()", but I'm not sure where, and I'm not really sure which header file should I look for.
Thanks in advance
Vader[BEN]
Code: Select all
task_t coffeeTask()
{
while(atWork){
if(!xStreamBufferIsEmpty(mug)){
coffeeDrink(mug);
} else {
xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
}
}
vTaskDelete(NULL);
}
- Vader_Mester
- Posts: 300
- Joined: Tue Dec 05, 2017 8:28 pm
- Location: Hungary
- Contact:
Re: Function for reading cycle count of CPU clock
Code: Select all
task_t coffeeTask()
{
while(atWork){
if(!xStreamBufferIsEmpty(mug)){
coffeeDrink(mug);
} else {
xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
}
}
vTaskDelete(NULL);
}
- Vader_Mester
- Posts: 300
- Joined: Tue Dec 05, 2017 8:28 pm
- Location: Hungary
- Contact:
Re: Function for reading cycle count of CPU clock
Upon checking the Xtensa documents, I found the CCOUNT register, and it says 32bit.
I assume when it reaches the value 0xFFFFFFFF, it will wrap to 0x00000000.
I also don't know if anything is writing/resetting this register during runtime. Perhaps someone can enlight me about this?
Thanks
Vader[BEN]
I assume when it reaches the value 0xFFFFFFFF, it will wrap to 0x00000000.
I also don't know if anything is writing/resetting this register during runtime. Perhaps someone can enlight me about this?
Thanks
Vader[BEN]
Code: Select all
task_t coffeeTask()
{
while(atWork){
if(!xStreamBufferIsEmpty(mug)){
coffeeDrink(mug);
} else {
xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
}
}
vTaskDelete(NULL);
}
Re: Function for reading cycle count of CPU clock
To the best of my knowledge, there is no way to reset / write to the register and it would be incredibly dangerous to do so. As I understand it this is a singleton and hardware ticker that ticks at the lowest level of the CPU operation. If logic needs to know how many cycles have passed between point A and point B then one would subtract A from B. If I could change the value of the register, that could break logic elsewhere that expected the register to monotonically increment without perturbation. Doing some mental math, I am guessing that it will look after about 20 elapsed seconds at 200MHz. Do you really need the finest possible granularity of time measurement over such a long duration? I think the standard gettimeofday returns a resolution at the microsecond level on an on-going basis.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
- Vader_Mester
- Posts: 300
- Joined: Tue Dec 05, 2017 8:28 pm
- Location: Hungary
- Contact:
Re: Function for reading cycle count of CPU clock
Thanks Iggr! Does setting the CCOUNT register do any harm in the ESP32?ESP_igrr wrote:Actually, we do...
https://github.com/espressif/esp-idf/bl ... clk.c#L726
I guess not, but would be nice to make sure. It should be making my job easier, to sort-of zero out the register before calculating.
Code: Select all
task_t coffeeTask()
{
while(atWork){
if(!xStreamBufferIsEmpty(mug)){
coffeeDrink(mug);
} else {
xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
}
}
vTaskDelete(NULL);
}
Re: Function for reading cycle count of CPU clock
It doesn't harm the CPU, but keep in mind that FreeRTOS ticks are generated when CCOUNT matches CCOMPARE0. So if you modify CCOUNT, this will likely affect FreeRTOS tick interval. If tick interval exceeds the interrupt watchdog interval, interrupt watchdog will trigger. Ticks are also responsible for timeouts in all FreeRTOS blocking functions.
You may want to consider Timer Group timers instead, which are entirely at application's disposal. These have 64 bit counters, which might make your job easier in some cases.
You may want to consider Timer Group timers instead, which are entirely at application's disposal. These have 64 bit counters, which might make your job easier in some cases.
-
- Posts: 1
- Joined: Sat Oct 20, 2018 7:07 pm
Re: Function for reading cycle count of CPU clock
I was reading through this thread, and was trying to figure out what ESP_igrr was referring to, but his link to master is no longer relevant of course.
I tracked down the version I'm pretty sure he was linking to, in case anyone reading this thread now is curious:
https://github.com/espressif/esp-idf/bl ... clk.c#L726
I tracked down the version I'm pretty sure he was linking to, in case anyone reading this thread now is curious:
https://github.com/espressif/esp-idf/bl ... clk.c#L726
Who is online
Users browsing this forum: aliarifat794 and 81 guests