Skip to content

Reduce the CPU load when waiting for the display #35

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

Merged
merged 2 commits into from
Feb 11, 2020
Merged

Reduce the CPU load when waiting for the display #35

merged 2 commits into from
Feb 11, 2020

Conversation

mariovisic
Copy link
Contributor

@mariovisic mariovisic commented Feb 6, 2020

In many places a pass instruction is used in loops to wait until we hear back
back from the display. This causes the loop to execute continuously which uses
all of the available CPU, if we instead sleep for 1ms, we don't lose much time
(less than 1ms each wait) and we dramatically reduce the load on the CPU.

Before the change (updating a 3-color 2.13" display):

time python3 ./update_display

real    0m19.664s
user    0m17.622s
sys     0m1.046s

After the change:

time python3 ./update_display

real    0m19.730s
user    0m3.563s
sys     0m0.792s1

The total time to run the script is about the same, but the CPU time has reduced dramatically.

In many places a `pass` instruction is used in loops to wait until we hear back
back from the display. This causes the loop to execute continuously which uses
all of the available CPU, if we instead sleep for 1ms, we don't lose much time
(less than 1ms each wait) and we dramatically reduce the load on the CPU.

Before the change (updating a 3-color 2.13" display):

```
time python3 ./update_display

real    0m19.664s
user    0m17.622s
sys     0m1.046s
```

After the change:

time python3 ./update_display

real    0m19.730s
user    0m3.563s
sys     0m0.792s1

The total time to run the script is about the same, but the CPU time has reduced dramatically.
@ladyada ladyada requested a review from makermelissa February 6, 2020 15:56
@ladyada
Copy link
Member

ladyada commented Feb 6, 2020

@makermelissa maybe check it still works on a feather m4 + wing in the next week or two? :)

@makermelissa
Copy link
Collaborator

I tried this out with a Feather M4 and both the mono and tri-color and neither worked. So then I tried the original code before this change and it didn't work for either display again, so I'll have to look into it further.

@makermelissa
Copy link
Collaborator

Ok! I got it working. It tested fine on both the mono and tri-color displays.

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and tested fine.

@makermelissa makermelissa merged commit 1f18b62 into adafruit:master Feb 11, 2020
@mariovisic
Copy link
Contributor Author

🙌 thank you so much :)

@mariovisic mariovisic deleted the nice_to_cpu branch February 11, 2020 02:49
@makermelissa
Copy link
Collaborator

Thank you!

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 11, 2020
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.

3 participants