@roomi-fields/grillhouse 0.44.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +24 -0
- package/cadre/templates/projet/.claude/settings.json +5 -0
- package/cadre/templates/projet/CLAUDE.md +15 -2
- package/cadre/templates/projet/docs/agents/issue-tracker.md +1 -1
- package/charte.md +3 -2
- package/dist/temporal/circuit/client.d.ts +7 -0
- package/dist/temporal/circuit/client.js +12 -2
- package/dist/temporal/circuit/client.js.map +1 -1
- package/dist/temporal/commande.js +5 -1
- package/dist/temporal/commande.js.map +1 -1
- package/dist/temporal/installation.d.ts +21 -1
- package/dist/temporal/installation.js +103 -12
- package/dist/temporal/installation.js.map +1 -1
- package/dist/temporal/tickets/activites.js +3 -1
- package/dist/temporal/tickets/activites.js.map +1 -1
- package/docs/ARCHITECTURE.md +204 -68
- package/docs/INTERFACE.md +23 -15
- package/package.json +1 -1
- package/scripts/activites.mjs +59 -43
- package/scripts/aiguillage.mjs +1 -0
- package/scripts/attente-de-la-machine.mjs +312 -0
- package/scripts/avancement.mjs +38 -31
- package/scripts/bilan.mjs +30 -5
- package/scripts/circuit.mjs +10 -7
- package/scripts/codes-de-sortie.mjs +1 -1
- package/scripts/coeurs-dedies.mjs +427 -0
- package/scripts/composants-affectes.mjs +3 -1
- package/scripts/consommation-des-passes.mjs +382 -0
- package/scripts/consommation.mjs +45 -0
- package/scripts/copies-finies.mjs +2 -2
- package/scripts/depart-du-ticket.mjs +3 -1
- package/scripts/disque-des-copies.mjs +1 -1
- package/scripts/echantillonneur-de-la-passe.mjs +103 -0
- package/scripts/enveloppe/enveloppe.mjs +1 -11
- package/scripts/enveloppe/travail-de-la-copie.mjs +3 -2
- package/scripts/grillhouse-maj.mjs +8 -4
- package/scripts/integration/file.mjs +10 -4
- package/scripts/jointure.d.ts +20 -9
- package/scripts/langages/cargo/commandes.mjs +8 -8
- package/scripts/langages/python/commandes.mjs +7 -6
- package/scripts/langages/typescript/tests-de-nuit.mjs +17 -4
- package/scripts/langages/typescript/tests.mjs +15 -6
- package/scripts/langages/typescript/verifier.mjs +23 -17
- package/scripts/langages/typescript/vitest-config/base.mjs +3 -3
- package/scripts/langages/typescript/vitest-config/machine.setup.mjs +7 -7
- package/scripts/mesure/base-de-passe.mjs +1 -1
- package/scripts/migrations/0.44.0-seuil-des-codes-de-tickets.mjs +47 -0
- package/scripts/migrations.mjs +2 -0
- package/scripts/passe-de-la-machine.mjs +456 -31
- package/scripts/places-de-la-machine.mjs +508 -61
- package/scripts/plafond-de-la-machine.d.mts +47 -2
- package/scripts/plafond-de-la-machine.mjs +197 -5
- package/scripts/preparation.mjs +1 -0
- package/scripts/regles-des-places.d.mts +40 -0
- package/scripts/regles-des-places.mjs +91 -0
- package/scripts/retirer-les-copies-finies.mjs +1 -1
- package/scripts/seances.mjs +4 -3
- package/scripts/services-du-noyau.mjs +3 -3
- package/scripts/sous-commandes.mjs +6 -7
- package/scripts/tableau.mjs +121 -112
- package/scripts/verrou-de-machine.mjs +0 -829
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
// The dedicated cores of a measure of time: the cores a measure plays on alone, the rest of the
|
|
2
|
+
// machine going on working, as the benches of rustc-perf and `pyperf system tune` isolate cores and
|
|
3
|
+
// pin the measure to them, as the static policy of the CPU Manager of Kubernetes gives a pod of the
|
|
4
|
+
// guaranteed class cores of its own, and as Slurm binds a job to its cores. Functions with the
|
|
5
|
+
// system as input (what it reads is passed in, nothing is changed here):
|
|
6
|
+
// - The key `grillhouse.mesure` of a project (`{ "coeurs": <integer ≥ 1> }`) and the number of
|
|
7
|
+
// dedicated cores: the default one is the default part of the budget (`partParDefautDe`).
|
|
8
|
+
// - The topology of the system (the sibling threads of a core, the memory node): a unit of
|
|
9
|
+
// dedicated core is a physical core whole, its sibling threads with it. The count stays in
|
|
10
|
+
// threads (« cores » of the budget), as the budget does.
|
|
11
|
+
// - The choice of the precise threads (`choisirLesCoeurs`), a pure function of the budget, the
|
|
12
|
+
// topology, the threads held and the request.
|
|
13
|
+
// - How the measure is attached (`attacheDesCoeurs`): in control groups whose allowed cores are
|
|
14
|
+
// fixed when the system delegates the cpuset controller to the account, else by the affinity
|
|
15
|
+
// of the launch, else not at all.
|
|
16
|
+
// - The rest of the dedicated cores: the load of those cores alone, read from /proc/stat.
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { availableParallelism } from 'node:os';
|
|
19
|
+
import { spawnSync } from 'node:child_process';
|
|
20
|
+
import { paquetsDeLEnveloppe } from './enveloppe/paquets-du-plan.mjs';
|
|
21
|
+
import { partParDefautDe } from './plafond-de-la-machine.mjs';
|
|
22
|
+
|
|
23
|
+
/** The tool that pins a command, and its children, to cores (util-linux). */
|
|
24
|
+
export const OUTIL_D_AFFINITE = 'taskset';
|
|
25
|
+
|
|
26
|
+
/** The load of the dedicated cores, out of the measure, above which they are not at rest: 10 %. */
|
|
27
|
+
export const SEUIL_DE_CHARGE = 0.1;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The cores a project declares for its measures in the key `grillhouse.mesure` of its
|
|
31
|
+
* `package.json` <pkg> (`{ coeurs }`): `{ declaree, faute }`, `declaree` null without the key,
|
|
32
|
+
* `faute` the line that names the key and what is wrong when it is.
|
|
33
|
+
* @param {{ grillhouse?: { mesure?: unknown } }} pkg
|
|
34
|
+
* @returns {{ declaree: { coeurs?: number } | null, faute: string | null }}
|
|
35
|
+
*/
|
|
36
|
+
export function mesureDeclareeDe(pkg) {
|
|
37
|
+
const mesure = pkg?.grillhouse?.mesure;
|
|
38
|
+
if (mesure === undefined) {
|
|
39
|
+
return { declaree: null, faute: null };
|
|
40
|
+
}
|
|
41
|
+
const faute = dit => ({
|
|
42
|
+
declaree: null,
|
|
43
|
+
faute: `grillhouse.mesure : ${dit} ({ "coeurs": <entier ≥ 1> } est attendu).`,
|
|
44
|
+
});
|
|
45
|
+
if (mesure === null || typeof mesure !== 'object' || Array.isArray(mesure)) {
|
|
46
|
+
return faute(`« ${JSON.stringify(mesure)} » n’est pas un objet`);
|
|
47
|
+
}
|
|
48
|
+
const inconnue = Object.keys(mesure).find(k => k !== 'coeurs');
|
|
49
|
+
if (inconnue !== undefined) {
|
|
50
|
+
return faute(`la clé « ${inconnue} » est inconnue`);
|
|
51
|
+
}
|
|
52
|
+
const { coeurs } = mesure;
|
|
53
|
+
if (coeurs !== undefined && !(Number.isInteger(coeurs) && coeurs >= 1)) {
|
|
54
|
+
return faute(`coeurs vaut ${JSON.stringify(coeurs)}`);
|
|
55
|
+
}
|
|
56
|
+
return { declaree: coeurs === undefined ? {} : { coeurs }, faute: null };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The number of dedicated cores (threads) a measure asks for: the one its project declares, else
|
|
61
|
+
* the default part of the budget; within the budget and one at least.
|
|
62
|
+
* @param {{ declaree: { coeurs?: number } | null, budget: { coeurs: number, memoire: number } }} o
|
|
63
|
+
* @returns {number}
|
|
64
|
+
*/
|
|
65
|
+
export function coeursDeLaMesureDe({ declaree, budget }) {
|
|
66
|
+
const voulus = declaree?.coeurs ?? partParDefautDe(budget).coeurs;
|
|
67
|
+
return Math.max(1, Math.min(budget.coeurs, voulus));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The threads of a list of the system, « 0-1,4 » → [0, 1, 4]; null when it does not read.
|
|
71
|
+
function fils(texte) {
|
|
72
|
+
if (typeof texte !== 'string' || texte.trim() === '') {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const sortie = [];
|
|
76
|
+
for (const morceau of texte.trim().split(',')) {
|
|
77
|
+
const m = /^(\d+)(?:-(\d+))?$/.exec(morceau.trim());
|
|
78
|
+
if (!m) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const a = Number(m[1]);
|
|
82
|
+
const b = m[2] === undefined ? a : Number(m[2]);
|
|
83
|
+
for (let i = a; i <= b; i++) {
|
|
84
|
+
sortie.push(i);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return sortie;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const lireUnFichier = chemin => {
|
|
91
|
+
try {
|
|
92
|
+
return readFileSync(chemin, 'utf8');
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The topology of the system: `{ lisible, coeurs: [{ fils, noeud }] }`, each physical core its
|
|
100
|
+
* sibling threads and its memory node. A topology that does not read (a thread whose siblings are
|
|
101
|
+
* unknown) counts each thread as a core, `lisible` false; nodes that do not read put every core
|
|
102
|
+
* on one node.
|
|
103
|
+
* @param {{ lire?: (chemin: string) => string | null, nombreDeFils?: number }} [o] `lire`, the
|
|
104
|
+
* reading of a file of the system (null when it does not read), for a trial
|
|
105
|
+
* @returns {{ lisible: boolean, coeurs: { fils: number[], noeud: number }[] }}
|
|
106
|
+
*/
|
|
107
|
+
export function lireLaTopologie({ lire = lireUnFichier, nombreDeFils = availableParallelism() } = {}) {
|
|
108
|
+
const cpu = n => `/sys/devices/system/cpu/cpu${n}/topology/thread_siblings_list`;
|
|
109
|
+
const groupes = new Map();
|
|
110
|
+
let lisible = true;
|
|
111
|
+
for (let n = 0; n < nombreDeFils && lisible; n++) {
|
|
112
|
+
const freres = fils(lire(cpu(n)));
|
|
113
|
+
if (freres === null || !freres.includes(n)) {
|
|
114
|
+
lisible = false;
|
|
115
|
+
} else {
|
|
116
|
+
groupes.set(freres.join(','), freres);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!lisible) {
|
|
120
|
+
return {
|
|
121
|
+
lisible: false,
|
|
122
|
+
coeurs: Array.from({ length: nombreDeFils }, (_, f) => ({ fils: [f], noeud: 0 })),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const noeudDe = new Map();
|
|
126
|
+
for (const noeud of fils(lire('/sys/devices/system/node/online')) ?? []) {
|
|
127
|
+
for (const f of fils(lire(`/sys/devices/system/node/node${noeud}/cpulist`)) ?? []) {
|
|
128
|
+
noeudDe.set(f, noeud);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const coeurs = [...groupes.values()]
|
|
132
|
+
.map(f => [...f].sort((a, b) => a - b))
|
|
133
|
+
.sort((a, b) => a[0] - b[0])
|
|
134
|
+
.map(f => ({ fils: f, noeud: noeudDe.get(f[0]) ?? 0 }));
|
|
135
|
+
return { lisible: true, coeurs };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A list of threads as the system writes it, sorted, the runs in intervals: [0, 1, 2, 5] → « 0-2,5 ».
|
|
140
|
+
* @param {number[]} liste
|
|
141
|
+
* @returns {string}
|
|
142
|
+
*/
|
|
143
|
+
export function listeDeCoeurs(liste) {
|
|
144
|
+
const tri = [...new Set(liste)].sort((a, b) => a - b);
|
|
145
|
+
const morceaux = [];
|
|
146
|
+
for (let i = 0; i < tri.length; ) {
|
|
147
|
+
let j = i;
|
|
148
|
+
while (j + 1 < tri.length && tri[j + 1] === tri[j] + 1) {
|
|
149
|
+
j++;
|
|
150
|
+
}
|
|
151
|
+
morceaux.push(j === i ? String(tri[i]) : `${tri[i]}-${tri[j]}`);
|
|
152
|
+
i = j + 1;
|
|
153
|
+
}
|
|
154
|
+
return morceaux.join(',');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The precise threads of the budget <budget> (a count of threads): physical cores whole, in the
|
|
159
|
+
* order of the topology, their sibling threads with them, the last one cut when the budget does
|
|
160
|
+
* not end on a core.
|
|
161
|
+
* @param {{ topologie: { coeurs: { fils: number[] }[] }, budget: number }} o
|
|
162
|
+
* @returns {number[]}
|
|
163
|
+
*/
|
|
164
|
+
export function budgetEnFils({ topologie, budget }) {
|
|
165
|
+
const choisis = [];
|
|
166
|
+
for (const c of topologie.coeurs) {
|
|
167
|
+
for (const f of c.fils) {
|
|
168
|
+
if (choisis.length < budget) {
|
|
169
|
+
choisis.push(f);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return choisis;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// The cores of the budget whole (every sibling thread in it), in the order of the topology.
|
|
177
|
+
const coeursEntiersDuBudget = (topologie, budget) =>
|
|
178
|
+
topologie.coeurs.filter(c => c.fils.every(f => budget.includes(f)));
|
|
179
|
+
|
|
180
|
+
// The cores to take to give <demande> threads, rounded up to a whole core while the cores
|
|
181
|
+
// <disponibles> allow it, else all they give, one core at least; the threads they hold.
|
|
182
|
+
const taille = coeurs => coeurs.reduce((n, c) => n + c.fils.length, 0);
|
|
183
|
+
function cible(disponibles, demande) {
|
|
184
|
+
const n = [];
|
|
185
|
+
let somme = 0;
|
|
186
|
+
for (const c of disponibles) {
|
|
187
|
+
if (somme >= demande) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
n.push(c);
|
|
191
|
+
somme += c.fils.length;
|
|
192
|
+
}
|
|
193
|
+
return n.length;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The threads a measure of time of <demande> threads takes, rounded up to physical cores whole
|
|
198
|
+
* while the budget allows it, down otherwise, one core at least; null when the budget holds no
|
|
199
|
+
* whole core.
|
|
200
|
+
* @param {{ budget: number[], topologie: { coeurs: { fils: number[], noeud: number }[] },
|
|
201
|
+
* demande: number }} o
|
|
202
|
+
* @returns {number | null}
|
|
203
|
+
*/
|
|
204
|
+
export function filsDeLaMesure({ budget, topologie, demande }) {
|
|
205
|
+
const entiers = coeursEntiersDuBudget(topologie, budget);
|
|
206
|
+
const n = cible(entiers, demande);
|
|
207
|
+
return n === 0 ? null : taille(entiers.slice(0, n));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The precise threads of a pass of <demande> threads: for a measure (<dedies>), physical cores
|
|
212
|
+
* whole rounded as `filsDeLaMesure` says, none of whose threads is held, of one memory node when a
|
|
213
|
+
* node holds them, else of the fewest; for an ordinary pass, threads of the budget not held, the
|
|
214
|
+
* cores that are whole free first. A pure function: null when what is left does not hold the
|
|
215
|
+
* request.
|
|
216
|
+
* @param {{ budget: number[], topologie: { coeurs: { fils: number[], noeud: number }[] },
|
|
217
|
+
* tenus: number[], demande: number, dedies: boolean }} o
|
|
218
|
+
* @returns {number[] | null}
|
|
219
|
+
*/
|
|
220
|
+
export function choisirLesCoeurs({ budget, topologie, tenus, demande, dedies }) {
|
|
221
|
+
const pris = new Set(tenus);
|
|
222
|
+
const dansLeBudget = new Set(budget);
|
|
223
|
+
if (!dedies) {
|
|
224
|
+
const entiers = [];
|
|
225
|
+
const partiels = [];
|
|
226
|
+
for (const c of topologie.coeurs) {
|
|
227
|
+
const libres = c.fils.filter(f => dansLeBudget.has(f) && !pris.has(f));
|
|
228
|
+
(libres.length === c.fils.length ? entiers : partiels).push(...libres);
|
|
229
|
+
}
|
|
230
|
+
const libres = [...entiers, ...partiels];
|
|
231
|
+
return libres.length < demande ? null : libres.slice(0, demande);
|
|
232
|
+
}
|
|
233
|
+
const voulu = filsDeLaMesure({ budget, topologie, demande });
|
|
234
|
+
if (voulu === null) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const libres = coeursEntiersDuBudget(topologie, budget).filter(c =>
|
|
238
|
+
c.fils.every(f => !pris.has(f))
|
|
239
|
+
);
|
|
240
|
+
const parNoeud = new Map();
|
|
241
|
+
for (const c of libres) {
|
|
242
|
+
parNoeud.set(c.noeud, [...(parNoeud.get(c.noeud) ?? []), c]);
|
|
243
|
+
}
|
|
244
|
+
const prendre = coeurs => {
|
|
245
|
+
const n = cible(coeurs, voulu);
|
|
246
|
+
const choisis = coeurs.slice(0, n);
|
|
247
|
+
return taille(choisis) >= voulu ? choisis.flatMap(c => c.fils) : null;
|
|
248
|
+
};
|
|
249
|
+
// One node that holds the request, the tightest; else the nodes with the most free cores first.
|
|
250
|
+
const qui = [...parNoeud.entries()]
|
|
251
|
+
.filter(([, c]) => taille(c) >= voulu)
|
|
252
|
+
.sort((a, b) => taille(a[1]) - taille(b[1]) || a[0] - b[0]);
|
|
253
|
+
if (qui.length > 0) {
|
|
254
|
+
return prendre(qui[0][1]);
|
|
255
|
+
}
|
|
256
|
+
const ordre = [...parNoeud.entries()]
|
|
257
|
+
.sort((a, b) => taille(b[1]) - taille(a[1]) || a[0] - b[0])
|
|
258
|
+
.flatMap(([, c]) => c);
|
|
259
|
+
return prendre(ordre);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Whether the controller of the cores (`cpuset`) is among the controllers the system delegates to
|
|
264
|
+
* the account, read from its `cgroup.controllers`.
|
|
265
|
+
* @param {string | null} texte
|
|
266
|
+
* @returns {boolean}
|
|
267
|
+
*/
|
|
268
|
+
export const delegationDesCoeurs = texte =>
|
|
269
|
+
typeof texte === 'string' && texte.split(/\s+/).includes('cpuset');
|
|
270
|
+
|
|
271
|
+
// What the system gives, asked once by process.
|
|
272
|
+
let delegue = null;
|
|
273
|
+
const delegationDuSysteme = () => {
|
|
274
|
+
const uid = process.getuid?.() ?? 0;
|
|
275
|
+
delegue ??= delegationDesCoeurs(
|
|
276
|
+
lireUnFichier(
|
|
277
|
+
`/sys/fs/cgroup/user.slice/user-${uid}.slice/user@${uid}.service/cgroup.controllers`
|
|
278
|
+
)
|
|
279
|
+
);
|
|
280
|
+
return delegue;
|
|
281
|
+
};
|
|
282
|
+
let attache = null;
|
|
283
|
+
const affiniteDuSysteme = () => {
|
|
284
|
+
attache ??=
|
|
285
|
+
spawnSync(OUTIL_D_AFFINITE, ['-c', '0', 'true'], { stdio: 'ignore', timeout: 20_000 }).status ===
|
|
286
|
+
0;
|
|
287
|
+
return attache;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* How a measure is attached to its dedicated cores: `{ voie, dit }`. `voie` « groupe » (the
|
|
292
|
+
* controller of the cores is delegated to the account: control groups whose allowed cores are
|
|
293
|
+
* fixed, and the programs out of the frame kept away from the dedicated cores), « affinite » (the
|
|
294
|
+
* affinity of the launch, children included; `dit` says once that the programs out of the frame
|
|
295
|
+
* are not kept away, and the poste's setting that delegates the controller), « aucune » (the
|
|
296
|
+
* envelope of an agent, or a system with neither: the measure plays without a part held, `dit`
|
|
297
|
+
* says it). The system is asked only out of the envelope.
|
|
298
|
+
* @param {{ env: Record<string, string | undefined>, delegation?: () => boolean,
|
|
299
|
+
* affinite?: () => boolean }} o
|
|
300
|
+
* @returns {{ voie: 'groupe' | 'affinite' | 'aucune', dit: string | null }}
|
|
301
|
+
*/
|
|
302
|
+
export function attacheDesCoeurs({
|
|
303
|
+
env,
|
|
304
|
+
delegation = delegationDuSysteme,
|
|
305
|
+
affinite = affiniteDuSysteme,
|
|
306
|
+
}) {
|
|
307
|
+
if (paquetsDeLEnveloppe(env) !== null) {
|
|
308
|
+
return {
|
|
309
|
+
voie: 'aucune',
|
|
310
|
+
dit: "dans l'enveloppe d'un agent, la mesure joue sans part tenue : ses cœurs ne sont ni réservés ni attachés.",
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
if (delegation()) {
|
|
314
|
+
return { voie: 'groupe', dit: null };
|
|
315
|
+
}
|
|
316
|
+
if (affinite()) {
|
|
317
|
+
return {
|
|
318
|
+
voie: 'affinite',
|
|
319
|
+
dit: 'les programmes hors du cadre ne sont pas tenus à l’écart des cœurs dédiés : le réglage du poste est `Delegate=cpuset cpu io memory pids` dans un fichier de `user@.service.d/` (le contrôleur cpuset délégué au compte).',
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
voie: 'aucune',
|
|
324
|
+
dit: 'la mesure joue sans part tenue : ce système ne délègue pas le contrôleur cpuset au compte et ne donne pas l’affinité de lancement (taskset).',
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* The command that keeps the programs out of the frame away from the dedicated cores <dedies>:
|
|
330
|
+
* the cores their group (`app.slice` of the user's manager) may use are the threads <fils> but
|
|
331
|
+
* them; all of them without a measure under way.
|
|
332
|
+
* @param {{ dedies: number[], fils: number[] }} o
|
|
333
|
+
* @returns {{ cmd: string, args: string[] }}
|
|
334
|
+
*/
|
|
335
|
+
export function ecartDesProgrammes({ dedies, fils: tous }) {
|
|
336
|
+
const permis = tous.filter(f => !dedies.includes(f));
|
|
337
|
+
return {
|
|
338
|
+
cmd: 'systemctl',
|
|
339
|
+
args: ['--user', 'set-property', '--runtime', 'app.slice', `AllowedCPUs=${listeDeCoeurs(permis)}`],
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The busy and the total time of each thread, from the text of /proc/stat (hundredths of a
|
|
345
|
+
* second): busy is user, nice, system, irq, softirq and steal; idle and iowait are rest. Null
|
|
346
|
+
* when the text does not read.
|
|
347
|
+
* @param {string | null} texte
|
|
348
|
+
* @returns {Record<number, { occupe: number, total: number }> | null}
|
|
349
|
+
*/
|
|
350
|
+
export function lireLesTempsOccupes(texte) {
|
|
351
|
+
if (typeof texte !== 'string') {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
const temps = {};
|
|
355
|
+
for (const ligne of texte.split('\n')) {
|
|
356
|
+
const m = /^cpu(\d+)\s+(.*)$/.exec(ligne);
|
|
357
|
+
if (!m) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
const [user, nice, system, idle, iowait, irq, softirq, steal] = m[2]
|
|
361
|
+
.split(/\s+/)
|
|
362
|
+
.map(Number);
|
|
363
|
+
const occupe = user + nice + system + irq + softirq + steal;
|
|
364
|
+
temps[Number(m[1])] = { occupe, total: occupe + idle + iowait };
|
|
365
|
+
}
|
|
366
|
+
return temps;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* The load of the dedicated threads <fils> out of the measure between two readings of the times
|
|
371
|
+
* (`lireLesTempsOccupes`): their busy time less <mesureNs> (the measure's own, read from its
|
|
372
|
+
* group) over their capacity, never under zero; null when a reading lacks.
|
|
373
|
+
* @param {{ avant: Record<number, { occupe: number, total: number }> | null,
|
|
374
|
+
* apres: Record<number, { occupe: number, total: number }> | null, fils: number[],
|
|
375
|
+
* mesureNs?: number }} o
|
|
376
|
+
* @returns {number | null}
|
|
377
|
+
*/
|
|
378
|
+
export function chargeHorsMesure({ avant, apres, fils: dedies, mesureNs = 0 }) {
|
|
379
|
+
if (!avant || !apres || dedies.length === 0) {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
let occupe = 0;
|
|
383
|
+
let total = 0;
|
|
384
|
+
for (const f of dedies) {
|
|
385
|
+
if (!avant[f] || !apres[f]) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
occupe += apres[f].occupe - avant[f].occupe;
|
|
389
|
+
total += apres[f].total - avant[f].total;
|
|
390
|
+
}
|
|
391
|
+
if (!(total > 0)) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
// A hundredth of a second is 1e7 ns.
|
|
395
|
+
return Math.max(0, occupe - mesureNs / 1e7) / total;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* The exit code of a measure of time: a red (1) played while the dedicated cores were loaded out of
|
|
400
|
+
* it beyond SEUIL_DE_CHARGE is « à repasser » (75); any other code stays, and so does a red
|
|
401
|
+
* without a reading of the load.
|
|
402
|
+
* @param {{ code: number, charge: number | null }} o
|
|
403
|
+
* @returns {number}
|
|
404
|
+
*/
|
|
405
|
+
export function codeDeLaMesure({ code, charge }) {
|
|
406
|
+
return code === 1 && charge !== null && charge > SEUIL_DE_CHARGE ? 75 : code;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Reads the load of the dedicated threads <fils> out of any measure over <ms> (two readings of
|
|
411
|
+
* /proc/stat, spaced): null without a reading.
|
|
412
|
+
* @param {number[]} fils
|
|
413
|
+
* @param {{ lire?: () => string | null, dormir?: (ms: number) => void }} [o]
|
|
414
|
+
* @returns {number | null}
|
|
415
|
+
*/
|
|
416
|
+
export function chargeDesCoeursDuSysteme(fils, { lire = () => lireUnFichier('/proc/stat'), dormir } = {}) {
|
|
417
|
+
const avant = lireLesTempsOccupes(lire());
|
|
418
|
+
(dormir ?? attendre)(1000);
|
|
419
|
+
return chargeHorsMesure({ avant, apres: lireLesTempsOccupes(lire()), fils });
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function attendre(ms) {
|
|
423
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** The text of /proc/stat, null when it does not read. */
|
|
427
|
+
export const tempsDuSysteme = () => lireUnFichier('/proc/stat');
|
|
@@ -427,7 +427,9 @@ export function commande(racine, args) {
|
|
|
427
427
|
maxBuffer: 256 * 1024 * 1024,
|
|
428
428
|
});
|
|
429
429
|
if (show.status !== 0) {
|
|
430
|
-
process.stderr.write(
|
|
430
|
+
process.stderr.write(
|
|
431
|
+
`⛔ ticket ${ticket} illisible : ${show.error?.message ?? show.stderr ?? ''}\n`
|
|
432
|
+
);
|
|
431
433
|
return 2;
|
|
432
434
|
}
|
|
433
435
|
const t = JSON.parse(show.stdout)[0] ?? {};
|