-
Notifications
You must be signed in to change notification settings - Fork 7.7k
-
I am trying to measure the number of cycles it takes for esp32s3 to set a bit , I did this to execute the function from the IRAM, I thought its gonna be faster. (I am using the touch peripheral)
void __attribute__ ((noinline)) IRAM_ATTR test(){
RTCCNTL.touch_ctrl2.touch_start_en = 0;
}
ccount = xt_utils_get_cycle_count();`
test();
elapsed = xt_utils_get_cycle_count() - ccount;
I measured the required processor cycles and it was 113 CPU cycle !!
The assembly code is shown as follows:
0x403776bb <+3>: l32r a9, 0x40374458 (0x60008000)
0x403776be <+6>: l32r a10, 0x403747f8 (0xffff7fff)
0x403776c1 <+9>: memw
0x403776c4 <+12>: l32i a8, a9, 0x10c
0x403776c7 <+15>: and a8, a8, a10
0x403776ca <+18>: tmemw
0x403776cd <+21>: s32i a8, a9, 0x10c
My question is why would these instruction take about 113 cycles to execute ?? even though they are just simple instructions, what is the issue ?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 6 replies
-
this is not a simple register write, it is in fact register read, then AND (to clear the bit from the register value) and then write again the result back into the actual register. You are setting a bit, not writing to the register a full value.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
To add more context, xt_utils_get_cycle_count()
also takes some cycles, as well as the jump to the test()
function.
ccount0 = xt_utils_get_cycle_count();
ccount1 = xt_utils_get_cycle_count();
RTCCNTL.touch_ctrl2.val = 0;
ccount2 = xt_utils_get_cycle_count();
elapsed = (ccount2 - ccount1) - (ccount1 - ccount0);
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes I counted those and removed them and Ended by 113 CPU cycle
Beta Was this translation helpful? Give feedback.
All reactions
-
don't forget that peripherals are on different clock domain than the CPU. They do not run at the CPU clock speed, so they do take more time
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Okay, that makes sense, I wonder whether some peripheral clocks are configurable or not ? or maybe using the DMA can help making it faster
Beta Was this translation helpful? Give feedback.
All reactions
-
you can look in the technical reference manual for the chip to find out what clock options are available for each peripheral. Not sure how DMA would help in setting registers though.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1