forked from justanhduc/task-spooler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu_bind.h
More file actions
80 lines (65 loc) · 2.51 KB
/
Copy pathcpu_bind.h
File metadata and controls
80 lines (65 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* cpu_bind.h — CPU binding allocator public API */
#ifndef CPU_BIND_H
#define CPU_BIND_H
#include "topology.h"
#include "vec.h"
/* ---- CPU topology types (merged from topology_types.h) ---- */
struct CoreGroup {
int group_id;
int node_id;
int num_cores;
int free_count;
int os_cpus[MAX_CORES_PER_GROUP];
};
struct NodeInfo {
int node_id;
int num_groups;
int num_cores;
int free_count;
int group_ids[MAX_GROUPS_PER_NODE];
};
struct Topology {
int num_nodes;
int num_groups;
struct CoreGroup groups[NUM_GROUPS];
struct NodeInfo nodes[NUM_NODES];
};
/* ---- 全局 CPU→jobid 映射 ---- */
/* 0 = 空闲, >0 = 被该 jobid 占用 */
extern int cpu_owner[MAX_OS_CPU];
/* ---- 分配结果 ---- */
struct CpuAlloc {
int primary_node; /* -1=跨节点不限制, ≥0=主节点 */
int mem_nodes; /* 涉及节点位图 */
int count; /* os_cpus 长度 */
int slots; /* 分配的容量(os_cpus[] 最大元素数) */
int jobid;
int error; /* 0=成功, 1=分配异常(部分失败) */
int quality; /* 0=完美 1=1个碎片group 2=2个碎片group */
int os_cpus[]; /* 柔性数组 */
};
extern struct Topology sys_topology;
extern vec_t cpu_allocs;
void cpu_bind_init(void);
int cpu_bind_enabled(void);
void cpu_bind_set_disabled(int disabled);
int cpu_bind_defrag_enabled(void);
void cpu_bind_set_defrag_disabled(int disabled);
struct CpuAlloc *cpu_bind_alloc_init(int jobid, int max_cpus);
void cpu_bind_alloc(struct CpuAlloc *alloc, int N);
void cpu_bind_free(struct CpuAlloc *alloc);
/* 碎片整理:暂停 quality>0 的 job,重建分配,更新 cpuset,恢复 */
int cpu_bind_defrag();
#ifdef TS_CPU_BIND
/* Async defrag API (thread-based) */
int cpu_bind_defrag_start(void);
/* Wait for defrag I/O thread before doing cgroup filesystem writes */
void cgroup_io_wait_if_busy(void);
#endif
char *cpu_bind_format_cpus(const struct CpuAlloc *alloc);
char *cpu_bind_format_mems(const struct CpuAlloc *alloc);
/* 重启恢复 — 从 cpuset 字符串认领已分配的 CPU */
int cpu_bind_parse_cpuset(const char *str, int *cpus, int max_cpus);
struct CpuAlloc *cpu_bind_claim(int jobid, const int *cpus, int count,
int mem_nodes, int primary_node);
#endif /* CPU_BIND_H */