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

Side by Side Diff: src/IceGlobalContext.cpp

Issue 878383004: Subzero: Fix timers for multithreaded translation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes 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 | « src/IceGlobalContext.h ('k') | src/IceTimerTree.h » ('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.cpp - Global context defs -------------===// 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===//
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 defines aspects of the compilation that persist across 10 // This file defines aspects of the compilation that persist across
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 /*Sequential=*/(Flags.NumTranslationThreads == 0)) { 136 /*Sequential=*/(Flags.NumTranslationThreads == 0)) {
137 // Make sure thread_local fields are properly initialized before any 137 // Make sure thread_local fields are properly initialized before any
138 // accesses are made. Do this here instead of at the start of 138 // accesses are made. Do this here instead of at the start of
139 // main() so that all clients (e.g. unit tests) can benefit for 139 // main() so that all clients (e.g. unit tests) can benefit for
140 // free. 140 // free.
141 GlobalContext::TlsInit(); 141 GlobalContext::TlsInit();
142 Cfg::TlsInit(); 142 Cfg::TlsInit();
143 // Create a new ThreadContext for the current thread. No need to 143 // Create a new ThreadContext for the current thread. No need to
144 // lock AllThreadContexts at this point since no other threads have 144 // lock AllThreadContexts at this point since no other threads have
145 // access yet to this GlobalContext object. 145 // access yet to this GlobalContext object.
146 AllThreadContexts.push_back(new ThreadContext()); 146 ThreadContext *MyTLS = new ThreadContext();
147 ICE_TLS_SET_FIELD(TLS, AllThreadContexts.back()); 147 AllThreadContexts.push_back(MyTLS);
148 ICE_TLS_SET_FIELD(TLS, MyTLS);
148 // Pre-register built-in stack names. 149 // Pre-register built-in stack names.
149 if (ALLOW_DUMP) { 150 if (ALLOW_DUMP) {
150 // TODO(stichnot): There needs to be a strong relationship between 151 // TODO(stichnot): There needs to be a strong relationship between
151 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. 152 // the newTimerStackID() return values and TSK_Default/TSK_Funcs.
152 newTimerStackID("Total across all functions"); 153 newTimerStackID("Total across all functions");
153 newTimerStackID("Per-function summary"); 154 newTimerStackID("Per-function summary");
154 } 155 }
156 Timers.initInto(MyTLS->Timers);
155 if (Flags.UseELFWriter) { 157 if (Flags.UseELFWriter) {
156 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); 158 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr));
157 } 159 }
158 } 160 }
159 161
160 void GlobalContext::translateFunctions() { 162 void GlobalContext::translateFunctions() {
161 while (Cfg *Func = cfgQueueBlockingPop()) { 163 while (Cfg *Func = cfgQueueBlockingPop()) {
162 // Reset per-function stats being accumulated in TLS. 164 // Reset per-function stats being accumulated in TLS.
163 resetStats(); 165 resetStats();
164 // Install Func in TLS for Cfg-specific container allocators. 166 // Install Func in TLS for Cfg-specific container allocators.
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 if (!ALLOW_DUMP) 498 if (!ALLOW_DUMP)
497 return 0; 499 return 0;
498 auto Timers = getTimers(); 500 auto Timers = getTimers();
499 TimerStackIdT NewID = Timers->size(); 501 TimerStackIdT NewID = Timers->size();
500 Timers->push_back(TimerStack(Name)); 502 Timers->push_back(TimerStack(Name));
501 return NewID; 503 return NewID;
502 } 504 }
503 505
504 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, 506 TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID,
505 const IceString &Name) { 507 const IceString &Name) {
506 auto Timers = getTimers(); 508 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
507 assert(StackID < Timers->size()); 509 assert(StackID < Timers->size());
508 return Timers->at(StackID).getTimerID(Name); 510 return Timers->at(StackID).getTimerID(Name);
509 } 511 }
510 512
511 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) { 513 void GlobalContext::pushTimer(TimerIdT ID, TimerStackIdT StackID) {
512 // TODO(stichnot): Timers are completely broken for multithreading; fix. 514 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
513 if (getFlags().NumTranslationThreads)
514 llvm::report_fatal_error("Timers and multithreading are currently broken");
515 auto Timers = getTimers();
516 assert(StackID < Timers->size()); 515 assert(StackID < Timers->size());
517 Timers->at(StackID).push(ID); 516 Timers->at(StackID).push(ID);
518 } 517 }
519 518
520 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) { 519 void GlobalContext::popTimer(TimerIdT ID, TimerStackIdT StackID) {
521 // TODO(stichnot): Timers are completely broken for multithreading; fix. 520 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
522 if (getFlags().NumTranslationThreads)
523 llvm::report_fatal_error("Timers and multithreading are currently broken");
524 auto Timers = getTimers();
525 assert(StackID < Timers->size()); 521 assert(StackID < Timers->size());
526 Timers->at(StackID).pop(ID); 522 Timers->at(StackID).pop(ID);
527 } 523 }
528 524
529 void GlobalContext::resetTimer(TimerStackIdT StackID) { 525 void GlobalContext::resetTimer(TimerStackIdT StackID) {
530 auto Timers = getTimers(); 526 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
531 assert(StackID < Timers->size()); 527 assert(StackID < Timers->size());
532 Timers->at(StackID).reset(); 528 Timers->at(StackID).reset();
533 } 529 }
534 530
535 void GlobalContext::setTimerName(TimerStackIdT StackID, 531 void GlobalContext::setTimerName(TimerStackIdT StackID,
536 const IceString &NewName) { 532 const IceString &NewName) {
537 auto Timers = getTimers(); 533 auto Timers = &ICE_TLS_GET_FIELD(TLS)->Timers;
538 assert(StackID < Timers->size()); 534 assert(StackID < Timers->size());
539 Timers->at(StackID).setName(NewName); 535 Timers->at(StackID).setName(NewName);
540 } 536 }
541 537
542 void GlobalContext::dumpStats(const IceString &Name, bool Final) { 538 void GlobalContext::dumpStats(const IceString &Name, bool Final) {
543 if (!ALLOW_DUMP || !getFlags().DumpStats) 539 if (!ALLOW_DUMP || !getFlags().DumpStats)
544 return; 540 return;
545 OstreamLocker OL(this); 541 OstreamLocker OL(this);
546 if (Final) { 542 if (Final) {
547 getStatsCumulative()->dump(Name, getStrDump()); 543 getStatsCumulative()->dump(Name, getStrDump());
548 } else { 544 } else {
549 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump()); 545 ICE_TLS_GET_FIELD(TLS)->StatsFunction.dump(Name, getStrDump());
550 getStatsCumulative()->dump("_TOTAL_", getStrDump()); 546 getStatsCumulative()->dump("_TOTAL_", getStrDump());
551 } 547 }
552 } 548 }
553 549
554 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { 550 void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
555 if (!ALLOW_DUMP) 551 if (!ALLOW_DUMP)
556 return; 552 return;
557 auto Timers = getTimers(); 553 auto Timers = getTimers();
558 assert(Timers->size() > StackID); 554 assert(Timers->size() > StackID);
559 OstreamLocker L(this); 555 OstreamLocker L(this);
560 Timers->at(StackID).dump(getStrDump(), DumpCumulative); 556 Timers->at(StackID).dump(getStrDump(), DumpCumulative);
561 } 557 }
562 558
563 TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func) 559 void TimerMarker::push() {
564 : ID(ID), Ctx(Func->getContext()), Active(false) { 560 switch (StackID) {
565 if (ALLOW_DUMP) { 561 case GlobalContext::TSK_Default:
566 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled; 562 Active = Ctx->getFlags().SubzeroTimingEnabled;
567 if (Active) 563 break;
568 Ctx->pushTimer(ID); 564 case GlobalContext::TSK_Funcs:
565 Active = Ctx->getFlags().TimeEachFunction;
jvoung (off chromium) 2015/01/30 21:04:44 add a break here too just in case?
Jim Stichnoth 2015/01/30 21:10:06 yikes, thanks!
566 default:
567 break;
569 } 568 }
569 if (Active)
570 Ctx->pushTimer(ID, StackID);
571 }
572
573 void TimerMarker::pushCfg(const Cfg *Func) {
574 Ctx = Func->getContext();
575 Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled;
576 if (Active)
577 Ctx->pushTimer(ID, StackID);
570 } 578 }
571 579
572 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 580 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
573 581
574 } // end of namespace Ice 582 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceTimerTree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698