diff --git a/Documentation/performance.rst b/Documentation/performance.rst index 515d1d335b..bf22b4e496 100644 --- a/Documentation/performance.rst +++ b/Documentation/performance.rst @@ -103,6 +103,15 @@ How to read this output: counters should be compared against "golden runs" to deduce any interesting trends. +It is also possible to reset the performance statistics interactively, using +``SIGUSR1`` signal. This helps to collect performance statistics only for a +particular period e.g., skipping the Gramine startup and application +initialization time and concentrating only on the actual application processing. +Send ``SIGUSR1`` using command ``kill -SIGUSR1 `` (note the +minus sign before ). Sending multiple ``SIGUSR1`` will result +in a sequential dump and reset of the statistics, each dump and reset of +statistics will be done after the previous ``SIGUSR1``. + Effects of system calls / ocalls -------------------------------- diff --git a/pal/src/host/linux-sgx/host_exception.c b/pal/src/host/linux-sgx/host_exception.c index a7da841202..f29d3078af 100644 --- a/pal/src/host/linux-sgx/host_exception.c +++ b/pal/src/host/linux-sgx/host_exception.c @@ -189,7 +189,7 @@ static void handle_dummy_signal(int signum, siginfo_t* info, struct ucontext* uc } static size_t send_sigusr1_signal_to_children(pid_t main_tid) { - size_t no_of_signal_sent = 0; + size_t no_of_signals_sent = 0; for (size_t i = 0; i < MAX_DBG_THREADS; i++) { int child_tid = ((struct enclave_dbginfo*)DBGINFO_ADDR)->thread_tids[i]; @@ -198,10 +198,10 @@ static size_t send_sigusr1_signal_to_children(pid_t main_tid) { if (child_tid) { DO_SYSCALL(tkill, child_tid, SIGUSR1); - no_of_signal_sent++; + no_of_signals_sent++; } } - return no_of_signal_sent; + return no_of_signals_sent; } static void dump_and_reset_stats(void) { @@ -210,13 +210,14 @@ static void dump_and_reset_stats(void) { if (DO_SYSCALL(gettid) == g_host_pid) { size_t no_of_children = send_sigusr1_signal_to_children(g_host_pid); - while ((__atomic_load_n(&no_of_children_visited, __ATOMIC_ACQUIRE)) < (no_of_children)) { + while ((__atomic_load_n(&no_of_children_visited, __ATOMIC_ACQUIRE)) < no_of_children) { DO_SYSCALL(sched_yield); } + log_always("----- DUMPING and RESETTING SGX STATS -----"); update_and_print_stats(/*process_wide=*/true); __atomic_store_n(&no_of_children_visited, 0, __ATOMIC_RELEASE); } else { - log_always("----- DUMPTING and RESETTING SGX STATS -----"); + log_always("----- DUMPING and RESETTING SGX STATS -----"); update_and_print_stats(/*process_wide=*/false); __atomic_fetch_add(&no_of_children_visited, 1, __ATOMIC_ACQ_REL); } @@ -231,8 +232,6 @@ static void handle_sigusr1(int signum, siginfo_t* info, struct ucontext* uc) { if (g_sgx_enable_stats) dump_and_reset_stats(); - - return; } int sgx_signal_setup(void) { diff --git a/pal/src/host/linux-sgx/host_thread.c b/pal/src/host/linux-sgx/host_thread.c index 12d43bb9c8..6a8a37164c 100644 --- a/pal/src/host/linux-sgx/host_thread.c +++ b/pal/src/host/linux-sgx/host_thread.c @@ -65,8 +65,10 @@ void update_and_print_stats(bool process_wide) { " # of AEXs: %lu\n" " # of sync signals: %lu\n" " # of async signals: %lu", - pid, __atomic_load_n(&g_eenter_cnt, __ATOMIC_ACQUIRE), __atomic_load_n(&g_eexit_cnt, __ATOMIC_ACQUIRE), - __atomic_load_n(&g_aex_cnt, __ATOMIC_ACQUIRE), __atomic_load_n(&g_sync_signal_cnt, __ATOMIC_ACQUIRE), + pid, __atomic_load_n(&g_eenter_cnt, __ATOMIC_ACQUIRE), + __atomic_load_n(&g_eexit_cnt, __ATOMIC_ACQUIRE), + __atomic_load_n(&g_aex_cnt, __ATOMIC_ACQUIRE), + __atomic_load_n(&g_sync_signal_cnt, __ATOMIC_ACQUIRE), __atomic_load_n(&g_async_signal_cnt, __ATOMIC_ACQUIRE)); __atomic_store_n(&g_eenter_cnt, 0, __ATOMIC_RELEASE);