Skip to content

Commit

Permalink
Merge pull request #5 from syswonder/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lhw2002426 authored Apr 1, 2024
2 parents ebf7954 + 8c43a6a commit f9e5908
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 107 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
/.cache
compile_commands.json

# downloaded opensbi binary
/fw_dynamic.bin

*.asm
disk.img
actual.out
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ NET ?= n
GRAPHIC ?= n
V9P ?= n
BUS ?= mmio
RISCV_BIOS ?= $(shell realpath ./platforms/riscv/fw_dynamic.bin)
RISCV_BIOS ?= default

DISK_IMG ?= disk.img
QEMU_LOG ?= n
Expand Down
1 change: 1 addition & 0 deletions apps/c/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std-benchmark/
56 changes: 44 additions & 12 deletions apps/c/cpp/axbuild.mk
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
CMAKE = cmake

ARCH ?= x86_64
C_COMPILER := $(shell which $(CC))
CXX_COMPILER := $(shell which $(CC))
AR := $(shell which $(AR))
RANLIB := $(shell which $(RANLIB))
CROSS_COMPILE_PATH := $(shell dirname $(C_COMPILER))/..
CXX_STD := c++20
CXX_STD ?= 20

app-objs := std_benchmark.o
std_benchmark_dir := $(APP)/std-benchmark
std_benchmark_build = $(std_benchmark_dir)/build

bench ?= all
benches_available := $(wildcard $(std_benchmark_dir)/cxx/*.bench.cpp)
benches_available := $(patsubst $(std_benchmark_dir)/cxx/%.bench.cpp,%,$(benches_available))

main-obj := main.o
app-objs := cpp.o
$(std_benchmark_dir):
@echo "Download std-benchmark source code"
cd $(APP)/ && git clone --recursive https://github.com/hiraditya/std-benchmark
patch -p1 -N -d $(std_benchmark_dir) --no-backup-if-mismatch -r - < $(APP)/std_benchmark.patch

$(APP)/$(app-objs): build_cpp
build_cpp: $(APP)/axbuild.mk $(APP)/main.cpp
$(C_COMPILER) -o $(APP)/$(main-obj) -nostdlib -static -no-pie -c -std=$(CXX_STD) \
$(APP)/main.cpp -I$(CROSS_COMPILE_PATH)/*-linux-musl/include/c++/*
$(LD) -o $(app-objs) $(APP)/$(main-obj) -nostdlib -static -no-pie -r -e main \
$(APP)/$(app-objs): build_std-benchmark
build_std-benchmark: $(std_benchmark_dir) $(APP)/axbuild.mk
cd $(std_benchmark_dir) && mkdir -p build && cd build && \
$(CMAKE) .. -DCMAKE_CXX_STANDARD=$(CXX_STD) -DCMAKE_C_COMPILER=$(C_COMPILER) -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) -DCMAKE_AR=$(AR) -DCMAKE_RANLIB=$(RANLIB) \
-DENABLE_C_BENCHMARKS=OFF -DENABLE_C_VS_CXX_BENCHMARKS=OFF -DENABLE_COMPILER_VS_PROGRAMMER=OFF -DBENCHMARK_ENABLE_TESTING=OFF && \
$(MAKE) -j
mkdir -p $(std_benchmark_build)/libgcc && cd $(std_benchmark_build)/libgcc && \
ln -s -f $(CROSS_COMPILE_PATH)/lib/gcc/*-linux-musl/*/libgcc.a ./ && \
$(AR) x libgcc.a _clrsbsi2.o
ifeq ($(bench), all)
$(error "Running all benches automatically is not supported, please add 'bench=' arg. \
Available benches: $(benches_available)")
endif
ifneq ($(filter $(bench),$(benches_available)),)
$(LD) -o $(app-objs) -nostdlib -static -no-pie -r -e main \
$(std_benchmark_build)/cxx/lib$(bench).bench.cpp.out.a \
$(std_benchmark_build)/benchmark/src/libbenchmark.a \
$(CROSS_COMPILE_PATH)/*-linux-musl/lib/libstdc++.a \
$(CROSS_COMPILE_PATH)/lib/gcc/*-linux-musl/*/libgcc_eh.a
$(CROSS_COMPILE_PATH)/lib/gcc/*-linux-musl/*/libgcc_eh.a \
$(std_benchmark_build)/libgcc/_clrsbsi2.o
else
$(error "Available benches: $(benches_available)")
endif

clean_c::
rm -rf $(app-objs)
rm -rf $(APP)/$(main-obj)
rm -rf $(std_benchmark_build)/

.PHONY: build_std-benchmark clean_c


.PHONY: build_cpp clean_c
2 changes: 2 additions & 0 deletions apps/c/cpp/features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ alloc
paging
irq
multitask
fs
random-hw
69 changes: 0 additions & 69 deletions apps/c/cpp/main.cpp

This file was deleted.

109 changes: 109 additions & 0 deletions apps/c/cpp/std_benchmark.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
--- /cxx/CMakeLists.txt
+++ /cxx/CMakeLists.txt
@@ -3,7 +3,7 @@ foreach(test_path ${BENCHMARK_TESTS})
get_filename_component(test_file "${test_path}" NAME)
set(target ${test_file}.out)
#EXCLUDE_FROM_ALL
- add_executable(${target} ${test_file})
+ add_library(${target} ${test_file})
# shlwapi for MSVC
#target_link_libraries(${target} benchmark -pthread shlwapi)
target_link_libraries(${target} benchmark -pthread)
--- /cxx/mutators.bench.cpp
+++ /cxx/mutators.bench.cpp
@@ -26,8 +27,8 @@ void BM_write_seq(benchmark::State& state) {
template<typename V>
void BM_push_back(benchmark::State& state) {
int N = state.range(0);
- V v;
while (state.KeepRunning()) {
+ V v;
for (int i = 0; i < N; ++i)
v.push_back(i);
}
@@ -37,8 +38,8 @@ void BM_push_back(benchmark::State& state) {
template<typename V>
void BM_push_back_resize(benchmark::State& state) {
int N = state.range(0);
- V v(N);
while (state.KeepRunning()) {
+ V v(N);
for (int i = 0; i < N; ++i)
v.push_back(i);
}
@@ -48,9 +49,9 @@ void BM_push_back_resize(benchmark::State& state) {
template<typename V>
void BM_push_back_vector_reserve(benchmark::State& state) {
int N = state.range(0);
- V v;
- v.reserve(N);
while (state.KeepRunning()) {
+ V v;
+ v.reserve(N);
for (int i = 0; i < N; ++i)
v.push_back(i);
}
@@ -60,9 +61,9 @@ void BM_push_back_vector_reserve(benchmark::State& state) {
template<typename V>
void BM_insert_begin(benchmark::State& state) {
int N = state.range(0);
- V v(N, 1);
- auto val = *v.begin();
while (state.KeepRunning()) {
+ V v(N, 1);
+ auto val = *v.begin();
v.insert(v.begin(), val);
}
state.SetComplexityN(N);
@@ -94,14 +95,15 @@ void BM_assoc_insert_random(benchmark::State& state) {
int N = state.range(0);
using CVT = typename V::value_type;
using VT = typename remove_const<CVT>::type;
- std::vector<VT> temp(N*1000);
+ // TODO: It will panic if *100 or *1000
+ std::vector<VT> temp(N*10);
fill_random(temp);
V v;
auto it = temp.begin();
while (state.KeepRunning()) {
v.insert(*it++);
if (it == temp.end()) // FIXME: After temp.end insert will just return.
- assert(0);//it = temp.begin();
+ it = temp.begin();
}
state.SetComplexityN(N);
}
--- /include/test_configs.h
+++ /include/test_configs.h
@@ -1,6 +1,8 @@
#ifndef TEST_CONFIGS_H
#define TEST_CONFIGS_H

+void *__dso_handle = 0;
+
#define KB << 10
#define MB << 20
#define GB << 30
@@ -12,9 +12,9 @@
#ifdef i7_4770
// To benchmark data residing completely in L1 cache.
#ifndef ENABLE_TRAVIS_BUILD
-#define L1 (32 KB)
+#define L1 (16)
// To benchmark data residing in L2 cache.
-#define L2 (256 KB)
+#define L2 (L1 << 7)
#else
// For the Travis CI to run the entire test.
#define L1 (16 KB)
--- /benchmark/CMakeLists.txt
+++ /benchmark/CMakeLists.txt
@@ -177,6 +177,8 @@ endif(BENCHMARK_USE_LIBCXX)
cxx_feature_check(STD_REGEX)
cxx_feature_check(GNU_POSIX_REGEX)
cxx_feature_check(POSIX_REGEX)
+add_compile_definitions(HAVE_STD_REGEX)
+set(HAVE_STD_REGEX 1)
if(NOT HAVE_STD_REGEX AND NOT HAVE_GNU_POSIX_REGEX AND NOT HAVE_POSIX_REGEX)
message(FATAL_ERROR "Failed to determine the source files for the regular expression backend")
endif()
54 changes: 37 additions & 17 deletions modules/rux9p/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl CommonNode {
const O_RDWR: u8 = 0x02;
const O_RDONLY: u8 = 0x00;
const EISDIR: u8 = 21;
const ELOOP: u8 = 40;

let result = if *protocol == "9P2000.L" {
dev.write().l_topen(fid, O_RDWR as u32)
Expand All @@ -131,23 +132,36 @@ impl CommonNode {
Ok(())
};

if let Err(EISDIR) = result {
if *protocol == "9P2000.L" {
handle_result!(
dev.write().l_topen(fid, O_RDONLY as u32),
"9pfs l_topen failed! error code: {}"
);
} else if *protocol == "9P2000.u" {
handle_result!(
dev.write().topen(fid, O_RDONLY),
"9pfs topen failed! error code: {}"
);
} else {
error!("9pfs open failed! Unsupported protocol version");
match result {
Err(EISDIR) if *protocol == "9P2000.L" => handle_result!(
dev.write().l_topen(fid, O_RDONLY as u32),
"9pfs l_topen failed! error code: {}"
),
Err(EISDIR) if *protocol == "9P2000.u" => handle_result!(
dev.write().topen(fid, O_RDONLY),
"9pfs topen failed! error code: {}"
),
Err(ELOOP) if *protocol == "9P2000.L" => {
let try_readlink = dev.write().treadlink(fid);
if let Ok(path) = try_readlink {
debug!("read link path ==> {:}", path);
let mut splited: Vec<&str> = path
.split('/')
.filter(|&x| !x.is_empty() && (x != "."))
.collect();
splited.insert(0, "..");
let try_walk = dev.write().twalk(fid, fid, splited.len() as u16, &splited);
match try_walk {
Ok(_) => return Self::new(fid, parent, dev, protocol),
Err(ecode) => error!("9pfs twalk failed! error code: {}", ecode),
}
} else {
error!("9pfs treadlink failed! error code: {:?}", try_readlink);
}
}
} else if let Err(ecode) = result {
error!("9pfs topen failed! error code: {}", ecode);
}
Err(ecode) => error!("9pfs topen failed! error code: {}", ecode),
_ => {}
};

Arc::new_cyclic(|this| Self {
inner: dev,
Expand Down Expand Up @@ -224,7 +238,13 @@ impl CommonNode {
fn try_get(&self, path: &str) -> VfsResult<VfsNodeRef> {
let (name, rest) = split_path(path);
if name == ".." {
return self.parent().unwrap().lookup(rest.unwrap_or(""));
match self.parent() {
Some(parent) => return parent.lookup(rest.unwrap_or("")),
None => {
error!("9pfs: try_get a directory out of 9pfs boundary");
return Err(VfsError::BadState);
}
}
} else if name == "." {
return self.try_get(rest.unwrap_or(""));
}
Expand Down
2 changes: 2 additions & 0 deletions modules/ruxfs/src/mounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ pub(crate) fn devfs() -> Arc<fs::devfs::DeviceFileSystem> {
let zero = fs::devfs::ZeroDev;
let bar = fs::devfs::ZeroDev;
let random = fs::devfs::RandomDev;
let urandom = fs::devfs::RandomDev;
let devfs = fs::devfs::DeviceFileSystem::new();
let foo_dir = devfs.mkdir("foo");
devfs.add("null", Arc::new(null));
devfs.add("zero", Arc::new(zero));
devfs.add("random", Arc::new(random));
devfs.add("urandom", Arc::new(urandom));
foo_dir.add("bar", Arc::new(bar));
Arc::new(devfs)
}
Expand Down
4 changes: 4 additions & 0 deletions modules/ruxhal/src/arch/aarch64/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use core::arch::global_asm;

#[cfg(feature = "irq")]
use crate::arch::enable_irqs;
use aarch64_cpu::registers::{ESR_EL1, FAR_EL1};
use tock_registers::interfaces::Readable;

Expand Down Expand Up @@ -56,6 +58,8 @@ fn handle_sync_exception(tf: &mut TrapFrame) {
#[cfg(feature = "musl")]
Some(ESR_EL1::EC::Value::SVC64) => {
debug!("Handle supervisor call {}", tf.r[8]);
#[cfg(feature = "irq")]
enable_irqs();
let result = crate::trap::handle_syscall(
tf.r[8] as usize,
[
Expand Down
Loading

0 comments on commit f9e5908

Please sign in to comment.