Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mesa: misc. bugfixes #716

Merged
merged 22 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8478f5c
mesa: account for null lss pairs
yosoyubik Aug 20, 2024
5b57c96
mesa: correct 2-bit tag for 3-byte fragments
yosoyubik Aug 21, 2024
97ec30f
mesa: don't delete from pit after _mesa_req_pact_done
yosoyubik Aug 21, 2024
86f2840
mesa: early return after hearing fragment outside window
yosoyubik Aug 21, 2024
764ed6d
mesa: only delete from bitset if fragmen was in flight
yosoyubik Aug 23, 2024
1528bad
mesa: on acked page, resend up to the next fragment
yosoyubik Aug 23, 2024
1802bb6
mesa: always bitset_del when adding to data buffer
yosoyubik Aug 27, 2024
95ef0b1
mesa: add out-of-window fragments to data buffer
yosoyubik Aug 27, 2024
1103e9b
mesa: fix misorder queue update
yosoyubik Aug 27, 2024
f9a18a8
mesa: restore early return for out of window fragments
yosoyubik Aug 27, 2024
2be8c02
mesa: bitset_del for misordered and lef_d fragment
yosoyubik Aug 27, 2024
c4dca5f
mesa: fix memory leak
yosoyubik Aug 27, 2024
c60fbb2
mesa WIP fix resend timer
yosoyubik Aug 27, 2024
05fe7e9
mesa: fix remaining fragments
yosoyubik Aug 28, 2024
b756796
mesa: init congestion to microseconds
yosoyubik Aug 28, 2024
2895f5d
mesa: update resent packet send time
yosoyubik Aug 28, 2024
f679742
mesa: use RTO as next timer resend
yosoyubik Aug 28, 2024
9c4a01d
mesa: burn misorder queue on out-ot-window fragments
yosoyubik Aug 28, 2024
5c932e9
mesa: don't try to resend after ack
yosoyubik Aug 28, 2024
a7821f2
mesa: use correct length when inserting jumbo frame
yosoyubik Aug 28, 2024
f19e314
mesa: remove misordered queue handling
yosoyubik Aug 28, 2024
6689197
mesa: fix misordered queue handling
yosoyubik Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 60 additions & 45 deletions pkg/vere/io/mesa.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ _mesa_request_key(u3_mesa_name* nam_u)
}

static void
_init_gage(u3_gage* gag_u)
_init_gage(u3_gage* gag_u) // microseconds
{
gag_u->rto_w = 1000000;
gag_u->rtt_w = 1000000;
gag_u->rtv_w = 1000000;
gag_u->rto_w = 1000 * 1000 * 1000; // ~s1
gag_u->rtt_w = 1000 * 1000 * 1000; // ~s1
gag_u->rtv_w = 1000 * 1000 * 1000; // ~s1
gag_u->con_w = 0;
gag_u->wnd_w = 1;
gag_u->sst_w = 10000;
Expand Down Expand Up @@ -802,7 +802,7 @@ static void _mesa_handle_ack(u3_gage* gag_u, u3_pact_stat* pat_u)
static inline c3_d
_mesa_req_get_remaining(u3_pend_req* req_u)
{
return req_u->tof_d - req_u->nex_d;
return req_u->tof_d - req_u->hav_d;
}

/*
Expand Down Expand Up @@ -1046,7 +1046,7 @@ _mesa_send_modal(u3_peer* per_u, c3_y* buf_y, c3_w len_w)
if ( ( c3y == _mesa_is_direct_mode(per_u) ) ||
// if we are the sponsor of the ship, don't send to ourselves
(our_o == c3y) ) {
u3l_log("mesa: direct");
// u3l_log("mesa: direct");
_mesa_send_buf(sam_u, per_u->dan_u, sen_y, len_w);
per_u->dir_u.sen_d = now_d;
}
Expand Down Expand Up @@ -1109,15 +1109,15 @@ _try_resend(u3_pend_req* req_u, c3_d ack_d)
if ( (c3y == bitset_has(&req_u->was_u, i_d)) &&
(now_d - req_u->wat_u[i_d].sen_d > req_u->gag_u->rto_w) ) {
los_o = c3y;

_mesa_req_pact_resent(req_u, &pac_u->pek_u.nam_u);
pac_u->pek_u.nam_u.fra_d = i_d;
c3_w len_w = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u);
_mesa_send_modal(req_u->per_u, buf_y, len_w);
}
}

if ( c3y == los_o ) {
req_u->gag_u->sst_w = (req_u->gag_u->wnd_w / 2) + 1;
req_u->gag_u->sst_w = c3_max(1, req_u->gag_u->wnd_w / 2);
req_u->gag_u->wnd_w = req_u->gag_u->sst_w;
req_u->gag_u->rto_w = _clamp_rto(req_u->gag_u->rto_w * 2);
}
Expand Down Expand Up @@ -1155,10 +1155,12 @@ _update_resend_timer(u3_pend_req *req_u)
}
req_u->old_d = idx_d;
req_u->tim_u.data = req_u;
c3_d gap_d = req_u->wat_u[idx_d].sen_d - now_d;
/* u3l_log("timeout %llu", (gag_u->rto_w - gap_d) / 1000); */
c3_w dur_w = (req_u->gag_u->rto_w - gap_d) / 1000;
uv_timer_start(&req_u->tim_u, _mesa_packet_timeout, dur_w, 0);
// c3_d gap_d = req_u->wat_u[idx_d].sen_d == 0 ?
// 0 :
// now_d - req_u->wat_u[idx_d].sen_d;
c3_d next_expiry = req_u->gag_u->rto_w;
// u3l_log("next_expiry %llu", next_expiry / 1000);
uv_timer_start(&req_u->tim_u, _mesa_packet_timeout, next_expiry / 1000, 0);
}

/* _mesa_packet_timeout(): callback for packet timeout
Expand Down Expand Up @@ -1187,10 +1189,16 @@ _mesa_burn_misorder_queue(u3_pend_req* req_u)
break;
}
}

// ratchet forward
num_w++; // account for the packet processed in _mesa_req_pact_done
memcpy(req_u->mis_u, req_u->mis_u + num_w, max_w - num_w);
memset(req_u->mis_u + max_w - num_w, 0, num_w * sizeof(u3_misord_buf));
num_w++; // account for the in-ordered packet processed in _mesa_req_pact_done
req_u->lef_d += num_w;
req_u->hav_d += num_w;
memset(req_u->mis_u, 0, num_w * sizeof(u3_misord_buf));
memcpy(req_u->mis_u,
(c3_y*)req_u->mis_u + (num_w * sizeof(u3_misord_buf)),
(max_w - num_w) * sizeof(u3_misord_buf));

return res_o;
}

Expand Down Expand Up @@ -1219,7 +1227,7 @@ _mesa_req_pact_done(u3_pend_req* req_u,

// received duplicate
if ( c3n == bitset_has(&req_u->was_u, nam_u->fra_d) ) {
MESA_LOG(sam_u, DUPE);
// MESA_LOG(sam_u, DUPE);
return;
}

Expand All @@ -1233,16 +1241,21 @@ _mesa_req_pact_done(u3_pend_req* req_u,

if ( req_u->los_u->counter != nam_u->fra_d ) {
if ( nam_u->fra_d < req_u->los_u->counter ) {
u3l_log("fragment number too low: %"PRIu64, nam_u->fra_d);
// u3l_log("fragment number too low: %"PRIu64, nam_u->fra_d);
c3_free(par_u);
return;
} else if ( nam_u->fra_d >= req_u->los_u->counter + (sizeof(req_u->mis_u)/sizeof(u3_misord_buf)) ) {
u3l_log("fragment number too high: %"PRIu64, nam_u->fra_d);
// u3l_log("fragment number too high: %"PRIu64, nam_u->fra_d);
c3_free(par_u);
return;
} else {
// insert into misordered queue
u3_misord_buf* buf_u = &req_u->mis_u[nam_u->fra_d - req_u->los_u->counter - 1];
buf_u->fra_y = c3_calloc(dat_u->len_w);
buf_u->len_w = dat_u->len_w;
memcpy(buf_u->fra_y, dat_u->fra_y, dat_u->len_w);
buf_u->par_u = par_u;
u3l_log("insert into misordered queue fra: [%llu] = %llu", nam_u->fra_d - req_u->los_u->counter - 1, nam_u->fra_d );
}
}
else if ( c3y != lss_verifier_ingest(req_u->los_u, dat_u->fra_y, dat_u->len_w, par_u) ) {
Expand All @@ -1259,27 +1272,21 @@ _mesa_req_pact_done(u3_pend_req* req_u,
return;
}
else {
u3l_log("about to other free");
// u3l_log("about to other free");
c3_free(par_u);
}

bitset_del(&req_u->was_u, nam_u->fra_d);
if ( nam_u->fra_d > req_u->ack_d ) {
req_u->ack_d = nam_u->fra_d;
}

#ifdef MESA_DEBUG
if ( nam_u->fra_d != 0 && req_u->wat_u[nam_u->fra_d].tie_y != 1 ) {
u3l_log("received retry %"PRIu64, nam_u->fra_d);
}
#endif

req_u->hav_d++;
bitset_del(&req_u->was_u, nam_u->fra_d);

#ifdef MESA_DEBUG
u3l_log("fragment %"PRIu64" len %"PRIu64, nam_u->fra_d, req_u->hav_d);
u3l_log("fragment %llu counter %llu hav_d %llu nex_d %llu ack_d %llu lef_d %llu old_d %llu", nam_u->fra_d, req_u->los_u->counter, req_u->hav_d, req_u->nex_d, req_u->ack_d, req_u->lef_d, req_u->old_d);
#endif
if ( req_u->lef_d == nam_u->fra_d ) {
req_u->hav_d++;
req_u->lef_d++;
}

Expand All @@ -1300,7 +1307,8 @@ _mesa_req_pact_done(u3_pend_req* req_u,
c3_w siz_w = (1 << (nam_u->boq_y - 3));
memcpy(req_u->dat_y + (siz_w * nam_u->fra_d), dat_u->fra_y, dat_u->len_w);

_try_resend(req_u, nam_u->fra_d);
// _try_resend(req_u, req_u->nex_d);
// _try_resend(req_u, nam_u->fra_d);
_update_resend_timer(req_u);
}

Expand Down Expand Up @@ -1861,7 +1869,7 @@ _mesa_get_jumbo_cache(u3_mesa* sam_u, u3_mesa_name* nam_u)
u3_noun pax = _name_to_jumbo_scry(nam_u);
u3_weak res = u3h_get(sam_u->pac_p, pax);
#ifdef MESA_DEBUG
u3m_p((u3_none == res)? "mesa: cache miss" : "mesa: cache hit ", pax);
// u3m_p((u3_none == res)? "mesa: cache miss" : "mesa: cache hit ", pax);
#endif
u3z(pax);
return ( u3_none == res ) ? NULL : u3a_into(res);
Expand Down Expand Up @@ -1919,9 +1927,9 @@ _mesa_send_leaf(u3_mesa* sam_u,
u3_weak pin = _mesa_get_pit(sam_u, nam_u);
if ( u3_none != pin) {
#ifdef MESA_DEBUG
u3l_log(" sending leaf packet, fra_d: %"PRIu64, nam_u->fra_d);
// u3l_log(" sending leaf packet, fra_d: %"PRIu64, nam_u->fra_d);
#endif
log_pact(pac_u);
// log_pact(pac_u);
_mesa_send_pact(sam_u, u3k(u3t(pin)), NULL, pac_u);
_mesa_del_pit(sam_u, nam_u);
u3z(pin);
Expand All @@ -1932,7 +1940,7 @@ static void
_mesa_send_jumbo_pieces(u3_mesa* sam_u, u3_mesa_line* lin_u, c3_d* fra_u)
{
#ifdef MESA_DEBUG
u3l_log("mesa: send_jumbo_pieces()");
// u3l_log("mesa: send_jumbo_pieces()");
#endif

u3_mesa_pact pac_u = {0};
Expand Down Expand Up @@ -2037,8 +2045,8 @@ _mesa_page_scry_jumbo_cb(void* vod_p, u3_noun res)
}

#ifdef MESA_DEBUG
u3l_log("mesa: scry_jumbo_cb()");
log_pact(pac_u);
// u3l_log("mesa: scry_jumbo_cb()");
// log_pact(pac_u);
#endif

u3_mesa_line* lin_u;
Expand All @@ -2047,7 +2055,6 @@ _mesa_page_scry_jumbo_cb(void* vod_p, u3_noun res)
c3_y* jumbo_y = c3_calloc(jumbo_w);
u3r_bytes(0, jumbo_w, jumbo_y, pac);

u3l_log("sifting jumbo packet len=%u", jumbo_w);
u3_mesa_pact jum_u;
c3_c* err_c = mesa_sift_pact_from_buf(&jum_u, jumbo_y, jumbo_w);
if ( err_c ) {
Expand Down Expand Up @@ -2080,8 +2087,14 @@ _mesa_page_scry_jumbo_cb(void* vod_p, u3_noun res)
lin_u->haz_y = lin_u->dat_y + dat_w;
memcpy(lin_u->dat_y, dat_u->fra_y, dat_u->len_w);

c3_y* haz_y = lin_u->haz_y;
while ( pas != u3_nul ) {
u3r_bytes(0, 64, haz_y, u3h(pas));
haz_y += 64;
pas = u3t(pas);
}

u3r_bytes(0, tip_w, lin_u->tip_y, pof);
u3r_bytes(0, haz_w, lin_u->haz_y, pas);

mesa_free_pact(&jum_u);
}
Expand Down Expand Up @@ -2255,7 +2268,6 @@ _mesa_req_pact_init(u3_mesa* sam_u, u3_mesa_pict* pic_u, u3_lane* lan_u)
lss_root(root, pof_u, pof_w);
req_u->los_u = c3_calloc(sizeof(lss_verifier));
lss_verifier_init(req_u->los_u, 0, req_u->tof_d, pof_u);
u3l_log("about to c3_free(pof_u)");
c3_free(pof_u);

req_u = _mesa_put_request(sam_u, nam_u, req_u);
Expand Down Expand Up @@ -2367,8 +2379,8 @@ static void
_mesa_hear_page(u3_mesa_pict* pic_u, u3_lane lan_u)
{
#ifdef MESA_DEBUG
u3l_log("mesa: hear_page()");
log_pact(&pic_u->pac_u);
// u3l_log("mesa: hear_page()");
// log_pact(&pic_u->pac_u);
u3_assert( PACT_PAGE == pic_u->pac_u.hed_u.typ_y );
#endif

Expand Down Expand Up @@ -2412,7 +2424,8 @@ _mesa_hear_page(u3_mesa_pict* pic_u, u3_lane lan_u)

if ( u3_none == pin ) {
#ifdef MESA_DEBUG
u3l_log(" no PIT entry");
// u3l_log(" no PIT entry");
// log_name(nam_u);
#endif
return;
}
Expand Down Expand Up @@ -2510,11 +2523,11 @@ _mesa_hear_page(u3_mesa_pict* pic_u, u3_lane lan_u)
c3_y boq_y = 31;
// c3_o done_with_jumbo_frame = __(0 == req_u->hav_d % boq_y);
c3_o done_with_jumbo_frame = __(req_u->hav_d == req_u->tof_d); // TODO: fix for non-message-sized jumbo frames
_mesa_del_pit(sam_u, nam_u);
// _mesa_del_pit(sam_u, nam_u); XX
if ( c3y == done_with_jumbo_frame ) {
u3_noun cad;

u3l_log(" received last packet, tot_d: %llu", req_u->tof_d);
u3l_log(" received last packet, tof_d: %llu tob_d: %llu", req_u->tof_d, req_u->tob_d);
c3_d now_d = _get_now_micros();
u3l_log("%llu kilobytes took %f ms", req_u->tof_d, (now_d - sam_u->tim_d)/1000.0);

Expand All @@ -2526,7 +2539,7 @@ _mesa_hear_page(u3_mesa_pict* pic_u, u3_lane lan_u)
pac_u->pag_u.nam_u.boq_y = boq_y;
pac_u->pag_u.dat_u.tob_d = req_u->tob_d;
pac_u->pag_u.nam_u.fra_d = (req_u->hav_d >> boq_y);
pac_u->pag_u.dat_u.len_w += (1024 * (lev_d - 1));
pac_u->pag_u.dat_u.len_w = req_u->tob_d;
pac_u->pag_u.dat_u.fra_y = req_u->dat_y;
pac_u->pag_u.dat_u.aut_u = req_u->aut_u;

Expand Down Expand Up @@ -2583,7 +2596,7 @@ static void
_mesa_hear_peek(u3_mesa_pict* pic_u, u3_lane lan_u)
{
#ifdef MESA_DEBUG
u3l_log("mesa: hear_peek()");
// u3l_log("mesa: hear_peek()");
u3_assert( PACT_PEEK == pic_u->pac_u.hed_u.typ_y );
#endif

Expand Down Expand Up @@ -2615,6 +2628,8 @@ _mesa_hear_peek(u3_mesa_pict* pic_u, u3_lane lan_u)
// otherwise, scry
lin_u = c3_calloc(sizeof(u3_mesa_line));
lin_u->typ_y = CTAG_WAIT;
_mesa_copy_name(&lin_u->nam_u, &pac_u->pek_u.nam_u); // XX

_mesa_put_jumbo_cache(sam_u, &pac_u->pek_u.nam_u, lin_u);
u3_noun sky = _name_to_jumbo_scry(&pac_u->pek_u.nam_u);
u3_noun our = u3i_chubs(2, sam_u->car_u.pir_u->who_d);
Expand Down
2 changes: 1 addition & 1 deletion pkg/vere/io/mesa/pact.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ _mesa_make_chub_tag(c3_d tot_d)
{
return (tot_d <= 0xff)? 0b00 :
(tot_d <= 0xffff)? 0b01 :
(tot_d <= 0xffffffff)? 0b10 :
(tot_d <= 0xffffff)? 0b10 :
0b11;
}

Expand Down
Loading