-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add IO manager support #12
Conversation
I'm marking that one as WIP for now. |
8e9874b
to
e0424b5
Compare
Could @sameo @andreeaflorescu @jiangliu take a look if there are any more comments? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nits, but the PR looks good to me.
@liujing2 you need to fix the CI by replacing |
Thanks very much for the review. |
@liujing2 ah ok then I agree we should bump the CI to the latest Rust version. |
@liujing2 Could you please force push to check if CI passes with the new container? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the PR looks good.
I would appreciate if we could separate the IO ops internal mutability changes into a separate commit, and also remove the vm-memory dependency (and split the addr
argument into base, offset
) from vm-device prior to merging that PR.
Sure, we can separate the PR into three.
For the 1st, the difference between passing |
If 'base + offset' is used, the driver may need to lookup some internal data structures by using base as the key. And |
Yes, that's right that the device may do some lookup, but this could easily be a O(1) lookup for those devices that actually need to look it up (PCI devices, yes). This seems to me like a micro optimization at that point, and the cost for it is a bound between the IO trait and the IO manager. In other words, callers of the IO trait methods must be stateful by keeping track of a cookie/token. Using this kind of API builds an implicit dependency between the trait and a registration method. To me, that's not the cleanest design, and the benefit we'd get for it is arguable (an O(1) lookup). |
Ok, let's use (base, offset) tuple, otherwise we are just blocking by small technical points:) |
/// Device IO trait. | ||
/// A device supporting memory based I/O should implement this trait, then | ||
/// register itself against the different IO type ranges it handles. | ||
/// The VMM will then dispatch IO (PIO or MMIO) VM exits by calling into the | ||
/// registered devices read or write method from this trait. | ||
/// The DeviceIo trait adopts the interior mutability pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having interior mutability here is a thorny issue and needs a separate discussion :( Why do you favor this over the previous interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some users of firecracker have mentioned that lacking support of multi-queue causes performance penalty, so we hope we could enable mutli-queue for virtio devices.
Moving lock into the device backend driver is the first step:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having interior mutability here is a thorny issue and needs a separate discussion :( Why do you favor this over the previous interface?
@alexandruag Any further comments on this? I'm ok with this PR, but I'd like to get your opinion on it and see if you want to block it until we agree on the inner mutability part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, apologies for the delay. The problem with assuming interior mutability is many devices mutate their state during normal operation, but have to go out of their way to actually implement interior mutability. I don't know what the best approach is long term (hopefully it'll become clearer as we start putting things together), but one potential solution right now is to add another trait (something like DeviceIoMut
) that defines the same methods as DeviceIo
but requiring &mut self
instead of &self
, and then also add a blanket implementation such as impl<T> DeviceIo for Mutex<T> where T: DeviceIoMut { ... }
, that allows a Mutex<T>
to be used as a DeviceIo
object automatically as long as the inner type implements DeviceIoMut
(same goes for other standard wrappers that offer interior mutability like RefCell
). Does that make any sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, this satisfies both side with an zero overhead abstraction.
How about merging the PR first and sending another PR for the DeviceIoMut proposal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once rebased on top of master, this PR will look good to me
Signed-off-by: Jing Liu <[email protected]>
In order to get a real multiple threads handling to enhance performance, the DeviceIo trait need adopt interior mutability pattern. Signed-off-by: Jing Liu <[email protected]>
Based on resources definition, this adds device IO manager to manage all devices IO ranges. Signed-off-by: Jing Liu <[email protected]>
IO manager is responsible for handling IO operation when VMExit. It works out the specific device according to the address range and hand over to DeviceIo trait. Signed-off-by: Jing Liu <[email protected]>
Unit tests for IO manager. Signed-off-by: Jing Liu <[email protected]>
Append missing tests for resources and fix some typo. Signed-off-by: Jing Liu <[email protected]>
Let's firstly add IO manager which focuses on device Port IO and MMIO management, and static IO mapping in runtime as the first step.
@sameo @andreeaflorescu @jiangliu PTAL, thanks.