-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_data.hpp
355 lines (329 loc) · 10.8 KB
/
resource_data.hpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*****************************************************************************\
* LLNL-CODE-658032 All rights reserved.
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the license, or (at your option)
* any later version.
*
* Flux is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
* See also: https://www.gnu.org/licenses/
\*****************************************************************************/
#ifndef RESOURCE_DATA_HPP
#define RESOURCE_DATA_HPP
#include <uuid/uuid.h>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include "planner/planner.h"
namespace Flux {
namespace resource_model {
// We create an x_checker planner for each resource vertex for quick exclusivity
// checking. We update x_checker for all of the vertices involved in each
// job allocation/reservation -- subtract 1 from x_checker planner for the
// scheduled span. Any vertex with less than X_CHECKER_NJOBS available in its
// x_checker cannot be exclusively allocated or reserved.
const char * const X_CHECKER_JOBS_STR = "jobs";
const int64_t X_CHECKER_NJOBS = 0x40000000;
typedef std::string subsystem_t;
typedef std::map<subsystem_t, std::string> multi_subsystems_t;
typedef std::map<subsystem_t, std::set<std::string> > multi_subsystemsS;
struct color_t {
enum color_offset_t {
WHITE_OFFSET = 0,
GRAY_OFFSET = 1,
BLACK_OFFSET = 2,
NEW_BASE = 3
};
uint64_t reset (uint64_t color_base) const
{
return color_base + (uint64_t)NEW_BASE;
}
bool white (uint64_t c, uint64_t color_base) const
{
return c <= (color_base + (uint64_t)WHITE_OFFSET);
}
uint64_t white (uint64_t color_base) const
{
return color_base + (uint64_t)WHITE_OFFSET;
}
bool gray (uint64_t c, uint64_t color_base) const
{
return c == (color_base + (uint64_t)GRAY_OFFSET);
}
uint64_t gray (uint64_t color_base) const
{
return color_base + (uint64_t)GRAY_OFFSET;
}
bool black (uint64_t c, uint64_t color_base) const
{
return c == (color_base + (uint64_t)BLACK_OFFSET);
}
uint64_t black (uint64_t color_base) const
{
return color_base + (uint64_t)BLACK_OFFSET;
}
};
//! Type to keep track of current schedule state
struct schedule_t {
schedule_t () { }
schedule_t (const schedule_t &o)
{
int64_t base_time = 0;
uint64_t duration = 0;
size_t len = 0;
// copy constructor does not copy the contents
// of the schedule tables and of the planner objects.
if (o.plans) {
base_time = planner_base_time (o.plans);
duration = planner_duration (o.plans);
len = planner_resources_len (o.plans);
plans = planner_new (base_time, duration,
planner_resource_totals (o.plans),
planner_resource_types (o.plans), len);
}
if (o.x_checker) {
base_time = planner_base_time (o.x_checker);
duration = planner_duration (o.x_checker);
len = planner_resources_len (o.x_checker);
x_checker = planner_new (base_time, duration,
planner_resource_totals (o.x_checker),
planner_resource_types (o.x_checker), len);
}
}
schedule_t &operator= (const schedule_t &o)
{
int64_t base_time = 0;
uint64_t duration = 0;
size_t len = 0;
// assign operator does not copy the contents
// of the schedule tables and of the planner objects.
if (o.plans) {
base_time = planner_base_time (o.plans);
duration = planner_duration (o.plans);
len = planner_resources_len (o.plans);
plans = planner_new (base_time, duration,
planner_resource_totals (o.plans),
planner_resource_types (o.plans), len);
}
if (o.x_checker) {
base_time = planner_base_time (o.x_checker);
duration = planner_duration (o.x_checker);
len = planner_resources_len (o.x_checker);
x_checker = planner_new (base_time, duration,
planner_resource_totals (o.x_checker),
planner_resource_types (o.x_checker), len);
}
return *this;
}
~schedule_t ()
{
tags.clear ();
allocations.clear ();
reservations.clear ();
x_spans.clear ();
if (plans)
planner_destroy (&plans);
if (x_checker)
planner_destroy (&x_checker);
}
std::map<int64_t, int64_t> tags;
std::map<int64_t, int64_t> allocations;
std::map<int64_t, int64_t> reservations;
std::map<int64_t, int64_t> x_spans;
planner_t *plans = NULL;
planner_t *x_checker = NULL;
};
/*! Base type to organize the data supporting scheduling infrastructure's
* operations (e.g., graph organization, coloring and edge evaluation).
*/
struct infra_base_t {
infra_base_t () { }
infra_base_t (const infra_base_t &o)
{
member_of = o.member_of;
}
infra_base_t &operator= (const infra_base_t &o)
{
member_of = o.member_of;
return *this;
}
virtual ~infra_base_t () { }
virtual void scrub () = 0;
multi_subsystems_t member_of;
};
struct pool_infra_t : public infra_base_t {
pool_infra_t () { }
pool_infra_t (const pool_infra_t &o): infra_base_t (o)
{
// don't copy the content of infrastructure tables and subtree
// planner objects.
colors = o.colors;
for (auto &kv : o.subplans) {
planner_t *p = kv.second;
if (!p)
continue;
int64_t base_time = planner_base_time (p);
uint64_t duration = planner_duration (p);
size_t len = planner_resources_len (p);
subplans[kv.first] = planner_new (base_time, duration,
planner_resource_totals (p),
planner_resource_types (p), len);
}
}
pool_infra_t &operator= (const pool_infra_t &o)
{
// don't copy the content of infrastructure tables and subtree
// planner objects.
infra_base_t::operator= (o);
colors = o.colors;
for (auto &kv : o.subplans) {
planner_t *p = kv.second;
if (!p)
continue;
int64_t base_time = planner_base_time (p);
uint64_t duration = planner_duration (p);
size_t len = planner_resources_len (p);
subplans[kv.first] = planner_new (base_time, duration,
planner_resource_totals (p),
planner_resource_types (p), len);
}
return *this;
}
virtual ~pool_infra_t ()
{
job2span.clear ();
for (auto &kv : subplans)
planner_destroy (&(kv.second));
colors.clear ();
}
virtual void scrub ()
{
job2span.clear ();
for (auto &kv : subplans)
planner_destroy (&(kv.second));
colors.clear ();
}
std::map<int64_t, int64_t> job2span;
std::map<subsystem_t, planner_t *> subplans;
std::map<subsystem_t, uint64_t> colors;
};
struct relation_infra_t : public infra_base_t {
relation_infra_t () { }
relation_infra_t (const relation_infra_t &o): infra_base_t (o)
{
needs = o.needs;
best_k_cnt = o.best_k_cnt;
exclusive = o.exclusive;
}
relation_infra_t &operator= (const relation_infra_t &o)
{
infra_base_t::operator= (o);
needs = o.needs;
best_k_cnt = o.best_k_cnt;
exclusive = o.exclusive;
return *this;
}
virtual ~relation_infra_t ()
{
}
virtual void scrub ()
{
needs = 0;
best_k_cnt = 0;
exclusive = 0;
}
uint64_t needs = 0;
uint64_t best_k_cnt = 0;
int exclusive = 0;
};
//! Resource pool data type
struct resource_pool_t {
resource_pool_t () { }
resource_pool_t (const resource_pool_t &o)
{
type = o.type;
paths = o.paths;
basename = o.basename;
name = o.name;
properties = o.properties;
id = o.id;
memcpy (uuid, o.uuid, sizeof (uuid));
size = o.size;
unit = o.unit;
schedule = o.schedule;
idata = o.idata;
}
resource_pool_t &operator= (const resource_pool_t &o)
{
type = o.type;
paths = o.paths;
basename = o.basename;
name = o.name;
properties = o.properties;
id = o.id;
memcpy (uuid, o.uuid, sizeof (uuid));
size = o.size;
unit = o.unit;
schedule = o.schedule;
idata = o.idata;
return *this;
}
~resource_pool_t ()
{
paths.clear ();
properties.clear ();
}
// Resource pool data
std::string type;
std::map<std::string, std::string> paths;
std::string basename;
std::string name;
std::map<std::string, std::string> properties;
int64_t id = -1;
uuid_t uuid;
unsigned int size = 0;
std::string unit;
schedule_t schedule; //!< schedule data
pool_infra_t idata; //!< scheduling infrastructure data
};
/*! Resource relationship type.
* An edge is annotated with a set of {key: subsystem, val: relationship}.
* An edge can represent a relationship within a subsystem and do this
* for multiple subsystems. However, it cannot represent multiple
* relationship within the same subsystem.
*/
struct resource_relation_t {
resource_relation_t () { }
resource_relation_t (const resource_relation_t &o)
{
name = o.name;
idata = o.idata;
}
resource_relation_t &operator= (const resource_relation_t &o)
{
name = o.name;
idata = o.idata;
return *this;
}
~resource_relation_t () { }
std::string name;
relation_infra_t idata; //!< scheduling infrastructure data
};
} // namespace resource_model
} // namespace Flux
#endif // RESOURCE_DATA_HPP
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/