mirror of
https://github.com/luxfi/zap.git
synced 2026-10-30 15:04:16 +00:00
Three orthogonal additions, one wire format. v2 package — generic ad-hoc schema dispatch (~/work/lux/zap/v2): - README + IMPOSSIBILITY + BENCH_RESULTS document the v1↔v2 split. - builder/field/iter/list/pool/registry/schema/view + codegen package emit v1-equivalent fast paths from declarative .zap sources. - _compile_fail_test/ + examples/ cover negative and positive cases. - v2_test.go exercises the generic dispatch path. - doc.go in v1 marks v1 deprecated for *new* schema authoring; existing v1 buffers stay parseable by both v1 and v2. bufpool — pooled read slabs (bufpool.go + bufpool_test.go): - Message gains optional *bufRef; Release() returns the slab to its pool when sourced from the pooled read path, GC-managed otherwise. - ParseHeader returns (data, rootOffset) without allocating *Message, used by zapv2 to avoid two allocations per parse. - bench_read_test.go + node_quic_stream_test.go cover both paths. Transport allocator + UMA/RDMA cgo (transport/*): - Transport.Caps()/Buffer interface: capability + slab-typed buffer contract. Bytes() vs DevicePtr() decoupled so UMA and GPUDirect can share the same call surface. - DPDK PMD + GPUDirect RDMA + CUDA UMA real cgo backends gated behind build tags; stub paths remain default on darwin / non-Linux. - transport_test.go covers Caps reporting + Buffer lifecycle on the default transport. LLM.md + go.mod follow the additions.
75 lines
2.5 KiB
C
75 lines
2.5 KiB
C
// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
//
|
|
//go:build cgo && linux && dpdk
|
|
//
|
|
// DPDK PMD-backed transport, host-side glue. Linked into the luxfi/zap
|
|
// binary only when the cgo + linux + dpdk build tags are set; see
|
|
// dpdk_linux_real.go for the Go cgo bridge.
|
|
//
|
|
// We deliberately keep this file pure C and avoid heavy DPDK headers
|
|
// outside the dpdk build tag. The build tag pulls in <rte_eal.h> via
|
|
// the per-tag flag-only file in dpdk_pmd_eal.c.
|
|
|
|
#include "dpdk_pmd.h"
|
|
|
|
#include <dirent.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
|
|
// hugepages_configured returns 1 when /sys/kernel/mm/hugepages reports
|
|
// at least one configured size with nr_hugepages > 0. We don't insist
|
|
// on a specific size — DPDK's mempool driver picks at init.
|
|
static int hugepages_configured(void) {
|
|
DIR* d = opendir("/sys/kernel/mm/hugepages");
|
|
if (!d) return 0;
|
|
int ok = 0;
|
|
struct dirent* e;
|
|
while ((e = readdir(d)) != NULL) {
|
|
if (strncmp(e->d_name, "hugepages-", 10) != 0) continue;
|
|
char path[512];
|
|
snprintf(path, sizeof(path),
|
|
"/sys/kernel/mm/hugepages/%s/nr_hugepages", e->d_name);
|
|
FILE* f = fopen(path, "r");
|
|
if (!f) continue;
|
|
unsigned long n = 0;
|
|
if (fscanf(f, "%lu", &n) == 1 && n > 0) {
|
|
ok = 1;
|
|
}
|
|
fclose(f);
|
|
if (ok) break;
|
|
}
|
|
closedir(d);
|
|
return ok;
|
|
}
|
|
|
|
// luxzap_dpdk_init / shutdown are defined in dpdk_pmd_eal.c which is
|
|
// compiled only when the dpdk build tag is set. To keep this file
|
|
// always-compilable (so static analysis sees a definition) we provide
|
|
// weak fall-back stubs that return EOPNOTSUPP. The link order ensures
|
|
// the real symbols win when present.
|
|
|
|
int __attribute__((weak)) luxzap_dpdk_init(int argc, char** argv) {
|
|
(void)argc;
|
|
(void)argv;
|
|
return EOPNOTSUPP;
|
|
}
|
|
|
|
int __attribute__((weak)) luxzap_dpdk_shutdown(void) { return EOPNOTSUPP; }
|
|
|
|
int luxzap_dpdk_probe(void) {
|
|
if (!hugepages_configured()) return 1;
|
|
// We cannot tell at runtime whether librte_eal is present without
|
|
// either dlopen'ing it or attempting rte_eal_init. The build-tag
|
|
// separation in dpdk_pmd_eal.c handles that: if the dpdk tag is
|
|
// set, that file's strong symbols replace the weak stubs here, and
|
|
// a one-shot probe-init returns 0 or the rte_errno.
|
|
int rc = luxzap_dpdk_init(0, NULL);
|
|
if (rc == EOPNOTSUPP) return 2;
|
|
if (rc != 0) return 3;
|
|
// Successful probe-init — leave EAL up for the live transport.
|
|
return 0;
|
|
}
|