From 02a40b359bd72f556b10a27854787145ea014cc3 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Tue, 12 Mar 2019 14:33:29 +0800 Subject: [PATCH] Only remap device memory region lazily --- kernel/src/drivers/net/e1000.rs | 33 +++++++++++++++++++-------------- kernel/src/syscall/fs.rs | 2 -- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/kernel/src/drivers/net/e1000.rs b/kernel/src/drivers/net/e1000.rs index 0e90021..560f162 100644 --- a/kernel/src/drivers/net/e1000.rs +++ b/kernel/src/drivers/net/e1000.rs @@ -72,10 +72,13 @@ impl Driver for E1000Interface { fn try_handle_interrupt(&self) -> bool { let irq = { let driver = self.driver.0.lock(); - let mut current_addr = driver.header; - while current_addr < driver.header + driver.size { - active_table().map_if_not_exists(current_addr, current_addr); - current_addr = current_addr + PAGE_SIZE; + + if let None = active_table().get_entry(driver.header) { + let mut current_addr = driver.header; + while current_addr < driver.header + driver.size { + active_table().map_if_not_exists(current_addr, current_addr); + current_addr = current_addr + PAGE_SIZE; + } } let e1000 = unsafe { @@ -115,11 +118,12 @@ impl Driver for E1000Interface { impl E1000 { fn transmit_available(&self) -> bool { - // TODO map it in all cpu - let mut current_addr = self.header; - while current_addr < self.header + self.size { - active_table().map_if_not_exists(current_addr, current_addr); - current_addr = current_addr + PAGE_SIZE; + if let None = active_table().get_entry(self.header) { + let mut current_addr = self.header; + while current_addr < self.header + self.size { + active_table().map_if_not_exists(current_addr, current_addr); + current_addr = current_addr + PAGE_SIZE; + } } let e1000 = @@ -136,11 +140,12 @@ impl E1000 { } fn receive_available(&self) -> bool { - // TODO map it in all cpu - let mut current_addr = self.header; - while current_addr < self.header + self.size { - active_table().map_if_not_exists(current_addr, current_addr); - current_addr = current_addr + PAGE_SIZE; + if let None = active_table().get_entry(self.header) { + let mut current_addr = self.header; + while current_addr < self.header + self.size { + active_table().map_if_not_exists(current_addr, current_addr); + current_addr = current_addr + PAGE_SIZE; + } } let e1000 = diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 33833a8..552ed8d 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -878,7 +878,6 @@ impl IoVecs { fn write_all_from_slice(&mut self, buf: &[u8]) { let mut copied_len = 0; - debug!("copy {:?}", buf); for slice in self.0.iter_mut() { let copy_len = min(slice.len(), buf.len() - copied_len); if copy_len == 0 { @@ -886,7 +885,6 @@ impl IoVecs { } slice[..copy_len].copy_from_slice(&buf[copied_len..copied_len + copy_len]); - debug!("copy to {:?}", slice); copied_len += copy_len; } }