Skip to content

Commit

Permalink
fixup! Dump and Reset stats data on demand using SIGUSR1 signal
Browse files Browse the repository at this point in the history
Signed-off-by: TejaswineeL <[email protected]>
  • Loading branch information
TejaswineeL committed May 10, 2024
1 parent b31b7d7 commit c876141
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
9 changes: 9 additions & 0 deletions Documentation/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gramine-pid>`` (note the
minus sign before <gramine-pid>). 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
--------------------------------

Expand Down
13 changes: 6 additions & 7 deletions pal/src/host/linux-sgx/host_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions pal/src/host/linux-sgx/host_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c876141

Please sign in to comment.