Skip to content

Commit

Permalink
Kill switch workaround around rx-queue saturation
Browse files Browse the repository at this point in the history
Uses a kill switch work around, which disables rx to avoid any potential
errors while receiving, thus allowing the egress part of the poll loop
to actually perform uninterrupted work. This is a hack, and should be
regarded as a a temporary, potentially buggy solution. Copy with care.
  • Loading branch information
HeroicKatora committed Mar 22, 2019
1 parent 4c50499 commit dc2a9af
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/phy/kill_switch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::rc::Rc;
use std::cell::RefCell;

use super::{Device, DeviceCapabilities};

pub struct KillSwitch<P> {
inner: P,
switch: Rc<RefCell<Config>>,
}

#[derive(Clone)]
pub struct Switch {
switch: Rc<RefCell<Config>>,
}

#[derive(Default)]
struct Config {
no_rx: bool,
no_tx: bool,
}

impl<P> KillSwitch<P> {
pub fn new(device: P) -> Self {
KillSwitch {
inner: device,
switch: Rc::default(),
}
}

pub fn switch(&self) -> Switch {
Switch {
switch: self.switch.clone(),
}
}
}

impl Switch {
pub fn kill_rx(&self, killed: bool) -> bool {
core::mem::replace(&mut self.switch.borrow_mut().no_rx, killed)
}

pub fn kill_tx(&self, killed: bool) -> bool {
core::mem::replace(&mut self.switch.borrow_mut().no_tx, killed)
}
}

impl<'a, P> Device<'a> for KillSwitch<P>
where P: Device<'a>
{
type RxToken = P::RxToken;
type TxToken = P::TxToken;

fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
if self.switch.borrow().no_rx {
None
} else {
self.inner.receive()
}
}

fn transmit(&'a mut self) -> Option<Self::TxToken> {
if self.switch.borrow().no_tx {
None
} else {
self.inner.transmit()
}
}

fn capabilities(&self) -> DeviceCapabilities {
self.inner.capabilities()
}
}
3 changes: 3 additions & 0 deletions src/phy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ use time::Instant;
mod sys;

mod tracer;
#[cfg(any(feature = "std", feature = "alloc"))]
mod kill_switch;
mod fault_injector;
mod pcap_writer;
#[cfg(any(feature = "std", feature = "alloc"))]
Expand All @@ -104,6 +106,7 @@ mod tap_interface;
pub use self::sys::wait;

pub use self::tracer::Tracer;
pub use self::kill_switch::KillSwitch;
pub use self::fault_injector::FaultInjector;
pub use self::pcap_writer::{PcapLinkType, PcapMode, PcapSink, PcapWriter};
#[cfg(any(feature = "std", feature = "alloc"))]
Expand Down

0 comments on commit dc2a9af

Please sign in to comment.