Skip to content

Improve optimistic_yield intervals for performance gain in sketches #7952

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dok-net
Copy link
Contributor

@dok-net dok-net commented Mar 31, 2021

The purpose of optimistic_yield is to be used in library functions that get called in tight loops from CONT, in order to avoid unnecessarily frequent yields to SYS, and the performance impact that entails. This PR tries to identify and fix a few places where very low intervals were used for no obvious purpose.

@dok-net dok-net mentioned this pull request Mar 31, 2021
@dok-net dok-net requested a review from earlephilhower March 31, 2021 09:40
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from 58708b3 to 8b164cc Compare April 9, 2021 22:34
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

As we discussed, I think the existing constants in optimistic_yield were chosen as a best-guess with no real "100% correct answer" possible. So I looked at the reasoning as to why the oy was there in the 1st place and how the change would affect it (considering expectation value of wait times for busywait loops).

@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from afb2656 to 40cff9e Compare April 11, 2021 21:46
@dok-net dok-net requested a review from earlephilhower April 11, 2021 21:49
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from 40cff9e to f3dbafc Compare April 19, 2021 09:24
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from f3dbafc to 816c727 Compare April 28, 2021 12:30
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 7 times, most recently from b903aa6 to b8bd44b Compare May 18, 2021 13:40
const uint32_t pulse_start_cycle_count = xthal_get_ccount();
WAIT_FOR_PIN_STATE(!state);
if (!waitForPinState(pin, !state, timeout_cycles, start_cycle_count)) {
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is wrong per my reading of the (not so hot docs) https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/?setlang=it

Return 0 on no pulse beginning edge detected. OTW, it should return the full timeout as the pulse width (i.e. get rid of the return 0 and just fallthru tho the return below).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@earlephilhower I thought I had answered a long time before. IIRC I researched and besides this refactoring not changing how the return works before, my reading of the docs etc was that returning 0 was and is correct. Hm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@earlephilhower Can you agree this year; the change is just same effective execution path as with the macros before?

@dok-net dok-net force-pushed the optimistic_yield_intervals branch from b8bd44b to da6c4e8 Compare May 23, 2021 17:09
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 3 times, most recently from c2b436e to 7fe3607 Compare June 8, 2021 01:42
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from 7fe3607 to e58126f Compare June 28, 2021 10:43
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from dc76df9 to e80a82b Compare October 16, 2021 10:36
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from e80a82b to 65deed2 Compare October 16, 2021 23:25
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from 65deed2 to 5fe47c9 Compare October 26, 2021 22:36
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from 5fe47c9 to c994b68 Compare December 3, 2021 00:22
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from c994b68 to ca07b3a Compare December 16, 2021 20:16
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from fbaebe3 to bd32d2c Compare March 13, 2022 18:37
@dok-net dok-net requested a review from earlephilhower March 13, 2022 19:22
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from bd32d2c to 1bf128f Compare December 10, 2022 22:06
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from 1bf128f to 342c94e Compare December 23, 2022 09:24
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