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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc

Issue 165433003: PnaclCoordinator: Use llc's module-splitting for pexe compilation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: retry upload Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "native_client/src/include/checked_cast.h" 10 #include "native_client/src/include/checked_cast.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", 193 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n",
194 static_cast<void*>(plugin), pexe_url.c_str())); 194 static_cast<void*>(plugin), pexe_url.c_str()));
195 PnaclCoordinator* coordinator = 195 PnaclCoordinator* coordinator =
196 new PnaclCoordinator(plugin, pexe_url, 196 new PnaclCoordinator(plugin, pexe_url,
197 pnacl_options, 197 pnacl_options,
198 translate_notify_callback); 198 translate_notify_callback);
199 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); 199 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds();
200 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, ", 200 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, ",
201 reinterpret_cast<const void*>(coordinator->manifest_.get()))); 201 reinterpret_cast<const void*>(coordinator->manifest_.get())));
202 202
203 int cpus = plugin->nacl_interface()->GetNumberOfProcessors();
204 coordinator->split_module_count_ = std::min(4, std::max(1, cpus));
205
203 // First start a network request for the pexe, to tickle the component 206 // First start a network request for the pexe, to tickle the component
204 // updater's On-Demand resource throttler, and to get Last-Modified/ETag 207 // updater's On-Demand resource throttler, and to get Last-Modified/ETag
205 // cache information. We can cancel the request later if there's 208 // cache information. We can cancel the request later if there's
206 // a bitcode->nexe cache hit. 209 // a bitcode->nexe cache hit.
207 coordinator->OpenBitcodeStream(); 210 coordinator->OpenBitcodeStream();
208 return coordinator; 211 return coordinator;
209 } 212 }
210 213
211 PnaclCoordinator::PnaclCoordinator( 214 PnaclCoordinator::PnaclCoordinator(
212 Plugin* plugin, 215 Plugin* plugin,
213 const nacl::string& pexe_url, 216 const nacl::string& pexe_url,
214 const PnaclOptions& pnacl_options, 217 const PnaclOptions& pnacl_options,
215 const pp::CompletionCallback& translate_notify_callback) 218 const pp::CompletionCallback& translate_notify_callback)
216 : translate_finish_error_(PP_OK), 219 : translate_finish_error_(PP_OK),
217 plugin_(plugin), 220 plugin_(plugin),
218 translate_notify_callback_(translate_notify_callback), 221 translate_notify_callback_(translate_notify_callback),
219 translation_finished_reported_(false), 222 translation_finished_reported_(false),
220 manifest_(new PnaclManifest()), 223 manifest_(new PnaclManifest()),
221 pexe_url_(pexe_url), 224 pexe_url_(pexe_url),
222 pnacl_options_(pnacl_options), 225 pnacl_options_(pnacl_options),
226 split_module_count_(1),
227 num_object_files_opened_(0),
223 is_cache_hit_(PP_FALSE), 228 is_cache_hit_(PP_FALSE),
224 error_already_reported_(false), 229 error_already_reported_(false),
225 pnacl_init_time_(0), 230 pnacl_init_time_(0),
226 pexe_size_(0), 231 pexe_size_(0),
227 pexe_bytes_compiled_(0), 232 pexe_bytes_compiled_(0),
228 expected_pexe_size_(-1) { 233 expected_pexe_size_(-1) {
229 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", 234 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n",
230 static_cast<void*>(this), static_cast<void*>(plugin))); 235 static_cast<void*>(this), static_cast<void*>(plugin)));
231 callback_factory_.Initialize(this); 236 callback_factory_.Initialize(this);
232 } 237 }
233 238
234 PnaclCoordinator::~PnaclCoordinator() { 239 PnaclCoordinator::~PnaclCoordinator() {
235 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " 240 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, "
236 "translate_thread=%p\n", 241 "translate_thread=%p\n",
237 static_cast<void*>(this), translate_thread_.get())); 242 static_cast<void*>(this), translate_thread_.get()));
238 // Stopping the translate thread will cause the translate thread to try to 243 // Stopping the translate thread will cause the translate thread to try to
239 // run translation_complete_callback_ on the main thread. This destructor is 244 // run translation_complete_callback_ on the main thread. This destructor is
240 // running from the main thread, and by the time it exits, callback_factory_ 245 // running from the main thread, and by the time it exits, callback_factory_
241 // will have been destroyed. This will result in the cancellation of 246 // will have been destroyed. This will result in the cancellation of
242 // translation_complete_callback_, so no notification will be delivered. 247 // translation_complete_callback_, so no notification will be delivered.
243 if (translate_thread_.get() != NULL) { 248 if (translate_thread_.get() != NULL) {
244 translate_thread_->AbortSubprocesses(); 249 translate_thread_->AbortSubprocesses();
245 } 250 }
246 if (!translation_finished_reported_) { 251 if (!translation_finished_reported_) {
247 plugin_->nacl_interface()->ReportTranslationFinished( 252 plugin_->nacl_interface()->ReportTranslationFinished(
248 plugin_->pp_instance(), 253 plugin_->pp_instance(),
249 PP_FALSE); 254 PP_FALSE);
250 } 255 }
256 for (int i = 0; i < num_object_files_opened_; i++) {
257 delete obj_files_[i];
258 }
251 } 259 }
252 260
253 nacl::DescWrapper* PnaclCoordinator::ReleaseTranslatedFD() { 261 nacl::DescWrapper* PnaclCoordinator::ReleaseTranslatedFD() {
254 DCHECK(temp_nexe_file_ != NULL); 262 DCHECK(temp_nexe_file_ != NULL);
255 return temp_nexe_file_->release_read_wrapper(); 263 return temp_nexe_file_->release_read_wrapper();
256 } 264 }
257 265
258 void PnaclCoordinator::ReportNonPpapiError(enum PluginErrorCode err_code, 266 void PnaclCoordinator::ReportNonPpapiError(enum PluginErrorCode err_code,
259 const nacl::string& message) { 267 const nacl::string& message) {
260 error_info_.SetReport(err_code, message); 268 error_info_.SetReport(err_code, message);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 if (is_cache_hit_ == PP_TRUE) { 532 if (is_cache_hit_ == PP_TRUE) {
525 // Cache hit -- no need to stream the rest of the file. 533 // Cache hit -- no need to stream the rest of the file.
526 streaming_downloader_.reset(NULL); 534 streaming_downloader_.reset(NULL);
527 // Open it for reading as the cached nexe file. 535 // Open it for reading as the cached nexe file.
528 pp::CompletionCallback cb = 536 pp::CompletionCallback cb =
529 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); 537 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen);
530 temp_nexe_file_->Open(cb, false); 538 temp_nexe_file_->Open(cb, false);
531 } else { 539 } else {
532 // Open an object file first so the translator can start writing to it 540 // Open an object file first so the translator can start writing to it
533 // during streaming translation. 541 // during streaming translation.
534 obj_file_.reset(new TempFile(plugin_)); 542 for (int i = 0; i < split_module_count_; i++) {
535 pp::CompletionCallback obj_cb = 543 obj_files_.push_back(new TempFile(plugin_));
536 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen); 544
537 obj_file_->Open(obj_cb, true); 545 pp::CompletionCallback obj_cb =
546 callback_factory_.NewCallback(&PnaclCoordinator::ObjectFileDidOpen);
547 obj_files_[i]->Open(obj_cb, true);
548 }
549 invalid_desc_wrapper_.reset(plugin_->wrapper_factory()->MakeInvalid());
538 550
539 // Meanwhile, a miss means we know we need to stream the bitcode, so stream 551 // Meanwhile, a miss means we know we need to stream the bitcode, so stream
540 // the rest of it now. (Calling FinishStreaming means that the downloader 552 // the rest of it now. (Calling FinishStreaming means that the downloader
541 // will begin handing data to the coordinator, which is safe any time after 553 // will begin handing data to the coordinator, which is safe any time after
542 // the translate_thread_ object has been initialized). 554 // the translate_thread_ object has been initialized).
543 pp::CompletionCallback finish_cb = callback_factory_.NewCallback( 555 pp::CompletionCallback finish_cb = callback_factory_.NewCallback(
544 &PnaclCoordinator::BitcodeStreamDidFinish); 556 &PnaclCoordinator::BitcodeStreamDidFinish);
545 streaming_downloader_->FinishStreaming(finish_cb); 557 streaming_downloader_->FinishStreaming(finish_cb);
546 } 558 }
547 } 559 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 648
637 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { 649 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) {
638 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" 650 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%"
639 NACL_PRId32 ")\n", pp_error)); 651 NACL_PRId32 ")\n", pp_error));
640 if (pp_error != PP_OK) { 652 if (pp_error != PP_OK) {
641 ReportPpapiError(ERROR_PNACL_CREATE_TEMP, 653 ReportPpapiError(ERROR_PNACL_CREATE_TEMP,
642 pp_error, 654 pp_error,
643 "Failed to open scratch object file."); 655 "Failed to open scratch object file.");
644 return; 656 return;
645 } 657 }
646 // Open the nexe file for connecting ld and sel_ldr. 658 num_object_files_opened_++;
647 // Start translation when done with this last step of setup! 659 if (num_object_files_opened_ == split_module_count_) {
648 pp::CompletionCallback cb = 660 // Open the nexe file for connecting ld and sel_ldr.
649 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); 661 // Start translation when done with this last step of setup!
650 temp_nexe_file_->Open(cb, true); 662 pp::CompletionCallback cb =
663 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate);
664 temp_nexe_file_->Open(cb, true);
665 }
651 } 666 }
652 667
653 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 668 void PnaclCoordinator::RunTranslate(int32_t pp_error) {
654 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 669 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%"
655 NACL_PRId32 ")\n", pp_error)); 670 NACL_PRId32 ")\n", pp_error));
656 // Invoke llc followed by ld off the main thread. This allows use of 671 // Invoke llc followed by ld off the main thread. This allows use of
657 // blocking RPCs that would otherwise block the JavaScript main thread. 672 // blocking RPCs that would otherwise block the JavaScript main thread.
658 pp::CompletionCallback report_translate_finished = 673 pp::CompletionCallback report_translate_finished =
659 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 674 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
660 675
661 CHECK(translate_thread_ != NULL); 676 CHECK(translate_thread_ != NULL);
662 translate_thread_->RunTranslate(report_translate_finished, 677 translate_thread_->RunTranslate(report_translate_finished,
663 manifest_.get(), 678 manifest_.get(),
664 obj_file_.get(), 679 &obj_files_,
665 temp_nexe_file_.get(), 680 temp_nexe_file_.get(),
681 invalid_desc_wrapper_.get(),
666 &error_info_, 682 &error_info_,
667 resources_.get(), 683 resources_.get(),
668 &pnacl_options_, 684 &pnacl_options_,
669 this, 685 this,
670 plugin_); 686 plugin_);
671 } 687 }
672 688
673 } // namespace plugin 689 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698