Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix esp32 hardware timer performance #2455

Merged
merged 3 commits into from
Dec 27, 2021
Merged

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Dec 26, 2021

This PR fix poor performance of hwtimer2 on ESP32 by using hardware directly.
It also fixes code so it can be used from C.

How many loop iterations can we achieve in 100 ms ?

ESP32

Using millis(), managed 105418 iterations, average loop time = 949ns (152 CPU cycles)
Using micros(), managed 102942 iterations, average loop time = 971ns (155 CPU cycles)

Using PolledTimer:
BEFORE: managed 135827 iterations, average loop time = 736ns (118 CPU cycles)
AFTER: managed 921085 iterations, average loop time = 109ns (17 CPU cycles)

ESP32C3

Using millis(), managed 98837 iterations, average loop time = 1012ns (162 CPU cycles)
Using micros(), managed 123863 iterations, average loop time = 807ns (129 CPU cycles)

Using PolledTimer:
BEFORE: managed 136670 iterations, average loop time = 732ns (117 CPU cycles)
AFTER: managed 551882 iterations, average loop time = 181ns (29 CPU cycles)

ESP32S2

Using millis(), managed 68260 iterations, average loop time = 1465ns (234 CPU cycles)
Using micros(), managed 68921 iterations, average loop time = 1451ns (232 CPU cycles)
Using PolledTimer:
AFTER: managed 528409 iterations, average loop time = 189ns (30 CPU cycles)

@mikee47 mikee47 changed the title Fix esp32 hardware timers Fix esp32 hardware timer performance Dec 26, 2021
Use hardware directly. Call overhead unacceptable.

How many loop iterations can we achieve in 100 ms ?

**ESP32**

Using millis(), managed 105418 iterations, average loop time = 949ns (152 CPU cycles)
Using micros(), managed 102942 iterations, average loop time = 971ns (155 CPU cycles)

Using PolledTimer:
  BEFORE: managed 135827 iterations, average loop time = 736ns (118 CPU cycles)
  AFTER: managed 921085 iterations, average loop time = 109ns (17 CPU cycles)

**ESP32C3**

Using millis(), managed 98837 iterations, average loop time = 1012ns (162 CPU cycles)
Using micros(), managed 123863 iterations, average loop time = 807ns (129 CPU cycles)

Using PolledTimer:
  BEFORE: managed 136670 iterations, average loop time = 732ns (117 CPU cycles)
  AFTER: managed 551882 iterations, average loop time = 181ns (29 CPU cycles)

**ESP32S2**

Using millis(), managed 68260 iterations, average loop time = 1465ns (234 CPU cycles)
Using micros(), managed 68921 iterations, average loop time = 1451ns (232 CPU cycles)
Using PolledTimer:
  AFTER: managed 528409 iterations, average loop time = 189ns (30 CPU cycles)
@slaff slaff added this to the 4.5.1 milestone Dec 27, 2021
@slaff slaff merged commit 8ca9bd4 into SmingHub:develop Dec 27, 2021
@mikee47 mikee47 deleted the fix/hwtimer-c branch December 27, 2021 11:32
mikee47 added a commit to mikee47/Sming that referenced this pull request Dec 27, 2021
SmingHub#2455 changed the timer2 timebase so it no longer corresponds with the microsecond system clock used for OsTimer.
slaff pushed a commit that referenced this pull request Dec 28, 2021
#2455 changed the timer2 timebase so it no longer corresponds with the microsecond system clock used for OsTimer.

Added check in HostTests to catch this.
Also improve Host CPU clock emulation to accurately reflect selected frequency.

Also fix rp2040 esp_get_ccount return value, now passes tests.
@slaff slaff mentioned this pull request Jan 10, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants