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