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

RFC: Reduce CPU usage with std::thread::sleep #27

Merged
merged 1 commit into from
May 29, 2024

Conversation

plaes
Copy link
Contributor

@plaes plaes commented May 28, 2024

There's lot of busy-polling happening when interfacing with remote device during longer runs and this causes noticeable CPU usage. Reduce this a bit by pausing execution for short periods.

This patch drops CPU (single core) usage down to ~15% on my machine.

@Dirbaio
Copy link
Member

Dirbaio commented May 28, 2024

i'm not sure about this. i've tried similar things in the past and the downside is it caps max rtt bandwidth. each "poll" you can transfer at most 1 buffer size worth, so this caps it to 10*buffer_size per second.

Perhaps a less agressive power saving is sleeping only if last poll didn't yield new data.

Interfacing with probe is a busy-loop, therefore the least we can do
is to sleep for a short period when defmt buffer read returns no data.

This lowers process' CPU usage to ~15% instead of previous full
utilization.
@plaes plaes force-pushed the teleprobe-reduce-cpu branch from e5b6bff to be044c8 Compare May 29, 2024 13:02
@plaes
Copy link
Contributor Author

plaes commented May 29, 2024

i'm not sure about this. i've tried similar things in the past and the downside is it caps max rtt bandwidth. each "poll" you can transfer at most 1 buffer size worth, so this caps it to 10*buffer_size per second.

Perhaps a less agressive power saving is sleeping only if last poll didn't yield new data.

Thanks for insight, I now sleep only when defmt.read() doesn't read any data.

@Dirbaio Dirbaio merged commit f29415d into embassy-rs:main May 29, 2024
1 check passed
@Dirbaio
Copy link
Member

Dirbaio commented May 29, 2024

thanks!

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