| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #ifndef STL_ACCEL_H
- #define STL_ACCEL_H
- #include <stddef.h>
- #include <stdint.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /* =========================================================================
- * 1. ISA Tiers & Runtime CPUID / XGETBV Dispatch
- * ========================================================================= */
- #define STL_ISA_SSE2 0
- #define STL_ISA_SSE42_POPCNT 1
- #define STL_ISA_AVX2_BMI 2
- int stl_cpu_tier_detect(void);
- int stl_active_isa_tier(void);
- void stl_force_isa_tier(int tier); /* -1 restores auto-detected tier */
- const char *stl_isa_tier_name(int tier);
- /* Assembly entry points (scan_asm.S) */
- uint64_t asm_xgetbv_eax0(void);
- size_t asm_base64_encode_sse2(const uint8_t *src, size_t len, uint8_t *dst);
- size_t asm_base64_encode_avx2(const uint8_t *src, size_t len, uint8_t *dst);
- /* Dispatched Base64 encoder */
- size_t stl_base64_encode(const uint8_t *src, size_t len, uint8_t *dst);
- /* =========================================================================
- * 2. Single-Pass Zero-Allocation Serial Clean + UEFI Fold + Split + Classify
- * ========================================================================= */
- #define STL_TAG_BRACKET (1u << 0) /* '[' banner / stage / tag */
- #define STL_TAG_PROMPT (1u << 1) /* '>' or '#' prompt candidate */
- #define STL_TAG_ERR_HINT (1u << 2) /* 'E','F','W','U' error/warning hint */
- #define STL_TAG_DIGIT (1u << 3) /* '0'..'9' numeric / coord / progress */
- #define STL_TAG_COLON_EQ (1u << 4) /* ':' or '=' key-value / table row */
- #define STL_HALF_LINE_CAP 1024
- typedef struct {
- uint32_t offset;
- uint32_t len;
- uint32_t tag_mask;
- uint8_t first_nonws;
- uint8_t term_kind; /* 1=LF, 2=CR, 4=ROW_JUMP, 5=WRAP */
- uint16_t reserved;
- } StlCleanLineSpan;
- typedef struct {
- uint32_t esc_state;
- uint32_t csi_p1;
- uint32_t csi_p2;
- uint32_t csi_param_idx;
- uint32_t cur_row;
- uint32_t cur_col;
- uint32_t prev_was_cr;
- uint32_t half_len;
- uint32_t tag_mask;
- uint8_t first_nonws;
- uint8_t csi_priv;
- uint16_t pad0;
- uint8_t half_buf[STL_HALF_LINE_CAP];
- } StlCleanStreamState;
- typedef struct {
- uint8_t *clean_buf;
- size_t clean_cap;
- size_t clean_written;
- StlCleanLineSpan *spans;
- size_t spans_cap;
- size_t spans_count;
- size_t src_consumed;
- } StlCleanOutput;
- _Static_assert(sizeof(StlCleanLineSpan) == 16, "StlCleanLineSpan must be 16 bytes");
- _Static_assert(offsetof(StlCleanStreamState, half_buf) == 40, "half_buf must be at offset 40");
- _Static_assert(sizeof(StlCleanOutput) == 56, "StlCleanOutput must be 56 bytes");
- void asm_clean_split_classify_sse2(
- StlCleanStreamState *state, const uint8_t *src, size_t src_len, StlCleanOutput *out);
- void asm_clean_split_classify_sse42(
- StlCleanStreamState *state, const uint8_t *src, size_t src_len, StlCleanOutput *out);
- void asm_clean_split_classify_avx2(
- StlCleanStreamState *state, const uint8_t *src, size_t src_len, StlCleanOutput *out);
- void stl_clean_stream_init(StlCleanStreamState *state);
- void stl_clean_stream_clear_halfline(StlCleanStreamState *state);
- void stl_clean_split_classify(
- StlCleanStreamState *state, const uint8_t *src, size_t src_len, StlCleanOutput *out);
- /* =========================================================================
- * 3. Monotonic 64-Bit mmap Ring Buffer (Hugepage + 64B Tail Pad + Guard Page)
- * ========================================================================= */
- typedef struct {
- uint8_t *buf; /* mmap base: [0..cap) ring, [cap..cap+64) zero pad, then PROT_NONE */
- size_t cap; /* power-of-two capacity (default 8 MiB) */
- size_t mask; /* cap - 1 */
- size_t mmap_total; /* total mmap length including guard page */
- uint64_t base_offset; /* oldest retained absolute byte offset (monotonic, never decreases) */
- uint64_t write_offset; /* next write absolute byte offset (monotonic, never decreases) */
- } StlRingBuf;
- int stl_ring_init(StlRingBuf *rb, size_t requested_cap);
- void stl_ring_destroy(StlRingBuf *rb);
- uint64_t stl_ring_append(StlRingBuf *rb, const uint8_t *data, size_t len);
- size_t stl_ring_read(
- const StlRingBuf *rb,
- uint64_t req_offset,
- uint8_t *dst,
- size_t max_len,
- uint64_t *out_actual_start,
- uint64_t *out_next_offset);
- void stl_ring_clear_monotonic(StlRingBuf *rb);
- /* =========================================================================
- * 4. Deterministic re2c Line Lexer (parser_re2c.re -> parser_re2c.c)
- * ========================================================================= */
- typedef enum {
- STL_LK_NONE = 0,
- STL_LK_ICT_BANNER_HOVSEE = 1,
- STL_LK_ICT_BANNER_CXMT = 2,
- STL_LK_ICT_START_STAGE1 = 3,
- STL_LK_ICT_START_STAGE2 = 4,
- STL_LK_ICT_ENTER_HINT = 5,
- STL_LK_ICT_PROMPT = 6,
- STL_LK_ICT_EXIT = 7,
- STL_LK_MRC_START = 8,
- STL_LK_MRC_DONE = 9,
- STL_LK_DIMM_INVENTORY = 10,
- STL_LK_RMT_START = 11,
- STL_LK_RMT_ROW = 12,
- STL_LK_RMT_STOP = 13,
- STL_LK_TRAINING_ERROR = 14,
- STL_LK_AMT_BANNER = 15,
- STL_LK_AMT_PROMPT = 16,
- STL_LK_AMT_PROGRESS = 17,
- STL_LK_AMT_SUMMARY = 18,
- STL_LK_AMT_ERROR = 19,
- STL_LK_UEFI_BANNER = 20,
- STL_LK_UEFI_PROMPT_ROOT = 21,
- STL_LK_UEFI_PROMPT_EFI = 22,
- STL_LK_PXE_BOOT = 23,
- STL_LK_MT_BANNER = 24,
- STL_LK_MT_PROGRESS = 25,
- STL_LK_MT_ERROR = 26,
- STL_LK_MT_PASS_COMPLETE = 27,
- STL_LK_MT_FAIL_COMPLETE = 28,
- STL_LK_INLINE_TEMP = 29,
- STL_LK_BIOS_BOOT = 30
- } StlLineKind;
- typedef struct {
- uint32_t kind; /* StlLineKind */
- uint8_t fw_family; /* 0=unknown, 1=Hovsee/GNR-4.3.3(24-algo), 2=CxmtDdrTest/GNR-4.3.0(19-algo) */
- int8_t cpu; /* -1 if unspecified, 0 or 1 */
- int8_t channel; /* -1 if unspecified, 0..11 */
- int8_t dimm; /* -1 if unspecified, 0..1 */
- int8_t rank; /* -1 if unspecified, 0..3 */
- int8_t bank; /* -1 if unspecified, validated 0..31 (never >= 32!) */
- int8_t subkind; /* 0=normal, 1=pass, 2=fail, 3=disabled, 4=present, 5=coord_cont */
- uint8_t fs_index; /* 0..9 for FSx:\ prompt */
- int32_t val0; /* algo_id / progress_pct / margin_rx_lo / error_cnt */
- int32_t val1; /* loop_or_total / margin_rx_hi */
- int32_t val2; /* step / margin_tx_lo */
- int32_t val3; /* margin_tx_hi / temp_c_x10 */
- uint64_t addr; /* parsed hex address if present */
- } StlRe2cEvent;
- _Static_assert(sizeof(StlRe2cEvent) == 40, "StlRe2cEvent must be 40 bytes");
- void stl_re2c_parse_line(const uint8_t *line, size_t len, uint32_t tag_mask, StlRe2cEvent *ev);
- int stl_re2c_detect_halfline_prompt(const uint8_t *buf, size_t len, StlRe2cEvent *ev);
- /* =========================================================================
- * 5. Linux epoll / timerfd / eventfd / Non-Blocking Serial & Socket Helpers
- * ========================================================================= */
- int stl_epoll_create(void);
- int stl_epoll_ctl_fd(int epfd, int op, int fd, uint32_t events, uint64_t token);
- int stl_epoll_wait_tokens(
- int epfd, uint64_t *out_tokens, uint32_t *out_events, int max_ev, int timeout_ms);
- int stl_timerfd_create_ms(uint64_t initial_ms, uint64_t interval_ms);
- int stl_timerfd_arm_ms(int tfd, uint64_t initial_ms, uint64_t interval_ms);
- void stl_timerfd_drain(int tfd);
- int stl_eventfd_create(void);
- void stl_eventfd_notify(int efd);
- void stl_eventfd_drain(int efd);
- int stl_set_nonblocking_nodelay(int fd, int is_tcp);
- int stl_open_tty_115200_raw(const char *path);
- int64_t stl_ws_writev2(int fd, const uint8_t *hdr, size_t hdr_len, const uint8_t *body, size_t body_len);
- void stl_pin_thread_to_core(int core_index);
- /* =========================================================================
- * 6. OpenCL Gen7.5-Gen9.5 Zero-Copy Batch Offload (Auto CPU Fallback)
- * ========================================================================= */
- typedef struct {
- int available; /* 1 if Intel/OpenCL iGPU initialized */
- int zero_copy_llc; /* 1 if unified memory CL_MEM_USE_HOST_PTR supported */
- uint32_t compute_units;
- uint64_t break_even_bytes; /* S* threshold (default 262144 = 256 KiB) */
- char device_name[96];
- } StlOpenClInfo;
- void stl_opencl_query_info(StlOpenClInfo *out_info);
- int stl_opencl_has_tdp_headroom(void);
- /* Batch historical log newline/error-marker pre-index; auto-falls back to CPU SIMD below S* or low TDP */
- size_t stl_batch_rescan_logs(
- const uint8_t *buf_4k_aligned,
- size_t len,
- uint32_t *out_line_offsets,
- uint8_t *out_line_tags,
- size_t max_lines,
- int *used_gpu);
- /* Multi-station RMT margin matrix min/max/mean & 16x16 eye-diagram bilinear interpolation */
- int stl_batch_rmt_eye_reduce(
- const float *margins_in, /* [station_count * 24 * 4] (rx_lo, rx_hi, tx_lo, tx_hi) */
- size_t station_count,
- float *eye_grid_out, /* [station_count * 24 * 256] (16x16 normalized eye surface) */
- float *summary_out, /* [station_count * 4] (min_timing, min_vref, mean_timing, mean_vref) */
- int *used_gpu);
- #ifdef __cplusplus
- }
- #endif
- #endif /* STL_ACCEL_H */
|