- 
                Notifications
    You must be signed in to change notification settings 
- Fork 22
Introduce Mutex<T: DeviceIoMut> adapter for DeviceIo #20
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
Conversation
60d5697    to
    31eba84      
    Compare
  
    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]>
606840f    to
    794c377      
    Compare
  
    | /// | ||
| /// The Mutex<T: DeviceIoMut> adapter is an zero overhead abstraction without | ||
| /// performance penalty. | ||
| pub trait DeviceIoMut: Send { | 
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.
I wonder whether adding the Send bound here is really necessary. What happens if we remove it?
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.
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 { | 
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.
It makes sense for this to be Sync, but (just wondering, like the previous question) does anything depend on it being Send as well?
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.
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>; | 
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.
Hmm, any reason to deref into a &Vec<Resource> and not a slice (&[Resource])?
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.
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]>
794c377    to
    11f77fb      
    Compare
  
    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]>
5f0c72d    to
    2d9c7e6      
    Compare
  
    | Can we close this one? | 
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]