#ifndef STL_ACCEL_H #define STL_ACCEL_H #include #include #include #ifdef __cplusplus extern "C" { #endif /* ========================================================================= * 1. 6-Tier ISA Runtime CPUID / XGETBV Dispatch * Tier 0: SSE2 baseline (2003+ x86-64) * Tier 1: SSSE3 (2012 Atom: PSHUFB Base64 / Hex) * Tier 2: SSE4.2 + POPCNT + PCLMULQDQ (Celeron J1800/J1900/N2830 / Pentium N3540) * Tier 3: Goldmont+ SHA-NI + AES-NI + PCLMULQDQ (Celeron J4125/J3455 / Pentium J5005) * Tier 4: AVX2 + BMI1/2 + PCLMULQDQ [+ SHA-NI/VPCLMULQDQ/GFNI] (Intel N100/N95/N200 & Core) * Tier 5: AVX-512F + BW + VL (Xeon / Core AVX-512) * ========================================================================= */ #define STL_ISA_SSE2 0 #define STL_ISA_SSSE3 1 #define STL_ISA_SSE42_PCLMUL 2 #define STL_ISA_GOLDMONT_SHA 3 #define STL_ISA_AVX2_BMI 4 #define STL_ISA_AVX512 5 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); /* Multi-tier SIMD kernels (simd_kernels.c) */ void *stl_aligned_buf_alloc(size_t size, size_t *out_aligned_cap); void stl_aligned_buf_free(void *ptr); uint64_t simd_mem_diff_64b_sse2(const uint8_t *a, const uint8_t *b, size_t len); uint64_t simd_mem_diff_64b_sse42(const uint8_t *a, const uint8_t *b, size_t len); uint64_t simd_mem_diff_64b_avx2(const uint8_t *a, const uint8_t *b, size_t len); uint64_t simd_mem_diff_64b_avx512(const uint8_t *a, const uint8_t *b, size_t len); size_t simd_hex_encode_sse2(const uint8_t *src, size_t len, uint8_t *dst); size_t simd_hex_encode_ssse3(const uint8_t *src, size_t len, uint8_t *dst); size_t simd_hex_encode_avx2(const uint8_t *src, size_t len, uint8_t *dst); size_t simd_base64_encode_ssse3(const uint8_t *src, size_t len, uint8_t *dst); size_t simd_base64_encode_avx2(const uint8_t *src, size_t len, uint8_t *dst); uint32_t simd_crc32_ieee_slicing8(uint32_t init_crc, const uint8_t *buf, size_t len); uint32_t simd_crc32_ieee_pclmul(uint32_t init_crc, const uint8_t *buf, size_t len); uint32_t simd_crc32_ieee_vpclmul(uint32_t init_crc, const uint8_t *buf, size_t len); void simd_sha1_sw(const uint8_t *data, size_t len, uint8_t out20[20]); void simd_sha1_shani(const uint8_t *data, size_t len, uint8_t out20[20]); /* Dispatched multi-tier CPU entry points */ size_t stl_base64_encode(const uint8_t *src, size_t len, uint8_t *dst); size_t stl_hex_encode(const uint8_t *src, size_t len, uint8_t *dst); uint32_t stl_crc32_ieee(uint32_t init_crc, const uint8_t *buf, size_t len); void stl_sha1_bytes(const uint8_t *data, size_t len, uint8_t out20[20]); size_t stl_ws_accept_key(const uint8_t *key_ptr, size_t key_len, uint8_t out28[28]); /* ========================================================================= * 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); int c_pty_open_serial_115200(const char *path); int c_open_tty_baud_raw(const char *path, int baud); int c_open_mcu_tty_baud_raw(const char *path, int baud); int c_pty_open_tcp_serial(const char *host, int port, int timeout_ms); int c_pty_open_tcp_listen(int port); int c_pty_accept_tcp_nonblock(int listen_fd); int c_pty_spawn_ssh_console( const char *host, int port, const char *user, const char *password, const char *known_hosts_path, int *out_master_fd, int *out_child_pid); int c_pty_spawn_ipmi_sol( const char *host, const char *user, const char *password, int *out_master_fd, int *out_child_pid); ssize_t c_pty_read_nonblock(int master_fd, uint8_t *buf, size_t cap); ssize_t c_mcu_tty_read_nonblock(int fd, uint8_t *buf, size_t cap, int is_serial); ssize_t c_pty_write_bytes(int master_fd, const uint8_t *buf, size_t len); int c_pty_is_alive(int child_pid); void c_pty_close(int master_fd, int child_pid); /* In-process libssh exec + SFTP atomic file transfer */ int c_ssh_exec_capture( const char *host, int port, const char *user, const char *password, const char *cmd, char *out_buf, size_t out_cap, size_t *out_len, int timeout_ms); int c_ssh_sftp_put_file( const char *host, int port, const char *user, const char *password, const char *local_path, const char *remote_path, int timeout_ms); int c_ssh_sftp_get_file( const char *host, int port, const char *user, const char *password, const char *remote_path, const char *local_path, int timeout_ms); /* In-process libfreeipmi persistent session & telemetry */ int c_ipmi_open( const char *host, const char *user, const char *password, int cipher_suite, int timeout_ms); void c_ipmi_close(int handle); int c_ipmi_is_alive(int handle); int c_ipmi_chassis_status(int handle, int *out_power_on, char *out_buf, size_t out_cap); int c_ipmi_chassis_control(int handle, int op); int c_ipmi_warm_reset(int handle); int c_ipmi_raw( int handle, uint8_t net_fn, uint8_t cmd, const uint8_t *payload, size_t payload_len, uint8_t *out_buf, size_t out_cap, size_t *out_len); int c_ipmi_sdr_temp_list(int handle, char *out_buf, size_t out_cap, size_t *out_len); void c_ipmi_invalidate_sdr_cache(int handle); int c_ipmi_device_info( int handle, const char *kind, char *out_buf, size_t out_cap, size_t *out_len); /* ========================================================================= * 6. OpenCL Gen7.5/Gen9.5/Gen12 Zero-Copy Batch GPU 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; /* Calibrated S* threshold (default 524288 = 512 KiB) */ uint64_t gpu_offload_count; uint64_t cpu_fallback_count; uint32_t calibrated_gpu_us; uint32_t calibrated_cpu_us; 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); /* Batch large-buffer Hex encode (GPU >= S* on 4KB-aligned buffer, CPU multi-tier SIMD fallback) */ size_t stl_batch_hex_encode( const uint8_t *src_4k_aligned, size_t len, uint8_t *dst_4k_aligned, int *used_gpu); /* Batch parallel 64 KiB block IEEE CRC-32 (for 50 MiB rotated trace volumes; CPU PCLMULQDQ fallback) */ size_t stl_batch_chunk_crc32( const uint8_t *buf_4k_aligned, size_t len, size_t chunk_size, uint32_t *out_crcs, size_t max_chunks, 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); /* Filesystem free-space guard, idle priority, monotonic clock, SIMD diff, permission & UDP/NIC helpers */ int stl_free_disk_bytes(const char *path, uint64_t *out_avail_bytes); void stl_set_thread_idle_priority(void); int stl_chmod_0600(const char *path); uint64_t stl_mono_us(void); uint64_t stl_mem_diff_64b_mask(const uint8_t *a, const uint8_t *b, size_t len); void stl_batch_mem_diff_64b_masks( const uint8_t *prev_base, const uint8_t *cur_base, size_t stride, size_t item_len, size_t count, uint64_t *out_masks); typedef struct { char name[32]; uint32_t ip_be; uint32_t mask_be; uint32_t bcast_be; uint32_t ifindex; uint8_t mac[6]; uint8_t is_up; uint8_t is_loopback; } StlNetIface; int c_list_ipv4_ifaces(StlNetIface *out_list, int max_count); int c_udp_bind_dhcp_socket(const char *iface, int port, int reuse_port); ssize_t c_udp_recv_pktinfo( int fd, uint8_t *buf, size_t cap, uint32_t *out_peer_ip_be, uint16_t *out_peer_port, uint32_t *out_local_ip_be, uint32_t *out_ifindex); ssize_t c_udp_send_pktinfo( int fd, const uint8_t *buf, size_t len, uint32_t dst_ip_be, uint16_t dst_port, uint32_t src_ip_be, uint32_t ifindex); #ifdef __cplusplus } #endif #endif /* STL_ACCEL_H */