From 5a6685e7c2908d2e987766bdbd1e265529cebd4d Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 19 Mar 2019 18:50:56 +0100 Subject: [PATCH] WIP debugging prog --- src/algo_rr.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/algo_rr.c b/src/algo_rr.c index b7c69fe..a07ce6a 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -19,7 +19,7 @@ struct rr_ctx { uint8_t my_links; uint16_t my_links_ver; uint8_t remote_links; - uint16_t mjit; + int64_t mjit; uint16_t recv_id; uint16_t sent_id; uint8_t current_link; @@ -70,7 +70,7 @@ co_error: exit(EXIT_FAILURE); } -int set_timeout(struct evt_core_ctx* evts, uint64_t micro_sec, struct waited_pkt* wpkt) { +int set_timeout(struct evt_core_ctx* evts, uint64_t milli_sec, struct waited_pkt* wpkt) { struct timespec now; struct itimerspec timer_config; char url[1024]; @@ -79,14 +79,15 @@ int set_timeout(struct evt_core_ctx* evts, uint64_t micro_sec, struct waited_pkt fdinfo.cat = &cat; fdinfo.url = url; - printf("Will add a timeout of %ld ms\n", micro_sec); + printf("Will add a timeout of %ld ms\n", milli_sec); if (clock_gettime(CLOCK_REALTIME, &now) == -1) { perror("clock_gettime"); exit(EXIT_FAILURE); } - timer_config.it_value.tv_sec = now.tv_sec + micro_sec / 1000; - timer_config.it_value.tv_nsec = now.tv_nsec + micro_sec % 1000 * 1000000; + uint64_t ns = now.tv_nsec + (milli_sec % 1000) * 1000000; + timer_config.it_value.tv_sec = now.tv_sec + milli_sec / 1000 + ns / 1000000000; + timer_config.it_value.tv_nsec = ns % 1000000000; timer_config.it_interval.tv_sec = 60; timer_config.it_interval.tv_nsec = 0; @@ -96,13 +97,13 @@ int set_timeout(struct evt_core_ctx* evts, uint64_t micro_sec, struct waited_pkt exit(EXIT_FAILURE); } if (timerfd_settime (fdinfo.fd, TFD_TIMER_ABSTIME, &timer_config, NULL) == -1) { - perror("Unable to timerfd_time"); + perror("Unable to timerfd_settime"); exit(EXIT_FAILURE); } fdinfo.cat->name = "timeout"; fdinfo.other = wpkt; // Should put the link number and the id fdinfo.free_other = NULL; - sprintf(fdinfo.url, "timer:%ld:1", micro_sec); + sprintf(fdinfo.url, "timer:%ld:1", milli_sec); evt_core_add_fd (evts, &fdinfo); return fdinfo.fd; @@ -121,7 +122,6 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, } // 2. If packet arrived too late, we discard it - printf("== %d > %d ? %d\n", rr->recv_id, bp->ip.ap.str.id - 1, ring_gt(rr->recv_id, bp->ip.ap.str.id - 1)); if (ring_gt(rr->recv_id, bp->ip.ap.str.id - 1)) { // Packet has already been delivered or dropped, we free the buffer mv_buffer_wtor (app_ctx, fdinfo, bp); @@ -129,15 +129,16 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, } // 3. If packet arrived too early, we register a timer - printf("== %d < %d ? %d\n", rr->recv_id, bp->ip.ap.str.id - 1, ring_lt(rr->recv_id, bp->ip.ap.str.id - 1)); if (ring_lt(rr->recv_id, bp->ip.ap.str.id - 1)) { int64_t timeout = rr->mjit - (int64_t) bp->ip.ap.str.deltat; + printf("%ld - %ld = %ld\n", rr->mjit, (int64_t) bp->ip.ap.str.deltat, timeout); if (timeout <= 0) timeout = 0; int idx_waited = (bp->ip.ap.str.id - 1) % PACKET_BUFFER_SIZE; rr->wait[idx_waited].on = 1; rr->wait[idx_waited].id = bp->ip.ap.str.id; rr->wait[idx_waited].link_num = bp->ip.ap.str.prevlink; rr->wait[idx_waited].timer_fd = set_timeout(ctx, timeout, &rr->wait[idx_waited]); + g_hash_table_remove(app_ctx->used_buffer, &fdinfo->fd); // We remove the packet from the reading buffer } // 4. We queue the packet @@ -282,7 +283,7 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { // 3. Prepare RR state and packet values struct timespec curr; int secs, nsecs; - uint64_t micro_sec; + uint64_t mili_sec; if (clock_gettime(CLOCK_MONOTONIC, &curr) == -1){ perror("clock_gettime error"); @@ -291,12 +292,12 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { secs = curr.tv_sec - rr->emit_time.tv_sec; nsecs = curr.tv_nsec - rr->emit_time.tv_nsec; - micro_sec = secs * 1000000 + nsecs / 1000; - if (micro_sec > rr->mjit) micro_sec = rr->mjit; + mili_sec = secs * 1000 + nsecs / 1000000; + if (mili_sec > rr->mjit) mili_sec = rr->mjit; bp->ip.ap.str.id = rr->sent_id; bp->ip.ap.str.flags = 0; - bp->ip.ap.str.deltat = micro_sec; + bp->ip.ap.str.deltat = mili_sec; bp->ip.ap.str.bitfield = rr->remote_links; bp->ip.ap.str.prevlink = rr->current_link;