eb-local.cpumask

module eb-local.cpumask  src/cpumask.zig[source][autodoc]

eb-local --cpu-target: build for another CPU target on this machine.

The target is an EESSI software subdirectory. A build for it runs in one of four routes: native (the host already is the target), cpuid (the host CPU shows the target’s identity to every child process: CPUID faulting on x86_64, a masked getauxval and /proc/cpuinfo on aarch64), kvm and tcg (a virtual machine, run by eb-local __vm-run). This file holds the target and profile data, the route choice, the preflight decision, the files of the cpuid route and the provenance record. The process handling stays in main.zig.

Types

pub const Arch = enum[source][autodoc]

The architectures a CPU target can have.

x86_64[source]
aarch64[source]
pub fn host() ?Arch[source][autodoc]

The architecture this program runs on, null when it has no profile.

pub const Resolved = union(enum)[source][autodoc]

What a --cpu-target word names.

subdir: []const u8[source]
refused: []const u8[source]

A message for the user.

pub const Profile = struct[source][autodoc]

One target’s identity, as profiles.conf records it.

subdir: []const u8[source]
arch: Arch[source]
vendor: []const u8 = ""[source]
family: u32 = 0[source]
model: u32 = 0[source]
model_name: []const u8 = ""[source]
gcc_march: []const u8 = ""[source]
host_vendors: []const []const u8 = &.{}[source]
needs: []const []const u8 = &.{}[source]
drop_flags: []const []const u8 = &.{}[source]
rules: []const []const u8 = &.{}[source]
cpu_part: []const u8 = ""[source]
gcc_cpu: []const u8 = ""[source]
features: []const []const u8 = &.{}[source]
hwcap: []const u8 = "0x0"[source]
hwcap2: []const u8 = "0x0"[source]
pub const Mode = enum[source][autodoc]

What --mask asks for.

auto[source]
cpuid[source]
kvm[source]
tcg[source]
pub const Route = enum[source][autodoc]

How the build runs.

native[source]
cpuid[source]
kvm[source]
tcg[source]
pub const Host = struct[source][autodoc]

What the choice of a route needs to know about this machine.

arch: Arch[source]
vendor: []const u8 = ""[source]

vendor_id of an x86_64 CPU, empty on aarch64.

flags: []const u8 = ""[source]

The flags (x86_64) or Features (aarch64) line of /proc/cpuinfo.

subdir: ?[]const u8 = null[source]

The EESSI subdirectory of this host, when it could be detected.

faulting: bool = false[source]

CPUID faulting works (x86_64).

kvm: bool = false[source]

/dev/kvm is usable.

vm_helper: bool = false[source]

eb-local __vm-run exists in this binary.

pub const Choice = union(enum)[source][autodoc]

The outcome of the route choice.

route: Route[source]
refuse: []const u8[source]

The message for the user.

pub const Observed = struct[source][autodoc]

What the build script saw inside the mask. A null field was not observable: the tool is missing.

devfd: bool[source]
archdetect: ?[]const u8 = null[source]

The output of eessi_archdetect.sh cpupath: subdirectories separated by ‘:’.

archspec: ?[]const u8 = null[source]

What archspec names the host, null when it cannot be imported.

gcc: ?[]const u8 = null[source]

The -march (x86_64) or -mcpu (aarch64) value of gcc -march=native.

vendor: ?[]const u8 = null[source]

The CPUID vendor string of a probe run in the mask.

faulting: ?bool = null[source]

Whether CPUID faulting is active in the probe.

archspec_allowed: bool = false[source]

--mask-allow-archspec-mismatch: an archspec name other than the target’s is noted, not refused.

pub const Finding = struct[source][autodoc]

One preflight check and what it found.

ok: bool[source]
text: []const u8[source]
pub const Libs = struct[source][autodoc]

The compiled preload library and probe.

preload: []const u8[source]

The preload library for the host architecture.

probe: []const u8[source]
dir: []const u8[source]
pub const Provenance = struct[source][autodoc]

What easybuild/eb-local-build-mode.json records.

target: []const u8[source]
route: Route[source]
profile: []const u8[source]

The profile’s subdirectory, empty for a route without one.

host_cpu: []const u8[source]
kernel: []const u8[source]
version: []const u8[source]
audit: []const u8[source]

“pass”, “fail” or “skipped”.

Functions

pub fn resolveTarget(a: Allocator, text: []const u8) Resolved[source][autodoc]

The subdirectory text names: a full subdirectory, or a short name that one known subdirectory ends in.

pub fn archOf(subdir: []const u8) ?Arch[source][autodoc]

The architecture a subdirectory is for.

pub fn parseProfiles(a: Allocator, text: []const u8) []Profile[source][autodoc]

The profiles in text, in file order.

pub fn builtinProfiles(a: Allocator) []Profile[source][autodoc]

The profiles that ship with eb-local.

pub fn findProfile(profiles: []const Profile, subdir: []const u8) ?Profile[source][autodoc]

The profile for subdir, or null.

pub fn rulesFile(a: Allocator, p: Profile) []const u8[source][autodoc]

The rule lines of p as cpuidmask reads them from CPUIDMASK_RULES.

pub fn maskedCpuinfo(a: Allocator, p: Profile, host: []const u8) []const u8[source][autodoc]

host, the text of /proc/cpuinfo, as it reads on the target: the identity fields of p, and without the flags p drops. Lines that name nothing the profile changes stay as they are.

pub fn cpuidProblem(a: Allocator, target: []const u8, profile: ?Profile, host: Host) ?[]const u8[source][autodoc]

Why the cpuid route cannot present target on host, or null when it can.

pub fn choose(a: Allocator, mode: Mode, target: []const u8, profile: ?Profile, host: Host) Choice[source][autodoc]

The route for target. The target the host already is needs no mask.

pub fn preflight(a: Allocator, p: Profile, route: Route, obs: Observed) []const Finding[source][autodoc]

Compare what the detectors report with p. Every detector must name the target; a build that goes on with one that does not would install a tree labelled for one CPU and compiled for another.

pub fn refused(findings: []const Finding) bool[source][autodoc]

Whether any finding refuses the build.

pub fn cpuinfoField(text: []const u8, key: []const u8) ?[]const u8[source][autodoc]

The first value of key in /proc/cpuinfo text.

pub fn faultingAvailable() bool[source][autodoc]

Whether the kernel lets this process turn on CPUID faulting.

pub fn kvmUsable() bool[source][autodoc]

Whether /dev/kvm can be opened for reading and writing.

pub fn readFile(a: Allocator, path: []const u8, limit: usize) ?[]const u8[source][autodoc]

The first limit bytes of the regular file path, or null.

pub fn readHost(a: Allocator, subdir: ?[]const u8, vm_helper: bool) ?Host[source][autodoc]

This machine as the route choice sees it. subdir is the detected EESSI subdirectory of the host, vm_helper whether __vm-run exists.

pub fn hostModel(a: Allocator) []const u8[source][autodoc]

A one-line name of the host CPU, for the provenance record.

pub fn kernelRelease(a: Allocator) []const u8[source][autodoc]

The running kernel’s release, from /proc/sys/kernel/osrelease.

pub fn cacheKey(a: Allocator, triple: []const u8, libc: []const u8) []const u8[source][autodoc]

The cache key of the compiled libraries: the sources, the compiler’s target triple and the C library’s version. A library built against one glibc does not load into every other.

pub fn ensureLibs(a: Allocator, envp: proc.Envp, path_env: []const u8, cache_home: []const u8, failure: *[]const u8) ?Libs[source][autodoc]

The preload library and probe for this host, compiled with the host’s cc into cache_home/eb-local/mask-KEY on first use. A static binary cannot be preloaded into the dynamically linked programs of a build, so the library is built from the C source embedded here.

pub fn namespaceWords(a: Allocator, unshare: []const u8, setpriv: ?[]const u8, fake: []const u8) []const []const u8[source][autodoc]

The words in front of the build command for the cpuid route: an unprivileged user and mount namespace that keeps the caller’s uid (a mapped root makes OpenMPI’s prterun refuse to start), with fake bound over /proc/cpuinfo. The ambient capabilities the namespace gives are dropped before the command runs when setpriv exists.

pub fn maskVariables(a: Allocator, p: Profile, libs: Libs, rules_path: []const u8, hooks_path: []const u8, self_exe: []const u8, route: Route, allow_archspec: bool) []const [2][]const u8[source][autodoc]

The variables the masked command gets.

pub fn provenanceJson(a: Allocator, p: Provenance) []const u8[source][autodoc]

The text of easybuild/eb-local-build-mode.json.

pub fn writeProvenance(a: Allocator, dir: []const u8, text: []const u8) bool[source][autodoc]

Write text as dir/name, replacing what is there.

pub fn writeFile(a: Allocator, path: []const u8, bytes: []const u8, mode: linux.mode_t) bool[source][autodoc]

Write bytes to path with mode, replacing what is there.

Constants

pub const hooks_py = @embedFile("mask_hooks_py")[source][autodoc]

EasyBuild hooks that chain the site’s and pin the GROMACS SIMD level.

pub const strict_exit: u8 = 97[source][autodoc]

The exit status of a process that cpuidmask stopped because the kernel has no CPUID faulting and CPUIDMASK_STRICT is set.

pub const known_subdirs = ...[source][autodoc]

The EESSI subdirectories eb-local knows by name. A short name resolves when it is the last component of exactly one of them.