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

sys/shell_lock: do not call strlen, less jumpy #19157

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

kfessel
Copy link
Contributor

@kfessel kfessel commented Jan 16, 2023

Contribution description

the current _safe_strcmp depends on not being optimized and not being inlined (implicitly given by the -O0), this new one does less (would say not since even O3 had compile results that should not return early or show different runtimes for different secrets).

the runtime of strlen depend on the length of the string (password) therefor it is removed. ifs are very jumpy and depend on the contend of password, this avoids ifs sadly clang still compiles some boolean statements to if.

with this PR the __attribute__((optimize("O0"))) should be removable.

Testing procedure

see https://godbolt.org/z/x35b85cEx
and run the <RIOT>/tests/shell_lock

Issues/PRs references

#19155 made me aware of this function

@github-actions github-actions bot added the Area: sys Area: System label Jan 16, 2023
@kfessel kfessel added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 16, 2023
@riot-ci
Copy link

riot-ci commented Jan 16, 2023

Murdock results

✔️ PASSED

8f167ba sys/shell_lock: do not call strlen, less jumpy

Success Failures Total Runtime
6785 0 6785 13m:21s

Artifacts

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Nice one!

@kfessel kfessel added Process: needs >1 ACK Integration Process: This PR requires more than one ACK and removed Process: needs >1 ACK Integration Process: This PR requires more than one ACK labels Jan 17, 2023
@kaspar030
Copy link
Contributor

bors merge

bors bot added a commit that referenced this pull request Jan 17, 2023
19157: sys/shell_lock: do not call strlen, less jumpy r=kaspar030 a=kfessel

### Contribution description

the current `_safe_strcmp` depends on not being optimized and not being inlined (implicitly given by the -O0), this new one does less (would say not since even O3 had compile results that should not return early or show different runtimes for different secrets).

the runtime of strlen depend on the length of the string (password) therefor it is removed. `ifs` are very jumpy and depend on the contend of password, this avoids `ifs` sadly clang still compiles some boolean statements to if.  

with this PR the `__attribute__((optimize("O0")))` should be removable. 

### Testing procedure

see https://godbolt.org/z/x35b85cEx
and run the `<RIOT>/tests/shell_lock` 

### Issues/PRs references
#19155 made me aware of this function 

Co-authored-by: Karl Fessel <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jan 17, 2023

Build failed:

@benpicco
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Jan 17, 2023

Build succeeded:

@bors bors bot merged commit 1c7300b into RIOT-OS:master Jan 17, 2023
@jia200x jia200x added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants