Skip to content

Commit

Permalink
feat: support multicore
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Apr 29, 2024
1 parent ed76271 commit d25558f
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 编译的目标平台
[build]
target = 'riscv64imac-unknown-none-elf'
target = 'riscv64gc-unknown-none-elf'
# target = 'x86_64-unknown-none'
# target = 'aarch64-unknown-none-softfloat'
# target = 'loongarch64-unknown-none'
Expand All @@ -10,6 +10,7 @@ rustflags = [
'-Cforce-frame-pointers=yes',
'-Clink-arg=-no-pie',
'--cfg=board="qemu"',
'--cfg=root_fs="ext4"',
'-Zunstable-options',
'-Ztls-model=local-exec',
# '--cfg=driver="kvirtio,kgoldfish-rtc,ns16550a"',
Expand Down
65 changes: 59 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ QEMU_EXEC ?=
BUILD_ARGS :=
GDB ?= gdb-multiarch
MOUNT_IMG_PATH ?= $(shell pwd)/mount.img
ROOT_FS := fat32

BUS := device
ifeq ($(ARCH), x86_64)
Expand All @@ -19,7 +20,7 @@ ifeq ($(ARCH), x86_64)
-cpu IvyBridge-v2
BUS := pci
else ifeq ($(ARCH), riscv64)
TARGET := riscv64imac-unknown-none-elf
TARGET := riscv64gc-unknown-none-elf
QEMU_EXEC += qemu-system-$(ARCH) \
-machine virt \
-bios $(SBI) \
Expand Down Expand Up @@ -48,9 +49,9 @@ SBI := tools/opensbi-$(BOARD).bin
features:=
K210-SERIALPORT = /dev/ttyUSB0
K210-BURNER = tools/k210/kflash.py
QEMU_EXEC += -m 1G\
QEMU_EXEC += -m 128M\
-nographic \
-smp 2 \
-smp 1 \
-D qemu.log -d in_asm,int,pcall,cpu_reset,guest_errors

ifeq ($(RELEASE), release)
Expand Down Expand Up @@ -85,15 +86,27 @@ offline:
rust-objcopy --binary-architecture=riscv64 $(KERNEL_ELF) --strip-all -O binary os.bin

fs-img:
ifeq ($(ROOT_FS), fat32)
rm -f $(FS_IMG)
dd if=/dev/zero of=$(FS_IMG) bs=1M count=64
dd if=/dev/zero of=$(FS_IMG) bs=1M count=128
mkfs.vfat -F 32 $(FS_IMG)
mkdir mount/ -p
sudo mount $(FS_IMG) mount/ -o uid=1000,gid=1000
rm -rf mount/*
-cp -rf tools/$(TESTCASE)/* mount/
sudo rm -rf mount/*
sudo cp -rf tools/$(TESTCASE)/* mount/
sudo chmod 777 $(FS_IMG)
sync
sudo umount $(FS_IMG)
else ifeq ($(ROOT_FS), ext4)
rm -f $(FS_IMG)
dd if=/dev/zero of=$(FS_IMG) bs=1M count=128
mkfs.ext4 -F -O ^metadata_csum_seed $(FS_IMG)
mkdir mount/ -p
sudo mount $(FS_IMG) mount/
sudo cp -rf tools/$(TESTCASE)/* mount/
sync
sudo umount $(FS_IMG)
endif

build:
# RUST_BACKTRACE=1 LOG=$(LOG) MOUNT_IMG_PATH=$(MOUNT_IMG_PATH) cargo build --target $(TARGET) $(BUILD_ARGS) --features "$(features)"
Expand Down
12 changes: 8 additions & 4 deletions byteos.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# build for riscv64-qemu
[bin.riscv64-qemu]
target = "riscv64imac-unknown-none-elf"
target = "riscv64gc-unknown-none-elf"
[bin.riscv64-qemu.configs]
board = "qemu"
driver = "kvirtio,kgoldfish-rtc,ns16550a"
root_fs = "ext4"

[bin.riscv64-qemu.env]
HEAP_SIZE = "0x0180_0000"
Expand All @@ -15,9 +16,10 @@ target = "x86_64-unknown-none"
[bin.x86_64-qemu.configs]
board = "qemu"
driver = "kvirtio,kgoldfish-rtc,ns16550a"
root_fs = "ext4"

[bin.x86_64-qemu.env]
HEAP_SIZE = "0x0200_0000"
HEAP_SIZE = "0x0180_0000"
MOUNT_IMG_PATH = "mount.img"

# build for aarch64-qemu
Expand All @@ -26,9 +28,10 @@ target = "aarch64-unknown-none-softfloat"
[bin.aarch64-qemu.configs]
board = "qemu"
driver = "kvirtio,kgoldfish-rtc,ns16550a"
root_fs = "fat32"

[bin.aarch64-qemu.env]
HEAP_SIZE = "0x0200_0000"
HEAP_SIZE = "0x0180_0000"
MOUNT_IMG_PATH = "mount.img"

# build for loongarch64-qemu
Expand All @@ -38,8 +41,9 @@ build_std = true
[bin.loongarch64-qemu.configs]
board = "qemu"
driver = "kramdisk"
root_fs = "ext4"

[bin.loongarch64-qemu.env]
HEAP_SIZE = "0x0200_0000"
HEAP_SIZE = "0x0180_0000"
CARGO_CFG_DRIVER = "kramdisk"
MOUNT_IMG_PATH = "mount.img"
6 changes: 5 additions & 1 deletion kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ fn kernel_interrupt(cx_ref: &mut TrapFrame, trap_type: TrapType) {
| TrapType::InstructionPageFault(addr)
| TrapType::LoadPageFault(addr) => {
if addr > VIRT_ADDR_START {
panic!("kernel error: {:#x}", addr);
panic!(
"kernel page error: {:#x} sepc: {:#x}",
addr,
cx_ref[TrapFrameArgs::SEPC]
);
}
// judge whether it is trigger by a user_task handler.
if let Some(task) = current_task().downcast_arc::<UserTask>().ok() {
Expand Down
14 changes: 6 additions & 8 deletions kernel/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ use core::panic::PanicInfo;
fn panic_handler(info: &PanicInfo) -> ! {
if let Some(location) = info.location() {
println!(
"\x1b[1;31m[Core {}][{}:{}]panic: '{}'\x1b[0m",
"\x1b[1;31m[Core {}] [{}:{}]\x1b[0m",
hart_id(),
location.file(),
location.line(),
info.message().unwrap()
);
} else {
println!(
"\x1b[1;31m[Core {}]panic: '{}'\x1b[0m",
hart_id(),
info.message().unwrap()
);
}
println!(
"\x1b[1;31m[Core {}] panic: '{}'\x1b[0m",
hart_id(),
info.message().unwrap()
);
// backtrace();
println!("!TEST FINISH!");
// loop {}
Expand Down
3 changes: 3 additions & 0 deletions kernel/src/syscall/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,9 @@ impl<T> UserRef<T> {

#[inline]
pub fn slice_until_valid(&self, is_valid: fn(T) -> bool) -> &'static mut [T] {
if self.addr.addr() == 0 {
return &mut [];
}
self.addr.slice_until(is_valid)
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/syscall/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl UserTaskContainer {
let new_dir = to_node(&self.task, newdir_fd, new_path)?;
if old_file_type == FileType::File {
let new_file = new_dir
.dentry_open(new_path, OpenFlags::empty())
.dentry_open(new_path, OpenFlags::O_CREAT)
.expect("can't find new file");
// TODO: Check the file exists
let file_size = old_file.metadata().map_err(from_vfs)?.size;
Expand Down
22 changes: 17 additions & 5 deletions kernel/src/tasks/initproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ fn clear() {

async fn kill_all_tasks() {
TASK_MAP.lock().values().into_iter().for_each(|task| {
task.upgrade().inspect(|x| x.exit(100));
task.upgrade().inspect(|x| {
if x.get_task_type() == TaskType::MonolithicTask {
x.exit(100)
}
});
});
}

Expand Down Expand Up @@ -264,7 +268,7 @@ pub async fn initproc() {
// command("./runtest.exe -w entry-static.exe pthread_cond_smasher").await;

// command("test-fscanf").await;
// command("./runtest.exe -w entry-static.exe argv").await;
// command("./runtest.exe -w entry-static.exe statvfs").await;
// command("entry-static.exe fscanf").await;
// command(" busybox sh").await;
// command("./a.out").await;
Expand All @@ -279,14 +283,22 @@ pub async fn initproc() {
// command("busybox sh busybox_testcode.sh").await;

// command("busybox echo run libctest_testcode.sh").await;
// command("busybox sh libctest_testcode.sh").await;
command("busybox sh libctest_testcode.sh").await;
// command("ls").await;

// simple_shell().await;
// command("busybox sh").await;

// command("busybox sh ./run-static.sh").await;
// command("./runtest.exe -w entry-dynamic.exe pthread_robust_detach").await;
// command("busybox echo 123").await;
// command("qjs.static test.js").await;
// command("qjs.static").await;
// command("busybox sh").await;
// command("busybox mkdir touch123").await;
// command("busybox rm -r touch123").await;
// command("busybox touch 123 >> touch123/123").await;
// command("busybox cat touch123/123").await;
// command("busybox echo run lua_testcode.sh").await;
// command("busybox sh lua_testcode.sh").await;

Expand All @@ -306,8 +318,8 @@ pub async fn initproc() {
// command("busybox echo run lmbench_testcode.sh").await;
// command("busybox sh lmbench_testcode.sh").await;

command("busybox echo run unixbench_testcode.sh").await;
command("busybox sh unixbench_testcode.sh").await;
// command("busybox echo run unixbench_testcode.sh").await;
// command("busybox sh unixbench_testcode.sh").await;

// command("copy-file-range-test-1").await;
// command("copy-file-range-test-2").await;
Expand Down

0 comments on commit d25558f

Please sign in to comment.