Skip to content

Devices: clean up interrupt sending code #335

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mtjhrc
Copy link
Collaborator

@mtjhrc mtjhrc commented May 26, 2025

This PR aims to remove some of the duplicate code we have in regards to sending interrupts.

We had around 15 copies of:

self.interrupt_status
    .fetch_or(VIRTIO_MMIO_INT_VRING as usize, Ordering::SeqCst);
if let Some(intc) = &self.intc {
    intc.lock()
        .unwrap()
        .set_irq(self.irq_line, Some(&self.interrupt_evt))?;

But also for each such a copy of the interrupt sending code, we had to pass around 4 variables (interrupt_status, irq_line, intc, interrupt_evt) to each worker thread, which is quite silly.

This simplifies the handling, by creating a struct InterruptTransport which holds the fields and has a signal_used_queue method. The InterruptTransport is managed by the MmioTransport passing it to the device upon activation.

@mtjhrc mtjhrc force-pushed the device-refactor branch 4 times, most recently from 6d84bbb to b10d57b Compare May 27, 2025 11:37
mtjhrc added 2 commits June 4, 2025 14:10
Add DeviceState::is_activated and use it in VirtioDevice::is_activated
implementations.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
Signed-off-by: Matej Hrica <mhrica@redhat.com>
@mtjhrc mtjhrc force-pushed the device-refactor branch from b10d57b to 2fbbc11 Compare June 4, 2025 12:12
mtjhrc added 2 commits June 4, 2025 14:29
Create an abstraction InterruptTransport which sits at the MmioTransport layer.
This holds all the necessary fields to send an interrupt. The InterruptTransport
is passed to a VirtioDevice as a parameter for the activate() method call and is
saved inside DeviceState::Active.

Make IrqChip now passed into the MmioTransport::new. Because it is now always
required, this removes the need to check if it is set before sending an interrupt.

Previously we had around 15 copied implementations of signal_used_queue in the
project. For every implementation/place (worker threads, etc) where
signal_used_queue was necessary, one had to also pass around 4 variables.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
Introduce the method VirtioDevice::device_name(). Use this method in order to log
with a custom target at the mmio transport layer, which contains the name as a
suffix. This makes sure to log all signal_used_queue() calls issued by devices.

Interrupt requests by a specific device can be filtered using the suffix.
E.g. when debugging the GPU device you can do:
RUST_LOG=devices::virtio::mmio[gpu]=trace,warn

This will enable logging the interrupts only for the GPU device, but `warn!` logs
will still be enabled globally, even for "devices::virtio::mmio". You can also
still specify "devices::virtio::mmio=trace", which will log fo all devices.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
@mtjhrc mtjhrc force-pushed the device-refactor branch from 2fbbc11 to 6750dc9 Compare June 4, 2025 12:34
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.

1 participant