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

perf(pci): remove Arc from PCI configs #194

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions alioth/src/device/pvpanic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<const N: u64> Mmio for PvPanicBar<N> {

#[derive(Debug)]
pub struct PvPanic {
pub config: Arc<EmulatedConfig>,
pub config: EmulatedConfig,
}

impl PvPanic {
Expand All @@ -82,9 +82,7 @@ impl PvPanic {
let mut bars = [const { PciBar::Empty }; 6];
bars[0] = bar0;
let config = EmulatedConfig::new_device(header, bar_masks, bars, PciCapList::new());
PvPanic {
config: Arc::new(config),
}
PvPanic { config }
}
}

Expand All @@ -95,8 +93,8 @@ impl Default for PvPanic {
}

impl Pci for PvPanic {
fn config(&self) -> Arc<dyn PciConfig> {
self.config.clone()
fn config(&self) -> &dyn PciConfig {
&self.config
}

fn reset(&self) -> pci::Result<()> {
Expand Down
12 changes: 4 additions & 8 deletions alioth/src/pci/host_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;

use crate::pci;
use crate::pci::cap::PciCapList;
use crate::pci::config::{CommonHeader, DeviceHeader, EmulatedConfig, HeaderType, PciConfig};
use crate::pci::{Pci, PciBar};

#[derive(Debug)]
pub struct HostBridge {
pub config: Arc<EmulatedConfig>,
pub config: EmulatedConfig,
}

impl Default for HostBridge {
Expand All @@ -45,15 +43,13 @@ impl HostBridge {
};
let bars = [const { PciBar::Empty }; 6];
let config = EmulatedConfig::new_device(header, [0; 6], bars, PciCapList::new());
HostBridge {
config: Arc::new(config),
}
HostBridge { config }
}
}

impl Pci for HostBridge {
fn config(&self) -> Arc<dyn PciConfig> {
self.config.clone()
fn config(&self) -> &dyn PciConfig {
&self.config
}

fn reset(&self) -> pci::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/pci/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum Error {
pub type Result<T, E = Error> = std::result::Result<T, E>;

pub trait Pci: Debug + Send + Sync + 'static {
fn config(&self) -> Arc<dyn PciConfig>;
fn config(&self) -> &dyn PciConfig;
fn reset(&self) -> Result<()>;
}

Expand Down
2 changes: 1 addition & 1 deletion alioth/src/pci/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::pci::{Bdf, Pci, PciDevice, Result};
struct EmptyDevice;

impl Pci for EmptyDevice {
fn config(&self) -> Arc<dyn PciConfig> {
fn config(&self) -> &dyn PciConfig {
unreachable!()
}

Expand Down
10 changes: 5 additions & 5 deletions alioth/src/vfio/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub struct VfioPciDev<M, D>
where
M: MsiSender,
{
config: Arc<PciPthConfig<D>>,
config: PciPthConfig<D>,
msix_table: Arc<MsixTableMmio<M::IrqFd>>,
}

Expand All @@ -396,8 +396,8 @@ where
D: Device,
M: MsiSender,
{
fn config(&self) -> Arc<dyn PciConfig> {
self.config.clone()
fn config(&self) -> &dyn PciConfig {
&self.config
}

fn reset(&self) -> pci::Result<()> {
Expand Down Expand Up @@ -538,7 +538,7 @@ where
}

Ok(VfioPciDev {
config: Arc::new(PciPthConfig {
config: PciPthConfig {
header: EmulatedHeader {
data: Arc::new(RwLock::new(HeaderData {
header: config_header,
Expand All @@ -555,7 +555,7 @@ where
offset: region_config.offset,
size: region_config.size as usize,
},
}),
},
msix_table,
})
}
Expand Down
10 changes: 4 additions & 6 deletions alioth/src/virtio/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ where
E: IoeventFd,
{
pub dev: VirtioDevice<D, PciIrqSender<M>, E>,
pub config: Arc<EmulatedConfig>,
pub config: EmulatedConfig,
pub registers: Arc<VirtioPciRegisterMmio<M>>,
}

Expand Down Expand Up @@ -854,9 +854,7 @@ where
}
}

let config = Arc::new(EmulatedConfig::new_device(
header, bar_masks, bars, cap_list,
));
let config = EmulatedConfig::new_device(header, bar_masks, bars, cap_list);

Ok(VirtioPciDevice {
dev,
Expand All @@ -872,8 +870,8 @@ where
D: Virtio,
E: IoeventFd,
{
fn config(&self) -> Arc<dyn PciConfig> {
self.config.clone()
fn config(&self) -> &dyn PciConfig {
&self.config
}
fn reset(&self) -> pci::Result<()> {
self.registers.wake_up_dev(WakeEvent::Reset);
Expand Down
4 changes: 1 addition & 3 deletions alioth/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ where
} else {
self.board.pci_bus.reserve(None, name.clone()).unwrap()
};
let config = dev.dev.config();
dev.dev.config().get_header().set_bdf(bdf);
self.board.pci_bus.add(bdf, dev);
let header = config.get_header();
header.set_bdf(bdf);
log::info!("{bdf}: device: {name}");
Ok(())
}
Expand Down