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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
#include <algorithm> // for greater, sort
#include <numeric>
#include <functional>
#include <limits.h>
#include <iostream>
#include "sharedres.h"
#include "res_io.h"
#include "time-types.h"
#include "math-helper.h"
#include "stl-helper.h"
#include "blocking.h"
const unsigned int UNLIMITED = UINT_MAX;
std::ostream& operator<<(std::ostream &os, const TaskInfo &ti)
{
os << "TaskInfo[";
if (ti.get_priority() != UINT_MAX)
os << "priority="
<< ti.get_priority() << ", ";
os << "period="
<< ti.get_period() << ", response="
<< ti.get_response() << ", cluster="
<< ti.get_cluster() << ", requests=<";
foreach(ti.get_requests(), it)
{
if (it != ti.get_requests().begin())
os << " ";
os << (*it);
}
os << ">]";
return os;
}
std::ostream& operator<<(std::ostream &os, const RequestBound &rb)
{
os << "(res-id="
<< rb.get_resource_id() << ", num="
<< rb.get_num_requests() << ", len="
<< rb.get_request_length() << ")";
return os;
}
std::ostream& operator<<(std::ostream &os, const ResourceSharingInfo &rsi)
{
foreach(rsi.get_tasks(), it)
{
const TaskInfo& tsk = *it;
os << "\t" << tsk << std::endl;
}
return os;
}
unsigned int RequestBound::get_max_num_requests(unsigned long interval) const
{
unsigned long num_jobs;
num_jobs = divide_with_ceil(interval + task->get_response(),
task->get_period());
return (unsigned int) (num_jobs * num_requests);
}
// ****** non-exported helpers *******
void split_by_cluster(const ResourceSharingInfo& info, Clusters& clusters)
{
foreach(info.get_tasks(), it)
{
const TaskInfo& tsk = *it;
unsigned int cluster = tsk.get_cluster();
while (cluster >= clusters.size())
clusters.push_back(Cluster());
clusters[cluster].push_back(&tsk);
}
}
bool has_higher_priority(const TaskInfo* a, const TaskInfo* b)
{
return a->get_priority() < b->get_priority();
}
void sort_by_priority(Clusters& clusters)
{
foreach(clusters, it)
{
Cluster& cluster = *it;
std::sort(cluster.begin(), cluster.end(), has_higher_priority);
}
}
void split_by_resource(const ResourceSharingInfo& info, Resources& resources)
{
foreach(info.get_tasks(), it)
{
const TaskInfo& tsk = *it;
foreach(tsk.get_requests(), jt)
{
const RequestBound& req = *jt;
unsigned int res = req.get_resource_id();
while (res >= resources.size())
resources.push_back(ContentionSet());
resources[res].push_back(&req);
}
}
}
void split_by_resource(const Cluster& cluster, Resources& resources)
{
foreach(cluster, it)
{
const TaskInfo* tsk = *it;
foreach(tsk->get_requests(), jt)
{
const RequestBound& req = *jt;
unsigned int res = req.get_resource_id();
while (res >= resources.size())
resources.push_back(ContentionSet());
resources[res].push_back(&req);
}
}
}
void split_by_resource(const Clusters& clusters,
ClusterResources& resources)
{
foreach(clusters, it)
{
resources.push_back(Resources());
split_by_resource(*it, resources.back());
}
}
void split_by_type(const ContentionSet& requests,
ContentionSet& reads,
ContentionSet& writes)
{
foreach(requests, it)
{
const RequestBound *req = *it;
if (req->get_request_type() == READ)
reads.push_back(req);
else
writes.push_back(req);
}
}
void split_by_type(const Resources& resources,
Resources &reads,
Resources &writes)
{
reads.reserve(resources.size());
writes.reserve(resources.size());
foreach(resources, it)
{
reads.push_back(ContentionSet());
writes.push_back(ContentionSet());
split_by_type(*it, reads.back(), writes.back());
}
}
void split_by_type(const ClusterResources& per_cluster,
ClusterResources &reads,
ClusterResources &writes)
{
reads.reserve(per_cluster.size());
writes.reserve(per_cluster.size());
foreach(per_cluster, it)
{
reads.push_back(Resources());
writes.push_back(Resources());
split_by_type(*it, reads.back(), writes.back());
}
}
static bool has_longer_request_length(const RequestBound* a,
const RequestBound* b)
{
return a->get_request_length() > b->get_request_length();
}
void sort_by_request_length(ContentionSet& cs)
{
std::sort(cs.begin(), cs.end(), has_longer_request_length);
}
static bool has_longer_request_length_lcs(const LimitedRequestBound &a,
const LimitedRequestBound &b)
{
return has_longer_request_length(a.request_bound, b.request_bound);
}
void sort_by_request_length(LimitedContentionSet &lcs)
{
std::sort(lcs.begin(), lcs.end(), has_longer_request_length_lcs);
}
void sort_by_request_length(Resources& resources)
{
apply_foreach(resources, sort_by_request_length);
}
void sort_by_request_length(ClusterResources& resources)
{
apply_foreach(resources, sort_by_request_length);
}
void determine_priority_ceilings(const Resources& resources,
PriorityCeilings& ceilings)
{
ceilings.reserve(resources.size());
foreach(resources, it)
{
unsigned int ceiling = UINT_MAX;
const ContentionSet& cs = *it;
foreach(cs, jt)
{
const RequestBound* req = *jt;
ceiling = std::min(ceiling, req->get_task()->get_priority());
}
ceilings.push_back(ceiling);
}
}
PriorityCeilings get_priority_ceilings(const ResourceSharingInfo& info)
{
Resources resources;
PriorityCeilings ceilings;
split_by_resource(info, resources);
determine_priority_ceilings(resources, ceilings);
return ceilings;
}
typedef std::vector<TaskContention> ClusterContention;
typedef std::vector<ContentionSet> TaskContention;
Interference bound_blocking(const ContentionSet& cont,
unsigned long interval,
unsigned int max_total_requests,
unsigned int max_requests_per_source,
const TaskInfo* exclude_tsk,
// Note: the following parameter excludes
// *high-priority* tasks. Used to exclude local higher-priority tasks.
// Default: all tasks can block (suitable for remote blocking).
unsigned int min_priority /* default == 0 */)
{
Interference inter;
unsigned int remaining;
remaining = max_total_requests;
foreach(cont, it)
{
const RequestBound* req = *it;
if (!remaining)
break;
// only use this source if it is not excluded
if (req->get_task() != exclude_tsk &&
req->get_task()->get_priority() >= min_priority)
{
unsigned int num;
// This makes the assumption that there is only one
// request object per task. This makes sense if the
// contention set has been split by resource. This may
// be pessimistic for contention sets that contain
// request objects for multiple resources. The
// assumption also works out if max_total_requests ==
// max_requests_per_source.
num = std::min(req->get_max_num_requests(interval),
max_requests_per_source);
num = std::min(num, remaining);
inter.total_length += num * req->get_request_length();
inter.count += num;
remaining -= num;
}
}
return inter;
}
Interference bound_blocking(const ContentionSet& cont,
unsigned long interval,
unsigned int max_total_requests,
unsigned int max_requests_per_source,
bool exclude_whole_cluster,
const TaskInfo* exclude_tsk)
{
Interference inter;
unsigned int remaining;
remaining = max_total_requests;
foreach(cont, it)
{
const RequestBound* req = *it;
if (!remaining)
break;
// only use this source if it is not excluded
if (req->get_task() != exclude_tsk &&
(!exclude_whole_cluster ||
req->get_task()->get_cluster() != exclude_tsk->get_cluster()))
{
unsigned int num;
num = std::min(req->get_max_num_requests(interval),
max_requests_per_source);
num = std::min(num, remaining);
inter.total_length += num * req->get_request_length();
inter.count += num;
remaining -= num;
}
}
return inter;
}
Interference bound_blocking_all_clusters(
const ClusterResources& clusters,
const ClusterLimits& limits,
unsigned int res_id,
unsigned long interval,
const TaskInfo* exclude_tsk)
{
Interference inter;
unsigned int i;
// add interference from each non-excluded cluster
enumerate(clusters, it, i)
{
const Resources& resources = *it;
const ClusterLimit& limit = limits[i];
if (resources.size() > res_id)
inter += bound_blocking(resources[res_id],
interval,
limit.max_total_requests,
limit.max_requests_per_source,
exclude_tsk);
}
return inter;
}
static Interference max_local_request_span(const TaskInfo &tsk,
const TaskInfos &tasks,
const BlockingBounds& bounds)
{
Interference span;
unsigned int i = 0;
enumerate(tasks, it, i)
{
const TaskInfo& t = *it;
if (&t != &tsk)
{
// only consider local, lower-priority tasks
if (t.get_cluster() == tsk.get_cluster() &&
t.get_priority() >= tsk.get_priority())
{
Interference b = bounds.get_max_request_span(i);
span = std::max(span, b);
}
}
}
return span;
}
void charge_arrival_blocking(const ResourceSharingInfo& info,
BlockingBounds& bounds)
{
unsigned int i = 0;
const TaskInfos& tasks = info.get_tasks();
enumerate(tasks, it, i)
{
Interference inf = max_local_request_span(*it, tasks, bounds);
bounds[i] += inf; // charge to total
bounds.set_arrival_blocking(i, inf);
}
}
// **** blocking term analysis ****
ClusterLimits np_fifo_limits(
const TaskInfo& tsk, const ClusterResources& clusters,
unsigned int procs_per_cluster,
const unsigned int issued,
int dedicated_irq)
{
ClusterLimits limits;
int idx;
limits.reserve(clusters.size());
enumerate(clusters, ct, idx)
{
unsigned int total, parallelism = procs_per_cluster;
if (idx == dedicated_irq)
parallelism--;
if (parallelism && (int) tsk.get_cluster() == idx)
parallelism--;
// At most one blocking request per remote CPU in
// cluster per request.
total = issued * parallelism;
limits.push_back(ClusterLimit(total, issued));
}
return limits;
}
Interference np_fifo_per_resource(
const TaskInfo& tsk, const ClusterResources& clusters,
unsigned int procs_per_cluster,
unsigned int res_id, unsigned int issued,
int dedicated_irq)
{
const unsigned long interval = tsk.get_response();
ClusterLimits limits = np_fifo_limits(tsk, clusters, procs_per_cluster,
issued, dedicated_irq);
return bound_blocking_all_clusters(clusters,
limits,
res_id,
interval,
&tsk);
}
#include "rw-blocking.h"
void merge_rw_requests(const TaskInfo &tsk, RWCounts &counts)
{
foreach(tsk.get_requests(), req)
{
unsigned int res_id = req->get_resource_id();
while (counts.size() <= res_id)
counts.push_back(RWCount(counts.size()));
if (req->is_read())
{
counts[res_id].num_reads += req->get_num_requests();
counts[res_id].rlength = req->get_request_length();
}
else
{
counts[res_id].num_writes += req->get_num_requests();
counts[res_id].wlength = req->get_request_length();
}
}
}
|