使nproc可以正确获取到cpu核心数 (#689)

This commit is contained in:
yuyi2439 2024-04-04 12:41:19 +08:00 committed by GitHub
parent 9b96c5b547
commit 9430523b46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 10 deletions

View File

@ -257,10 +257,10 @@ impl ProcFSInode {
offset: usize,
len: usize,
buf: &mut [u8],
_pdata: &mut ProcfsFilePrivateData,
pdata: &mut ProcfsFilePrivateData,
) -> Result<usize, SystemError> {
let start = _pdata.data.len().min(offset);
let end = _pdata.data.len().min(offset + len);
let start = pdata.data.len().min(offset);
let end = pdata.data.len().min(offset + len);
// buffer空间不足
if buf.len() < (end - start) {
@ -268,7 +268,7 @@ impl ProcFSInode {
}
// 拷贝数据
let src = &_pdata.data[start..end];
let src = &pdata.data[start..end];
buf[0..src.len()].copy_from_slice(src);
return Ok(src.len());
}

View File

@ -80,6 +80,10 @@ impl CpuMask {
begin: true,
}
}
pub fn inner(&self) -> &AllocBitmap {
&self.bmp
}
}
pub struct CpuMaskIter<'a> {

View File

@ -13,6 +13,7 @@ use self::{
pub mod core;
pub mod cpu;
pub mod init;
mod syscall;
pub fn kick_cpu(cpu_id: ProcessorId) -> Result<(), SystemError> {
// todo: 增加对cpu_id的有效性检查

15
kernel/src/smp/syscall.rs Normal file
View File

@ -0,0 +1,15 @@
use bitmap::traits::BitMapOps;
use system_error::SystemError;
use crate::syscall::Syscall;
use super::cpu::smp_cpu_manager;
impl Syscall {
pub fn getaffinity(_pid: i32, set: &mut [u8]) -> Result<usize, SystemError> {
let cpu_manager = smp_cpu_manager();
let src = unsafe { cpu_manager.possible_cpus().inner().as_bytes() };
set[0..src.len()].copy_from_slice(src);
Ok(0)
}
}

View File

@ -963,9 +963,15 @@ impl Syscall {
}
SYS_SCHED_GETAFFINITY => {
// todo: 这个系统调用还没有实现
let pid = args[0] as i32;
let size = args[1];
let set_vaddr = args[2];
Err(SystemError::ENOSYS)
let mut user_buffer_writer =
UserBufferWriter::new(set_vaddr as *mut u8, size, frame.is_from_user())?;
let set: &mut [u8] = user_buffer_writer.buffer(0)?;
Self::getaffinity(pid, set)
}
#[cfg(target_arch = "x86_64")]

View File

@ -25,7 +25,7 @@ ifeq ("$(DADK_VERSION)", "")
@echo "\n\tcargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION)"
@echo "\n"
@echo "Auto installing dadk..."
CC=gcc AS=as AR=ar LD=ld OBJCOPY=objcopy NM=nm cargo install dadk
cargo install dadk
else
# 如果DADK版本过低则自动更新
@echo "dadk version $(DADK_VERSION) installed"
@ -33,7 +33,7 @@ else
ifneq ($(shell printf '%s\n%s' "$(DADK_VERSION)" "$(MIN_DADK_VERSION)" | sort -V | head -n1), $(MIN_DADK_VERSION))
@echo "dadk version is too low, please update to $(MIN_DADK_VERSION) or higher version"
@echo "Updating dadk..."
CC=gcc AS=as AR=ar LD=ld OBJCOPY=objcopy NM=nm cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION) || (echo "dadk update failed" && exit 1)
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION) || (echo "dadk update failed" && exit 1)
@echo "dadk updated"
endif
endif
@ -55,11 +55,11 @@ all:
mkdir -p $(ROOT_PATH)/bin/sysroot
$(MAKE) dadk_run
$(MAKE) copy_services
$(MAKE) copy_sysconfig
@echo 用户态程序编译完成
copy_services: dadk_run
copy_sysconfig: dadk_run
cp -r sysconfig/* $(ROOT_PATH)/bin/sysroot/