From a33918ffb42a6f3de69e53cd4d0df7039ce03dde Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 16 Oct 2019 14:39:54 +0200 Subject: [PATCH] Add disable scheduler option + remove recovery option --- src/algo_lightning.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/algo_lightning.c b/src/algo_lightning.c index c87f25d..0331860 100644 --- a/src/algo_lightning.c +++ b/src/algo_lightning.c @@ -46,13 +46,13 @@ struct light_ctx { uint8_t selected_link; uint8_t total_links; int fast_count; - int sleep_duration; int sent_past_links; struct timespec window; size_t monit_pkt_size; uint8_t csv; uint8_t is_measlat; uint8_t explain; + uint8_t disable_scheduler; }; void algo_lightning_free(void* v) { @@ -73,11 +73,11 @@ void algo_lightning_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, str lightc->selected_link = lightc->total_links - 1; lightc->sent_past_links = lightc->total_links; lightc->fast_count = lightc->total_links / 2; - lightc->sleep_duration = 500; lightc->csv = 0; lightc->explain = 0; lightc->pkt_sent_id = 1; lightc->uniq_pkt_sent_id = 1; + lightc->disable_scheduler = 0; uint64_t window = 2000; if (ap->algo_specific_params != NULL) { @@ -87,12 +87,12 @@ void algo_lightning_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, str token = strtok_r(params, ",", &parse_ptr); if (token == NULL) break; sscanf(token, "fast_count=%d", &lightc->fast_count); - sscanf(token, "recovery=%d", &lightc->sleep_duration); sscanf(token, "window=%ld", &window); sscanf(token, "sent_past_links=%d", &lightc->sent_past_links); sscanf(token, "csv=%d", &lightc->csv); sscanf(token, "measlat=%d", &lightc->is_measlat); sscanf(token, "explain=%d", &lightc->explain); + sscanf(token, "disable_scheduler=%d", &lightc->disable_scheduler); } } @@ -108,12 +108,12 @@ void algo_lightning_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, str timespec_set_unit (&lightc->window, window, MILISEC); printf("fast_count = %d\n", lightc->fast_count); - printf("recovery = %d ms\n", lightc->sleep_duration); printf("window check = %ld ms\n", window); printf("sent_past_links = %d\n", lightc->sent_past_links); printf("csv = %s\n", lightc->csv ? "yes" : "no"); printf("measlat = %s\n", lightc->is_measlat ? "yes" : "no"); printf("explain = %s\n", lightc->explain ? "yes" : "no"); + printf("disable_scheduler = %s\n", lightc->disable_scheduler ? "yes" : "no"); } void algo_lightning_pad(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) { @@ -298,7 +298,8 @@ void algo_lightning_update_stats (struct light_ctx *lightc, struct stat_entry *s } // Sort - qsort(stats, lightc->total_links, sizeof(struct stat_entry), compare_stat_entry_max); + if (!lightc->disable_scheduler) + qsort(stats, lightc->total_links, sizeof(struct stat_entry), compare_stat_entry_max); } int send_message(struct evt_core_ctx* ctx, struct buffer_packet* bp) { @@ -376,7 +377,7 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* } // Init vars - struct timespec now, sel_link_last, temp_time; + struct timespec now, sel_link_last; set_now(&now); uint64_t now_timestamp = timespec_get_unit(&now, MILISEC); @@ -392,17 +393,7 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* send_message (ctx, bp); if (lightc->csv) printf("%ld,%d,fast\n", now_timestamp, lightc->selected_link); - // Select slow link - sel_link_last = now; - lightc->selected_link = UINT8_MAX; - for (int i = lightc->fast_count; i < lightc->total_links; i++) { - if (timespec_lt (&lightc->last[stats[i].link_id], &sel_link_last)) { - lightc->selected_link = stats[i].link_id; - sel_link_last = lightc->last[stats[i].link_id]; - } - } - timespec_diff (&now, &sel_link_last, &temp_time); - uint64_t elapsed = timespec_get_unit(&temp_time, MILISEC); + // Tag packets for slow link if (lightc->is_measlat) { union abstract_packet* cur = ap; while (cur != NULL) { @@ -415,10 +406,18 @@ int algo_lightning_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* cur = ap_next(cur); } } - if (elapsed >= lightc->sleep_duration) { - send_message (ctx, bp); - if (lightc->csv) printf("%ld,%d,slow\n", now_timestamp, lightc->selected_link); + + // Select slow link + sel_link_last = now; + lightc->selected_link = UINT8_MAX; + for (int i = lightc->fast_count; i < lightc->total_links; i++) { + if (timespec_lt (&lightc->last[stats[i].link_id], &sel_link_last)) { + lightc->selected_link = stats[i].link_id; + sel_link_last = lightc->last[stats[i].link_id]; + } } + send_message (ctx, bp); + if (lightc->csv) printf("%ld,%d,slow\n", now_timestamp, lightc->selected_link); lightc->uniq_pkt_sent_id++; mv_buffer_rtof (&app_ctx->br, fdinfo);