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

fdctl: tiles specify their own run loop #1762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
59 changes: 38 additions & 21 deletions src/app/fdctl/run/tiles/fd_bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ scratch_footprint( fd_topo_tile_t const * tile ) {
return FD_LAYOUT_FINI( l, scratch_align() );
}

FD_FN_CONST static inline void *
mux_ctx( void * scratch ) {
return (void*)fd_ulong_align_up( (ulong)scratch, alignof( fd_bank_ctx_t ) );
}

static inline void
metrics_write( void * _ctx ) {
fd_bank_ctx_t * ctx = (fd_bank_ctx_t *)_ctx;
Expand Down Expand Up @@ -292,27 +287,49 @@ unprivileged_init( fd_topo_t * topo,
ctx->out_chunk = ctx->out_chunk0;
}

static long
lazy( fd_topo_tile_t * tile ) {
(void)tile;
/* See explanation in fd_pack */
return 128L * 300L;
static void
run( fd_topo_t * topo,
fd_topo_tile_t * tile,
void * scratch,
fd_cnc_t * cnc,
ulong in_cnt,
fd_frag_meta_t const ** in_mcache,
ulong ** in_fseq,
fd_frag_meta_t * mcache,
ulong out_cnt,
ulong ** out_fseq ) {
FD_SCRATCH_ALLOC_INIT( l, scratch );
fd_bank_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_bank_ctx_t ), sizeof( fd_bank_ctx_t ) );

fd_mux_callbacks_t callbacks = {
.before_frag = before_frag,
.during_frag = during_frag,
.after_frag = after_frag,
.metrics_write = metrics_write,
};

fd_rng_t rng[1];
fd_mux_tile( cnc,
FD_MUX_FLAG_COPY | FD_MUX_FLAG_MANUAL_PUBLISH,
in_cnt,
in_mcache,
in_fseq,
mcache,
out_cnt,
out_fseq,
1UL,
0UL,
128L*300L, /* See explanation in fd_pack */
fd_rng_join( fd_rng_new( rng, 0, 0UL ) ),
fd_alloca( FD_MUX_TILE_SCRATCH_ALIGN, FD_MUX_TILE_SCRATCH_FOOTPRINT( in_cnt, out_cnt ) ),
ctx,
&callbacks );
}

fd_topo_run_tile_t fd_tile_bank = {
.name = "bank",
.mux_flags = FD_MUX_FLAG_COPY | FD_MUX_FLAG_MANUAL_PUBLISH,
.burst = 1UL,
.mux_ctx = mux_ctx,
.mux_before_frag = before_frag,
.mux_during_frag = during_frag,
.mux_after_frag = after_frag,
.mux_metrics_write = metrics_write,
.lazy = lazy,
.populate_allowed_seccomp = NULL,
.populate_allowed_fds = NULL,
.scratch_align = scratch_align,
.scratch_footprint = scratch_footprint,
.privileged_init = NULL,
.unprivileged_init = unprivileged_init,
.run = run,
};
52 changes: 40 additions & 12 deletions src/app/fdctl/run/tiles/fd_blackhole.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "tiles.h"

/**
* Tile used to filter out all packets when used as a consumer.
* As the name suggests, it is a "black hole" for incoming packets.
*/
/* A /dev/null semantic tile which just drops (filters) every incoming
packet it receives. */

static void
before_frag( void * _ctx FD_PARAM_UNUSED,
Expand All @@ -19,20 +17,50 @@ populate_allowed_fds( void * scratch,
ulong out_fds_cnt,
int * out_fds ) {
(void)scratch;
if( FD_UNLIKELY( out_fds_cnt < 2 ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));

ulong out_cnt = 0;
ulong out_cnt = 0UL;
out_fds[ out_cnt++ ] = 2; /* stderr */
if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
return out_cnt;
}

static void
run( fd_topo_t * topo,
fd_topo_tile_t * tile,
void * scratch,
fd_cnc_t * cnc,
ulong in_cnt,
fd_frag_meta_t const ** in_mcache,
ulong ** in_fseq,
fd_frag_meta_t * mcache,
ulong out_cnt,
ulong ** out_fseq ) {
fd_mux_callbacks_t callbacks = {
.before_frag = before_frag,
};

fd_rng_t rng[1];
fd_mux_tile( cnc,
FD_MUX_FLAG_COPY | FD_MUX_FLAG_MANUAL_PUBLISH,
in_cnt,
in_mcache,
in_fseq,
mcache,
out_cnt,
out_fseq,
1UL,
0UL,
0L,
fd_rng_join( fd_rng_new( rng, 0, 0UL ) ),
fd_alloca( FD_MUX_TILE_SCRATCH_ALIGN, FD_MUX_TILE_SCRATCH_FOOTPRINT( in_cnt, out_cnt ) ),
NULL,
&callbacks );
}

fd_topo_run_tile_t fd_tile_blackhole = {
.name = "bhole",
.mux_flags = FD_MUX_FLAG_MANUAL_PUBLISH | FD_MUX_FLAG_COPY,
.burst = 1UL,
.mux_before_frag = before_frag,
.populate_allowed_fds = populate_allowed_fds,
.privileged_init = NULL,
.name = "bhole",
.populate_allowed_fds = populate_allowed_fds,
.run = run,
};
49 changes: 38 additions & 11 deletions src/app/fdctl/run/tiles/fd_dedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ scratch_footprint( fd_topo_tile_t const * tile ) {
return FD_LAYOUT_FINI( l, scratch_align() );
}

FD_FN_CONST static inline void *
mux_ctx( void * scratch ) {
return (void*)fd_ulong_align_up( (ulong)scratch, alignof( fd_dedup_ctx_t ) );
}

/* during_frag is called between pairs for sequence number checks, as
we are reading incoming frags. We don't actually need to copy the
fragment here, flow control prevents it getting overrun, and
Expand Down Expand Up @@ -189,17 +184,49 @@ populate_allowed_fds( void * scratch,
return out_cnt;
}

static void
run( fd_topo_t * topo,
fd_topo_tile_t * tile,
void * scratch,
fd_cnc_t * cnc,
ulong in_cnt,
fd_frag_meta_t const ** in_mcache,
ulong ** in_fseq,
fd_frag_meta_t * mcache,
ulong out_cnt,
ulong ** out_fseq ) {
FD_SCRATCH_ALLOC_INIT( l, scratch );
fd_dedup_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_dedup_ctx_t ), sizeof( fd_dedup_ctx_t ) );

fd_mux_callbacks_t callbacks = {
.during_frag = during_frag,
.after_frag = after_frag,
};

fd_rng_t rng[1];
fd_mux_tile( cnc,
FD_MUX_FLAG_COPY,
in_cnt,
in_mcache,
in_fseq,
mcache,
out_cnt,
out_fseq,
1UL,
0UL,
0L,
fd_rng_join( fd_rng_new( rng, 0, 0UL ) ),
fd_alloca( FD_MUX_TILE_SCRATCH_ALIGN, FD_MUX_TILE_SCRATCH_FOOTPRINT( in_cnt, out_cnt ) ),
ctx,
&callbacks );
}

fd_topo_run_tile_t fd_tile_dedup = {
.name = "dedup",
.mux_flags = FD_MUX_FLAG_COPY,
.burst = 1UL,
.mux_ctx = mux_ctx,
.mux_during_frag = during_frag,
.mux_after_frag = after_frag,
.populate_allowed_seccomp = populate_allowed_seccomp,
.populate_allowed_fds = populate_allowed_fds,
.scratch_align = scratch_align,
.scratch_footprint = scratch_footprint,
.privileged_init = NULL,
.unprivileged_init = unprivileged_init,
.run = run,
};
47 changes: 40 additions & 7 deletions src/app/fdctl/run/tiles/fd_gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,20 +608,53 @@ populate_allowed_fds( void * scratch FD_PARAM_UNUSED,
return out_cnt;
}

static void
run( fd_topo_t * topo,
fd_topo_tile_t * tile,
void * scratch,
fd_cnc_t * cnc,
ulong in_cnt,
fd_frag_meta_t const ** in_mcache,
ulong ** in_fseq,
fd_frag_meta_t * mcache,
ulong out_cnt,
ulong ** out_fseq ) {
FD_SCRATCH_ALLOC_INIT( l, scratch );
fd_gossip_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_gossip_tile_ctx_t), sizeof(fd_gossip_tile_ctx_t) );

fd_mux_callbacks_t callbacks = {
.after_credit = after_credit,
.before_frag = before_frag,
.during_frag = during_frag,
.after_frag = after_frag,
};

fd_rng_t rng[1];
fd_mux_tile( cnc,
FD_MUX_FLAG_MANUAL_PUBLISH | FD_MUX_FLAG_COPY,
in_cnt,
in_mcache,
in_fseq,
mcache,
out_cnt,
out_fseq,
1UL,
0UL,
0L,
fd_rng_join( fd_rng_new( rng, 0, 0UL ) ),
fd_alloca( FD_MUX_TILE_SCRATCH_ALIGN, FD_MUX_TILE_SCRATCH_FOOTPRINT( in_cnt, out_cnt ) ),
ctx,
&callbacks );
}

fd_topo_run_tile_t fd_tile_gossip = {
.name = "gossip",
.mux_flags = FD_MUX_FLAG_MANUAL_PUBLISH | FD_MUX_FLAG_COPY,
.burst = 1UL,
.loose_footprint = loose_footprint,
.mux_ctx = mux_ctx,
.mux_after_credit = after_credit,
.mux_before_frag = before_frag,
.mux_during_frag = during_frag,
.mux_after_frag = after_frag,
.populate_allowed_seccomp = populate_allowed_seccomp,
.populate_allowed_fds = populate_allowed_fds,
.scratch_align = scratch_align,
.scratch_footprint = scratch_footprint,
.privileged_init = privileged_init,
.unprivileged_init = unprivileged_init,
.run = run,
};
43 changes: 38 additions & 5 deletions src/app/fdctl/run/tiles/fd_metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,50 @@ populate_allowed_fds( void * scratch,
return out_cnt;
}

static void
run( fd_topo_t * topo,
fd_topo_tile_t * tile,
void * scratch,
fd_cnc_t * cnc,
ulong in_cnt,
fd_frag_meta_t const ** in_mcache,
ulong ** in_fseq,
fd_frag_meta_t * mcache,
ulong out_cnt,
ulong ** out_fseq ) {
FD_SCRATCH_ALLOC_INIT( l, scratch );
fd_metric_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_metric_ctx_t ), sizeof( fd_metric_ctx_t ) );

fd_mux_callbacks_t callbacks = {
.before_credit = before_credit,
};

fd_rng_t rng[1];
fd_mux_tile( cnc,
FD_MUX_FLAG_MANUAL_PUBLISH | FD_MUX_FLAG_COPY,
in_cnt,
in_mcache,
in_fseq,
mcache,
out_cnt,
out_fseq,
1UL,
0UL,
0L,
fd_rng_join( fd_rng_new( rng, 0, 0UL ) ),
fd_alloca( FD_MUX_TILE_SCRATCH_ALIGN, FD_MUX_TILE_SCRATCH_FOOTPRINT( in_cnt, out_cnt ) ),
ctx,
&callbacks );
}

fd_topo_run_tile_t fd_tile_metric = {
.name = "metric",
.mux_flags = FD_MUX_FLAG_MANUAL_PUBLISH | FD_MUX_FLAG_COPY,
.burst = 1UL,
.rlimit_file_cnt = MAX_CONNS+1,
.mux_ctx = mux_ctx,
.mux_before_credit = before_credit,
.rlimit_file_cnt = MAX_CONNS+1UL,
.populate_allowed_seccomp = populate_allowed_seccomp,
.populate_allowed_fds = populate_allowed_fds,
.scratch_align = scratch_align,
.scratch_footprint = scratch_footprint,
.privileged_init = privileged_init,
.unprivileged_init = unprivileged_init,
.run = run,
};
Loading
Loading