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

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: remove unused field 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(PP_OK);
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(int32_t pp_error) {
Derek Schuff 2015/05/08 22:45:59 is LoadCompiler ever used as a callback? does it a
jvoung (off chromium) 2015/05/08 23:59:31 No -- and I added the check of temp_nexe_file_->Op
408 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 418 PLUGIN_PRINTF(("PnaclCoordinator::LoadCompiler (pp_error=%" NACL_PRId32 ")\n",
409 NACL_PRId32 ")\n", pp_error)); 419 pp_error));
420 // If previous setup failed we would not have invoked LoadCompiler.
421 // So we only expect PP_OK here.
422 DCHECK(pp_error == PP_OK);
423 if (pp_error != PP_OK) {
424 return;
425 }
426 int64_t compiler_load_start_time = NaClGetTimeOfDayMicroseconds();
427 pp::CompletionCallback load_finished = callback_factory_.NewCallback(
428 &PnaclCoordinator::RunCompile, compiler_load_start_time);
429 PnaclResources::ResourceType compiler_type = pnacl_options_.use_subzero
430 ? PnaclResources::SUBZERO
431 : PnaclResources::LLC;
432 // On success, ownership of file_info is transferred.
433 PP_NaClFileInfo file_info = resources_->TakeFileInfo(compiler_type);
434 const std::string& url = resources_->GetUrl(compiler_type);
435 plugin_->LoadHelperNaClModule(url, file_info, &compiler_subprocess_,
436 load_finished);
437 }
438
439 void PnaclCoordinator::RunCompile(int32_t pp_error,
440 int64_t compiler_load_start_time) {
441 PLUGIN_PRINTF(
442 ("PnaclCoordinator::RunCompile (pp_error=%" NACL_PRId32 ")\n", pp_error));
443 if (pp_error != PP_OK) {
444 ReportNonPpapiError(
445 PP_NACL_ERROR_PNACL_LLC_SETUP,
446 "PnaclCoordinator: Compiler process could not be created.");
447 return;
448 }
449 int64_t compiler_load_time_total =
450 NaClGetTimeOfDayMicroseconds() - compiler_load_start_time;
451 GetNaClInterface()->LogTranslateTime("NaCl.Perf.PNaClLoadTime.LoadCompiler",
452 compiler_load_time_total);
453 GetNaClInterface()->LogTranslateTime(
454 pnacl_options_.use_subzero
455 ? "NaCl.Perf.PNaClLoadTime.LoadCompiler.Subzero"
456 : "NaCl.Perf.PNaClLoadTime.LoadCompiler.LLC",
457 compiler_load_time_total);
458
410 // Invoke llc followed by ld off the main thread. This allows use of 459 // Invoke llc followed by ld off the main thread. This allows use of
411 // blocking RPCs that would otherwise block the JavaScript main thread. 460 // blocking RPCs that would otherwise block the JavaScript main thread.
412 pp::CompletionCallback report_translate_finished = 461 pp::CompletionCallback report_translate_finished =
413 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 462 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
463 pp::CompletionCallback compile_finished =
464 callback_factory_.NewCallback(&PnaclCoordinator::LoadLinker);
465 CHECK(translate_thread_ != NULL);
466 translate_thread_->SetupState(
467 report_translate_finished, &compiler_subprocess_, &ld_subprocess_,
468 &obj_files_, num_threads_, temp_nexe_file_.get(),
469 invalid_desc_wrapper_.get(), &error_info_, &pnacl_options_,
470 architecture_attributes_, this);
471 translate_thread_->RunCompile(compile_finished);
472 }
414 473
415 CHECK(translate_thread_ != NULL); 474 void PnaclCoordinator::LoadLinker(int32_t pp_error) {
416 translate_thread_->RunTranslate(report_translate_finished, &obj_files_, 475 PLUGIN_PRINTF(
417 num_threads_, temp_nexe_file_.get(), 476 ("PnaclCoordinator::LoadLinker (pp_error=%" NACL_PRId32 ")\n", pp_error));
418 invalid_desc_wrapper_.get(), &error_info_, 477 // Errors in the previous step would have skipped to TranslateFinished
419 resources_.get(), &pnacl_options_, 478 // so we only expect PP_OK here.
420 architecture_attributes_, this, plugin_); 479 DCHECK(pp_error == PP_OK);
480 if (pp_error != PP_OK) {
481 return;
482 }
483 ErrorInfo error_info;
484 int64_t ld_load_start_time = NaClGetTimeOfDayMicroseconds();
485 pp::CompletionCallback load_finished = callback_factory_.NewCallback(
486 &PnaclCoordinator::RunLink, ld_load_start_time);
487 PP_NaClFileInfo ld_file_info = resources_->TakeFileInfo(PnaclResources::LD);
488 // On success, ownership of ld_file_info is transferred.
489 plugin_->LoadHelperNaClModule(resources_->GetUrl(PnaclResources::LD),
490 ld_file_info, &ld_subprocess_, load_finished);
491 }
492
493 void PnaclCoordinator::RunLink(int32_t pp_error, int64_t ld_load_start_time) {
494 PLUGIN_PRINTF(
495 ("PnaclCoordinator::RunLink (pp_error=%" NACL_PRId32 ")\n", pp_error));
496 if (pp_error != PP_OK) {
497 ReportNonPpapiError(
498 PP_NACL_ERROR_PNACL_LD_SETUP,
499 "PnaclCoordinator: Linker process could not be created.");
500 return;
501 }
502 GetNaClInterface()->LogTranslateTime(
503 "NaCl.Perf.PNaClLoadTime.LoadLinker",
504 NaClGetTimeOfDayMicroseconds() - ld_load_start_time);
505 translate_thread_->RunLink();
421 } 506 }
422 507
423 } // namespace plugin 508 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698