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

vere: adds %quic loom measurement, support it and |mass in conn #740

Merged
merged 6 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions pkg/c3/motes.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
# define c3__ice c3_s3('i','c','e')
# define c3__iced c3_s4('i','c','e','d')
# define c3__id c3_s2('i','d')
# define c3__idle c3_s4('i','d','l','e')
# define c3__if c3_s2('i','f')
# define c3__ifix c3_s4('i','f','i','x')
# define c3__in c3_s2('i','n')
Expand Down Expand Up @@ -966,6 +967,7 @@
# define c3__push c3_s4('p','u','s','h')
# define c3__put c3_s3('p','u','t')
# define c3__quac c3_s4('q','u','a','c')
# define c3__quic c3_s4('q','u','i','c')
# define c3__qual c3_s4('q','u','a','l')
# define c3__quat c3_s4('q','u','a','t')
# define c3__quax c3_s4('q','u','a','x')
Expand Down
92 changes: 69 additions & 23 deletions pkg/vere/io/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,68 @@ _conn_ovum_news(u3_ovum* egg_u, u3_ovum_news new_e)
}
}

/* _conn_make_cran(): alloc/init new request.
*/
static u3_cran*
_conn_make_cran(u3_chan* can_u, u3_atom rid)
{
u3_cran* ran_u = c3_calloc(sizeof(*ran_u));

ran_u->rid = rid;
ran_u->can_u = can_u;
ran_u->nex_u = can_u->ran_u;
can_u->ran_u = ran_u;
return ran_u;
}

static void
_conn_peel_quiz_cb(c3_m mot_m, void* ptr_v, u3_noun res)
{
u3_cran* ran_u = ptr_v;
u3_chan* can_u = ran_u->can_u;

if ( !can_u ) {
// chan was closed; noop.
//
u3z(ran_u->rid); c3_free(ran_u);
u3z(res); return;
}

_conn_send_noun(can_u, u3nt(ran_u->rid, c3__peel, res));
_conn_drop_cran(can_u, ran_u);
}

static void
_conn_async_peel(u3_conn* con_u,
u3_chan* can_u,
u3_atom rid,
u3_noun dat)
{
u3_pier* pir_u = con_u->car_u.pir_u;
c3_m mot_m = u3h(dat);

switch ( mot_m ) {
case c3__quic:
case c3__mass: {
u3_lord_quiz(pir_u->god_u,
(c3__quic == mot_m) ? c3__quic : c3__quac,
_conn_make_cran(can_u, rid), _conn_peel_quiz_cb);
} break;

default: u3_assert(0);
}

u3z(dat);
}

/* _conn_read_peel(): response to a %peel request, sans rid.
*/
static u3_noun
static u3_weak
_conn_read_peel(u3_conn* con_u, u3_noun dat)
{
u3_pier* pir_u = con_u->car_u.pir_u;
u3_noun i_dat, t_dat, it_dat, tt_dat;
u3_noun res;
u3_pier* pir_u = con_u->car_u.pir_u;
u3_noun i_dat, t_dat, it_dat, tt_dat;
u3_weak res;

if ( c3n == u3r_cell(dat, &i_dat, &t_dat) ) {
res = u3_nul;
Expand All @@ -456,6 +510,7 @@ _conn_read_peel(u3_conn* con_u, u3_noun dat)
u3i_list(u3nc(c3__help, u3_nul), u3nc(c3__info, u3_nul),
u3nc(c3__khan, u3_nul), u3nc(c3__live, u3_nul),
u3nc(c3__mass, u3_nul),
u3nc(c3__quic, u3_nul),
u3nc(c3__port,
u3i_list(c3__ames, c3__htls, c3__http, u3_none)),
u3nc(c3__v, u3_nul), u3nc(c3__who, u3_nul),
Expand All @@ -473,10 +528,9 @@ _conn_read_peel(u3_conn* con_u, u3_noun dat)
} break;
// |mass output
//
case c3__quic:
case c3__mass: {
// TODO |mass
//
res = u3_nul;
res = u3_none;
} break;
// runtime metrics.
//
Expand Down Expand Up @@ -529,20 +583,6 @@ _conn_read_peel(u3_conn* con_u, u3_noun dat)
u3z(dat); return res;
}

/* _conn_make_cran(): alloc/init new request.
*/
static u3_cran*
_conn_make_cran(u3_chan* can_u, u3_atom rid)
{
u3_cran* ran_u = c3_calloc(sizeof(*ran_u));

ran_u->rid = rid;
ran_u->can_u = can_u;
ran_u->nex_u = can_u->ran_u;
can_u->ran_u = ran_u;
return ran_u;
}

/* _conn_moor_poke(): called on message read from u3_moor.
*/
static void
Expand Down Expand Up @@ -602,8 +642,14 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y)
} break;

case c3__peel: {
_conn_send_noun(
can_u, u3nc(u3k(rid), _conn_read_peel(con_u, u3k(dat))));
u3_weak out;

if ( u3_none != (out = _conn_read_peel(con_u, u3k(dat))) ) {
_conn_send_noun(can_u, u3nc(u3k(rid), out));
}
else {
_conn_async_peel(con_u, can_u, u3k(rid), u3k(dat));
}
} break;

case c3__ovum: {
Expand Down
10 changes: 2 additions & 8 deletions pkg/vere/io/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ _reck_orchid(u3_noun fot, u3_noun txt, c3_l* tid_l)
/* _term_io_quiz(): handle quiz (query to serf).
*/
static void
_term_io_quiz(void* vod_p, u3_noun res)
_term_io_quiz(c3_m mot_m, void* vod_p, u3_noun res)
{
u3_auto* car_u = (u3_auto*)vod_p;
u3_noun wir = u3nt(c3__term, '1', u3_nul);
Expand Down Expand Up @@ -1755,13 +1755,7 @@ _term_io_kick(u3_auto* car_u, u3_noun wir, u3_noun cad)

case c3__quac: {
ret_o = c3y;
u3_writ* wit_u = u3_lord_writ_new(u3K.pir_u->god_u);
wit_u->typ_e = u3_writ_quiz;
wit_u->qui_u.ptr_v = car_u;
wit_u->qui_u.quiz_f = _term_io_quiz;

u3_lord_writ_plan(u3K.pir_u->god_u, wit_u);

u3_lord_quiz(u3K.pir_u->god_u, c3__quac, car_u, _term_io_quiz);
} break;
}
}
Expand Down
79 changes: 51 additions & 28 deletions pkg/vere/lord.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
== ==
[%peek mil=@ sam=*] :: gang (each path $%([%once @tas @tas path] [%beam @tas beam]))
[%play eve=@ lit=(list ?((pair @da ovum) *))]
$: %quiz
$% [%quac ~]
[%quic ~]
== ==
[%work mil=@ job=(pair @da ovum)]
[%quiz $%([%quac ~])]
==
:: +plea: from serf to king
::
Expand All @@ -32,7 +35,6 @@
[%ripe [pro=%1 hon=@ nok=@] eve=@ mug=@]
[%slog pri=@ tank]
[%flog cord]
[%quiz $%([%quac p=*])]
$: %peek
$% [%done dat=(unit (cask))]
[%bail dud=goof]
Expand All @@ -41,6 +43,10 @@
$% [%done mug=@]
[%bail eve=@ mug=@ dud=goof]
== ==
$: %quiz
$% [%quac p=*]
[%quic p=*]
== ==
$: %work
$% [%done eve=@ mug=@ fec=(list ovum)]
[%swap eve=@ mug=@ job=(pair @da ovum) fec=(list ovum)]
Expand Down Expand Up @@ -105,7 +111,8 @@ _lord_writ_free(u3_writ* wit_u)
case u3_writ_cram:
case u3_writ_meld:
case u3_writ_pack:
case u3_writ_exit: {
case u3_writ_exit:
case u3_writ_quiz: {
} break;
}

Expand Down Expand Up @@ -203,6 +210,7 @@ _lord_writ_str(u3_writ_type typ_e)
case u3_writ_meld: return "meld";
case u3_writ_pack: return "pack";
case u3_writ_exit: return "exit";
case u3_writ_quiz: return "quiz";
}
}

Expand Down Expand Up @@ -540,8 +548,7 @@ static void
_lord_plea_quiz(u3_lord* god_u, u3_noun dat)
{
u3_writ* wit_u = _lord_writ_need(god_u, u3_writ_quiz);
wit_u->qui_u.quiz_f(wit_u->qui_u.ptr_v, dat);
u3z(dat);
wit_u->qiz_u.qiz_f(wit_u->qiz_u.qiz_m, wit_u->qiz_u.ptr_v, dat);
}

/* _lord_work_spin(): update spinner if more work is in progress.
Expand Down Expand Up @@ -781,10 +788,10 @@ _lord_on_plea(void* ptr_v, c3_d len_d, c3_y* byt_y)
u3z(jar);
}

/* u3_lord_writ_new(): allocate a new writ.
/* _lord_writ_new(): allocate a new writ.
*/
u3_writ*
u3_lord_writ_new(u3_lord* god_u)
static u3_writ*
_lord_writ_new(u3_lord* god_u)
{
u3_writ* wit_u = c3_calloc(sizeof(*wit_u));
return wit_u;
Expand Down Expand Up @@ -848,7 +855,7 @@ _lord_writ_make(u3_lord* god_u, u3_writ* wit_u)
} break;

case u3_writ_quiz: {
msg = u3nt(c3__quiz, c3__quac, u3_nul);
msg = u3nt(c3__quiz, wit_u->qiz_u.qiz_m, u3_nul);
} break;
}

Expand Down Expand Up @@ -887,10 +894,10 @@ _lord_writ_send(u3_lord* god_u, u3_writ* wit_u)
}
}

/* u3_lord_writ_plan(): enqueue a writ and send.
/* _lord_writ_plan(): enqueue a writ and send.
*/
void
u3_lord_writ_plan(u3_lord* god_u, u3_writ* wit_u)
static void
_lord_writ_plan(u3_lord* god_u, u3_writ* wit_u)
{
if ( !god_u->ent_u ) {
u3_assert( !god_u->ext_u );
Expand All @@ -912,7 +919,7 @@ u3_lord_writ_plan(u3_lord* god_u, u3_writ* wit_u)
void
u3_lord_peek(u3_lord* god_u, u3_pico* pic_u)
{
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_peek;
wit_u->pek_u = c3_calloc(sizeof(*wit_u->pek_u));
wit_u->pek_u->ptr_v = pic_u->ptr_v;
Expand Down Expand Up @@ -943,31 +950,31 @@ u3_lord_peek(u3_lord* god_u, u3_pico* pic_u)

// XX cache check, unless last
//
u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);
}

/* u3_lord_play(): recompute batch.
*/
void
u3_lord_play(u3_lord* god_u, u3_info fon_u)
{
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_play;
wit_u->fon_u = fon_u;

// XX wat do?
//
// u3_assert( !pay_u.ent_u->nex_u );

u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);
}

/* u3_lord_work(): attempt work.
*/
void
u3_lord_work(u3_lord* god_u, u3_ovum* egg_u, u3_noun job)
{
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_work;
wit_u->wok_u.egg_u = egg_u;
wit_u->wok_u.job = job;
Expand All @@ -981,7 +988,7 @@ u3_lord_work(u3_lord* god_u, u3_ovum* egg_u, u3_noun job)
god_u->pin_o = c3y;
}

u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);
}

/* u3_lord_save(): save a snapshot.
Expand All @@ -993,9 +1000,9 @@ u3_lord_save(u3_lord* god_u)
return c3n;
}
else {
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_save;
u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);
return c3y;
}
}
Expand All @@ -1009,9 +1016,9 @@ u3_lord_cram(u3_lord* god_u)
return c3n;
}
else {
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_cram;
u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);
return c3y;
}
}
Expand All @@ -1021,29 +1028,45 @@ u3_lord_cram(u3_lord* god_u)
void
u3_lord_meld(u3_lord* god_u)
{
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_meld;
u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);
}

/* u3_lord_pack(): defragment persistent state.
*/
void
u3_lord_pack(u3_lord* god_u)
{
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_pack;
u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);
}

/* u3_lord_quiz(): query the serf.
*/
void
u3_lord_quiz(u3_lord* god_u,
c3_m qiz_m,
void* ptr_v,
void (*qiz_f)(c3_m, void*, u3_noun))
{
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_quiz;
wit_u->qiz_u.qiz_m = qiz_m;
wit_u->qiz_u.ptr_v = ptr_v;
wit_u->qiz_u.qiz_f = qiz_f;
_lord_writ_plan(god_u, wit_u);
}

/* u3_lord_exit(): shutdown gracefully.
*/
void
u3_lord_exit(u3_lord* god_u)
{
u3_writ* wit_u = u3_lord_writ_new(god_u);
u3_writ* wit_u = _lord_writ_new(god_u);
wit_u->typ_e = u3_writ_exit;
u3_lord_writ_plan(god_u, wit_u);
_lord_writ_plan(god_u, wit_u);

// XX set timer, then halt
}
Expand Down
Loading
Loading