00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __DEBUGWORKLIST_H_
00021 #define __DEBUGWORKLIST_H_
00022
00023 #include <fstream>
00024 #include <map>
00025
00026 namespace GaloisRuntime {
00027 namespace WorkList {
00028
00029 template<typename T, typename Indexer, typename realWL>
00030 class WorkListTracker {
00031 PerCPU<FIFO<std::pair<unsigned int, unsigned int>, false > > tracking;
00032
00033 cache_line_storage<unsigned int> clock;
00034
00035 cache_line_storage<unsigned int> thread_clock;
00036
00037 realWL wl;
00038 Indexer I;
00039
00040 struct info {
00041 unsigned int min;
00042 unsigned int max;
00043 unsigned int count;
00044 unsigned int sum;
00045 info() :min(std::numeric_limits<unsigned int>::max()), max(0), count(0), sum(0) {}
00046 void add(unsigned int val) {
00047 if (val < min)
00048 min = val;
00049 if (val > max)
00050 max = val;
00051 sum += val;
00052 ++count;
00053 }
00054 };
00055
00056 public:
00057 typedef T value_type;
00058
00059 WorkListTracker()
00060 {
00061 clock.data = 0;
00062 thread_clock.data = 0;
00063 }
00064
00065 ~WorkListTracker() {
00066
00067 static const char* translation[] = {
00068 "00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
00069 "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
00070 "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
00071 "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
00072 "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
00073 "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"
00074 };
00075
00076
00077 std::map<unsigned int, info> AMap;
00078 for (int t = 0; t < tracking.size(); ++t) {
00079
00080 std::string name = "tracking.";
00081 name += translation[t];
00082 name += ".txt";
00083 std::ofstream file(name.c_str());
00084
00085 std::map<unsigned int, info> LMap;
00086 while (!tracking.get(t).empty()) {
00087 std::pair<bool, std::pair<unsigned int, unsigned int> > r = tracking.get(t).pop();
00088 if (r.first) {
00089 LMap[r.second.first].add(r.second.second);
00090 AMap[r.second.first].add(r.second.second);
00091 }
00092 }
00093
00094 for (int x = 0; x < clock.data + 1; ++x) {
00095 info& i = LMap[x];
00096 if (i.count)
00097 file << x << " "
00098 << ((double)i.sum / (double)i.count) << " "
00099 << i.min << " "
00100 << i.max << " "
00101 << i.count << "\n";
00102 }
00103 }
00104 std::ofstream file("tracking.avg.txt");
00105 for (int x = 0; x < clock.data + 1; ++x) {
00106 info& i = AMap[x];
00107 if (i.count)
00108 file << x << " "
00109 << ((double)i.sum / (double)i.count) << " "
00110 << i.min << " "
00111 << i.max << " "
00112 << i.count << "\n";
00113 }
00114 }
00115
00117 bool push(value_type val) {
00118 return wl.push(val);
00119 }
00120
00121 bool aborted(value_type val) {
00122 return wl.push(val);
00123 }
00124
00125 std::pair<bool, value_type> pop() {
00126 std::pair<bool, value_type> ret = wl.pop();
00127 if (!ret.first) return ret;
00128 unsigned int index = I(ret.second);
00129 tracking.get().push(std::make_pair(clock.data, index));
00130 if (tracking.myEffectiveID() == 0) {
00131 ++thread_clock.data;
00132 if (thread_clock.data == 1024*10) {
00133 thread_clock.data = 0;
00134 __sync_fetch_and_add(&clock.data, 1);
00135 }
00136 }
00137 return ret;
00138 }
00139
00140 std::pair<bool, value_type> try_pop() {
00141 return pop();
00142 }
00143
00144 bool empty() {
00145 return wl.empty();
00146 }
00147
00148 template<typename iter>
00149 void fillInitial(iter begin, iter end) {
00150 return wl.fillInitial(begin, end);
00151 }
00152 };
00153
00154 template<typename iWL>
00155 class NoInlineFilter {
00156 iWL wl;
00157
00158 public:
00159 typedef typename iWL::value_type value_type;
00160
00161 template<bool concurrent>
00162 struct rethread {
00163 typedef NoInlineFilter<typename iWL::template rethread<concurrent>::WL> WL;
00164 };
00165
00167 bool push(value_type val) __attribute__((noinline)) {
00168 return wl.push(val);
00169 }
00170
00171 bool aborted(value_type val) __attribute__((noinline)) {
00172 return wl.push(val);
00173 }
00174
00175 std::pair<bool, value_type> pop() __attribute__((noinline)) {
00176 return wl.pop();
00177 }
00178
00179 std::pair<bool, value_type> try_pop() __attribute__((noinline)) {
00180 return wl.try_pop();
00181 }
00182
00183 bool empty() __attribute__((noinline)) {
00184 return wl.empty();
00185 }
00186
00187 template<typename iter>
00188 void fillInitial(iter begin, iter end) {
00189 return wl.fillInitial(begin, end);
00190 }
00191 };
00192
00193
00194 }
00195 }
00196
00197 #endif