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

ISSUE-29: Switch IRQ handler's map from BTreeMap to array #35

Merged
merged 2 commits into from
Oct 31, 2021
Merged

ISSUE-29: Switch IRQ handler's map from BTreeMap to array #35

merged 2 commits into from
Oct 31, 2021

Conversation

Lurk
Copy link
Contributor

@Lurk Lurk commented Oct 31, 2021

Fixes #29

I have very little knowledge of how OS should work, but some parts of IRQ handlers do not feel right.

Here
https://github.com/Lurk/kerla/blob/b213c965d3127a35b429da62fa9d134304107fbf/kernel/interrupt.rs#L28-L31
we do not check if the handler is already assigned. That will definitely lead to strange bugs.

And here
https://github.com/Lurk/kerla/blob/b213c965d3127a35b429da62fa9d134304107fbf/kernel/interrupt.rs#L33-L38
The call of net::process_packets feels like it should be done in the handler.

If I am right, should I tackle it in this pull request or create separate issues and pull requests?

// TODO: Use a simple array for faster access.
static IRQ_HANDLERS: SpinLock<BTreeMap<u8, Box<dyn FnMut() + Send + Sync>>> =
SpinLock::new(BTreeMap::new());
static IRQ_HANDLERS: SpinLock<[Option<Box<dyn FnMut() + Send + Sync>>; 255]> = SpinLock::new([
Copy link
Owner

Choose a reason for hiding this comment

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

An IRQ number can be in the range of [0, 255]. We need 256 slots.

Suggested change
static IRQ_HANDLERS: SpinLock<[Option<Box<dyn FnMut() + Send + Sync>>; 255]> = SpinLock::new([
static IRQ_HANDLERS: SpinLock<[Option<Box<dyn FnMut() + Send + Sync>>; 256]> = SpinLock::new([

Copy link
Owner

Choose a reason for hiding this comment

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

How about using a const to avoid writing a lot of None?

const DEFAULT_IRQ_HANDLER: Option<Box<dyn FnMut() + Send + Sync>> = None;
static IRQ_HANDLERS: SpinLock<[Option<Box<dyn FnMut() + Send + Sync>>; 256]> =
    SpinLock::new([DEFAULT_IRQ_HANDLER; 256]);

Copy link
Contributor Author

@Lurk Lurk Oct 31, 2021

Choose a reason for hiding this comment

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

I was googling for a solution like this but somehow did not find it :)
Replaced
And size is also fixed.

Copy link
Owner

Choose a reason for hiding this comment

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

I found this stackoverflow answer. I was beginning to give up on that too ;)

@nuta
Copy link
Owner

nuta commented Oct 31, 2021

Here
https://github.com/Lurk/kerla/blob/b213c965d3127a35b429da62fa9d134304107fbf/kernel/interrupt.rs#L28-L31
we do not check if the handler is already assigned. That will definitely lead to strange bugs.

Good point. it will be helpful if there's an assertion to ensure no handlers are already registered.

And here
https://github.com/Lurk/kerla/blob/b213c965d3127a35b429da62fa9d134304107fbf/kernel/interrupt.rs#L33-L38
The call of net::process_packets feels like it should be done in the handler.

I think so too. It should be moved to somewhere else.

If I am right, should I tackle it in this pull request or create separate issues and pull requests?

I agree these points should be improved, but I'd merge them as separate PRs.

@nuta nuta merged commit b2fe564 into nuta:main Oct 31, 2021
@nuta
Copy link
Owner

nuta commented Oct 31, 2021

Merged. Thank you @Lurk!

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.

Switch IRQ handler's map from BTreeMap to array
2 participants