Skip to content

Commit a1be470

Browse files
authored
feat(net): prepare the poller task for network interfaces (#636)
Signed-off-by: Yuuki Takano <ytakanoster@gmail.com>
1 parent 2a537d7 commit a1be470

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

applications/awkernel_services/src/network_service.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use awkernel_async_lib::{
88
const NETWORK_SERVICE_RENDEZVOUS: &str = "/awkernel/network_service";
99

1010
const GARBAGE_COLLECTOR_NAME: &str = "[Awkernel] TCP garbage collector";
11+
const NETWORK_IF_POLLER_NAME: &str = "[Awkernel] Network interface poller";
1112

1213
type ProtoInterruptHandler = Recv<(), Send<(), Eps>>;
1314
type ChanProtoInterruptHandlerDual = Chan<(), <ProtoInterruptHandler as HasDual>::Dual>;
@@ -22,6 +23,13 @@ pub async fn run() {
2223
)
2324
.await;
2425

26+
awkernel_async_lib::spawn(
27+
NETWORK_IF_POLLER_NAME.into(),
28+
network_interface_poller(),
29+
SchedulerType::PrioritizedFIFO(0),
30+
)
31+
.await;
32+
2533
let mut ch_irq_handlers = BTreeMap::new();
2634
let mut ch_poll_handlers = BTreeMap::new();
2735
let mut ch_tick_handlers = BTreeMap::new();
@@ -101,6 +109,18 @@ pub async fn run() {
101109
}
102110
}
103111

112+
async fn network_interface_poller() {
113+
loop {
114+
let n = awkernel_lib::net::poll(); // Poll network devices.
115+
116+
if n == 0 {
117+
awkernel_async_lib::sleep(Duration::from_secs(1)).await;
118+
} else {
119+
awkernel_async_lib::r#yield().await;
120+
}
121+
}
122+
}
123+
104124
async fn spawn_handlers(
105125
if_status: awkernel_lib::net::IfStatus,
106126
ch_irq_handlers: &mut BTreeMap<u16, ChanProtoInterruptHandlerDual>,

awkernel_lib/src/net.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,14 @@ pub fn poll_interface(interface_id: u64) -> bool {
604604
///
605605
/// 1. `NetManager.read()`
606606
/// 2. `POLL_WAKERS.lock()`
607-
pub fn poll() {
607+
pub fn poll() -> usize {
608608
let net_manager = NET_MANAGER.read();
609609

610+
let mut n = 0;
611+
610612
for (interface_id, if_net) in net_manager.interfaces.iter() {
611613
if if_net.is_poll_mode && if_net.net_device.poll() {
614+
n += 1;
612615
let mut node = MCSNode::new();
613616
let mut w = POLL_WAKERS.lock(&mut node);
614617

@@ -628,6 +631,8 @@ pub fn poll() {
628631
}
629632
}
630633
}
634+
635+
n
631636
}
632637

633638
/// If some packets are processed, true is returned.

kernel/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ fn main<Info: Debug>(kernel_info: KernelInfo<Info>) {
8181
}
8282

8383
let dur = wake_task(); // Wake executable tasks periodically.
84-
awkernel_lib::net::poll(); // Poll network devices.
8584

8685
#[cfg(feature = "std")]
8786
{

0 commit comments

Comments
 (0)