mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 07:06:47 +00:00
使nproc可以正确获取到cpu核心数 (#689)
This commit is contained in:
parent
9b96c5b547
commit
9430523b46
@ -257,10 +257,10 @@ impl ProcFSInode {
|
|||||||
offset: usize,
|
offset: usize,
|
||||||
len: usize,
|
len: usize,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
_pdata: &mut ProcfsFilePrivateData,
|
pdata: &mut ProcfsFilePrivateData,
|
||||||
) -> Result<usize, SystemError> {
|
) -> Result<usize, SystemError> {
|
||||||
let start = _pdata.data.len().min(offset);
|
let start = pdata.data.len().min(offset);
|
||||||
let end = _pdata.data.len().min(offset + len);
|
let end = pdata.data.len().min(offset + len);
|
||||||
|
|
||||||
// buffer空间不足
|
// buffer空间不足
|
||||||
if buf.len() < (end - start) {
|
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);
|
buf[0..src.len()].copy_from_slice(src);
|
||||||
return Ok(src.len());
|
return Ok(src.len());
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,10 @@ impl CpuMask {
|
|||||||
begin: true,
|
begin: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn inner(&self) -> &AllocBitmap {
|
||||||
|
&self.bmp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CpuMaskIter<'a> {
|
pub struct CpuMaskIter<'a> {
|
||||||
|
@ -13,6 +13,7 @@ use self::{
|
|||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
mod syscall;
|
||||||
|
|
||||||
pub fn kick_cpu(cpu_id: ProcessorId) -> Result<(), SystemError> {
|
pub fn kick_cpu(cpu_id: ProcessorId) -> Result<(), SystemError> {
|
||||||
// todo: 增加对cpu_id的有效性检查
|
// todo: 增加对cpu_id的有效性检查
|
||||||
|
15
kernel/src/smp/syscall.rs
Normal file
15
kernel/src/smp/syscall.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
@ -963,9 +963,15 @@ impl Syscall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SYS_SCHED_GETAFFINITY => {
|
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")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
@ -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\tcargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION)"
|
||||||
@echo "\n"
|
@echo "\n"
|
||||||
@echo "Auto installing dadk..."
|
@echo "Auto installing dadk..."
|
||||||
CC=gcc AS=as AR=ar LD=ld OBJCOPY=objcopy NM=nm cargo install dadk
|
cargo install dadk
|
||||||
else
|
else
|
||||||
# 如果DADK版本过低,则自动更新
|
# 如果DADK版本过低,则自动更新
|
||||||
@echo "dadk version $(DADK_VERSION) installed"
|
@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))
|
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 "dadk version is too low, please update to $(MIN_DADK_VERSION) or higher version"
|
||||||
@echo "Updating dadk..."
|
@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"
|
@echo "dadk updated"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@ -55,11 +55,11 @@ all:
|
|||||||
mkdir -p $(ROOT_PATH)/bin/sysroot
|
mkdir -p $(ROOT_PATH)/bin/sysroot
|
||||||
|
|
||||||
$(MAKE) dadk_run
|
$(MAKE) dadk_run
|
||||||
$(MAKE) copy_services
|
$(MAKE) copy_sysconfig
|
||||||
|
|
||||||
@echo 用户态程序编译完成
|
@echo 用户态程序编译完成
|
||||||
|
|
||||||
copy_services: dadk_run
|
copy_sysconfig: dadk_run
|
||||||
cp -r sysconfig/* $(ROOT_PATH)/bin/sysroot/
|
cp -r sysconfig/* $(ROOT_PATH)/bin/sysroot/
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user