Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump and Reset stats data on demand using SIGUSR1 signal #1857

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5fcbfed
Add a support for debug-stats dumping and resetting on demand
TejaswineeL Apr 23, 2024
14a8be3
fixup! Dump and Reset stats data on demand using SIGUSR1 signal
TejaswineeL Apr 29, 2024
dfb0310
fixup! fixup! Dump and Reset stats data on demand using SIGUSR1 signal
TejaswineeL Apr 29, 2024
b31b7d7
fixup! Dump and Reset stats data on demand using SIGUSR1 signal
TejaswineeL May 6, 2024
c876141
fixup! Dump and Reset stats data on demand using SIGUSR1 signal
TejaswineeL May 10, 2024
337d385
Merge branch 'master' into debug_stats_dump_reset
TejaswineeL May 13, 2024
c8317ba
fixup! Dump and Reset stats data on demand using SIGUSR1 signal
TejaswineeL May 14, 2024
003f356
fixup! Dump and Reset stats data on demand using SIGUSR1 signal
TejaswineeL May 16, 2024
3cb3bff
Add a support for debug-stats dumping and resetting on demand
TejaswineeL Jul 1, 2024
6da0092
fixup! Add a support for debug-stats dumping and resetting on demand
TejaswineeL Jul 2, 2024
7cdaacf
fixup! fixup! Add a support for debug-stats dumping and resetting on …
TejaswineeL Jul 3, 2024
26c4684
fixup! Add support for dumping and resetting debug stats on demand
TejaswineeL Jul 12, 2024
68f4f3a
fixup! Add a support for debug-stats dumping and resetting on demand
sreeharikax Jul 30, 2024
f09d9ec
fixup! Add a support for debug-stats dumping and resetting on demand
sreeharikax Jul 30, 2024
2966f33
fixup! Add a support for debug-stats dumping and resetting on demand
TejaswineeL Aug 14, 2024
5e4aaa1
fixup! Add a support for debug-stats dumping and resetting on demand
TejaswineeL Aug 14, 2024
b5fcb60
fixup! Add a support for debug-stats dumping and resetting on demand
dimakuv Aug 19, 2024
8daa0cb
fixup! Add a support for debug-stats dumping and resetting on demand
dimakuv Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Documentation/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ How to read this output:
counters should be compared against "golden runs" to deduce any interesting
trends.

It is also possible to dump and reset SGX-related statistics interactively, using
``SIGUSR1`` signal. This helps to collect SGX-related 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>``.

Effects of system calls / ocalls
--------------------------------

Expand Down
54 changes: 52 additions & 2 deletions pal/src/host/linux-sgx/host_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* ../../../include/arch/x86_64/linux/ucontext.h:136:5: error: unknown type name ‘__sigset_t’
* __sigset_t uc_sigmask;
*/


#include <linux/signal.h>
#include <stdbool.h>

#include "api.h"
#include "cpu.h"
#include "debug_map.h"
#include "gdb_integration/sgx_gdb.h"
#include "host_internal.h"
#include "pal_rpc_queue.h"
#include "pal_tcb.h"
#include "sigreturn.h"
#include "ucontext.h"

Expand Down Expand Up @@ -188,6 +188,52 @@ static void handle_dummy_signal(int signum, siginfo_t* info, struct ucontext* uc
/* we need this handler to interrupt blocking syscalls in RPC threads */
}

static size_t send_sigusr1_signal_to_children(pid_t main_tid) {
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];
if (child_tid == main_tid)
continue;

if (child_tid) {
DO_SYSCALL(tkill, child_tid, SIGUSR1);
no_of_signals_sent++;
}
}
return no_of_signals_sent;
}

static void dump_and_reset_stats(void) {
static size_t no_of_children_visited = 0;

if (DO_SYSCALL(gettid) == g_host_pid) {
size_t no_of_children = send_sigusr1_signal_to_children(g_host_pid);

log_always("----- DUMPING and RESETTING SGX STATS -----");
while ((__atomic_load_n(&no_of_children_visited, __ATOMIC_ACQUIRE)) < no_of_children) {
DO_SYSCALL(sched_yield);
}

update_and_print_stats(/*process_wide=*/true);
__atomic_store_n(&no_of_children_visited, 0, __ATOMIC_RELEASE);
} else {
update_and_print_stats(/*process_wide=*/false);
__atomic_fetch_add(&no_of_children_visited, 1, __ATOMIC_ACQ_REL);
}

pal_host_tcb_reset_stats();
}

static void handle_sigusr1(int signum, siginfo_t* info, struct ucontext* uc) {
__UNUSED(signum);
__UNUSED(info);
__UNUSED(uc);

if (g_sgx_enable_stats)
dump_and_reset_stats();
}

int sgx_signal_setup(void) {
int ret;

Expand Down Expand Up @@ -226,6 +272,10 @@ int sgx_signal_setup(void) {
if (ret < 0)
goto err;

ret = set_signal_handler(SIGUSR1, handle_sigusr1);
if (ret < 0)
goto err;

/* SIGUSR2 is reserved for Gramine usage: interrupting blocking syscalls in RPC threads.
* We block SIGUSR2 in enclave threads; it is unblocked by each RPC thread explicitly. */
ret = set_signal_handler(SIGUSR2, handle_dummy_signal);
Expand Down
32 changes: 25 additions & 7 deletions pal/src/host/linux-sgx/host_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ void update_and_print_stats(bool process_wide) {
tid, tcb->eenter_cnt, tcb->eexit_cnt, tcb->aex_cnt,
tcb->sync_signal_cnt, tcb->async_signal_cnt);

g_eenter_cnt += tcb->eenter_cnt;
g_eexit_cnt += tcb->eexit_cnt;
g_aex_cnt += tcb->aex_cnt;
g_sync_signal_cnt += tcb->sync_signal_cnt;
g_async_signal_cnt += tcb->async_signal_cnt;
__atomic_fetch_add(&g_eenter_cnt, tcb->eenter_cnt, __ATOMIC_ACQ_REL);
__atomic_fetch_add(&g_eexit_cnt, tcb->eexit_cnt, __ATOMIC_ACQ_REL);
__atomic_fetch_add(&g_aex_cnt, tcb->aex_cnt, __ATOMIC_ACQ_REL);
__atomic_fetch_add(&g_sync_signal_cnt, tcb->sync_signal_cnt, __ATOMIC_ACQ_REL);
__atomic_fetch_add(&g_async_signal_cnt, tcb->async_signal_cnt, __ATOMIC_ACQ_REL);

if (process_wide) {
int pid = g_host_pid;
Expand All @@ -65,8 +65,17 @@ void update_and_print_stats(bool process_wide) {
" # of AEXs: %lu\n"
" # of sync signals: %lu\n"
" # of async signals: %lu",
pid, g_eenter_cnt, g_eexit_cnt, g_aex_cnt,
g_sync_signal_cnt, g_async_signal_cnt);
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);
__atomic_store_n(&g_eexit_cnt, 0, __ATOMIC_RELEASE);
__atomic_store_n(&g_aex_cnt, 0, __ATOMIC_RELEASE);
__atomic_store_n(&g_sync_signal_cnt, 0, __ATOMIC_RELEASE);
__atomic_store_n(&g_async_signal_cnt, 0, __ATOMIC_RELEASE);
}
}

Expand All @@ -87,6 +96,15 @@ void pal_host_tcb_init(PAL_HOST_TCB* tcb, void* stack, void* alt_stack) {
tcb->last_async_event = PAL_EVENT_NO_EVENT;
}

void pal_host_tcb_reset_stats(void) {
PAL_HOST_TCB* tcb = pal_get_host_tcb();
tcb->eenter_cnt = 0;
tcb->eexit_cnt = 0;
tcb->aex_cnt = 0;
tcb->sync_signal_cnt = 0;
tcb->async_signal_cnt = 0;
}

int create_tcs_mapper(void* tcs_base, unsigned int thread_num) {
sgx_arch_tcs_t* enclave_tcs = tcs_base;

Expand Down
1 change: 1 addition & 0 deletions pal/src/host/linux-sgx/pal_tcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ typedef struct pal_host_tcb {
} PAL_HOST_TCB;

extern void pal_host_tcb_init(PAL_HOST_TCB* tcb, void* stack, void* alt_stack);
extern void pal_host_tcb_reset_stats(void);

static inline PAL_HOST_TCB* pal_get_host_tcb(void) {
PAL_HOST_TCB* tcb;
Expand Down