These patches fix platform-specific issues when running J on FreeBSD. While J officially supports FreeBSD, some functionality requires adjustments for proper operation on this platform.
Patch: libblis-build.patch
Changes the BLAS library J links against on FreeBSD from OpenBLAS to BLIS (BLAS-like Library Instantiation Software).
FreeBSD’s pkg system provides BLIS as a readily
available, well-optimized BLAS implementation. While OpenBLAS is also
available, it fails to build correctly on modern FreeBSD.
The change modifies jsrc/cblas.c to use
libblis.so instead of libopenblas.so.0:
// Before:
#elif defined(__FreeBSD__)
#define LIBCBLASNAME "libopenblas.so.0"
// After:
#elif defined(__FreeBSD__)
#define LIBCBLASNAME "libblis.so"J dynamically loads the BLAS library at runtime for matrix operations. This change simply updates the library name that J searches for.
Install BLIS on FreeBSD:
pkg install bliscd /path/to/jsource
git apply libblis-build.patchPatch: delay-cpu-fix.patch
Fixes the 6!:3 (delay) foreign function to properly
sleep without consuming 100% CPU on FreeBSD.
Before this patch, executing a delay in J would consume an entire CPU core:
6!:3 (5) NB. Sleep for 5 seconds - was using 100% CPU!This occurred because the futex-based sleep implementation had two bugs:
waitval|1 instead of waitval, causing the wait
to return immediatelyThe fix modifies jsrc/mt.c in the jtjsleep
function:
// Bug 1 - Wrong comparison value:
// Before:
I i=jfutex_waitn(&ftx,waitval|1,MIN(ns,1000000000));
// After:
I i=jfutex_waitn(&ftx,waitval,MIN(ns,1000000000));
// Bug 2 - Premature exit on timeout:
// Before:
if(i==-1){r=0;break;} //timed out
// After:
if(i==-1){goto retime;} //timed out - recalculate remaining time and continueJ’s delay function uses a futex (fast userspace mutex) for efficient sleeping:
This design allows delays to be interruptible (you can press Ctrl+C) while still being efficient.
| Metric | Before | After |
|---|---|---|
CPU usage during 6!:3 (1) |
~100% | <1% |
| Delay accuracy | Correct | Correct |
| Interruptibility | Yes | Yes |
cd /path/to/jsource
git apply delay-cpu-fix.patchTo apply both FreeBSD patches at once:
cd /path/to/jsource
git am /path/to/freebsd-platform/*/*.patchOr apply them individually in any order (they are independent).