aboutsummaryrefslogtreecommitdiffstats
path: root/native/src/sharedres.cpp
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-05-16 11:52:20 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2012-05-16 11:52:20 -0400
commitf906d6f40b3f447fd1ba65df3f5e4406972a2331 (patch)
treeb8929ebda202ad77c37584eebbe275ae0461307b /native/src/sharedres.cpp
parent5fefa18a3dc969640196c1fc9f33b6c1c2a08665 (diff)
C++: Break out the DPCP code into own file
Part of refactoring sharedres.cpp.
Diffstat (limited to 'native/src/sharedres.cpp')
-rw-r--r--native/src/sharedres.cpp202
1 files changed, 6 insertions, 196 deletions
diff --git a/native/src/sharedres.cpp b/native/src/sharedres.cpp
index a691ef9..935d20f 100644
--- a/native/src/sharedres.cpp
+++ b/native/src/sharedres.cpp
@@ -20,6 +20,8 @@
20#define hashmap __gnu_cxx::hash_map 20#define hashmap __gnu_cxx::hash_map
21#endif 21#endif
22 22
23#include "blocking.h"
24
23static const unsigned int UNLIMITED = UINT_MAX; 25static const unsigned int UNLIMITED = UINT_MAX;
24 26
25std::ostream& operator<<(std::ostream &os, const TaskInfo &ti) 27std::ostream& operator<<(std::ostream &os, const TaskInfo &ti)
@@ -108,25 +110,6 @@ void sort_by_priority(Clusters& clusters)
108 } 110 }
109} 111}
110 112
111typedef std::vector<const RequestBound*> ContentionSet;
112typedef std::vector<ContentionSet> Resources;
113typedef std::vector<Resources> ClusterResources;
114
115typedef std::vector<ContentionSet> AllPerCluster;
116
117
118struct LimitedRequestBound {
119 LimitedRequestBound(const RequestBound *rqb, unsigned int l) :
120 request_bound(rqb), limit(l) {};
121 LimitedRequestBound() : request_bound(NULL), limit(0) {};
122
123 const RequestBound *request_bound;
124 unsigned int limit;
125};
126
127typedef std::vector<LimitedRequestBound> LimitedContentionSet;
128
129
130 113
131static void split_by_resource(const ResourceSharingInfo& info, Resources& resources) 114static void split_by_resource(const ResourceSharingInfo& info, Resources& resources)
132{ 115{
@@ -251,7 +234,7 @@ static bool has_longer_request_length(const RequestBound* a,
251 return a->get_request_length() > b->get_request_length(); 234 return a->get_request_length() > b->get_request_length();
252} 235}
253 236
254static void sort_by_request_length(ContentionSet& cs) 237void sort_by_request_length(ContentionSet& cs)
255{ 238{
256 std::sort(cs.begin(), cs.end(), has_longer_request_length); 239 std::sort(cs.begin(), cs.end(), has_longer_request_length);
257} 240}
@@ -262,17 +245,17 @@ static bool has_longer_request_length_lcs(const LimitedRequestBound &a,
262 return has_longer_request_length(a.request_bound, b.request_bound); 245 return has_longer_request_length(a.request_bound, b.request_bound);
263} 246}
264 247
265static void sort_by_request_length(LimitedContentionSet &lcs) 248void sort_by_request_length(LimitedContentionSet &lcs)
266{ 249{
267 std::sort(lcs.begin(), lcs.end(), has_longer_request_length_lcs); 250 std::sort(lcs.begin(), lcs.end(), has_longer_request_length_lcs);
268} 251}
269 252
270static void sort_by_request_length(Resources& resources) 253void sort_by_request_length(Resources& resources)
271{ 254{
272 apply_foreach(resources, sort_by_request_length); 255 apply_foreach(resources, sort_by_request_length);
273} 256}
274 257
275static void sort_by_request_length(ClusterResources& resources) 258void sort_by_request_length(ClusterResources& resources)
276{ 259{
277 apply_foreach(resources, sort_by_request_length); 260 apply_foreach(resources, sort_by_request_length);
278} 261}
@@ -2051,176 +2034,3 @@ BlockingBounds* mpcp_bounds(const ResourceSharingInfo& info,
2051} 2034}
2052 2035
2053 2036
2054// ************************************************** DPCP **************
2055/*
2056
2057 DPCP blocking terms (Rajkumar, 1991, page 87):
2058
2059 1) Local PCP blocking => does not apply here, we only care about global
2060 resources.
2061
2062 2) A lower-priority gcs on a remote proc each time that Ji issues a request.
2063
2064 3) All requests of all higher-priority tasks on all remote processors that Ji
2065 accesses.
2066
2067 4) Global critical sections on Ji's CPU. Since gcs are not part of the job
2068 execution time in our model, it does not matter whether the local gcs's
2069 belong to lower or higher-priority tasks.
2070 */
2071
2072
2073static void split_by_locality(const ResourceSharingInfo& info,
2074 const ResourceLocality& locality,
2075 AllPerCluster& per_cluster)
2076{
2077 foreach(info.get_tasks(), it)
2078 {
2079 while (it->get_cluster() >= per_cluster.size())
2080 per_cluster.push_back(ContentionSet());
2081
2082 foreach(it->get_requests(), jt)
2083 {
2084 const RequestBound &req = *jt;
2085 int cpu = locality[req.get_resource_id()];
2086
2087 if (cpu == NO_CPU)
2088 // NO_CPU => dedicated synchronization processor
2089 continue;
2090
2091 while ((unsigned int) cpu >= per_cluster.size())
2092 per_cluster.push_back(ContentionSet());
2093
2094 per_cluster[cpu].push_back(&req);
2095 }
2096 }
2097}
2098
2099static unsigned int count_requests_to_cpu(
2100 const TaskInfo& tsk,
2101 const ResourceLocality& locality,
2102 int cpu)
2103{
2104 unsigned int count = 0;
2105
2106 foreach(tsk.get_requests(), req)
2107 if (locality[req->get_resource_id()] == cpu)
2108 count += req->get_num_requests();
2109
2110 return count;
2111}
2112
2113static Interference bound_blocking_dpcp(
2114 const TaskInfo* tsk,
2115 const ContentionSet& cont,
2116 unsigned int max_lower_prio)
2117{
2118 Interference inter;
2119 const unsigned int interval = tsk->get_response();
2120
2121 // assumption: cont is ordered by request length
2122 foreach(cont, it)
2123 {
2124 const RequestBound* req = *it;
2125
2126 // can't block itself
2127 if (req->get_task() != tsk)
2128 {
2129 unsigned int num;
2130 if (req->get_task()->get_priority() < tsk->get_priority())
2131 {
2132 // higher prio => all of them
2133 num = req->get_max_num_requests(interval);
2134 inter.count += num;
2135 inter.total_length += num * req->get_request_length();
2136 }
2137 else if (max_lower_prio)
2138 {
2139 // lower prio => only remaining
2140 num = std::min(req->get_max_num_requests(interval), max_lower_prio);
2141 inter.count += num;
2142 inter.total_length += num * req->get_request_length();
2143 max_lower_prio -= num;
2144 }
2145 }
2146 }
2147
2148 return inter;
2149}
2150
2151static Interference dpcp_remote_bound(
2152 const TaskInfo& tsk,
2153 const ResourceLocality& locality,
2154 const AllPerCluster& per_cpu)
2155{
2156 Interference blocking;
2157 unsigned int cpu = 0;
2158
2159 foreach(per_cpu, it)
2160 {
2161 // this is about remote delays
2162 if (cpu != tsk.get_cluster())
2163 {
2164 const ContentionSet &cs = *it;
2165 unsigned int reqs;
2166 reqs = count_requests_to_cpu(tsk, locality, cpu);
2167
2168 if (reqs > 0)
2169 blocking += bound_blocking_dpcp(&tsk, cs, reqs);
2170 }
2171 cpu++;
2172 }
2173
2174 return blocking;
2175}
2176
2177
2178static Interference dpcp_local_bound(
2179 const TaskInfo* tsk,
2180 const ContentionSet& local)
2181{
2182 Interference blocking;
2183 const unsigned int interval = tsk->get_response();
2184
2185 foreach(local, it)
2186 {
2187 const RequestBound* req = *it;
2188 if (req->get_task() != tsk)
2189 {
2190 unsigned int num;
2191 num = req->get_max_num_requests(interval);
2192 blocking.count += num;
2193 blocking.total_length += num * req->get_request_length();
2194 }
2195 }
2196
2197 return blocking;
2198}
2199
2200
2201BlockingBounds* dpcp_bounds(const ResourceSharingInfo& info,
2202 const ResourceLocality& locality)
2203{
2204 AllPerCluster per_cpu;
2205
2206 split_by_locality(info, locality, per_cpu);
2207 sort_by_request_length(per_cpu);
2208
2209 BlockingBounds* _results = new BlockingBounds(info);
2210 BlockingBounds& results = *_results;
2211
2212 for (unsigned int i = 0; i < info.get_tasks().size(); i++)
2213 {
2214 const TaskInfo& tsk = info.get_tasks()[i];
2215 Interference remote, local;
2216
2217 remote = dpcp_remote_bound(tsk, locality, per_cpu);
2218 local = dpcp_local_bound(&tsk, per_cpu[tsk.get_cluster()]);
2219
2220 results[i] = remote + local;
2221 results.set_remote_blocking(i, remote);
2222 results.set_local_blocking(i, local);
2223 }
2224 return _results;
2225}
2226