fix: correct atomics

master
Sean McBride 4 years ago
parent 575d64eba8
commit a307d6193a

@ -31,13 +31,16 @@ _Atomic uint32_t runtime_total_5XX_responses = 0;
void void
runtime_log_requests_responses() runtime_log_requests_responses()
{ {
int64_t total_responses = runtime_total_2XX_responses + runtime_total_4XX_responses uint32_t total_reqs = atomic_load(&runtime_total_requests);
+ runtime_total_5XX_responses; uint32_t total_2XX = atomic_load(&runtime_total_2XX_responses);
int64_t outstanding_requests = (int64_t)runtime_total_requests - total_responses; uint32_t total_4XX = atomic_load(&runtime_total_4XX_responses);
uint32_t total_5XX = atomic_load(&runtime_total_5XX_responses);
int64_t total_responses = total_2XX + total_4XX + total_5XX;
int64_t outstanding_requests = (int64_t)total_reqs - total_responses;
debuglog("Requests: %u (%ld outstanding)\n\tResponses: %ld\n\t\t2XX: %u\n\t\t4XX: %u\n\t\t5XX: %u\n", debuglog("Requests: %u (%ld outstanding)\n\tResponses: %ld\n\t\t2XX: %u\n\t\t4XX: %u\n\t\t5XX: %u\n",
runtime_total_requests, outstanding_requests, total_responses, runtime_total_2XX_responses, total_reqs, outstanding_requests, total_responses, total_2XX, total_4XX, total_5XX);
runtime_total_4XX_responses, runtime_total_5XX_responses);
}; };
#endif #endif
@ -59,11 +62,20 @@ _Atomic uint32_t runtime_total_complete_sandboxes = 0;
void void
runtime_log_sandbox_states() runtime_log_sandbox_states()
{ {
uint32_t total_initialized = atomic_load(&runtime_total_initialized_sandboxes);
uint32_t total_runnable = atomic_load(&runtime_total_runnable_sandboxes);
uint32_t total_blocked = atomic_load(&runtime_total_blocked_sandboxes);
uint32_t total_running = atomic_load(&runtime_total_running_sandboxes);
uint32_t total_preempted = atomic_load(&runtime_total_preempted_sandboxes);
uint32_t total_returned = atomic_load(&runtime_total_returned_sandboxes);
uint32_t total_error = atomic_load(&runtime_total_error_sandboxes);
uint32_t total_complete = atomic_load(&runtime_total_complete_sandboxes);
debuglog("Initialized: %u\n\tRunnable: %u\n\tBlocked: %u\n\tRunning: %u\n\tPreempted: %u\n\tReturned: " debuglog("Initialized: %u\n\tRunnable: %u\n\tBlocked: %u\n\tRunning: %u\n\tPreempted: %u\n\tReturned: "
"%u\n\tError: %u\n\tComplete: %u\n", "%u\n\tError: %u\n\tComplete: %u\n",
runtime_total_initialized_sandboxes, runtime_total_runnable_sandboxes, runtime_total_blocked_sandboxes, total_initialized, total_runnable, total_blocked, total_running, total_preempted, total_returned,
runtime_total_running_sandboxes, runtime_total_preempted_sandboxes, runtime_total_returned_sandboxes, total_error, total_complete);
runtime_total_error_sandboxes, runtime_total_complete_sandboxes);
}; };
#endif #endif
@ -77,6 +89,24 @@ runtime_log_sandbox_states()
void void
runtime_initialize(void) runtime_initialize(void)
{ {
#ifdef LOG_TOTAL_REQS_RESPS
atomic_init(&runtime_total_requests, 0);
atomic_init(&runtime_total_2XX_responses, 0);
atomic_init(&runtime_total_4XX_responses, 0);
atomic_init(&runtime_total_5XX_responses, 0);
#endif
#ifdef LOG_SANDBOX_TOTALS
atomic_init(&runtime_total_freed_requests, 0);
atomic_init(&runtime_total_initialized_sandboxes, 0);
atomic_init(&runtime_total_runnable_sandboxes, 0);
atomic_init(&runtime_total_blocked_sandboxes, 0);
atomic_init(&runtime_total_running_sandboxes, 0);
atomic_init(&runtime_total_preempted_sandboxes, 0);
atomic_init(&runtime_total_returned_sandboxes, 0);
atomic_init(&runtime_total_error_sandboxes, 0);
atomic_init(&runtime_total_complete_sandboxes, 0);
#endif
/* Setup epoll */ /* Setup epoll */
runtime_epoll_file_descriptor = epoll_create1(0); runtime_epoll_file_descriptor = epoll_create1(0);
assert(runtime_epoll_file_descriptor >= 0); assert(runtime_epoll_file_descriptor >= 0);
@ -127,7 +157,7 @@ listener_thread_reject(int client_socket)
}; };
#ifdef LOG_TOTAL_REQS_RESPS #ifdef LOG_TOTAL_REQS_RESPS
runtime_total_5XX_responses++; atomic_fetch_add(&runtime_total_5XX_responses, 1);
#endif #endif
close: close:
@ -225,7 +255,7 @@ listener_thread_main(void *dummy)
} }
#ifdef LOG_TOTAL_REQS_RESPS #ifdef LOG_TOTAL_REQS_RESPS
runtime_total_requests++; atomic_fetch_add(&runtime_total_requests, 1);
#endif #endif
/* Perform Admission Control */ /* Perform Admission Control */

@ -343,7 +343,7 @@ current_sandbox_main(void)
}; };
#ifdef LOG_TOTAL_REQS_RESPS #ifdef LOG_TOTAL_REQS_RESPS
runtime_total_2XX_responses++; atomic_fetch_add(&runtime_total_2XX_responses, 1);
#endif #endif
sandbox->response_timestamp = __getcycles(); sandbox->response_timestamp = __getcycles();
@ -385,7 +385,7 @@ err:
#ifdef LOG_TOTAL_REQS_RESPS #ifdef LOG_TOTAL_REQS_RESPS
if (rc >= 0) { if (rc >= 0) {
runtime_total_4XX_responses++; atomic_fetch_add(&runtime_total_4XX_responses, 1);
debuglog("At %llu, Sandbox %lu - 4XX\n", __getcycles(), sandbox->request_arrival_timestamp); debuglog("At %llu, Sandbox %lu - 4XX\n", __getcycles(), sandbox->request_arrival_timestamp);
} }
#endif #endif
@ -529,7 +529,7 @@ sandbox_set_as_initialized(struct sandbox *sandbox, struct sandbox_request *sand
sandbox->state = SANDBOX_INITIALIZED; sandbox->state = SANDBOX_INITIALIZED;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_initialized_sandboxes++; atomic_fetch_add(&runtime_total_initialized_sandboxes, 1);
#endif #endif
} }
@ -564,16 +564,16 @@ sandbox_set_as_runnable(struct sandbox *sandbox, sandbox_state_t last_state)
case SANDBOX_INITIALIZED: { case SANDBOX_INITIALIZED: {
sandbox->initializing_duration += duration_of_last_state; sandbox->initializing_duration += duration_of_last_state;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_initialized_sandboxes--; atomic_fetch_sub(&runtime_total_initialized_sandboxes, 1);
runtime_total_runnable_sandboxes++; atomic_fetch_add(&runtime_total_runnable_sandboxes, 1);
#endif #endif
break; break;
} }
case SANDBOX_BLOCKED: { case SANDBOX_BLOCKED: {
sandbox->blocked_duration += duration_of_last_state; sandbox->blocked_duration += duration_of_last_state;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_blocked_sandboxes--; atomic_fetch_sub(&runtime_total_blocked_sandboxes, 1);
runtime_total_runnable_sandboxes++; atomic_fetch_add(&runtime_total_runnable_sandboxes, 1);
#endif #endif
break; break;
} }
@ -620,16 +620,16 @@ sandbox_set_as_running(struct sandbox *sandbox, sandbox_state_t last_state)
case SANDBOX_RUNNABLE: { case SANDBOX_RUNNABLE: {
sandbox->runnable_duration += duration_of_last_state; sandbox->runnable_duration += duration_of_last_state;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_runnable_sandboxes--; atomic_fetch_sub(&runtime_total_runnable_sandboxes, 1);
runtime_total_running_sandboxes++; atomic_fetch_add(&runtime_total_running_sandboxes, 1);
#endif #endif
break; break;
} }
case SANDBOX_PREEMPTED: { case SANDBOX_PREEMPTED: {
sandbox->preempted_duration += duration_of_last_state; sandbox->preempted_duration += duration_of_last_state;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_preempted_sandboxes--; atomic_fetch_sub(&runtime_total_preempted_sandboxes, 1);
runtime_total_running_sandboxes++; atomic_fetch_add(&runtime_total_running_sandboxes, 1);
#endif #endif
break; break;
} }
@ -673,8 +673,8 @@ sandbox_set_as_preempted(struct sandbox *sandbox, sandbox_state_t last_state)
case SANDBOX_RUNNING: { case SANDBOX_RUNNING: {
sandbox->running_duration += duration_of_last_state; sandbox->running_duration += duration_of_last_state;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_running_sandboxes--; atomic_fetch_sub(&runtime_total_running_sandboxes, 1);
runtime_total_preempted_sandboxes++; atomic_fetch_add(&runtime_total_preempted_sandboxes, 1);
#endif #endif
break; break;
} }
@ -716,8 +716,8 @@ sandbox_set_as_blocked(struct sandbox *sandbox, sandbox_state_t last_state)
sandbox->running_duration += duration_of_last_state; sandbox->running_duration += duration_of_last_state;
local_runqueue_delete(sandbox); local_runqueue_delete(sandbox);
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_running_sandboxes--; atomic_fetch_sub(&runtime_total_running_sandboxes, 1);
runtime_total_blocked_sandboxes++; atomic_fetch_add(&runtime_total_blocked_sandboxes, 1);
#endif #endif
break; break;
} }
@ -763,8 +763,8 @@ sandbox_set_as_returned(struct sandbox *sandbox, sandbox_state_t last_state)
local_runqueue_delete(sandbox); local_runqueue_delete(sandbox);
sandbox_free_linear_memory(sandbox); sandbox_free_linear_memory(sandbox);
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_running_sandboxes--; atomic_fetch_sub(&runtime_total_running_sandboxes, 1);
runtime_total_returned_sandboxes++; atomic_fetch_add(&runtime_total_returned_sandboxes, 1);
#endif #endif
break; break;
} }
@ -809,16 +809,16 @@ sandbox_set_as_error(struct sandbox *sandbox, sandbox_state_t last_state)
/* Technically, this is a degenerate sandbox that we generate by hand */ /* Technically, this is a degenerate sandbox that we generate by hand */
sandbox->initializing_duration += duration_of_last_state; sandbox->initializing_duration += duration_of_last_state;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_initialized_sandboxes--; atomic_fetch_sub(&runtime_total_initialized_sandboxes, 1);
runtime_total_error_sandboxes++; atomic_fetch_add(&runtime_total_error_sandboxes, 1);
#endif #endif
break; break;
case SANDBOX_RUNNING: { case SANDBOX_RUNNING: {
sandbox->running_duration += duration_of_last_state; sandbox->running_duration += duration_of_last_state;
local_runqueue_delete(sandbox); local_runqueue_delete(sandbox);
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_running_sandboxes--; atomic_fetch_sub(&runtime_total_running_sandboxes, 1);
runtime_total_error_sandboxes++; atomic_fetch_add(&runtime_total_error_sandboxes, 1);
#endif #endif
break; break;
} }
@ -875,8 +875,8 @@ sandbox_set_as_complete(struct sandbox *sandbox, sandbox_state_t last_state)
sandbox->completion_timestamp = now; sandbox->completion_timestamp = now;
sandbox->returned_duration += duration_of_last_state; sandbox->returned_duration += duration_of_last_state;
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_returned_sandboxes--; atomic_fetch_sub(&runtime_total_returned_sandboxes, 1);
runtime_total_complete_sandboxes++; atomic_fetch_add(&runtime_total_complete_sandboxes, 1);
#endif #endif
break; break;
} }
@ -950,7 +950,7 @@ sandbox_allocate(struct sandbox_request *sandbox_request)
sandbox_set_as_initialized(sandbox, sandbox_request, now); sandbox_set_as_initialized(sandbox, sandbox_request, now);
#ifdef LOG_SANDBOX_TOTALS #ifdef LOG_SANDBOX_TOTALS
runtime_total_freed_requests++; atomic_fetch_add(&runtime_total_freed_requests, 1);
#endif #endif
free(sandbox_request); free(sandbox_request);
done: done:

Loading…
Cancel
Save