mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 18:03:25 +00:00
Minor optimizations on both lat-syscall-stat
and lat-syscall-open
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
fc77c474db
commit
f2af6136da
@ -191,7 +191,7 @@ impl<'a> ReadCString for VmReader<'a, Fallible> {
|
|||||||
|
|
||||||
// Handle the first few bytes to make `cur_addr` aligned with `size_of::<usize>`
|
// Handle the first few bytes to make `cur_addr` aligned with `size_of::<usize>`
|
||||||
read_one_byte_at_a_time_while!(
|
read_one_byte_at_a_time_while!(
|
||||||
(self.cursor() as usize) % mem::size_of::<usize>() != 0 && buffer.len() < max_len
|
!is_addr_aligned(self.cursor() as usize) && buffer.len() < max_len
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle the rest of the bytes in bulk
|
// Handle the rest of the bytes in bulk
|
||||||
@ -253,3 +253,8 @@ fn check_vaddr(va: Vaddr) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if the given address is aligned.
|
||||||
|
const fn is_addr_aligned(addr: usize) -> bool {
|
||||||
|
(addr & (mem::size_of::<usize>() - 1)) == 0
|
||||||
|
}
|
||||||
|
@ -187,6 +187,7 @@ impl FsResolver {
|
|||||||
/// If `follow_tail_link` is true and the trailing component is a symlink,
|
/// If `follow_tail_link` is true and the trailing component is a symlink,
|
||||||
/// it will be followed.
|
/// it will be followed.
|
||||||
/// Symlinks in earlier components of the path will always be followed.
|
/// Symlinks in earlier components of the path will always be followed.
|
||||||
|
#[allow(clippy::redundant_closure)]
|
||||||
fn lookup_from_parent(
|
fn lookup_from_parent(
|
||||||
&self,
|
&self,
|
||||||
parent: &Arc<Dentry>,
|
parent: &Arc<Dentry>,
|
||||||
@ -205,7 +206,7 @@ impl FsResolver {
|
|||||||
|
|
||||||
// To handle symlinks
|
// To handle symlinks
|
||||||
let follow_tail_link = lookup_ctx.follow_tail_link;
|
let follow_tail_link = lookup_ctx.follow_tail_link;
|
||||||
let mut link_path = String::new();
|
let mut link_path_opt = None;
|
||||||
let mut follows = 0;
|
let mut follows = 0;
|
||||||
|
|
||||||
// Initialize the first dentry and the relative path
|
// Initialize the first dentry and the relative path
|
||||||
@ -263,9 +264,10 @@ impl FsResolver {
|
|||||||
if link_path_remain.starts_with('/') {
|
if link_path_remain.starts_with('/') {
|
||||||
dentry = self.root.clone();
|
dentry = self.root.clone();
|
||||||
}
|
}
|
||||||
|
let link_path = link_path_opt.get_or_insert_with(|| String::new());
|
||||||
link_path.clear();
|
link_path.clear();
|
||||||
link_path.push_str(link_path_remain.trim_start_matches('/'));
|
link_path.push_str(link_path_remain.trim_start_matches('/'));
|
||||||
relative_path = &link_path;
|
relative_path = link_path;
|
||||||
follows += 1;
|
follows += 1;
|
||||||
} else {
|
} else {
|
||||||
// If path ends with `/`, the inode must be a directory
|
// If path ends with `/`, the inode must be a directory
|
||||||
|
@ -12,11 +12,11 @@ impl InodeHandle<Rights> {
|
|||||||
access_mode: AccessMode,
|
access_mode: AccessMode,
|
||||||
status_flags: StatusFlags,
|
status_flags: StatusFlags,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let inode = dentry.inode();
|
let inode_mode = dentry.inode().mode()?;
|
||||||
if access_mode.is_readable() && !inode.mode()?.is_readable() {
|
if access_mode.is_readable() && !inode_mode.is_readable() {
|
||||||
return_errno_with_message!(Errno::EACCES, "file is not readable");
|
return_errno_with_message!(Errno::EACCES, "file is not readable");
|
||||||
}
|
}
|
||||||
if access_mode.is_writable() && !inode.mode()?.is_writable() {
|
if access_mode.is_writable() && !inode_mode.is_writable() {
|
||||||
return_errno_with_message!(Errno::EACCES, "file is not writable");
|
return_errno_with_message!(Errno::EACCES, "file is not writable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ impl InodeHandle<Rights> {
|
|||||||
status_flags: StatusFlags,
|
status_flags: StatusFlags,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let inode = dentry.inode();
|
let inode = dentry.inode();
|
||||||
if access_mode.is_writable() && inode.type_() == InodeType::Dir {
|
if inode.type_() == InodeType::Dir && access_mode.is_writable() {
|
||||||
return_errno_with_message!(Errno::EISDIR, "directory cannot open to write");
|
return_errno_with_message!(Errno::EISDIR, "directory cannot open to write");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,10 +68,6 @@ impl RamFS {
|
|||||||
fn alloc_id(&self) -> u64 {
|
fn alloc_id(&self) -> u64 {
|
||||||
self.inode_allocator.fetch_add(1, Ordering::SeqCst)
|
self.inode_allocator.fetch_add(1, Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn device_id(&self) -> u64 {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileSystem for RamFS {
|
impl FileSystem for RamFS {
|
||||||
@ -783,6 +779,9 @@ impl Inode for RamInode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn as_device(&self) -> Option<Arc<dyn Device>> {
|
fn as_device(&self) -> Option<Arc<dyn Device>> {
|
||||||
|
if !self.typ.is_device() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
self.node.read().inner.as_device().cloned()
|
self.node.read().inner.as_device().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1146,20 +1145,21 @@ impl Inode for RamInode {
|
|||||||
|
|
||||||
fn metadata(&self) -> Metadata {
|
fn metadata(&self) -> Metadata {
|
||||||
let self_inode = self.node.read();
|
let self_inode = self.node.read();
|
||||||
|
let inode_metadata = &self_inode.metadata;
|
||||||
Metadata {
|
Metadata {
|
||||||
dev: self.fs.upgrade().unwrap().device_id(),
|
dev: 0,
|
||||||
ino: self.ino as _,
|
ino: self.ino as _,
|
||||||
size: self_inode.metadata.size,
|
size: inode_metadata.size,
|
||||||
blk_size: BLOCK_SIZE,
|
blk_size: BLOCK_SIZE,
|
||||||
blocks: self_inode.metadata.blocks,
|
blocks: inode_metadata.blocks,
|
||||||
atime: self_inode.metadata.atime,
|
atime: inode_metadata.atime,
|
||||||
mtime: self_inode.metadata.mtime,
|
mtime: inode_metadata.mtime,
|
||||||
ctime: self_inode.metadata.ctime,
|
ctime: inode_metadata.ctime,
|
||||||
type_: self.typ,
|
type_: self.typ,
|
||||||
mode: self_inode.metadata.mode,
|
mode: inode_metadata.mode,
|
||||||
nlinks: self_inode.metadata.nlinks,
|
nlinks: inode_metadata.nlinks,
|
||||||
uid: self_inode.metadata.uid,
|
uid: inode_metadata.uid,
|
||||||
gid: self_inode.metadata.gid,
|
gid: inode_metadata.gid,
|
||||||
rdev: {
|
rdev: {
|
||||||
if let Some(device) = self_inode.inner.as_device() {
|
if let Some(device) = self_inode.inner.as_device() {
|
||||||
device.id().into()
|
device.id().into()
|
||||||
|
@ -6,5 +6,5 @@ set -e
|
|||||||
|
|
||||||
echo "*** Running the LMbench open latency test ***"
|
echo "*** Running the LMbench open latency test ***"
|
||||||
|
|
||||||
touch test_file
|
touch testfile
|
||||||
/benchmark/bin/lmbench/lat_syscall -P 1 open test_file
|
/benchmark/bin/lmbench/lat_syscall -P 1 -W 1000 -N 1000 open testfile
|
@ -6,5 +6,5 @@ set -e
|
|||||||
|
|
||||||
echo "*** Running the LMbench stat latency test ***"
|
echo "*** Running the LMbench stat latency test ***"
|
||||||
|
|
||||||
touch test_file
|
touch testfile
|
||||||
/benchmark/bin/lmbench/lat_syscall -P 1 stat test_file
|
/benchmark/bin/lmbench/lat_syscall -P 1 -W 1000 -N 1000 stat testfile
|
Reference in New Issue
Block a user