From c77fcf148d8244fae1cb9b7901a0200f9a14c735 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 26 Jan 2021 12:53:32 +0100 Subject: [PATCH] Hardening my measurement tool --- src/evt_core.c | 22 ++++++++++++++++++++-- src/evt_core.h | 2 ++ src/meas_lat.c | 8 +++++--- src/measure.c | 26 +++++++++++++++----------- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/evt_core.c b/src/evt_core.c index 44c3271..ffa7ca6 100644 --- a/src/evt_core.c +++ b/src/evt_core.c @@ -176,7 +176,11 @@ struct evt_core_cat* evt_core_rm_fd(struct evt_core_ctx* ctx, int fd) { // 3. Remove structure from urltofd and socklist g_hash_table_remove(ctx->urltofd, fdinfo->url); - g_hash_table_remove(ctx->socklist, &fd); // Will be free here + g_hash_table_remove(ctx->socklist, &fd); // Will be freed here + + // 4. List the fd as blacklisted for the end of the current loop + ctx->blacklisted_fds[ctx->blacklisted_fds_count] = fd; + ctx->blacklisted_fds_count++; // 4. Close and remove file descriptor // Done in free_fdinfo @@ -193,8 +197,18 @@ void evt_core_free(struct evt_core_ctx* ctx) { g_hash_table_destroy (ctx->urltofd); } +int evt_core_fd_bl(struct evt_core_ctx* ctx, int fd) { + for (int j = 0; j < ctx->blacklisted_fds_count; j++) { + if (ctx->blacklisted_fds[j] == fd) { + fprintf(stderr, "fd=%d has been deleted, skipping epoll notification\n", ctx->blacklisted_fds[j]); + return 1; + } + } + return 0; +} + void evt_core_loop(struct evt_core_ctx* ctx) { - struct epoll_event current_event, events[EVT_CORE_MAX_EVENTS]; + struct epoll_event events[EVT_CORE_MAX_EVENTS]; struct evt_core_fdinfo* fdinfo; struct evt_core_cat* cat; int return_code; @@ -211,6 +225,7 @@ void evt_core_loop(struct evt_core_ctx* ctx) { printf("--- Start main loop\n"); int num_fd, n = 0; while(ctx->loop) { + ctx->blacklisted_fds_count = 0; timing_fx_start(&tfx_epoll); num_fd = epoll_wait(ctx->epollfd, events, EVT_CORE_MAX_EVENTS, -1); timing_fx_stop(&tfx_epoll); @@ -224,6 +239,7 @@ void evt_core_loop(struct evt_core_ctx* ctx) { // 1. Handle errors for (n = 0 ; n < num_fd; n++) { if (!(events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP))) continue; + if (evt_core_fd_bl(ctx, events[n].data.fd)) continue; int err_fd = events[n].data.fd; int evt = events[n].events; @@ -268,6 +284,8 @@ void evt_core_loop(struct evt_core_ctx* ctx) { // 2. Fetch info and call appropriate function for (n = 0 ; n < num_fd; n++) { if (events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) continue; + if (evt_core_fd_bl(ctx, events[n].data.fd)) continue; + fdinfo = g_hash_table_lookup(ctx->socklist, &(events[n].data.fd)); if (fdinfo == NULL) { fprintf(stderr, "Ignoring file descriptor %d as it is not registered. This is a bug.\n", events[n].data.fd); diff --git a/src/evt_core.h b/src/evt_core.h index c6d2438..9884039 100644 --- a/src/evt_core.h +++ b/src/evt_core.h @@ -39,6 +39,8 @@ struct evt_core_ctx { int epollfd; uint8_t verbose; uint8_t loop; + int blacklisted_fds[EVT_CORE_MAX_EVENTS]; + int blacklisted_fds_count; GHashTable* catlist; // name -> category GHashTable* socklist; // fd -> category GHashTable* urltofd; // url -> fd, like "tcp:127.0.0.1:7500" diff --git a/src/meas_lat.c b/src/meas_lat.c index b138329..0095ef7 100644 --- a/src/meas_lat.c +++ b/src/meas_lat.c @@ -24,7 +24,6 @@ struct measlat_ctx { }; void free_ms(void* obj) { - printf("free measure state\n"); measure_state_free (obj); free(obj); } @@ -91,14 +90,17 @@ int on_receive_measure_packet_err(struct evt_core_ctx* ctx, struct evt_core_fdin sprintf(url, "timer:%d", fdinfo->fd); struct evt_core_fdinfo* assoc_timer = evt_core_get_from_url (ctx, url); if (assoc_timer != NULL) { + measure_summary (&mctx->mp, assoc_timer->other); evt_core_rm_fd (ctx, assoc_timer->fd); printf("Deleted associated timer %s\n", url); } else { printf("No associated timer %s\n", url); } - if (mctx->connectionless) return 1; - else return 0; + if (mctx->role == MEASLAT_CLIENT) exit(EXIT_FAILURE); + + if (mctx->connectionless) return 1; // keep the NET FD + else return 0; // delete the NET fd } void measlat_stop( diff --git a/src/measure.c b/src/measure.c index 4678b08..6b304ae 100644 --- a/src/measure.c +++ b/src/measure.c @@ -178,29 +178,33 @@ void measure_summary(struct measure_params* mp, struct measure_state* ms) { real_log_size--; } printf("[summary] cutted %lu values in total\n", mp->max_measure - real_log_size); + fprintf(stdout, "%s,%s,count,%lu\n", mp->tag, uuidstr, real_log_size); + if (real_log_size == 0) return; + // AVERAGE + double avg = 0; + for (int i = 0; i < real_log_size; i++) { + avg += ((double) real_log[i]) / ((double) real_log_size); + } + fprintf(stdout, "%s,%s,avg,%f\n", mp->tag, uuidstr, avg); + + // DISTRIBUTION + qsort (real_log, real_log_size, sizeof(uint64_t), cmpuint64t); uint64_t min = real_log[0]; fprintf(stdout, "%s,%s,min,%lu\n", mp->tag, uuidstr, min); uint64_t max = real_log[real_log_size-1]; fprintf(stdout, "%s,%s,max,%lu\n", mp->tag, uuidstr, max); - uint64_t med = real_log[(int)(0.50 * (real_log_size - 1))]; + uint64_t med = real_log[(int)(0.50 * real_log_size)]; fprintf(stdout, "%s,%s,med,%lu\n", mp->tag, uuidstr, med); - uint64_t q25 = real_log[(int)(0.25 * (real_log_size - 1))]; + uint64_t q25 = real_log[(int)(0.25 * real_log_size)]; fprintf(stdout, "%s,%s,q25,%lu\n", mp->tag, uuidstr, q25); - uint64_t q75 = real_log[(int)(0.75 * (real_log_size - 1))]; + uint64_t q75 = real_log[(int)(0.75 * real_log_size)]; fprintf(stdout, "%s,%s,q75,%lu\n", mp->tag, uuidstr, q75); - uint64_t q99 = real_log[(int)(0.99 * (real_log_size - 1))]; + uint64_t q99 = real_log[(int)(0.99 * real_log_size)]; fprintf(stdout, "%s,%s,q99,%lu\n", mp->tag, uuidstr, q99); - - qsort (real_log, real_log_size, sizeof(uint64_t), cmpuint64t); - double avg = 0; - for (int i = 0; i < real_log_size-1; i++) { - avg += ((double) real_log[i]) / ((double) (real_log_size - 1)); - } - fprintf(stdout, "%s,%s,avg,%f\n", mp->tag, uuidstr, avg); }