Skip to content

Conversation

@jiangliu
Copy link
Member

This is an following-up PR for #12 .

Many device backend drivers will mutate itself when handling IO
requests. The DeviceIo trait assumes interior mutability, but it's
a little complex to support interior mutability. So introduce the
Mutex<T: DeviceIoMut> adapter to ease device backend driver
implementations. And the Mutex<T: DeviceIoMut> adapter is an zero
overhead abstraction without performance penalty.

Liu Jiang [email protected]

@jiangliu jiangliu self-assigned this Jan 22, 2020
@jiangliu jiangliu force-pushed the device_io_mut branch 2 times, most recently from 60d5697 to 31eba84 Compare January 22, 2020 06:02
Many device backend drivers will mutate itself when handling IO
requests. The DeviceIo trait assumes interior mutability, but it's
a little complex to support interior mutability. So introduce the
Mutex<T: DeviceIoMut> adapter to ease device backend driver
implementations. And the Mutex<T: DeviceIoMut> adapter is an zero
overhead abstraction without performance penalty.

Liu Jiang <[email protected]>
Previously DeviceIo depends on Send, but doesn't depend on Sync,
which fails to share Arc<IoManager> among vCPU threads. So make
DeviceIo depend on Sync too.

Signed-off-by: Liu Jiang <[email protected]>
@jiangliu jiangliu force-pushed the device_io_mut branch 6 times, most recently from 606840f to 794c377 Compare February 6, 2020 09:15
///
/// The Mutex<T: DeviceIoMut> adapter is an zero overhead abstraction without
/// performance penalty.
pub trait DeviceIoMut: Send {
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 whether adding the Send bound here is really necessary. What happens if we remove it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The propagation chain for Send/Sync is something like:
EpollHandler -> Vmm -> Device Manager -> IoManager -> DeviceIo

/// focusing on high performance, they may use the Mutex<T: DeviceIoMut>
/// adapter to simplify implementation.
pub trait DeviceIo: Send {
pub trait DeviceIo: Send + Sync {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes sense for this to be Sync, but (just wondering, like the previous question) does anything depend on it being Send as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

The the DeviceIo needs to be Send + Sync for Arc to be Sync:)

src/resources.rs Outdated
}

impl Deref for DeviceResources {
type Target = Vec<Resource>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, any reason to deref into a &Vec<Resource> and not a slice (&[Resource])?

Copy link
Member Author

Choose a reason for hiding this comment

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

good suggestion, will change to return a slice.

Implement Clone for IoManager, which will be needed for RCU-style
device hotplug.

Liu Jiang <[email protected]>
Export IoSize and IoRange as pub, which may be reused.

Liu Jiang <[email protected]>
Implement Deref for DeviceResources, so we could walk all resource
entries in an Resources object.

Signed-off-by: Liu Jiang <[email protected]>
Add #[derive(Debug)] for resource related data structs, so we could
use assert!() and assert_eq!() etc in unit test cases.

Signed-off-by: Liu Jiang <[email protected]>
The design to multiplex IoAddress/IoSize for MMIO and PIO makes
the device driver implmentation a little complex, so build dedicated
data structs and interfaces to handle PIO requests. Also make PIO
related code x86 specific.

Signed-off-by: Liu Jiang <[email protected]>
@jiangliu jiangliu force-pushed the device_io_mut branch 8 times, most recently from 5f0c72d to 2d9c7e6 Compare May 26, 2020 12:26
@gsserge
Copy link

gsserge commented Jan 12, 2022

Can we close this one?

@jiangliu jiangliu closed this Feb 21, 2022
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