Notify virtqueue in a batch manner

This commit is contained in:
jiangjianfeng
2024-12-17 02:24:07 +00:00
committed by Tate, Hongliang Tian
parent acc10376e6
commit 9a540d0fb6
5 changed files with 109 additions and 17 deletions

View File

@ -18,3 +18,9 @@ pub trait WithDevice: Send + Sync {
where
F: FnOnce(&mut Self::Device) -> R;
}
/// A trait for notifying device drivers about the polling process.
pub trait NotifyDevice {
/// Notifies the device driver that polling has ended.
fn notify_poll_end(&mut self);
}

View File

@ -13,7 +13,7 @@ use smoltcp::{
};
use crate::{
device::WithDevice,
device::{NotifyDevice, WithDevice},
ext::Ext,
iface::{
common::IfaceCommon, iface::internal::IfaceInternal, time::get_network_timestamp, Iface,
@ -70,7 +70,10 @@ impl<D, E: Ext> IfaceInternal<E> for EtherIface<D, E> {
}
}
impl<D: WithDevice + 'static, E: Ext> Iface<E> for EtherIface<D, E> {
impl<D: WithDevice + 'static, E: Ext> Iface<E> for EtherIface<D, E>
where
D::Device: NotifyDevice,
{
fn poll(&self) {
self.driver.with(|device| {
let next_poll = self.common.poll(
@ -78,6 +81,7 @@ impl<D: WithDevice + 'static, E: Ext> Iface<E> for EtherIface<D, E> {
|data, iface_cx, tx_token| self.process(data, iface_cx, tx_token),
|pkt, iface_cx, tx_token| self.dispatch(pkt, iface_cx, tx_token),
);
device.notify_poll_end();
self.common.sched_poll().schedule_next_poll(next_poll);
});
}