From d1731162eb27f4d94a5e78a803d7fc853f44a46c Mon Sep 17 00:00:00 2001 From: "Tate, Hongliang Tian" Date: Tue, 8 Jan 2019 21:23:41 +0800 Subject: [PATCH] Add perf test for spawn+wait4 --- src/libos/src/syscall/mod.rs | 4 ++- src/libos/src/vm/process_vm.rs | 2 ++ src/libos/src/vm/vm_range.rs | 2 ++ src/libos/src/vm/vm_space_prealloced.c | 2 +- test/Makefile | 7 +++++ test/perf_spawn_and_wait4/Makefile | 5 ++++ test/perf_spawn_and_wait4/main.c | 36 ++++++++++++++++++++++++++ 7 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/perf_spawn_and_wait4/Makefile create mode 100644 test/perf_spawn_and_wait4/main.c diff --git a/src/libos/src/syscall/mod.rs b/src/libos/src/syscall/mod.rs index c680ddef..e9cce890 100644 --- a/src/libos/src/syscall/mod.rs +++ b/src/libos/src/syscall/mod.rs @@ -462,7 +462,9 @@ pub extern "C" fn occlum_exit(status: i32) #[no_mangle] pub extern "C" fn occlum_unknown(num: u32) { - println!("[WARNING] Unknown syscall (num = {})", num); + if cfg!(debug_assertions) { + //println!("[WARNING] Unknown syscall (num = {})", num); + } } #[no_mangle] diff --git a/src/libos/src/vm/process_vm.rs b/src/libos/src/vm/process_vm.rs index f95b8744..7aecdcc6 100644 --- a/src/libos/src/vm/process_vm.rs +++ b/src/libos/src/vm/process_vm.rs @@ -1,5 +1,7 @@ use super::*; +// TODO: examine the ProcessVM code for memory leakage + lazy_static! { static ref DATA_SPACE: SgxMutex = { let (addr, size) = { diff --git a/src/libos/src/vm/vm_range.rs b/src/libos/src/vm/vm_range.rs index e2ee815a..988eb97a 100644 --- a/src/libos/src/vm/vm_range.rs +++ b/src/libos/src/vm/vm_range.rs @@ -372,9 +372,11 @@ impl PartialEq for VMRange { impl Drop for VMRange { fn drop(&mut self) { if !self.is_dealloced() { + println!("VMRange::drop::panic1"); panic!("A range must be dealloc'ed before drop"); } if self.has_subranges() { + println!("VMRange::drop::panic2"); panic!("All sub-ranges must be removed explicitly before drop"); } } diff --git a/src/libos/src/vm/vm_space_prealloced.c b/src/libos/src/vm/vm_space_prealloced.c index 1aefde86..cfcd0abd 100644 --- a/src/libos/src/vm/vm_space_prealloced.c +++ b/src/libos/src/vm/vm_space_prealloced.c @@ -1,6 +1,6 @@ #include -#define DATA_SPACE_SIZE (16*1024*1024) +#define DATA_SPACE_SIZE (32*1024*1024) static char __prealloced_data_space[DATA_SPACE_SIZE] __attribute__ (( diff --git a/test/Makefile b/test/Makefile index 93244c38..462b39ca 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,14 @@ CUR_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) PROJECT_DIR := $(realpath $(CUR_DIR)/../) +# Whether test performance or not? +PERF = yes + +ifeq ($(PERF),no) TEST_SUITES := empty argv hello_world malloc file getpid spawn pipe time +else +TEST_SUITES := empty perf_spawn_and_wait4 +endif BUILD_TEST_SUITES := $(TEST_SUITES:%=%) RUN_TEST_SUITES := $(TEST_SUITES:%=test-%) CLEAN_TEST_SUITES := $(TEST_SUITES:%=clean-%) diff --git a/test/perf_spawn_and_wait4/Makefile b/test/perf_spawn_and_wait4/Makefile new file mode 100644 index 00000000..9e1b6dec --- /dev/null +++ b/test/perf_spawn_and_wait4/Makefile @@ -0,0 +1,5 @@ +include ../test_common.mk + +EXTRA_C_FLAGS := +EXTRA_LINK_FLAGS := +BIN_ARGS := diff --git a/test/perf_spawn_and_wait4/main.c b/test/perf_spawn_and_wait4/main.c new file mode 100644 index 00000000..8713c995 --- /dev/null +++ b/test/perf_spawn_and_wait4/main.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +#define NREPEATS 5000 + +int main(int argc, const char* argv[]) { + struct timeval tv_start, tv_end; + + gettimeofday(&tv_start, NULL); + for (unsigned long i = 0; i < NREPEATS; i++) { + int child_pid, status; + if (posix_spawn(&child_pid, "empty/bin.encrypted", NULL, NULL, NULL, NULL) <0) { + printf("ERROR: failed to spawn (# of repeats = %lu)\n", i); + return -1; + } + if (wait4(-1, &status, 0, NULL) < 0) { + printf("ERROR: failed to wait4 (# of repeats = %lu)\n", i); + return -1; + } + if (status != 0) { + printf("ERROR: child process exits with error\n"); + return -1; + } + } + gettimeofday(&tv_end, NULL); + + suseconds_t total_us = (tv_end.tv_sec - tv_start.tv_sec) * 1000000UL + + + (tv_end.tv_usec - tv_start.tv_usec); + suseconds_t latency = total_us / NREPEATS; + printf("Latency of spawn/exit = %lu us\n", latency); + return 0; +}