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 6, 2024
1 parent dfb0310 commit b31b7d7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 45 deletions.
51 changes: 19 additions & 32 deletions pal/src/host/linux-sgx/host_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* ../../../include/arch/x86_64/linux/ucontext.h:136:5: error: unknown type name ‘__sigset_t’
* __sigset_t uc_sigmask;
*/

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

Expand Down Expand Up @@ -190,39 +188,31 @@ 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 int send_sigusr1_signal_to_children(void) {
int signal_counter= 0;
static size_t send_sigusr1_signal_to_children(pid_t main_tid) {
size_t no_of_signal_sent = 0;

for (size_t i = 1; i < MAX_DBG_THREADS; i++) {
for (size_t i = 0; i < MAX_DBG_THREADS; i++) {
int child_tid = ((struct enclave_dbginfo*)DBGINFO_ADDR)->thread_tids[i];
if(child_tid > 0) {
if (child_tid == main_tid)
continue;

if (child_tid) {
DO_SYSCALL(tkill, child_tid, SIGUSR1);
signal_counter++;
no_of_signal_sent++;
}
}

return signal_counter;
return no_of_signal_sent;
}

static void dump_and_reset_stats(void)
{
static atomic_int no_of_children_visited = 0;
static const uint64_t LOOP_ATTEMPTS_MAX = 10000; /* rather arbitrary */

if(DO_SYSCALL(gettid) == g_host_pid) {
int no_of_children = send_sigusr1_signal_to_children();
uint64_t loop_attempts = 0;

/* Wait here until all the children are done processing the signal. */
while((no_of_children) > (__atomic_load_n(&no_of_children_visited, __ATOMIC_ACQUIRE))) {
if (loop_attempts == LOOP_ATTEMPTS_MAX) {
DO_SYSCALL(sched_yield);
} else {
loop_attempts++;
CPU_RELAX();
}
}
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);

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 {
Expand All @@ -231,18 +221,15 @@ static void dump_and_reset_stats(void)
__atomic_fetch_add(&no_of_children_visited, 1, __ATOMIC_ACQ_REL);
}

PAL_HOST_TCB* tcb = pal_get_host_tcb();
int ret = pal_host_tcb_reset_stats(tcb);
if(ret < 0)
return;
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)
if (g_sgx_enable_stats)
dump_and_reset_stats();

return;
Expand Down
17 changes: 5 additions & 12 deletions pal/src/host/linux-sgx/host_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ 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);
Expand All @@ -93,21 +94,13 @@ void pal_host_tcb_init(PAL_HOST_TCB* tcb, void* stack, void* alt_stack) {
tcb->last_async_event = PAL_EVENT_NO_EVENT;
}

int pal_host_tcb_reset_stats(PAL_HOST_TCB* tcb) {
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 ret;

ret = DO_SYSCALL(arch_prctl, ARCH_SET_GS, tcb);
if (ret < 0) {
ret = -EPERM;
log_always("error at pal_thread_reset_stats %d", ret);
}
return ret;
}

int create_tcs_mapper(void* tcs_base, unsigned int thread_num) {
Expand Down
2 changes: 1 addition & 1 deletion pal/src/host/linux-sgx/pal_tcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +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 int pal_host_tcb_reset_stats(PAL_HOST_TCB* tcb);
extern void pal_host_tcb_reset_stats(void);

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

0 comments on commit b31b7d7

Please sign in to comment.