From ad98a1698e1a995224a41c6e6ca4ecc90294029d Mon Sep 17 00:00:00 2001 From: WangRunji Date: Sun, 21 Apr 2019 17:28:06 +0800 Subject: [PATCH] add timing by shenyouren --- src/Enclave.edl | 2 ++ src/libos/src/entry.rs | 4 ++++ src/pal/pal.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/Enclave.edl b/src/Enclave.edl index 034febdf..82e084fd 100644 --- a/src/Enclave.edl +++ b/src/Enclave.edl @@ -10,6 +10,8 @@ enclave { /* define ECALLs here. */ public int libos_boot([in, string] const char* executable_path, [user_check] const char** argv); public int libos_run(void); + /* This is only for debug usage */ + public int dummy_ecall(void); }; untrusted { diff --git a/src/libos/src/entry.rs b/src/libos/src/entry.rs index f299d51e..6bad71a2 100644 --- a/src/libos/src/entry.rs +++ b/src/libos/src/entry.rs @@ -35,6 +35,10 @@ pub extern "C" fn libos_run() -> i32 { .unwrap_or(EXIT_STATUS_INTERNAL_ERROR) } +#[no_mangle] +pub extern "C" fn dummy_ecall() -> i32 { + 0 +} // Use 127 as a special value to indicate internal error from libos, not from // user programs, although it is completely ok for a user program to return 127. const EXIT_STATUS_INTERNAL_ERROR: i32 = 127; diff --git a/src/pal/pal.c b/src/pal/pal.c index 91d3cf31..f0937c6a 100644 --- a/src/pal/pal.c +++ b/src/pal/pal.c @@ -213,6 +213,9 @@ void ocall_sync(void) { /* Application entry */ int SGX_CDECL main(int argc, const char *argv[]) { + struct timeval startup, libosready, appdie; + + gettimeofday(&startup, NULL); sgx_status_t sgx_ret = SGX_SUCCESS; int status = 0; uint32_t sealed_log_size = 1024; @@ -238,9 +241,22 @@ int SGX_CDECL main(int argc, const char *argv[]) print_error_message(sgx_ret); return status; } + // First ecall do a lot initializations. + // Count it as startup time. + dummy_ecall(global_eid, &status); + + gettimeofday(&libosready, NULL); status = wait_all_tasks(); + gettimeofday(&appdie, NULL); + + uint64_t libos_startup_time, app_runtime; + libos_startup_time = (libosready.tv_sec - startup.tv_sec) * 1000000 + (libosready.tv_usec - startup.tv_usec); + app_runtime = (appdie.tv_sec - libosready.tv_sec) * 1000000 + (appdie.tv_usec - libosready.tv_usec); + printf("LibOS startup time: %d microseconds\n", libos_startup_time); + printf("Apps running time: %d microseconds\n", app_runtime); + /* Destroy the enclave */ sgx_destroy_enclave(global_eid);