1/* @ajax/mesh-sched-place: the scheduler's placement pass (sched.rs place): Nomad's feasibility then
2 * score, per program in a fixed order (priority, anchors before what is colocated with them, name;
3 * ties go to the lower system id, so every leader computes the same answer from the same inputs).
4 * A valid placement is kept: place only fills what is missing (a new program, a replica on a member
5 * down for replace_ms, a member that no longer fits). Moving a running program for a better score is
6 * the rebalancer's (mesh-sched-tracker). Also the lockstep group's member choice. */
7#ifndef MESH_SCHED_PLACE_H
8#define MESH_SCHED_PLACE_H
910#include "mesh/fleet_doc.h"
11#include "mesh/member_list.h"
12#include "mesh/sched_member.h"
13#include "mesh/sched_score.h"
14#include "mesh/sched_weights.h"
1516#include <stdbool.h>
17#include <stdint.h>
1819/* What the scheduler reads: the committed document, the members (index = id), the measured
20 * performance per (program, member). */
21typedef struct {
22 const mfd_doc *doc;
23 const msm_member *members;
24 size_t nmembers;
25 const msm_perfs *perf;
26 const msw_weights *w;
27} msp_input;
2829/* A member's verdict for a program: a score, or why not. */
30typedef struct {
31 uint32_t k;
32 bool ok;
33 msc_score_t score; /* ok */
34 char *why; /* !ok */
35} msp_row;
3637/* Why a program is where it is: every member's verdict. */
38typedef struct {
39 char *program, *needs, *summary;
40 msp_row *rows;
41 size_t nrows;
42 ml_opt chosen;
43} msp_explain;
4445char *msp_explain_text(const msp_explain *e);
46bool msp_score_of(const msp_explain *e, uint32_t k, double *score);
47void msp_explain_free(msp_explain *e);
4849/* explains by program, in the document's order. */
50typedef struct {
51 msp_explain *v;
52 size_t n;
53} msp_explains;
5455void msp_explains_free(msp_explains *e);
56const msp_explain *msp_explains_get(const msp_explains *e, const char *program);
5758/* The order programs are placed in: names into a new list. */
59mt_strs msp_order(const mfd_doc *doc);
60/* The members a placement puts a program on (none: every member that can run it). */
61ml_list msp_members_of_at(const ml_opt *at, const msm_member *ms, size_t nms, const mesh_needs *n);
6263/* A placement pass: the document with every program's placement made valid, the changes, and every
64 * program's explain. A program being migrated (from) is left to the leader. */
65mfd_doc msp_place(const msp_input *in, mt_strs *changes, msp_explains *explains);
6667/* The member set a group should have now (every eligible up member matching group_members;
68 * group_size > 0: the best scoring that many, grown for link RTT among them), in system order, and
69 * why; false when no member is eligible. */
70bool msp_group_choice(const msp_input *in, const mfd_group *g, ml_list *members, char **why);
71/* The group's score: the sum of its members' scores (a member that cannot run it counts 0). */
72double msp_group_score(const msp_input *in, const mfd_group *g, const ml_list *members);
7374/* ---- for the rebalancer (mesh-sched-tracker) */
7576/* The bookkeeping while a pass runs: programs, reservations, and the views and slots placed on
77 * members that do not hold them yet. */
78typedef struct {
79 size_t n;
80 uint32_t *placed, *mem, *view_kb, *nnew;
81 float *cpu;
82} msp_books;
8384msp_books msp_books_new(size_t n);
85void msp_books_free(msp_books *b);
86void msp_books_add(msp_books *b, uint32_t k, const mesh_needs *n);
87/* Every member's verdict for program name (current: its placement now; anchor: NULL or the anchor's
88 * members). */
89void msp_rows(const msp_input *in, const char *name, const ml_list *current, const msp_books *books, const ml_list *anchor, msp_row **rows, size_t *nrows);
90void msp_rows_free(msp_row *rows, size_t n);
91/* The feasible rows' (k, total), best first (ties: the lower id). */
92size_t msp_sorted_ok(const msp_row *rows, size_t n, uint32_t *ks, double *totals);
9394#endif