diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-07 13:51:20 -0400 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2013-02-12 06:49:39 -0500 |
| commit | 6bd218ab3d181a6295de0da88489abe40ffd3cec (patch) | |
| tree | 1728ec9175b18d31ab795b5c7912828bcdeb2d71 /native/include | |
| parent | 54d69ea3e123b20303871b0179599f92a39aafdf (diff) | |
Extract sharedres_types.h from sharedres.h
The LP code requires many of the same definitions. Therefore, this patch splits the reusable
type definitions into an individual file to facilitate inclusion.
Diffstat (limited to 'native/include')
| -rw-r--r-- | native/include/sharedres.h | 385 | ||||
| -rw-r--r-- | native/include/sharedres_types.h | 390 |
2 files changed, 391 insertions, 384 deletions
diff --git a/native/include/sharedres.h b/native/include/sharedres.h index c0b2e3a..7765fd8 100644 --- a/native/include/sharedres.h +++ b/native/include/sharedres.h | |||
| @@ -1,390 +1,7 @@ | |||
| 1 | #ifndef SHAREDRES_H | 1 | #ifndef SHAREDRES_H |
| 2 | #define SHAREDRES_H | 2 | #define SHAREDRES_H |
| 3 | 3 | ||
| 4 | #ifndef SWIG | 4 | #include "sharedres_types.h" |
| 5 | #include <limits.h> | ||
| 6 | #include <assert.h> | ||
| 7 | |||
| 8 | #include <vector> | ||
| 9 | #include <algorithm> | ||
| 10 | #endif | ||
| 11 | |||
| 12 | typedef enum { | ||
| 13 | WRITE = 0, | ||
| 14 | READ = 1, | ||
| 15 | } request_type_t; | ||
| 16 | |||
| 17 | class TaskInfo; | ||
| 18 | |||
| 19 | class RequestBound | ||
| 20 | { | ||
| 21 | private: | ||
| 22 | unsigned int resource_id; | ||
| 23 | unsigned int num_requests; | ||
| 24 | unsigned int request_length; | ||
| 25 | const TaskInfo* task; | ||
| 26 | request_type_t request_type; | ||
| 27 | |||
| 28 | public: | ||
| 29 | RequestBound(unsigned int res_id, | ||
| 30 | unsigned int num, | ||
| 31 | unsigned int length, | ||
| 32 | const TaskInfo* tsk, | ||
| 33 | request_type_t type = WRITE) | ||
| 34 | : resource_id(res_id), | ||
| 35 | num_requests(num), | ||
| 36 | request_length(length), | ||
| 37 | task(tsk), | ||
| 38 | request_type(type) | ||
| 39 | {} | ||
| 40 | |||
| 41 | unsigned int get_max_num_requests(unsigned long interval) const; | ||
| 42 | |||
| 43 | unsigned int get_resource_id() const { return resource_id; } | ||
| 44 | unsigned int get_num_requests() const { return num_requests; } | ||
| 45 | unsigned int get_request_length() const { return request_length; } | ||
| 46 | |||
| 47 | request_type_t get_request_type() const { return request_type; } | ||
| 48 | |||
| 49 | bool is_read() const { return get_request_type() == READ; } | ||
| 50 | bool is_write() const { return get_request_type() == WRITE; } | ||
| 51 | |||
| 52 | const TaskInfo* get_task() const { return task; } | ||
| 53 | }; | ||
| 54 | |||
| 55 | typedef std::vector<RequestBound> Requests; | ||
| 56 | |||
| 57 | class TaskInfo | ||
| 58 | { | ||
| 59 | private: | ||
| 60 | unsigned int priority; | ||
| 61 | unsigned long period; | ||
| 62 | unsigned long response; | ||
| 63 | unsigned int cluster; | ||
| 64 | |||
| 65 | Requests requests; | ||
| 66 | |||
| 67 | public: | ||
| 68 | TaskInfo(unsigned long _period, | ||
| 69 | unsigned long _response, | ||
| 70 | unsigned int _cluster, | ||
| 71 | unsigned int _priority) | ||
| 72 | : priority(_priority), | ||
| 73 | period(_period), | ||
| 74 | response(_response), | ||
| 75 | cluster(_cluster) | ||
| 76 | {} | ||
| 77 | |||
| 78 | void add_request(unsigned int res_id, | ||
| 79 | unsigned int num, | ||
| 80 | unsigned int length, | ||
| 81 | request_type_t type = WRITE) | ||
| 82 | { | ||
| 83 | requests.push_back(RequestBound(res_id, num, length, this, type)); | ||
| 84 | } | ||
| 85 | |||
| 86 | const Requests& get_requests() const | ||
| 87 | { | ||
| 88 | return requests; | ||
| 89 | } | ||
| 90 | |||
| 91 | unsigned int get_priority() const { return priority; } | ||
| 92 | unsigned long get_period() const { return period; } | ||
| 93 | unsigned long get_response() const { return response; } | ||
| 94 | unsigned int get_cluster() const { return cluster; } | ||
| 95 | |||
| 96 | unsigned int get_num_arrivals() const | ||
| 97 | { | ||
| 98 | return get_total_num_requests() + 1; // one for the job release | ||
| 99 | } | ||
| 100 | |||
| 101 | unsigned int get_total_num_requests() const | ||
| 102 | { | ||
| 103 | unsigned int count = 0; | ||
| 104 | Requests::const_iterator it; | ||
| 105 | for (it = requests.begin(); | ||
| 106 | it != requests.end(); | ||
| 107 | it++) | ||
| 108 | count += it->get_num_requests(); | ||
| 109 | return count; | ||
| 110 | } | ||
| 111 | |||
| 112 | unsigned int get_max_request_length() const | ||
| 113 | { | ||
| 114 | unsigned int len = 0; | ||
| 115 | Requests::const_iterator it; | ||
| 116 | for (it = requests.begin(); | ||
| 117 | it != requests.end(); | ||
| 118 | it++) | ||
| 119 | len = std::max(len, it->get_request_length()); | ||
| 120 | return len; | ||
| 121 | } | ||
| 122 | |||
| 123 | }; | ||
| 124 | |||
| 125 | typedef std::vector<TaskInfo> TaskInfos; | ||
| 126 | |||
| 127 | class ResourceSharingInfo | ||
| 128 | { | ||
| 129 | private: | ||
| 130 | TaskInfos tasks; | ||
| 131 | |||
| 132 | public: | ||
| 133 | ResourceSharingInfo(unsigned int num_tasks) | ||
| 134 | { | ||
| 135 | // Make sure all tasks will fit without re-allocation. | ||
| 136 | tasks.reserve(num_tasks); | ||
| 137 | } | ||
| 138 | |||
| 139 | const TaskInfos& get_tasks() const | ||
| 140 | { | ||
| 141 | return tasks; | ||
| 142 | } | ||
| 143 | |||
| 144 | void add_task(unsigned long period, | ||
| 145 | unsigned long response, | ||
| 146 | unsigned int cluster = 0, | ||
| 147 | unsigned int priority = UINT_MAX) | ||
| 148 | { | ||
| 149 | // Avoid re-allocation! | ||
| 150 | assert(tasks.size() < tasks.capacity()); | ||
| 151 | tasks.push_back(TaskInfo(period, response, cluster, priority)); | ||
| 152 | } | ||
| 153 | |||
| 154 | void add_request(unsigned int resource_id, | ||
| 155 | unsigned int max_num, | ||
| 156 | unsigned int max_length) | ||
| 157 | { | ||
| 158 | assert(!tasks.empty()); | ||
| 159 | |||
| 160 | TaskInfo& last_added = tasks.back(); | ||
| 161 | last_added.add_request(resource_id, max_num, max_length); | ||
| 162 | } | ||
| 163 | |||
| 164 | void add_request_rw(unsigned int resource_id, | ||
| 165 | unsigned int max_num, | ||
| 166 | unsigned int max_length, | ||
| 167 | int type) | ||
| 168 | { | ||
| 169 | assert(!tasks.empty()); | ||
| 170 | assert(type == WRITE || type == READ); | ||
| 171 | |||
| 172 | TaskInfo& last_added = tasks.back(); | ||
| 173 | last_added.add_request(resource_id, max_num, max_length, (request_type_t) type); | ||
| 174 | } | ||
| 175 | |||
| 176 | }; | ||
| 177 | |||
| 178 | |||
| 179 | #define NO_CPU (-1) | ||
| 180 | |||
| 181 | class ResourceLocality | ||
| 182 | { | ||
| 183 | private: | ||
| 184 | std::vector<int> mapping; | ||
| 185 | |||
| 186 | public: | ||
| 187 | void assign_resource(unsigned int res_id, unsigned int processor) | ||
| 188 | { | ||
| 189 | while (mapping.size() <= res_id) | ||
| 190 | mapping.push_back(NO_CPU); | ||
| 191 | |||
| 192 | mapping[res_id] = processor; | ||
| 193 | } | ||
| 194 | |||
| 195 | int operator[](unsigned int res_id) const | ||
| 196 | { | ||
| 197 | if (mapping.size() <= res_id) | ||
| 198 | return NO_CPU; | ||
| 199 | else | ||
| 200 | return mapping[res_id]; | ||
| 201 | } | ||
| 202 | |||
| 203 | }; | ||
| 204 | |||
| 205 | class ReplicaInfo | ||
| 206 | { | ||
| 207 | private: | ||
| 208 | std::vector<unsigned int> num_replicas; | ||
| 209 | |||
| 210 | public: | ||
| 211 | void set_replicas(unsigned int res_id, unsigned int replicas) | ||
| 212 | { | ||
| 213 | assert(replicas >= 1); | ||
| 214 | |||
| 215 | while (num_replicas.size() <= res_id) | ||
| 216 | num_replicas.push_back(1); // default: not replicated | ||
| 217 | |||
| 218 | num_replicas[res_id] = replicas; | ||
| 219 | } | ||
| 220 | |||
| 221 | unsigned int operator[](unsigned int res_id) const | ||
| 222 | { | ||
| 223 | if (num_replicas.size() <= res_id) | ||
| 224 | return 1; // default: not replicated | ||
| 225 | else | ||
| 226 | return num_replicas[res_id]; | ||
| 227 | } | ||
| 228 | }; | ||
| 229 | |||
| 230 | struct Interference | ||
| 231 | { | ||
| 232 | unsigned int count; | ||
| 233 | unsigned long total_length; | ||
| 234 | |||
| 235 | Interference() : count(0), total_length(0) {} | ||
| 236 | |||
| 237 | Interference& operator+=(const Interference& other) | ||
| 238 | { | ||
| 239 | count += other.count; | ||
| 240 | total_length += other.total_length; | ||
| 241 | return *this; | ||
| 242 | } | ||
| 243 | |||
| 244 | Interference operator+(const Interference& other) const | ||
| 245 | { | ||
| 246 | Interference result; | ||
| 247 | result.count = this->count + other.count; | ||
| 248 | result.total_length = this->total_length + other.total_length; | ||
| 249 | return result; | ||
| 250 | } | ||
| 251 | |||
| 252 | bool operator<(const Interference& other) const | ||
| 253 | { | ||
| 254 | return total_length < other.total_length || | ||
| 255 | (total_length == other.total_length | ||
| 256 | && count < other.count); | ||
| 257 | } | ||
| 258 | }; | ||
| 259 | |||
| 260 | class BlockingBounds | ||
| 261 | { | ||
| 262 | private: | ||
| 263 | std::vector<Interference> blocking; | ||
| 264 | std::vector<Interference> request_span; | ||
| 265 | std::vector<Interference> arrival; | ||
| 266 | std::vector<Interference> remote; | ||
| 267 | std::vector<Interference> local; | ||
| 268 | |||
| 269 | public: | ||
| 270 | BlockingBounds(unsigned int num_tasks) | ||
| 271 | : blocking(num_tasks), | ||
| 272 | request_span(num_tasks) | ||
| 273 | {} | ||
| 274 | |||
| 275 | BlockingBounds(const ResourceSharingInfo& info) | ||
| 276 | : blocking(info.get_tasks().size()), | ||
| 277 | request_span(info.get_tasks().size()), | ||
| 278 | arrival(info.get_tasks().size()), | ||
| 279 | remote(info.get_tasks().size()), | ||
| 280 | local(info.get_tasks().size()) | ||
| 281 | {} | ||
| 282 | |||
| 283 | const Interference& operator[](unsigned int idx) const | ||
| 284 | { | ||
| 285 | assert( idx < size() ); | ||
| 286 | return blocking[idx]; | ||
| 287 | } | ||
| 288 | |||
| 289 | Interference& operator[](unsigned int idx) | ||
| 290 | { | ||
| 291 | assert( idx < size() ); | ||
| 292 | return blocking[idx]; | ||
| 293 | } | ||
| 294 | |||
| 295 | void raise_request_span(unsigned idx, const Interference& val) | ||
| 296 | { | ||
| 297 | assert( idx < size() ); | ||
| 298 | request_span[idx] = std::max(request_span[idx], val); | ||
| 299 | } | ||
| 300 | |||
| 301 | const Interference& get_max_request_span(unsigned idx) const | ||
| 302 | { | ||
| 303 | assert( idx < size() ); | ||
| 304 | return request_span[idx]; | ||
| 305 | } | ||
| 306 | |||
| 307 | size_t size() const | ||
| 308 | { | ||
| 309 | return blocking.size(); | ||
| 310 | } | ||
| 311 | |||
| 312 | unsigned long get_blocking_term(unsigned int tsk_index) const | ||
| 313 | { | ||
| 314 | assert( tsk_index < blocking.size() ); | ||
| 315 | return blocking[tsk_index].total_length; | ||
| 316 | } | ||
| 317 | |||
| 318 | unsigned long get_blocking_count(unsigned int tsk_index) const | ||
| 319 | { | ||
| 320 | assert( tsk_index < blocking.size() ); | ||
| 321 | return blocking[tsk_index].count; | ||
| 322 | } | ||
| 323 | |||
| 324 | unsigned long get_span_term(unsigned int tsk_index) const | ||
| 325 | { | ||
| 326 | assert( tsk_index < blocking.size() ); | ||
| 327 | return request_span[tsk_index].total_length; | ||
| 328 | } | ||
| 329 | |||
| 330 | unsigned long get_span_count(unsigned int tsk_index) const | ||
| 331 | { | ||
| 332 | assert( tsk_index < blocking.size() ); | ||
| 333 | return request_span[tsk_index].count; | ||
| 334 | } | ||
| 335 | |||
| 336 | |||
| 337 | unsigned long get_remote_blocking(unsigned int tsk_index) const | ||
| 338 | { | ||
| 339 | assert( tsk_index < remote.size() ); | ||
| 340 | return remote[tsk_index].total_length; | ||
| 341 | } | ||
| 342 | |||
| 343 | unsigned long get_remote_count(unsigned int tsk_index) const | ||
| 344 | { | ||
| 345 | assert( tsk_index < remote.size() ); | ||
| 346 | return remote[tsk_index].count; | ||
| 347 | } | ||
| 348 | |||
| 349 | void set_remote_blocking(unsigned int tsk_index, | ||
| 350 | const Interference& inf) | ||
| 351 | { | ||
| 352 | assert( tsk_index < remote.size() ); | ||
| 353 | remote[tsk_index] = inf; | ||
| 354 | } | ||
| 355 | |||
| 356 | unsigned long get_local_blocking(unsigned int tsk_index) const | ||
| 357 | { | ||
| 358 | assert( tsk_index < local.size() ); | ||
| 359 | return local[tsk_index].total_length; | ||
| 360 | } | ||
| 361 | |||
| 362 | unsigned long get_local_count(unsigned int tsk_index) const | ||
| 363 | { | ||
| 364 | assert( tsk_index < local.size() ); | ||
| 365 | return local[tsk_index].count; | ||
| 366 | } | ||
| 367 | |||
| 368 | void set_local_blocking(unsigned int tsk_index, | ||
| 369 | const Interference& inf) | ||
| 370 | { | ||
| 371 | assert( tsk_index < local.size() ); | ||
| 372 | local[tsk_index] = inf; | ||
| 373 | } | ||
| 374 | |||
| 375 | unsigned long get_arrival_blocking(unsigned int tsk_index) const | ||
| 376 | { | ||
| 377 | assert( tsk_index < arrival.size() ); | ||
| 378 | return arrival[tsk_index].total_length; | ||
| 379 | } | ||
| 380 | |||
| 381 | void set_arrival_blocking(unsigned int tsk_index, | ||
| 382 | const Interference& inf) | ||
| 383 | { | ||
| 384 | assert( tsk_index < arrival.size() ); | ||
| 385 | arrival[tsk_index] = inf; | ||
| 386 | } | ||
| 387 | }; | ||
| 388 | 5 | ||
| 389 | // spinlocks | 6 | // spinlocks |
| 390 | 7 | ||
diff --git a/native/include/sharedres_types.h b/native/include/sharedres_types.h new file mode 100644 index 0000000..17fda46 --- /dev/null +++ b/native/include/sharedres_types.h | |||
| @@ -0,0 +1,390 @@ | |||
| 1 | #ifndef SHAREDRES_TYPES_H | ||
| 2 | #define SHAREDRES_TYPES_H | ||
| 3 | |||
| 4 | #ifndef SWIG | ||
| 5 | #include <limits.h> | ||
| 6 | #include <assert.h> | ||
| 7 | |||
| 8 | #include <vector> | ||
| 9 | #include <algorithm> | ||
| 10 | #endif | ||
| 11 | |||
| 12 | typedef enum { | ||
| 13 | WRITE = 0, | ||
| 14 | READ = 1, | ||
| 15 | } request_type_t; | ||
| 16 | |||
| 17 | class TaskInfo; | ||
| 18 | |||
| 19 | class RequestBound | ||
| 20 | { | ||
| 21 | private: | ||
| 22 | unsigned int resource_id; | ||
| 23 | unsigned int num_requests; | ||
| 24 | unsigned int request_length; | ||
| 25 | const TaskInfo* task; | ||
| 26 | request_type_t request_type; | ||
| 27 | |||
| 28 | public: | ||
| 29 | RequestBound(unsigned int res_id, | ||
| 30 | unsigned int num, | ||
| 31 | unsigned int length, | ||
| 32 | const TaskInfo* tsk, | ||
| 33 | request_type_t type = WRITE) | ||
| 34 | : resource_id(res_id), | ||
| 35 | num_requests(num), | ||
| 36 | request_length(length), | ||
| 37 | task(tsk), | ||
| 38 | request_type(type) | ||
| 39 | {} | ||
| 40 | |||
| 41 | unsigned int get_max_num_requests(unsigned long interval) const; | ||
| 42 | |||
| 43 | unsigned int get_resource_id() const { return resource_id; } | ||
| 44 | unsigned int get_num_requests() const { return num_requests; } | ||
| 45 | unsigned int get_request_length() const { return request_length; } | ||
| 46 | |||
| 47 | request_type_t get_request_type() const { return request_type; } | ||
| 48 | |||
| 49 | bool is_read() const { return get_request_type() == READ; } | ||
| 50 | bool is_write() const { return get_request_type() == WRITE; } | ||
| 51 | |||
| 52 | const TaskInfo* get_task() const { return task; } | ||
| 53 | }; | ||
| 54 | |||
| 55 | typedef std::vector<RequestBound> Requests; | ||
| 56 | |||
| 57 | class TaskInfo | ||
| 58 | { | ||
| 59 | private: | ||
| 60 | unsigned int priority; | ||
| 61 | unsigned long period; | ||
| 62 | unsigned long response; | ||
| 63 | unsigned int cluster; | ||
| 64 | |||
| 65 | Requests requests; | ||
| 66 | |||
| 67 | public: | ||
| 68 | TaskInfo(unsigned long _period, | ||
| 69 | unsigned long _response, | ||
| 70 | unsigned int _cluster, | ||
| 71 | unsigned int _priority) | ||
| 72 | : priority(_priority), | ||
| 73 | period(_period), | ||
| 74 | response(_response), | ||
| 75 | cluster(_cluster) | ||
| 76 | {} | ||
| 77 | |||
| 78 | void add_request(unsigned int res_id, | ||
| 79 | unsigned int num, | ||
| 80 | unsigned int length, | ||
| 81 | request_type_t type = WRITE) | ||
| 82 | { | ||
| 83 | requests.push_back(RequestBound(res_id, num, length, this, type)); | ||
| 84 | } | ||
| 85 | |||
| 86 | const Requests& get_requests() const | ||
| 87 | { | ||
| 88 | return requests; | ||
| 89 | } | ||
| 90 | |||
| 91 | unsigned int get_priority() const { return priority; } | ||
| 92 | unsigned long get_period() const { return period; } | ||
| 93 | unsigned long get_response() const { return response; } | ||
| 94 | unsigned int get_cluster() const { return cluster; } | ||
| 95 | |||
| 96 | unsigned int get_num_arrivals() const | ||
| 97 | { | ||
| 98 | return get_total_num_requests() + 1; // one for the job release | ||
| 99 | } | ||
| 100 | |||
| 101 | unsigned int get_total_num_requests() const | ||
| 102 | { | ||
| 103 | unsigned int count = 0; | ||
| 104 | Requests::const_iterator it; | ||
| 105 | for (it = requests.begin(); | ||
| 106 | it != requests.end(); | ||
| 107 | it++) | ||
| 108 | count += it->get_num_requests(); | ||
| 109 | return count; | ||
| 110 | } | ||
| 111 | |||
| 112 | unsigned int get_max_request_length() const | ||
| 113 | { | ||
| 114 | unsigned int len = 0; | ||
| 115 | Requests::const_iterator it; | ||
| 116 | for (it = requests.begin(); | ||
| 117 | it != requests.end(); | ||
| 118 | it++) | ||
| 119 | len = std::max(len, it->get_request_length()); | ||
| 120 | return len; | ||
| 121 | } | ||
| 122 | |||
| 123 | }; | ||
| 124 | |||
| 125 | typedef std::vector<TaskInfo> TaskInfos; | ||
| 126 | |||
| 127 | class ResourceSharingInfo | ||
| 128 | { | ||
| 129 | private: | ||
| 130 | TaskInfos tasks; | ||
| 131 | |||
| 132 | public: | ||
| 133 | ResourceSharingInfo(unsigned int num_tasks) | ||
| 134 | { | ||
| 135 | // Make sure all tasks will fit without re-allocation. | ||
| 136 | tasks.reserve(num_tasks); | ||
| 137 | } | ||
| 138 | |||
| 139 | const TaskInfos& get_tasks() const | ||
| 140 | { | ||
| 141 | return tasks; | ||
| 142 | } | ||
| 143 | |||
| 144 | void add_task(unsigned long period, | ||
| 145 | unsigned long response, | ||
| 146 | unsigned int cluster = 0, | ||
| 147 | unsigned int priority = UINT_MAX) | ||
| 148 | { | ||
| 149 | // Avoid re-allocation! | ||
| 150 | assert(tasks.size() < tasks.capacity()); | ||
| 151 | tasks.push_back(TaskInfo(period, response, cluster, priority)); | ||
| 152 | } | ||
| 153 | |||
| 154 | void add_request(unsigned int resource_id, | ||
| 155 | unsigned int max_num, | ||
| 156 | unsigned int max_length) | ||
| 157 | { | ||
| 158 | assert(!tasks.empty()); | ||
| 159 | |||
| 160 | TaskInfo& last_added = tasks.back(); | ||
| 161 | last_added.add_request(resource_id, max_num, max_length); | ||
| 162 | } | ||
| 163 | |||
| 164 | void add_request_rw(unsigned int resource_id, | ||
| 165 | unsigned int max_num, | ||
| 166 | unsigned int max_length, | ||
| 167 | int type) | ||
| 168 | { | ||
| 169 | assert(!tasks.empty()); | ||
| 170 | assert(type == WRITE || type == READ); | ||
| 171 | |||
| 172 | TaskInfo& last_added = tasks.back(); | ||
| 173 | last_added.add_request(resource_id, max_num, max_length, (request_type_t) type); | ||
| 174 | } | ||
| 175 | |||
| 176 | }; | ||
| 177 | |||
| 178 | |||
| 179 | #define NO_CPU (-1) | ||
| 180 | |||
| 181 | class ResourceLocality | ||
| 182 | { | ||
| 183 | private: | ||
| 184 | std::vector<int> mapping; | ||
| 185 | |||
| 186 | public: | ||
| 187 | void assign_resource(unsigned int res_id, unsigned int processor) | ||
| 188 | { | ||
| 189 | while (mapping.size() <= res_id) | ||
| 190 | mapping.push_back(NO_CPU); | ||
| 191 | |||
| 192 | mapping[res_id] = processor; | ||
| 193 | } | ||
| 194 | |||
| 195 | int operator[](unsigned int res_id) const | ||
| 196 | { | ||
| 197 | if (mapping.size() <= res_id) | ||
| 198 | return NO_CPU; | ||
| 199 | else | ||
| 200 | return mapping[res_id]; | ||
| 201 | } | ||
| 202 | |||
| 203 | }; | ||
| 204 | |||
| 205 | class ReplicaInfo | ||
| 206 | { | ||
| 207 | private: | ||
| 208 | std::vector<unsigned int> num_replicas; | ||
| 209 | |||
| 210 | public: | ||
| 211 | void set_replicas(unsigned int res_id, unsigned int replicas) | ||
| 212 | { | ||
| 213 | assert(replicas >= 1); | ||
| 214 | |||
| 215 | while (num_replicas.size() <= res_id) | ||
| 216 | num_replicas.push_back(1); // default: not replicated | ||
| 217 | |||
| 218 | num_replicas[res_id] = replicas; | ||
| 219 | } | ||
| 220 | |||
| 221 | unsigned int operator[](unsigned int res_id) const | ||
| 222 | { | ||
| 223 | if (num_replicas.size() <= res_id) | ||
| 224 | return 1; // default: not replicated | ||
| 225 | else | ||
| 226 | return num_replicas[res_id]; | ||
| 227 | } | ||
| 228 | }; | ||
| 229 | |||
| 230 | struct Interference | ||
| 231 | { | ||
| 232 | unsigned int count; | ||
| 233 | unsigned long total_length; | ||
| 234 | |||
| 235 | Interference() : count(0), total_length(0) {} | ||
| 236 | |||
| 237 | Interference& operator+=(const Interference& other) | ||
| 238 | { | ||
| 239 | count += other.count; | ||
| 240 | total_length += other.total_length; | ||
| 241 | return *this; | ||
| 242 | } | ||
| 243 | |||
| 244 | Interference operator+(const Interference& other) const | ||
| 245 | { | ||
| 246 | Interference result; | ||
| 247 | result.count = this->count + other.count; | ||
| 248 | result.total_length = this->total_length + other.total_length; | ||
| 249 | return result; | ||
| 250 | } | ||
| 251 | |||
| 252 | bool operator<(const Interference& other) const | ||
| 253 | { | ||
| 254 | return total_length < other.total_length || | ||
| 255 | (total_length == other.total_length | ||
| 256 | && count < other.count); | ||
| 257 | } | ||
| 258 | }; | ||
| 259 | |||
| 260 | class BlockingBounds | ||
| 261 | { | ||
| 262 | private: | ||
| 263 | std::vector<Interference> blocking; | ||
| 264 | std::vector<Interference> request_span; | ||
| 265 | std::vector<Interference> arrival; | ||
| 266 | std::vector<Interference> remote; | ||
| 267 | std::vector<Interference> local; | ||
| 268 | |||
| 269 | public: | ||
| 270 | BlockingBounds(unsigned int num_tasks) | ||
| 271 | : blocking(num_tasks), | ||
| 272 | request_span(num_tasks) | ||
| 273 | {} | ||
| 274 | |||
| 275 | BlockingBounds(const ResourceSharingInfo& info) | ||
| 276 | : blocking(info.get_tasks().size()), | ||
| 277 | request_span(info.get_tasks().size()), | ||
| 278 | arrival(info.get_tasks().size()), | ||
| 279 | remote(info.get_tasks().size()), | ||
| 280 | local(info.get_tasks().size()) | ||
| 281 | {} | ||
| 282 | |||
| 283 | const Interference& operator[](unsigned int idx) const | ||
| 284 | { | ||
| 285 | assert( idx < size() ); | ||
| 286 | return blocking[idx]; | ||
| 287 | } | ||
| 288 | |||
| 289 | Interference& operator[](unsigned int idx) | ||
| 290 | { | ||
| 291 | assert( idx < size() ); | ||
| 292 | return blocking[idx]; | ||
| 293 | } | ||
| 294 | |||
| 295 | void raise_request_span(unsigned idx, const Interference& val) | ||
| 296 | { | ||
| 297 | assert( idx < size() ); | ||
| 298 | request_span[idx] = std::max(request_span[idx], val); | ||
| 299 | } | ||
| 300 | |||
| 301 | const Interference& get_max_request_span(unsigned idx) const | ||
| 302 | { | ||
| 303 | assert( idx < size() ); | ||
| 304 | return request_span[idx]; | ||
| 305 | } | ||
| 306 | |||
| 307 | size_t size() const | ||
| 308 | { | ||
| 309 | return blocking.size(); | ||
| 310 | } | ||
| 311 | |||
| 312 | unsigned long get_blocking_term(unsigned int tsk_index) const | ||
| 313 | { | ||
| 314 | assert( tsk_index < blocking.size() ); | ||
| 315 | return blocking[tsk_index].total_length; | ||
| 316 | } | ||
| 317 | |||
| 318 | unsigned long get_blocking_count(unsigned int tsk_index) const | ||
| 319 | { | ||
| 320 | assert( tsk_index < blocking.size() ); | ||
| 321 | return blocking[tsk_index].count; | ||
| 322 | } | ||
| 323 | |||
| 324 | unsigned long get_span_term(unsigned int tsk_index) const | ||
| 325 | { | ||
| 326 | assert( tsk_index < blocking.size() ); | ||
| 327 | return request_span[tsk_index].total_length; | ||
| 328 | } | ||
| 329 | |||
| 330 | unsigned long get_span_count(unsigned int tsk_index) const | ||
| 331 | { | ||
| 332 | assert( tsk_index < blocking.size() ); | ||
| 333 | return request_span[tsk_index].count; | ||
| 334 | } | ||
| 335 | |||
| 336 | |||
| 337 | unsigned long get_remote_blocking(unsigned int tsk_index) const | ||
| 338 | { | ||
| 339 | assert( tsk_index < remote.size() ); | ||
| 340 | return remote[tsk_index].total_length; | ||
| 341 | } | ||
| 342 | |||
| 343 | unsigned long get_remote_count(unsigned int tsk_index) const | ||
| 344 | { | ||
| 345 | assert( tsk_index < remote.size() ); | ||
| 346 | return remote[tsk_index].count; | ||
| 347 | } | ||
| 348 | |||
| 349 | void set_remote_blocking(unsigned int tsk_index, | ||
| 350 | const Interference& inf) | ||
| 351 | { | ||
| 352 | assert( tsk_index < remote.size() ); | ||
| 353 | remote[tsk_index] = inf; | ||
| 354 | } | ||
| 355 | |||
| 356 | unsigned long get_local_blocking(unsigned int tsk_index) const | ||
| 357 | { | ||
| 358 | assert( tsk_index < local.size() ); | ||
| 359 | return local[tsk_index].total_length; | ||
| 360 | } | ||
| 361 | |||
| 362 | unsigned long get_local_count(unsigned int tsk_index) const | ||
| 363 | { | ||
| 364 | assert( tsk_index < local.size() ); | ||
| 365 | return local[tsk_index].count; | ||
| 366 | } | ||
| 367 | |||
| 368 | void set_local_blocking(unsigned int tsk_index, | ||
| 369 | const Interference& inf) | ||
| 370 | { | ||
| 371 | assert( tsk_index < local.size() ); | ||
| 372 | local[tsk_index] = inf; | ||
| 373 | } | ||
| 374 | |||
| 375 | unsigned long get_arrival_blocking(unsigned int tsk_index) const | ||
| 376 | { | ||
| 377 | assert( tsk_index < arrival.size() ); | ||
| 378 | return arrival[tsk_index].total_length; | ||
| 379 | } | ||
| 380 | |||
| 381 | void set_arrival_blocking(unsigned int tsk_index, | ||
| 382 | const Interference& inf) | ||
| 383 | { | ||
| 384 | assert( tsk_index < arrival.size() ); | ||
| 385 | arrival[tsk_index] = inf; | ||
| 386 | } | ||
| 387 | }; | ||
| 388 | |||
| 389 | #endif | ||
| 390 | |||
