mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 08:53:29 +00:00
Move network polling code to bottom half
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
9804f053f2
commit
7d24e63216
@ -7,7 +7,8 @@ use alloc::{
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
use ostd::sync::{LocalIrqDisabled, SpinLock, SpinLockGuard};
|
||||
use aster_softirq::BottomHalfDisabled;
|
||||
use ostd::sync::{SpinLock, SpinLockGuard};
|
||||
use smoltcp::{
|
||||
iface::{packet::Packet, Context},
|
||||
phy::Device,
|
||||
@ -30,9 +31,9 @@ use crate::{
|
||||
|
||||
pub struct IfaceCommon<E: Ext> {
|
||||
name: String,
|
||||
interface: SpinLock<PollableIface<E>, LocalIrqDisabled>,
|
||||
used_ports: SpinLock<BTreeMap<u16, usize>, LocalIrqDisabled>,
|
||||
sockets: SpinLock<SocketTable<E>, LocalIrqDisabled>,
|
||||
interface: SpinLock<PollableIface<E>, BottomHalfDisabled>,
|
||||
used_ports: SpinLock<BTreeMap<u16, usize>, BottomHalfDisabled>,
|
||||
sockets: SpinLock<SocketTable<E>, BottomHalfDisabled>,
|
||||
sched_poll: E::ScheduleNextPoll,
|
||||
}
|
||||
|
||||
@ -67,12 +68,12 @@ impl<E: Ext> IfaceCommon<E> {
|
||||
// Lock order: `interface` -> `sockets`
|
||||
impl<E: Ext> IfaceCommon<E> {
|
||||
/// Acquires the lock to the interface.
|
||||
pub(crate) fn interface(&self) -> SpinLockGuard<'_, PollableIface<E>, LocalIrqDisabled> {
|
||||
pub(crate) fn interface(&self) -> SpinLockGuard<'_, PollableIface<E>, BottomHalfDisabled> {
|
||||
self.interface.lock()
|
||||
}
|
||||
|
||||
/// Acquires the lock to the socket table.
|
||||
pub(crate) fn sockets(&self) -> SpinLockGuard<'_, SocketTable<E>, LocalIrqDisabled> {
|
||||
pub(crate) fn sockets(&self) -> SpinLockGuard<'_, SocketTable<E>, BottomHalfDisabled> {
|
||||
self.sockets.lock()
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
use alloc::{collections::btree_map::BTreeMap, string::String, sync::Arc};
|
||||
|
||||
use ostd::sync::{LocalIrqDisabled, SpinLock};
|
||||
use aster_softirq::BottomHalfDisabled;
|
||||
use ostd::sync::SpinLock;
|
||||
use smoltcp::{
|
||||
iface::{packet::Packet, Config, Context},
|
||||
phy::{DeviceCapabilities, TxToken},
|
||||
@ -25,7 +26,7 @@ pub struct EtherIface<D, E: Ext> {
|
||||
driver: D,
|
||||
common: IfaceCommon<E>,
|
||||
ether_addr: EthernetAddress,
|
||||
arp_table: SpinLock<BTreeMap<Ipv4Address, EthernetAddress>, LocalIrqDisabled>,
|
||||
arp_table: SpinLock<BTreeMap<Ipv4Address, EthernetAddress>, BottomHalfDisabled>,
|
||||
}
|
||||
|
||||
impl<D: WithDevice, E: Ext> EtherIface<D, E> {
|
||||
|
@ -6,7 +6,8 @@ use alloc::{
|
||||
};
|
||||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
use ostd::sync::{LocalIrqDisabled, SpinLock, SpinLockGuard};
|
||||
use aster_softirq::BottomHalfDisabled;
|
||||
use ostd::sync::{SpinLock, SpinLockGuard};
|
||||
use smoltcp::{
|
||||
socket::{tcp::State, PollAt},
|
||||
time::Duration,
|
||||
@ -34,7 +35,7 @@ pub type TcpConnection<E> = Socket<TcpConnectionInner<E>, E>;
|
||||
|
||||
/// States needed by [`TcpConnectionBg`].
|
||||
pub struct TcpConnectionInner<E: Ext> {
|
||||
socket: SpinLock<RawTcpSocketExt<E>, LocalIrqDisabled>,
|
||||
socket: SpinLock<RawTcpSocketExt<E>, BottomHalfDisabled>,
|
||||
poll_key: PollKey,
|
||||
connection_key: ConnectionKey,
|
||||
}
|
||||
@ -243,7 +244,7 @@ impl<E: Ext> TcpConnectionInner<E> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn lock(&self) -> SpinLockGuard<RawTcpSocketExt<E>, LocalIrqDisabled> {
|
||||
pub(super) fn lock(&self) -> SpinLockGuard<RawTcpSocketExt<E>, BottomHalfDisabled> {
|
||||
self.socket.lock()
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
use alloc::{boxed::Box, collections::btree_map::BTreeMap, sync::Arc, vec::Vec};
|
||||
|
||||
use ostd::sync::{LocalIrqDisabled, SpinLock};
|
||||
use aster_softirq::BottomHalfDisabled;
|
||||
use ostd::sync::SpinLock;
|
||||
use smoltcp::{
|
||||
socket::PollAt,
|
||||
time::Duration,
|
||||
@ -35,7 +36,7 @@ pub struct TcpBacklog<E: Ext> {
|
||||
|
||||
/// States needed by [`TcpListenerBg`].
|
||||
pub struct TcpListenerInner<E: Ext> {
|
||||
pub(super) backlog: SpinLock<TcpBacklog<E>, LocalIrqDisabled>,
|
||||
pub(super) backlog: SpinLock<TcpBacklog<E>, BottomHalfDisabled>,
|
||||
listener_key: ListenerKey,
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,8 @@
|
||||
use alloc::{boxed::Box, sync::Arc};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use ostd::sync::{LocalIrqDisabled, SpinLock};
|
||||
use aster_softirq::BottomHalfDisabled;
|
||||
use ostd::sync::SpinLock;
|
||||
use smoltcp::{
|
||||
iface::Context,
|
||||
socket::udp::UdpMetadata,
|
||||
@ -22,7 +23,7 @@ pub type UdpSocket<E> = Socket<UdpSocketInner, E>;
|
||||
|
||||
/// States needed by [`UdpSocketBg`].
|
||||
pub struct UdpSocketInner {
|
||||
socket: SpinLock<Box<RawUdpSocket>, LocalIrqDisabled>,
|
||||
socket: SpinLock<Box<RawUdpSocket>, BottomHalfDisabled>,
|
||||
need_dispatch: AtomicBool,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user