libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_runtime.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * Use of this source code is governed by the ISC License.
4 *
5 * src/inc/xtc_runtime.h
6 * Process-level runtime introspection -- one call that reports
7 * what this process was given: how many event loops it runs, the
8 * CPU topology it sees, and any configured memory budget. Where
9 * xtc_inspect.h (xtc_inspect_loops / xtc_inspect_procs) gives the
10 * live per-loop / per-proc detail, this is the single aggregate a
11 * libxtc application reads once at startup to size itself to the
12 * box: buffer-pool bytes, worker counts, morsel granularity.
13 *
14 * The aim is that an application never has to reach into the
15 * internal __os_* topology surface (os_cpu.h) or stitch together
16 * xtc_exec_n_loops + xtc_app_exec by hand; xtc_runtime_info()
17 * collects it all into one struct.
18 */
19
20#ifndef XTC_RUNTIME_H
21#define XTC_RUNTIME_H
22
23#include "xtc_export.h"
24
25#include <stdint.h>
26
27#include "xtc.h"
28
29/*
30 * A one-shot snapshot of the process runtime environment.
31 *
32 * The CPU and NUMA fields are queried from the OS at call time
33 * (they do not change over the life of the process on any supported
34 * platform). n_loops reflects the executor the CALLER is running on
35 * (see below). The memory fields report a configured cap and the
36 * bytes currently charged against it, if such accounting is in force.
37 */
38typedef struct xtc_runtime_info {
39 int n_loops; /* event loops in the running app/exec, or 1 standalone */
40 int n_cpus_online; /* __os_ncpus() */
41 int n_cpus_perf; /* __os_ncpus_perf() -- performance cores */
42 int n_cpus_effic; /* __os_ncpus_effic() -- efficiency cores */
43 int numa_nodes; /* __os_numa_nnodes() */
44 int64_t mem_cap_bytes; /* configured memory cap, or 0 if none/unknown */
45 int64_t mem_used_bytes; /* currently accounted memory in use, or 0 */
47
48/*
49 * PUBLIC: int xtc_runtime_info __P((xtc_runtime_info_t *));
50 */
51
52/*
53 * Fill *out with a snapshot of the runtime environment. Returns
54 * XTC_OK on success, or XTC_E_INVAL if `out` is NULL.
55 *
56 * Field semantics:
57 *
58 * n_loops
59 * The number of event loops in the executor the CALLER runs on.
60 * When called from a fiber/task on a loop owned by a multi-loop
61 * executor (xtc_exec / a multi-loop xtc_app), this is that
62 * executor's loop count. On a standalone loop it is 1. When
63 * called from a thread that is NOT on any loop (e.g. before the
64 * executor starts, or from a plain helper thread), there is no
65 * thread-local "current executor" to consult, so it defaults to
66 * 1. LIMITATION: libxtc keeps no process-global registry of the
67 * current app/exec, only a thread-local current-loop; to read the
68 * true loop count from off-loop, hold the exec handle and call
69 * xtc_exec_n_loops(xtc_app_exec(app)) directly.
70 *
71 * n_cpus_online / n_cpus_perf / n_cpus_effic / numa_nodes
72 * The OS-reported CPU topology (online logical CPUs, performance
73 * cores, efficiency cores, NUMA nodes). On platforms or
74 * hardware without a perf/effic split, all online CPUs count as
75 * performance cores and n_cpus_effic is 0. numa_nodes is at
76 * least 1.
77 *
78 * mem_cap_bytes / mem_used_bytes
79 * A configured memory budget and the bytes charged against it.
80 * LIMITATION: libxtc's memory accounting (xtc_res, XTC_RES_MEM_BYTES)
81 * is an opt-in, caller-owned facility -- there is no process-global
82 * or default resource accountant reachable from here, and these
83 * fields are NOT the OS-reported RSS. Both are therefore reported
84 * as 0 ("no cap / unknown"); an application that wants its own
85 * quota reflected should read its xtc_res_t directly with
86 * xtc_res_used(r, XTC_RES_MEM_BYTES) against r->caps.mem_bytes.
87 */
88XTC_API int xtc_runtime_info(xtc_runtime_info_t *out);
89
90#endif /* XTC_RUNTIME_H */