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(AddressRange): create and use a proper type #144

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

n1tram1
Copy link
Collaborator

@n1tram1 n1tram1 commented Aug 30, 2023

Previously AddressRange was just a type alias to a usize pair. This caused confusion as sometimes it was (addr, size) or (start, end) and lead to a few confusing debugs.

The new type hopefully clear up confusions and make it easy to iterate over the pages in an addressrange.

pub fn round_up_to_page(self, page_size: usize) -> Self {
Self {
start: self.start,
end: mm::align_up(self.end, page_size),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be cool if mm was able to find the page_size by itself

}
}

pub fn iter_pages(self, page_size: usize) -> impl Iterator<Item = usize> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should just provide page_size to new. Are we using AddressRange for something else than pages?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use it for anything else than pages, I've checked

Comment on lines +48 to +51
pub fn count_pages(&self, page_size: usize) -> usize {
mm::align_up(self.size(), page_size) / page_size
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dito

Comment on lines 54 to 56
pub fn align_up(addr: usize) -> usize {
mm::align_up(addr, PageTable::PAGE_SIZE)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think in the future we should just merge hal_core with hal_archXXX with conditional compilation. There is place for some code factoring but that for another time

@n1tram1 n1tram1 force-pushed the temp/address-range-refactor branch from 8488939 to ff621e5 Compare August 31, 2023 09:35
@n1tram1
Copy link
Collaborator Author

n1tram1 commented Aug 31, 2023

I agree with all the remarks about page_size.
This is an issue I want to address but I would rather do it outside of this PR if ok ?

@n1tram1 n1tram1 requested a review from Skallwar August 31, 2023 09:37
}

impl AddressRange {
pub fn new(start: usize, end: usize) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Could be nice to have a constructor from a Range<usize>, the syntax would be a bit more range like: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=38449a783dbfc3192aba75f8c9f6de67

Not sure if that's useful though!

@n1tram1 n1tram1 force-pushed the temp/address-range-refactor branch from ff621e5 to 4465779 Compare August 31, 2023 12:03
Previously AddressRange was just a type alias to a usize pair.
This caused confusion as sometimes it was (addr, size) or (start, end)
and lead to a few confusing debugs.

The new type hopefully clear up confusions and make it easy to iterate
over the pages in an addressrange.
@n1tram1 n1tram1 force-pushed the temp/address-range-refactor branch from 4465779 to 8348f2d Compare August 31, 2023 12:04
@n1tram1 n1tram1 merged commit 03a517c into main Aug 31, 2023
7 checks passed
@n1tram1 n1tram1 deleted the temp/address-range-refactor branch August 31, 2023 12:09
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