Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "native_client/src/include/portability_io.h" | 11 #include "native_client/src/include/portability_io.h" |
| 12 #include "native_client/src/shared/platform/nacl_check.h" | 12 #include "native_client/src/shared/platform/nacl_check.h" |
| 13 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" | 13 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" |
| 14 | 14 |
| 15 #include "ppapi/c/pp_bool.h" | 15 #include "ppapi/c/pp_bool.h" |
| 16 #include "ppapi/c/pp_errors.h" | 16 #include "ppapi/c/pp_errors.h" |
| 17 #include "ppapi/c/private/ppb_uma_private.h" | 17 #include "ppapi/c/private/ppb_uma_private.h" |
| 18 | 18 |
| 19 #include "ppapi/native_client/src/trusted/plugin/manifest.h" | |
| 20 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 19 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 21 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" | 20 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" |
| 22 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h" | 21 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h" |
| 23 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" | 22 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" |
| 24 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h" | 23 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h" |
| 25 | 24 |
| 26 namespace plugin { | 25 namespace plugin { |
| 27 | 26 |
| 28 ////////////////////////////////////////////////////////////////////// | 27 ////////////////////////////////////////////////////////////////////// |
| 29 // Pnacl-specific manifest support. | |
| 30 ////////////////////////////////////////////////////////////////////// | |
| 31 | |
| 32 // The PNaCl linker gets file descriptors via the service runtime's | |
| 33 // reverse service lookup. The reverse service lookup requires a manifest. | |
| 34 // Normally, that manifest is an NMF containing mappings for shared libraries. | |
| 35 // Here, we provide a manifest that redirects to PNaCl component files | |
| 36 // that are part of Chrome. | |
| 37 class PnaclManifest : public Manifest { | |
| 38 public: | |
| 39 PnaclManifest(const nacl::string& sandbox_arch) | |
| 40 : sandbox_arch_(sandbox_arch) { } | |
| 41 | |
| 42 virtual ~PnaclManifest() { } | |
| 43 | |
| 44 virtual bool GetProgramURL(nacl::string* full_url, | |
| 45 PP_PNaClOptions* pnacl_options, | |
| 46 bool* uses_nonsfi_mode, | |
| 47 ErrorInfo* error_info) const { | |
| 48 // Does not contain program urls. | |
| 49 UNREFERENCED_PARAMETER(full_url); | |
| 50 UNREFERENCED_PARAMETER(pnacl_options); | |
| 51 UNREFERENCED_PARAMETER(uses_nonsfi_mode); | |
| 52 UNREFERENCED_PARAMETER(error_info); | |
| 53 PLUGIN_PRINTF(("PnaclManifest does not contain a program\n")); | |
| 54 error_info->SetReport(PP_NACL_ERROR_MANIFEST_GET_NEXE_URL, | |
| 55 "pnacl manifest does not contain a program."); | |
| 56 return false; | |
| 57 } | |
| 58 | |
| 59 virtual bool ResolveKey(const nacl::string& key, | |
| 60 nacl::string* full_url, | |
| 61 PP_PNaClOptions* pnacl_options) const { | |
| 62 // All of the component files are native (do not require pnacl translate). | |
| 63 pnacl_options->translate = PP_FALSE; | |
| 64 // We can only resolve keys in the files/ namespace. | |
| 65 const nacl::string kFilesPrefix = "files/"; | |
| 66 size_t files_prefix_pos = key.find(kFilesPrefix); | |
| 67 if (files_prefix_pos == nacl::string::npos) { | |
| 68 PLUGIN_PRINTF(("key did not start with files/")); | |
| 69 return false; | |
| 70 } | |
| 71 // Resolve the full URL to the file. Provide it with a platform-specific | |
| 72 // prefix. | |
| 73 nacl::string key_basename = key.substr(kFilesPrefix.length()); | |
| 74 *full_url = PnaclUrls::GetBaseUrl() + sandbox_arch_ + "/" + key_basename; | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclManifest); | |
| 80 | |
| 81 nacl::string sandbox_arch_; | |
| 82 }; | |
| 83 | |
| 84 ////////////////////////////////////////////////////////////////////// | |
| 85 // UMA stat helpers. | 28 // UMA stat helpers. |
| 86 ////////////////////////////////////////////////////////////////////// | 29 ////////////////////////////////////////////////////////////////////// |
| 87 | 30 |
| 88 namespace { | 31 namespace { |
| 89 | 32 |
| 90 // Assume translation time metrics *can be* large. | 33 // Assume translation time metrics *can be* large. |
| 91 // Up to 12 minutes. | 34 // Up to 12 minutes. |
| 92 const int64_t kTimeLargeMin = 10; // in ms | 35 const int64_t kTimeLargeMin = 10; // in ms |
| 93 const int64_t kTimeLargeMax = 720000; // in ms | 36 const int64_t kTimeLargeMax = 720000; // in ms |
| 94 const uint32_t kTimeLargeBuckets = 100; | 37 const uint32_t kTimeLargeBuckets = 100; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 const nacl::string& pexe_url, | 117 const nacl::string& pexe_url, |
| 175 const PP_PNaClOptions& pnacl_options, | 118 const PP_PNaClOptions& pnacl_options, |
| 176 const pp::CompletionCallback& translate_notify_callback) { | 119 const pp::CompletionCallback& translate_notify_callback) { |
| 177 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", | 120 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", |
| 178 static_cast<void*>(plugin), pexe_url.c_str())); | 121 static_cast<void*>(plugin), pexe_url.c_str())); |
| 179 PnaclCoordinator* coordinator = | 122 PnaclCoordinator* coordinator = |
| 180 new PnaclCoordinator(plugin, pexe_url, | 123 new PnaclCoordinator(plugin, pexe_url, |
| 181 pnacl_options, | 124 pnacl_options, |
| 182 translate_notify_callback); | 125 translate_notify_callback); |
| 183 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); | 126 coordinator->pnacl_init_time_ = NaClGetTimeOfDayMicroseconds(); |
| 184 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, ", | |
| 185 reinterpret_cast<const void*>(coordinator->manifest_.get()))); | |
| 186 | |
|
bbudge
2014/05/01 23:32:33
Is there a way to keep this output, perhaps from a
teravest
2014/05/02 14:23:15
I've restored this line and print the manifest_id_
| |
| 187 int cpus = plugin->nacl_interface()->GetNumberOfProcessors(); | 127 int cpus = plugin->nacl_interface()->GetNumberOfProcessors(); |
| 188 coordinator->split_module_count_ = std::min(4, std::max(1, cpus)); | 128 coordinator->split_module_count_ = std::min(4, std::max(1, cpus)); |
| 189 | 129 |
| 190 // First start a network request for the pexe, to tickle the component | 130 // First start a network request for the pexe, to tickle the component |
| 191 // updater's On-Demand resource throttler, and to get Last-Modified/ETag | 131 // updater's On-Demand resource throttler, and to get Last-Modified/ETag |
| 192 // cache information. We can cancel the request later if there's | 132 // cache information. We can cancel the request later if there's |
| 193 // a bitcode->nexe cache hit. | 133 // a bitcode->nexe cache hit. |
| 194 coordinator->OpenBitcodeStream(); | 134 coordinator->OpenBitcodeStream(); |
| 195 return coordinator; | 135 return coordinator; |
| 196 } | 136 } |
| 197 | 137 |
| 198 PnaclCoordinator::PnaclCoordinator( | 138 PnaclCoordinator::PnaclCoordinator( |
| 199 Plugin* plugin, | 139 Plugin* plugin, |
| 200 const nacl::string& pexe_url, | 140 const nacl::string& pexe_url, |
| 201 const PP_PNaClOptions& pnacl_options, | 141 const PP_PNaClOptions& pnacl_options, |
| 202 const pp::CompletionCallback& translate_notify_callback) | 142 const pp::CompletionCallback& translate_notify_callback) |
| 203 : translate_finish_error_(PP_OK), | 143 : translate_finish_error_(PP_OK), |
| 204 plugin_(plugin), | 144 plugin_(plugin), |
| 205 translate_notify_callback_(translate_notify_callback), | 145 translate_notify_callback_(translate_notify_callback), |
| 206 translation_finished_reported_(false), | 146 translation_finished_reported_(false), |
| 207 manifest_(new PnaclManifest(plugin->nacl_interface()->GetSandboxArch())), | 147 manifest_id_( |
| 148 GetNaClInterface()->CreatePnaclManifest(plugin->pp_instance())), | |
| 208 pexe_url_(pexe_url), | 149 pexe_url_(pexe_url), |
| 209 pnacl_options_(pnacl_options), | 150 pnacl_options_(pnacl_options), |
| 210 split_module_count_(1), | 151 split_module_count_(1), |
| 211 num_object_files_opened_(0), | 152 num_object_files_opened_(0), |
| 212 is_cache_hit_(PP_FALSE), | 153 is_cache_hit_(PP_FALSE), |
| 213 error_already_reported_(false), | 154 error_already_reported_(false), |
| 214 pnacl_init_time_(0), | 155 pnacl_init_time_(0), |
| 215 pexe_size_(0), | 156 pexe_size_(0), |
| 216 pexe_bytes_compiled_(0), | 157 pexe_bytes_compiled_(0), |
| 217 expected_pexe_size_(-1) { | 158 expected_pexe_size_(-1) { |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 void PnaclCoordinator::RunTranslate(int32_t pp_error) { | 602 void PnaclCoordinator::RunTranslate(int32_t pp_error) { |
| 662 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" | 603 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" |
| 663 NACL_PRId32 ")\n", pp_error)); | 604 NACL_PRId32 ")\n", pp_error)); |
| 664 // Invoke llc followed by ld off the main thread. This allows use of | 605 // Invoke llc followed by ld off the main thread. This allows use of |
| 665 // blocking RPCs that would otherwise block the JavaScript main thread. | 606 // blocking RPCs that would otherwise block the JavaScript main thread. |
| 666 pp::CompletionCallback report_translate_finished = | 607 pp::CompletionCallback report_translate_finished = |
| 667 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); | 608 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); |
| 668 | 609 |
| 669 CHECK(translate_thread_ != NULL); | 610 CHECK(translate_thread_ != NULL); |
| 670 translate_thread_->RunTranslate(report_translate_finished, | 611 translate_thread_->RunTranslate(report_translate_finished, |
| 671 manifest_.get(), | 612 manifest_id_, |
| 672 &obj_files_, | 613 &obj_files_, |
| 673 temp_nexe_file_.get(), | 614 temp_nexe_file_.get(), |
| 674 invalid_desc_wrapper_.get(), | 615 invalid_desc_wrapper_.get(), |
| 675 &error_info_, | 616 &error_info_, |
| 676 resources_.get(), | 617 resources_.get(), |
| 677 &pnacl_options_, | 618 &pnacl_options_, |
| 678 this, | 619 this, |
| 679 plugin_); | 620 plugin_); |
| 680 } | 621 } |
| 681 | 622 |
| 682 } // namespace plugin | 623 } // namespace plugin |
| OLD | NEW |