Line data Source code
1 : #ifndef HEADER_fd_src_disco_events_fd_event_report_h 2 : #define HEADER_fd_src_disco_events_fd_event_report_h 3 : 4 : /* fd_event_report.h provides a thread-local, fire-and-forget path for a 5 : tile to report a telemetry event to the event tile, mirroring how the 6 : metrics thread-local (fd_metrics_tl / FD_MCNT_*) works. 7 : 8 : A tile opts in by setting fd_topo_run_tile_t.max_event_sz; the topology 9 : then auto-wires a dedicated unreliable link from the tile to the event 10 : tile (see topology construction). At tile boot, fd_event_register() 11 : sets up the thread-local reporter from that link. Generated code emits 12 : one fd_event_report_<name>( msg ) macro per event schema (see 13 : generated/fd_event_gen.h) which forwards to fd_event_report_(). 14 : 15 : The link is written directly via fd_mcache_publish (outside fd_stem); it 16 : is unreliable, so events are dropped if the event tile falls behind. 17 : When a tile has no event link (telemetry off / max_event_sz==0), 18 : fd_event_tl is NULL and reporting is a no-op. */ 19 : 20 : #include "../topo/fd_topo.h" 21 : #include "../../tango/mcache/fd_mcache.h" 22 : #include "../../tango/dcache/fd_dcache.h" 23 : 24 : struct fd_event_reporter { 25 : fd_frag_meta_t * mcache; /* mcache of the event link (joined) */ 26 : ulong depth; /* mcache depth */ 27 : ulong seq; /* next sequence number to publish */ 28 : 29 : fd_wksp_t * mem; /* workspace containing the dcache (chunk base) */ 30 : ulong chunk; /* current write chunk */ 31 : ulong chunk0; /* first chunk */ 32 : ulong wmark; /* wrap watermark */ 33 : ulong mtu; /* link mtu (== max_event_sz) */ 34 : }; 35 : 36 : typedef struct fd_event_reporter fd_event_reporter_t; 37 : 38 : /* The thread-local reporter for the currently running tile, or NULL if the 39 : tile has no event link. */ 40 : 41 : extern FD_TL fd_event_reporter_t * fd_event_tl; 42 : 43 : FD_PROTOTYPES_BEGIN 44 : 45 : /* fd_event_register sets up fd_event_tl for the calling tile. If the tile 46 : has an event link (tile->event_link_id != ULONG_MAX) it joins the link's 47 : mcache/dcache; otherwise fd_event_tl is left NULL and reporting is a 48 : no-op. Must be called once, after the tile's tango objects are joined 49 : (i.e. after fd_topo_fill_tile), before the run loop. */ 50 : 51 : void 52 : fd_event_register( fd_topo_t const * topo, 53 : fd_topo_tile_t const * tile ); 54 : 55 : /* fd_event_report_ publishes a single event of sz bytes (the serialized 56 : fd_event_<name>_t struct) to the event link. type is the event schema 57 : id, carried in the frag sig so the event tile can dispatch. No-op when 58 : fd_event_tl is NULL. The generated fd_event_report_<name>() macros call 59 : this with the right type and sizeof. */ 60 : 61 : static inline void 62 : fd_event_report_( ulong type, 63 : void const * event, 64 0 : ulong sz ) { 65 0 : fd_event_reporter_t * r = fd_event_tl; 66 0 : if( FD_UNLIKELY( !r ) ) return; /* no event link / telemetry off */ 67 : 68 0 : FD_TEST( sz<=r->mtu ); 69 : 70 0 : ulong tspub = fd_frag_meta_ts_comp( fd_tickcount() ); 71 : 72 0 : fd_memcpy( fd_chunk_to_laddr( r->mem, r->chunk ), event, sz ); 73 0 : fd_mcache_publish( r->mcache, r->depth, r->seq, type, r->chunk, sz, 0UL, 0UL, tspub ); 74 0 : r->seq = fd_seq_inc( r->seq, 1UL ); 75 0 : r->chunk = fd_dcache_compact_next( r->chunk, sz, r->chunk0, r->wmark ); 76 0 : } 77 : 78 : FD_PROTOTYPES_END 79 : 80 : #endif /* HEADER_fd_src_disco_events_fd_event_report_h */