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

Side by Side Diff: components/nacl/renderer/plugin/pnacl_coordinator.cc

Issue 1128943003: Move PNaCl process startup back to the main thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 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
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 "components/nacl/renderer/plugin/pnacl_coordinator.h" 5 #include "components/nacl/renderer/plugin/pnacl_coordinator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <sstream> 8 #include <sstream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 PnaclCoordinator::PnaclCoordinator( 91 PnaclCoordinator::PnaclCoordinator(
92 Plugin* plugin, 92 Plugin* plugin,
93 const std::string& pexe_url, 93 const std::string& pexe_url,
94 const PP_PNaClOptions& pnacl_options, 94 const PP_PNaClOptions& pnacl_options,
95 const pp::CompletionCallback& translate_notify_callback) 95 const pp::CompletionCallback& translate_notify_callback)
96 : translate_finish_error_(PP_OK), 96 : translate_finish_error_(PP_OK),
97 plugin_(plugin), 97 plugin_(plugin),
98 translate_notify_callback_(translate_notify_callback), 98 translate_notify_callback_(translate_notify_callback),
99 translation_finished_reported_(false), 99 translation_finished_reported_(false),
100 compiler_subprocess_("compiler.nexe", NULL, NULL),
101 ld_subprocess_("linker.nexe", NULL, NULL),
100 pexe_url_(pexe_url), 102 pexe_url_(pexe_url),
101 pnacl_options_(pnacl_options), 103 pnacl_options_(pnacl_options),
102 architecture_attributes_(GetArchitectureAttributes(plugin)), 104 architecture_attributes_(GetArchitectureAttributes(plugin)),
103 split_module_count_(0), 105 split_module_count_(0),
104 num_threads_(0), 106 num_threads_(0),
105 error_already_reported_(false), 107 error_already_reported_(false),
106 pexe_size_(0), 108 pexe_size_(0),
107 pexe_bytes_compiled_(0), 109 pexe_bytes_compiled_(0),
108 expected_pexe_size_(-1) { 110 expected_pexe_size_(-1) {
109 callback_factory_.Initialize(this); 111 callback_factory_.Initialize(this);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 return; 323 return;
322 } else { 324 } else {
323 obj_files_.push_back(temp_file.release()); 325 obj_files_.push_back(temp_file.release());
324 } 326 }
325 } 327 }
326 invalid_desc_wrapper_.reset(plugin_->wrapper_factory()->MakeInvalid()); 328 invalid_desc_wrapper_.reset(plugin_->wrapper_factory()->MakeInvalid());
327 329
328 temp_nexe_file_.reset(new TempFile(plugin_, nexe_handle)); 330 temp_nexe_file_.reset(new TempFile(plugin_, nexe_handle));
329 // Open the nexe file for connecting ld and sel_ldr. 331 // Open the nexe file for connecting ld and sel_ldr.
330 // Start translation when done with this last step of setup! 332 // Start translation when done with this last step of setup!
331 RunTranslate(temp_nexe_file_->Open(true)); 333 int32_t pp_error = temp_nexe_file_->Open(true);
334 if (pp_error != PP_OK) {
335 ReportNonPpapiError(
336 PP_NACL_ERROR_PNACL_CREATE_TEMP,
337 std::string(
338 "PnaclCoordinator: Got bad temp file handle from writing nexe"));
339 return;
340 }
341 LoadCompiler();
332 } 342 }
333 343
334 void PnaclCoordinator::BitcodeStreamGotData(const void* data, int32_t length) { 344 void PnaclCoordinator::BitcodeStreamGotData(const void* data, int32_t length) {
335 DCHECK(translate_thread_.get()); 345 DCHECK(translate_thread_.get());
336 346
337 translate_thread_->PutBytes(data, length); 347 translate_thread_->PutBytes(data, length);
338 if (data && length > 0) 348 if (data && length > 0)
339 pexe_size_ += length; 349 pexe_size_ += length;
340 } 350 }
341 351
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 expected_pexe_size_); 407 expected_pexe_size_);
398 } 408 }
399 } 409 }
400 410
401 pp::CompletionCallback PnaclCoordinator::GetCompileProgressCallback( 411 pp::CompletionCallback PnaclCoordinator::GetCompileProgressCallback(
402 int64_t bytes_compiled) { 412 int64_t bytes_compiled) {
403 return callback_factory_.NewCallback(&PnaclCoordinator::BitcodeGotCompiled, 413 return callback_factory_.NewCallback(&PnaclCoordinator::BitcodeGotCompiled,
404 bytes_compiled); 414 bytes_compiled);
405 } 415 }
406 416
407 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 417 void PnaclCoordinator::LoadCompiler() {
408 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 418 PLUGIN_PRINTF(("PnaclCoordinator::LoadCompiler"));
409 NACL_PRId32 ")\n", pp_error)); 419 int64_t compiler_load_start_time = NaClGetTimeOfDayMicroseconds();
420 pp::CompletionCallback load_finished = callback_factory_.NewCallback(
421 &PnaclCoordinator::RunCompile, compiler_load_start_time);
422 PnaclResources::ResourceType compiler_type = pnacl_options_.use_subzero
423 ? PnaclResources::SUBZERO
424 : PnaclResources::LLC;
425 // Transfer file_info ownership to the sel_ldr launcher.
426 PP_NaClFileInfo file_info = resources_->TakeFileInfo(compiler_type);
427 const std::string& url = resources_->GetUrl(compiler_type);
428 plugin_->LoadHelperNaClModule(url, file_info, &compiler_subprocess_,
429 load_finished);
430 }
431
432 void PnaclCoordinator::RunCompile(int32_t pp_error,
433 int64_t compiler_load_start_time) {
434 PLUGIN_PRINTF(
435 ("PnaclCoordinator::RunCompile (pp_error=%" NACL_PRId32 ")\n", pp_error));
436 if (pp_error != PP_OK) {
437 ReportNonPpapiError(
438 PP_NACL_ERROR_PNACL_LLC_SETUP,
439 "PnaclCoordinator: Compiler process could not be created.");
440 return;
441 }
442 int64_t compiler_load_time_total =
443 NaClGetTimeOfDayMicroseconds() - compiler_load_start_time;
444 GetNaClInterface()->LogTranslateTime("NaCl.Perf.PNaClLoadTime.LoadCompiler",
445 compiler_load_time_total);
446 GetNaClInterface()->LogTranslateTime(
447 pnacl_options_.use_subzero
448 ? "NaCl.Perf.PNaClLoadTime.LoadCompiler.Subzero"
449 : "NaCl.Perf.PNaClLoadTime.LoadCompiler.LLC",
450 compiler_load_time_total);
451
410 // Invoke llc followed by ld off the main thread. This allows use of 452 // Invoke llc followed by ld off the main thread. This allows use of
411 // blocking RPCs that would otherwise block the JavaScript main thread. 453 // blocking RPCs that would otherwise block the JavaScript main thread.
412 pp::CompletionCallback report_translate_finished = 454 pp::CompletionCallback report_translate_finished =
413 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 455 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
456 pp::CompletionCallback compile_finished =
457 callback_factory_.NewCallback(&PnaclCoordinator::LoadLinker);
458 CHECK(translate_thread_ != NULL);
459 translate_thread_->SetupState(
460 report_translate_finished, &compiler_subprocess_, &ld_subprocess_,
461 &obj_files_, num_threads_, temp_nexe_file_.get(),
462 invalid_desc_wrapper_.get(), &error_info_, &pnacl_options_,
463 architecture_attributes_, this);
464 translate_thread_->RunCompile(compile_finished);
465 }
414 466
415 CHECK(translate_thread_ != NULL); 467 void PnaclCoordinator::LoadLinker(int32_t pp_error) {
416 translate_thread_->RunTranslate(report_translate_finished, &obj_files_, 468 PLUGIN_PRINTF(
417 num_threads_, temp_nexe_file_.get(), 469 ("PnaclCoordinator::LoadLinker (pp_error=%" NACL_PRId32 ")\n", pp_error));
418 invalid_desc_wrapper_.get(), &error_info_, 470 // Errors in the previous step would have skipped to TranslateFinished
419 resources_.get(), &pnacl_options_, 471 // so we only expect PP_OK here.
420 architecture_attributes_, this, plugin_); 472 DCHECK(pp_error == PP_OK);
473 if (pp_error != PP_OK) {
474 return;
475 }
476 ErrorInfo error_info;
477 int64_t ld_load_start_time = NaClGetTimeOfDayMicroseconds();
478 pp::CompletionCallback load_finished = callback_factory_.NewCallback(
479 &PnaclCoordinator::RunLink, ld_load_start_time);
480 // Transfer file_info ownership to the sel_ldr launcher.
481 PP_NaClFileInfo ld_file_info = resources_->TakeFileInfo(PnaclResources::LD);
482 plugin_->LoadHelperNaClModule(resources_->GetUrl(PnaclResources::LD),
483 ld_file_info, &ld_subprocess_, load_finished);
484 }
485
486 void PnaclCoordinator::RunLink(int32_t pp_error, int64_t ld_load_start_time) {
487 PLUGIN_PRINTF(
488 ("PnaclCoordinator::RunLink (pp_error=%" NACL_PRId32 ")\n", pp_error));
489 if (pp_error != PP_OK) {
490 ReportNonPpapiError(
491 PP_NACL_ERROR_PNACL_LD_SETUP,
492 "PnaclCoordinator: Linker process could not be created.");
493 return;
494 }
495 GetNaClInterface()->LogTranslateTime(
496 "NaCl.Perf.PNaClLoadTime.LoadLinker",
497 NaClGetTimeOfDayMicroseconds() - ld_load_start_time);
498 translate_thread_->RunLink();
421 } 499 }
422 500
423 } // namespace plugin 501 } // namespace plugin
OLDNEW
« no previous file with comments | « components/nacl/renderer/plugin/pnacl_coordinator.h ('k') | components/nacl/renderer/plugin/pnacl_translate_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698