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

Refactor rtt [3/2] #573

Closed
wants to merge 4 commits into from
Closed

Refactor rtt [3/2] #573

wants to merge 4 commits into from

Conversation

Urhengulas
Copy link
Member

@Urhengulas Urhengulas commented Sep 8, 2021

This PR mainly factors out the common part of fn blocking_write and fn nonblocking_write into one common method.

@Urhengulas Urhengulas marked this pull request as draft September 8, 2021 19:50
@Urhengulas Urhengulas mentioned this pull request Sep 8, 2021
@Urhengulas Urhengulas changed the title Refactor defmt-rtt Refactor rtt [2/2] Sep 8, 2021
bors bot added a commit that referenced this pull request Sep 17, 2021
574: Refactor rtt [1/2] r=jonas-schievink a=Urhengulas

First half of #573:
*  defmt-rtt: Move struct Channel into own module
* defmt-rtt: Make fn host_is_connected a method of Channel
* defmt-rtt: Move struct Header into own module
* defmt-rtt: Rename fn handle to fn channel + mv to mod channel


Co-authored-by: Johann Hemmann <[email protected]>
firmware/defmt-rtt/src/channel.rs Show resolved Hide resolved
firmware/defmt-rtt/src/channel.rs Show resolved Hide resolved
///
/// Returns the amount of bytes copied.
fn write_impl(&self, bytes: &[u8], available: usize) -> usize {
let cursor = self.write.load(Ordering::Acquire);
Copy link
Member

Choose a reason for hiding this comment

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

if you do an atomic load here you'll end up doing two atomic loads of the write cursor in the blocking_write method. the compiler never merges atomic operations so this will end up adding more instructions and make the blocking_write operations slower.

Copy link
Member Author

Choose a reason for hiding this comment

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

So we rather add it as another argument to the function?

Copy link
Member

Choose a reason for hiding this comment

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

maybe. the main point here is that if you reorder atomic operations, add new ones or move memory operations around the atomic operations you are no longer refactoring the code: you are subtly changing its semantics.

Copy link
Member Author

Choose a reason for hiding this comment

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

I get that. I've split out the not-error-prone changes to #622 and converted this one to a draft.

I'd like to keep it open, because it is a quite obvious case of code-duplication.

@Urhengulas Urhengulas marked this pull request as draft October 31, 2021 21:18
@Urhengulas Urhengulas changed the title Refactor rtt [2/2] Refactor rtt [3/2] Oct 31, 2021
@Urhengulas Urhengulas mentioned this pull request Oct 31, 2021
@Urhengulas Urhengulas closed this Feb 2, 2022
bors bot added a commit that referenced this pull request Feb 15, 2022
622: Refactor rtt [2/2] r=Urhengulas a=Urhengulas

This PR contains the not-error-prone changes from #573 and addresses the review given to #573.

661: `snapshot-tests`: Add tests for cell types r=Urhengulas a=Urhengulas

Follow-up to #656, which add snapshot tests for the new `defmt::Format` implementations.

Co-authored-by: Johann Hemmann <[email protected]>
bors bot added a commit that referenced this pull request Oct 3, 2022
695: `defmt-rtt`: Refactor rtt [3/2] r=Urhengulas a=Urhengulas

This is the second attempt to land #573. This time I am not touching atomic variables, but only de-duplicate the almost copy pasted parts of `blocking_write` and `nonblocking_write`. Especially the first commit makes the duplication quite clear.

Co-authored-by: Urhengulas <[email protected]>
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