aboutsummaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-08-07 13:51:20 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2013-02-12 06:49:39 -0500
commit6bd218ab3d181a6295de0da88489abe40ffd3cec (patch)
tree1728ec9175b18d31ab795b5c7912828bcdeb2d71 /native
parent54d69ea3e123b20303871b0179599f92a39aafdf (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')
-rw-r--r--native/include/sharedres.h385
-rw-r--r--native/include/sharedres_types.h390
-rw-r--r--native/interface/locking.i14
-rw-r--r--native/interface/sharedres_types.i13
4 files changed, 405 insertions, 397 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
12typedef enum {
13 WRITE = 0,
14 READ = 1,
15} request_type_t;
16
17class TaskInfo;
18
19class RequestBound
20{
21private:
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
28public:
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
55typedef std::vector<RequestBound> Requests;
56
57class TaskInfo
58{
59private:
60 unsigned int priority;
61 unsigned long period;
62 unsigned long response;
63 unsigned int cluster;
64
65 Requests requests;
66
67public:
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
125typedef std::vector<TaskInfo> TaskInfos;
126
127class ResourceSharingInfo
128{
129private:
130 TaskInfos tasks;
131
132public:
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
181class ResourceLocality
182{
183private:
184 std::vector<int> mapping;
185
186public:
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
205class ReplicaInfo
206{
207private:
208 std::vector<unsigned int> num_replicas;
209
210public:
211 void set_replicas(unsigned int res_id, unsigned int replicas)