Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: src/IceGlobalContext.h

Issue 887213002: Subzero: Fix stats collection and output for multithreading. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Convert CodeStats to x-macros Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/IceGlobalContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===// 1 //===- subzero/src/IceGlobalContext.h - Global context defs -----*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file declares aspects of the compilation that persist across 10 // This file declares aspects of the compilation that persist across
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 }; 55 };
56 56
57 class GlobalContext { 57 class GlobalContext {
58 GlobalContext(const GlobalContext &) = delete; 58 GlobalContext(const GlobalContext &) = delete;
59 GlobalContext &operator=(const GlobalContext &) = delete; 59 GlobalContext &operator=(const GlobalContext &) = delete;
60 60
61 // CodeStats collects rudimentary statistics during translation. 61 // CodeStats collects rudimentary statistics during translation.
62 class CodeStats { 62 class CodeStats {
63 CodeStats(const CodeStats &) = delete; 63 CodeStats(const CodeStats &) = delete;
64 CodeStats &operator=(const CodeStats &) = default; 64 CodeStats &operator=(const CodeStats &) = default;
65 #define CODESTATS_TABLE \
66 /* dump string, enum value */ \
67 X("Inst Count ", InstCount) \
68 X("Regs Saved ", RegsSaved) \
69 X("Frame Bytes ", FrameByte) \
70 X("Spills ", NumSpills) \
71 X("Fills ", NumFills)
72 //#define X(str, tag)
JF 2015/01/31 17:46:25 Leftover?
Jim Stichnoth 2015/01/31 18:32:29 No - our x-macros style when defining the table is
65 73
66 public: 74 public:
67 CodeStats() 75 enum CSTag {
68 : InstructionsEmitted(0), RegistersSaved(0), FrameBytes(0), Spills(0), 76 #define X(str, tag) CS_##tag,
69 Fills(0) {} 77 CODESTATS_TABLE
70 void reset() { *this = CodeStats(); } 78 #undef X
71 void updateEmitted(uint32_t InstCount) { InstructionsEmitted += InstCount; } 79 CS_NUM
72 void updateRegistersSaved(uint32_t Num) { RegistersSaved += Num; } 80 };
73 void updateFrameBytes(uint32_t Bytes) { FrameBytes += Bytes; } 81 CodeStats() { reset(); }
74 void updateSpills() { ++Spills; } 82 void reset() {
75 void updateFills() { ++Fills; } 83 for (uint32_t i = 0; i < CS_NUM; ++i)
84 Stats[i] = 0;
85 }
86 void update(CSTag Tag, uint32_t Count = 1) {
87 assert(Tag < CS_NUM);
88 Stats[Tag] += Count;
89 }
90 void add(const CodeStats &Other) {
91 for (uint32_t i = 0; i < CS_NUM; ++i)
92 Stats[i] += Other.Stats[i];
93 }
76 void dump(const IceString &Name, Ostream &Str); 94 void dump(const IceString &Name, Ostream &Str);
77 95
78 private: 96 private:
79 uint32_t InstructionsEmitted; 97 uint32_t Stats[CS_NUM];
JF 2015/01/31 17:46:25 std::array, and then you can use the std algorithm
Jim Stichnoth 2015/01/31 18:32:29 Done.
80 uint32_t RegistersSaved;
81 uint32_t FrameBytes;
82 uint32_t Spills;
83 uint32_t Fills;
84 }; 98 };
85 99
86 // TimerList is a vector of TimerStack objects, with extra methods 100 // TimerList is a vector of TimerStack objects, with extra methods
87 // to initialize and merge these vectors. 101 // to initialize and merge these vectors.
88 class TimerList : public std::vector<TimerStack> { 102 class TimerList : public std::vector<TimerStack> {
89 public: 103 public:
90 // initInto() initializes a target list of timers based on the 104 // initInto() initializes a target list of timers based on the
91 // current list. In particular, it creates the same number of 105 // current list. In particular, it creates the same number of
92 // timers, in the same order, with the same names, but initially 106 // timers, in the same order, with the same names, but initially
93 // empty of timing data. 107 // empty of timing data.
(...skipping 20 matching lines...) Expand all
114 128
115 // ThreadContext contains thread-local data. This data can be 129 // ThreadContext contains thread-local data. This data can be
116 // combined/reduced as needed after all threads complete. 130 // combined/reduced as needed after all threads complete.
117 class ThreadContext { 131 class ThreadContext {
118 ThreadContext(const ThreadContext &) = delete; 132 ThreadContext(const ThreadContext &) = delete;
119 ThreadContext &operator=(const ThreadContext &) = delete; 133 ThreadContext &operator=(const ThreadContext &) = delete;
120 134
121 public: 135 public:
122 ThreadContext() {} 136 ThreadContext() {}
123 CodeStats StatsFunction; 137 CodeStats StatsFunction;
138 CodeStats StatsCumulative;
124 TimerList Timers; 139 TimerList Timers;
125 }; 140 };
126 141
127 public: 142 public:
128 GlobalContext(Ostream *OsDump, Ostream *OsEmit, ELFStreamer *ELFStreamer, 143 GlobalContext(Ostream *OsDump, Ostream *OsEmit, ELFStreamer *ELFStreamer,
129 VerboseMask Mask, TargetArch Arch, OptLevel Opt, 144 VerboseMask Mask, TargetArch Arch, OptLevel Opt,
130 IceString TestPrefix, const ClFlags &Flags); 145 IceString TestPrefix, const ClFlags &Flags);
131 ~GlobalContext(); 146 ~GlobalContext();
132 147
133 VerboseMask getVerbose() const { return VMask; } 148 VerboseMask getVerbose() const { return VMask; }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 217
203 // Reset stats at the beginning of a function. 218 // Reset stats at the beginning of a function.
204 void resetStats() { 219 void resetStats() {
205 if (ALLOW_DUMP) 220 if (ALLOW_DUMP)
206 ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset(); 221 ICE_TLS_GET_FIELD(TLS)->StatsFunction.reset();
207 } 222 }
208 void dumpStats(const IceString &Name, bool Final = false); 223 void dumpStats(const IceString &Name, bool Final = false);
209 void statsUpdateEmitted(uint32_t InstCount) { 224 void statsUpdateEmitted(uint32_t InstCount) {
210 if (!ALLOW_DUMP || !getFlags().DumpStats) 225 if (!ALLOW_DUMP || !getFlags().DumpStats)
211 return; 226 return;
212 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateEmitted(InstCount); 227 ThreadContext *TLS = ICE_TLS_GET_FIELD(TLS);
213 getStatsCumulative()->updateEmitted(InstCount); 228 TLS->StatsFunction.update(CodeStats::CS_InstCount, InstCount);
229 TLS->StatsCumulative.update(CodeStats::CS_InstCount, InstCount);
214 } 230 }
215 void statsUpdateRegistersSaved(uint32_t Num) { 231 void statsUpdateRegistersSaved(uint32_t Num) {
216 if (!ALLOW_DUMP || !getFlags().DumpStats) 232 if (!ALLOW_DUMP || !getFlags().DumpStats)
217 return; 233 return;
218 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateRegistersSaved(Num); 234 ThreadContext *TLS = ICE_TLS_GET_FIELD(TLS);
219 getStatsCumulative()->updateRegistersSaved(Num); 235 TLS->StatsFunction.update(CodeStats::CS_RegsSaved, Num);
236 TLS->StatsCumulative.update(CodeStats::CS_RegsSaved, Num);
220 } 237 }
221 void statsUpdateFrameBytes(uint32_t Bytes) { 238 void statsUpdateFrameBytes(uint32_t Bytes) {
222 if (!ALLOW_DUMP || !getFlags().DumpStats) 239 if (!ALLOW_DUMP || !getFlags().DumpStats)
223 return; 240 return;
224 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFrameBytes(Bytes); 241 ThreadContext *TLS = ICE_TLS_GET_FIELD(TLS);
225 getStatsCumulative()->updateFrameBytes(Bytes); 242 TLS->StatsFunction.update(CodeStats::CS_FrameByte, Bytes);
243 TLS->StatsCumulative.update(CodeStats::CS_FrameByte, Bytes);
226 } 244 }
227 void statsUpdateSpills() { 245 void statsUpdateSpills() {
228 if (!ALLOW_DUMP || !getFlags().DumpStats) 246 if (!ALLOW_DUMP || !getFlags().DumpStats)
229 return; 247 return;
230 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateSpills(); 248 ThreadContext *TLS = ICE_TLS_GET_FIELD(TLS);
231 getStatsCumulative()->updateSpills(); 249 TLS->StatsFunction.update(CodeStats::CS_NumSpills);
250 TLS->StatsCumulative.update(CodeStats::CS_NumSpills);
232 } 251 }
233 void statsUpdateFills() { 252 void statsUpdateFills() {
234 if (!ALLOW_DUMP || !getFlags().DumpStats) 253 if (!ALLOW_DUMP || !getFlags().DumpStats)
235 return; 254 return;
236 ICE_TLS_GET_FIELD(TLS)->StatsFunction.updateFills(); 255 ThreadContext *TLS = ICE_TLS_GET_FIELD(TLS);
237 getStatsCumulative()->updateFills(); 256 TLS->StatsFunction.update(CodeStats::CS_NumFills);
257 TLS->StatsCumulative.update(CodeStats::CS_NumFills);
238 } 258 }
239 259
240 // These are predefined TimerStackIdT values. 260 // These are predefined TimerStackIdT values.
241 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num }; 261 enum TimerStackKind { TSK_Default = 0, TSK_Funcs, TSK_Num };
242 262
243 // newTimerStackID() creates a new TimerStack in the global space. 263 // newTimerStackID() creates a new TimerStack in the global space.
244 // It does not affect any TimerStack objects in TLS. 264 // It does not affect any TimerStack objects in TLS.
245 TimerStackIdT newTimerStackID(const IceString &Name); 265 TimerStackIdT newTimerStackID(const IceString &Name);
246 // dumpTimers() dumps the global timer data. As such, one probably 266 // dumpTimers() dumps the global timer data. As such, one probably
247 // wants to call mergeTimerStacks() as a prerequisite. 267 // wants to call mergeTimerStacks() as a prerequisite.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 for (std::thread &Worker : TranslationThreads) { 309 for (std::thread &Worker : TranslationThreads) {
290 Worker.join(); 310 Worker.join();
291 } 311 }
292 TranslationThreads.clear(); 312 TranslationThreads.clear();
293 // TODO(stichnot): join the emitter thread. 313 // TODO(stichnot): join the emitter thread.
294 if (ALLOW_DUMP) { 314 if (ALLOW_DUMP) {
295 auto Timers = getTimers(); 315 auto Timers = getTimers();
296 for (ThreadContext *TLS : AllThreadContexts) 316 for (ThreadContext *TLS : AllThreadContexts)
297 Timers->mergeFrom(TLS->Timers); 317 Timers->mergeFrom(TLS->Timers);
298 } 318 }
319 if (ALLOW_DUMP) {
320 // Do a separate loop over AllThreadContexts to avoid holding
321 // two locks at once.
322 auto Stats = getStatsCumulative();
323 for (ThreadContext *TLS : AllThreadContexts)
324 Stats->add(TLS->StatsCumulative);
325 }
299 } 326 }
300 327
301 // Translation thread startup routine. 328 // Translation thread startup routine.
302 void translateFunctionsWrapper(ThreadContext *MyTLS) { 329 void translateFunctionsWrapper(ThreadContext *MyTLS) {
303 ICE_TLS_SET_FIELD(TLS, MyTLS); 330 ICE_TLS_SET_FIELD(TLS, MyTLS);
304 translateFunctions(); 331 translateFunctions();
305 } 332 }
306 // Translate functions from the Cfg queue until the queue is empty. 333 // Translate functions from the Cfg queue until the queue is empty.
307 void translateFunctions(); 334 void translateFunctions();
308 335
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); } 466 explicit OstreamLocker(GlobalContext *Ctx) : Ctx(Ctx) { Ctx->lockStr(); }
440 ~OstreamLocker() { Ctx->unlockStr(); } 467 ~OstreamLocker() { Ctx->unlockStr(); }
441 468
442 private: 469 private:
443 GlobalContext *const Ctx; 470 GlobalContext *const Ctx;
444 }; 471 };
445 472
446 } // end of namespace Ice 473 } // end of namespace Ice
447 474
448 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H 475 #endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H
OLDNEW
« no previous file with comments | « no previous file | src/IceGlobalContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698