Skip to content

feat(net): 引入kthread,将Inet-网卡处理流程移入内核线程中 #1130

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

Merged

Conversation

Samuka007
Copy link
Member

@Samuka007 Samuka007 commented Apr 9, 2025

todo:

  • kthread 调度优先级
  • 为每个 Iface 引入中断处理线程,性能会更好?
  • 仍然有死锁问题?

@github-actions github-actions bot added the enhancement New feature or request label Apr 9, 2025
@Samuka007
Copy link
Member Author

#[unified_init(INITCALL_SUBSYS)]
pub fn net_poll_init() -> Result<(), system_error::SystemError> {
let closure = KernelThreadClosure::StaticEmptyClosure((&(net_poll_thread as fn() -> i32), ()));
let pcb = KernelThreadMechanism::create_and_run(closure, "net_poll".to_owned())
.ok_or("")
.expect("create net_poll thread failed");
log::info!("net_poll thread created");
unsafe {
NET_POLL_THREAD = Some(pcb);
}
return Ok(());
}
fn net_poll_thread() -> i32 {
log::info!("net_poll thread started");
loop {
for (_, iface) in NET_DEVICES.read_irqsave().iter() {
iface.poll();
}
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
ProcessManager::mark_sleep(true).expect("clocksource_watchdog_kthread:mark sleep failed");
drop(irq_guard);
schedule(SchedMode::SM_NONE);
}
}
/// 拉起线程
pub(super) fn wakeup_poll_thread() {
if unsafe { NET_POLL_THREAD.is_none() } {
return;
}
let _ = ProcessManager::wakeup(unsafe { NET_POLL_THREAD.as_ref().unwrap() });
}

目前是只为整个中断流程起了单独一个内核线程,在任意网卡中断来临时,处理所有网卡。

@fslongjin 调度优先级是要在哪个地方改?

@Samuka007 Samuka007 added the A-network Area: 网络子系统 label Apr 9, 2025
@fslongjin
Copy link
Member

#[unified_init(INITCALL_SUBSYS)]
pub fn net_poll_init() -> Result<(), system_error::SystemError> {
let closure = KernelThreadClosure::StaticEmptyClosure((&(net_poll_thread as fn() -> i32), ()));
let pcb = KernelThreadMechanism::create_and_run(closure, "net_poll".to_owned())
.ok_or("")
.expect("create net_poll thread failed");
log::info!("net_poll thread created");
unsafe {
NET_POLL_THREAD = Some(pcb);
}
return Ok(());
}
fn net_poll_thread() -> i32 {
log::info!("net_poll thread started");
loop {
for (_, iface) in NET_DEVICES.read_irqsave().iter() {
iface.poll();
}
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
ProcessManager::mark_sleep(true).expect("clocksource_watchdog_kthread:mark sleep failed");
drop(irq_guard);
schedule(SchedMode::SM_NONE);
}
}
/// 拉起线程
pub(super) fn wakeup_poll_thread() {
if unsafe { NET_POLL_THREAD.is_none() } {
return;
}
let _ = ProcessManager::wakeup(unsafe { NET_POLL_THREAD.as_ref().unwrap() });
}

目前是只为整个中断流程起了单独一个内核线程,在任意网卡中断来临时,处理所有网卡。
@fslongjin 调度优先级是要在哪个地方改?

cfs的话应该是调整nice值。
目前为了能跑,可以先不管这个。

@Samuka007 Samuka007 merged commit b6cc375 into DragonOS-Community:feat-network-rebuild Apr 14, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-network Area: 网络子系统 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants