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 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ | 5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ |
| 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ | 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "native_client/src/include/nacl_macros.h" | 12 #include "native_client/src/include/nacl_macros.h" |
| 13 #include "native_client/src/include/nacl_string.h" | 13 #include "native_client/src/include/nacl_string.h" |
| 14 #include "native_client/src/shared/platform/nacl_sync_raii.h" | 14 #include "native_client/src/shared/platform/nacl_sync_raii.h" |
| 15 #include "native_client/src/shared/srpc/nacl_srpc.h" | 15 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 16 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 16 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 17 | 17 |
| 18 #include "ppapi/cpp/completion_callback.h" | 18 #include "ppapi/cpp/completion_callback.h" |
| 19 | 19 |
| 20 #include "ppapi/native_client/src/trusted/plugin/callback_source.h" | |
| 21 #include "ppapi/native_client/src/trusted/plugin/file_downloader.h" | |
| 22 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" | 20 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" |
| 23 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" | 21 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" |
| 24 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" | 22 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" |
| 25 | 23 |
| 24 #include "ppapi/utility/completion_callback_factory.h" | |
| 25 | |
| 26 struct PP_PNaClOptions; | 26 struct PP_PNaClOptions; |
| 27 | 27 |
| 28 namespace plugin { | 28 namespace plugin { |
| 29 | 29 |
| 30 class Plugin; | 30 class Plugin; |
| 31 class PnaclCoordinator; | 31 class PnaclCoordinator; |
| 32 class PnaclTranslateThread; | 32 class PnaclTranslateThread; |
| 33 class TempFile; | 33 class TempFile; |
| 34 | 34 |
| 35 // A class invoked by Plugin to handle PNaCl client-side translation. | 35 // A class invoked by Plugin to handle PNaCl client-side translation. |
| 36 // Usage: | 36 // Usage: |
| 37 // (1) Invoke the factory method, e.g., | 37 // (1) Invoke the factory method, e.g., |
| 38 // PnaclCoordinator* coord = BitcodeToNative(plugin, | 38 // PnaclCoordinator* coord = BitcodeToNative(plugin, |
| 39 // "http://foo.com/my.pexe", | 39 // "http://foo.com/my.pexe", |
| 40 // pnacl_options, | 40 // pnacl_options, |
| 41 // TranslateNotifyCallback); | 41 // TranslateNotifyCallback); |
| 42 // (2) TranslateNotifyCallback gets invoked when translation is complete. | 42 // (2) TranslateNotifyCallback gets invoked when translation is complete. |
| 43 // If the translation was successful, the pp_error argument is PP_OK. | 43 // If the translation was successful, the pp_error argument is PP_OK. |
| 44 // Other values indicate errors. | 44 // Other values indicate errors. |
| 45 // (3) After finish_callback runs, get the file descriptor of the translated | 45 // (3) After finish_callback runs, get the file descriptor of the translated |
| 46 // nexe, e.g., | 46 // nexe, e.g., |
| 47 // fd = coord->ReleaseTranslatedFD(); | 47 // fd = coord->ReleaseTranslatedFD(); |
| 48 // (4) Load the nexe from "fd". | 48 // (4) Load the nexe from "fd". |
| 49 // (5) delete coord. | 49 // (5) delete coord. |
| 50 // | 50 // |
| 51 // Translation proceeds in two steps: | 51 // Translation proceeds in two steps: |
| 52 // (1) llc translates the bitcode in pexe_url_ to an object in obj_file_. | 52 // (1) llc translates the bitcode in pexe_url_ to an object in obj_file_. |
| 53 // (2) ld links the object code in obj_file_ and produces a nexe in nexe_file_. | 53 // (2) ld links the object code in obj_file_ and produces a nexe in nexe_file_. |
| 54 class PnaclCoordinator: public CallbackSource<FileStreamData> { | 54 class PnaclCoordinator { |
|
dmichael (off chromium)
2014/07/17 16:13:21
Ooh, it looks like maybe you can delete CallbackSo
teravest
2014/07/21 18:33:21
I believe that's already done in this change.
dmichael (off chromium)
2014/07/21 19:49:22
Acknowledged.
| |
| 55 public: | 55 public: |
| 56 // Maximum number of object files passable to the translator. Cannot be | 56 // Maximum number of object files passable to the translator. Cannot be |
| 57 // changed without changing the RPC signatures. | 57 // changed without changing the RPC signatures. |
| 58 const static size_t kMaxTranslatorObjectFiles = 16; | 58 const static size_t kMaxTranslatorObjectFiles = 16; |
| 59 virtual ~PnaclCoordinator(); | 59 virtual ~PnaclCoordinator(); |
| 60 | 60 |
| 61 // The factory method for translations. | 61 // The factory method for translations. |
| 62 static PnaclCoordinator* BitcodeToNative( | 62 static PnaclCoordinator* BitcodeToNative( |
| 63 Plugin* plugin, | 63 Plugin* plugin, |
| 64 const nacl::string& pexe_url, | 64 const nacl::string& pexe_url, |
| 65 const PP_PNaClOptions& pnacl_options, | 65 const PP_PNaClOptions& pnacl_options, |
| 66 const pp::CompletionCallback& translate_notify_callback); | 66 const pp::CompletionCallback& translate_notify_callback); |
| 67 | 67 |
| 68 // Call this to take ownership of the FD of the translated nexe after | 68 // Call this to take ownership of the FD of the translated nexe after |
| 69 // BitcodeToNative has completed (and the finish_callback called). | 69 // BitcodeToNative has completed (and the finish_callback called). |
| 70 PP_FileHandle TakeTranslatedFileHandle(); | 70 PP_FileHandle TakeTranslatedFileHandle(); |
| 71 | 71 |
| 72 // Implement FileDownloader's template of the CallbackSource interface. | |
| 73 // This method returns a callback which will be called by the FileDownloader | |
| 74 // to stream the bitcode data as it arrives. The callback | |
| 75 // (BitcodeStreamGotData) passes it to llc over SRPC. | |
| 76 StreamCallback GetCallback(); | |
| 77 | |
| 78 // Return a callback that should be notified when |bytes_compiled| bytes | 72 // Return a callback that should be notified when |bytes_compiled| bytes |
| 79 // have been compiled. | 73 // have been compiled. |
| 80 pp::CompletionCallback GetCompileProgressCallback(int64_t bytes_compiled); | 74 pp::CompletionCallback GetCompileProgressCallback(int64_t bytes_compiled); |
| 81 | 75 |
| 82 // Get the last known load progress. | 76 // Get the last known load progress. |
| 83 void GetCurrentProgress(int64_t* bytes_loaded, int64_t* bytes_total); | 77 void GetCurrentProgress(int64_t* bytes_loaded, int64_t* bytes_total); |
| 84 | 78 |
| 85 // Return true if we should delay the progress event reporting. | 79 // Return true if we should delay the progress event reporting. |
| 86 // This delay approximates: | 80 // This delay approximates: |
| 87 // - the size of the buffer of bytes sent but not-yet-compiled by LLC. | 81 // - the size of the buffer of bytes sent but not-yet-compiled by LLC. |
| 88 // - the linking time. | 82 // - the linking time. |
| 89 bool ShouldDelayProgressEvent() { | 83 bool ShouldDelayProgressEvent() { |
| 90 const uint32_t kProgressEventSlopPct = 5; | 84 const uint32_t kProgressEventSlopPct = 5; |
| 91 return ((expected_pexe_size_ - pexe_bytes_compiled_) * 100 / | 85 return ((expected_pexe_size_ - pexe_bytes_compiled_) * 100 / |
| 92 expected_pexe_size_) < kProgressEventSlopPct; | 86 expected_pexe_size_) < kProgressEventSlopPct; |
| 93 } | 87 } |
| 94 | 88 |
| 89 | |
| 90 void BitcodeStreamCacheHit(PP_FileHandle handle); | |
| 91 void BitcodeStreamCacheMiss(int64_t expected_pexe_size); | |
| 92 | |
| 93 // Invoked when a pexe data chunk arrives (when using streaming translation) | |
| 94 void BitcodeStreamGotData(const void* data, int32_t length); | |
| 95 | |
| 96 // Invoked when the pexe download finishes (using streaming translation) | |
| 97 void BitcodeStreamDidFinish(int32_t pp_error); | |
| 98 | |
| 95 private: | 99 private: |
| 96 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclCoordinator); | 100 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclCoordinator); |
| 97 | 101 |
| 98 // BitcodeToNative is the factory method for PnaclCoordinators. | 102 // BitcodeToNative is the factory method for PnaclCoordinators. |
| 99 // Therefore the constructor is private. | 103 // Therefore the constructor is private. |
| 100 PnaclCoordinator(Plugin* plugin, | 104 PnaclCoordinator(Plugin* plugin, |
| 101 const nacl::string& pexe_url, | 105 const nacl::string& pexe_url, |
| 102 const PP_PNaClOptions& pnacl_options, | 106 const PP_PNaClOptions& pnacl_options, |
| 103 const pp::CompletionCallback& translate_notify_callback); | 107 const pp::CompletionCallback& translate_notify_callback); |
| 104 | 108 |
| 105 // Invoke to issue a GET request for bitcode. | 109 // Invoke to issue a GET request for bitcode. |
| 106 void OpenBitcodeStream(); | 110 void OpenBitcodeStream(); |
| 107 // Invoked when we've started an URL fetch for the pexe to check for | |
| 108 // caching metadata. | |
| 109 void BitcodeStreamDidOpen(int32_t pp_error); | |
| 110 | 111 |
| 111 // Invoked when we've gotten a temp FD for the nexe, either with the nexe | 112 // Invoked when we've gotten a temp FD for the nexe, either with the nexe |
| 112 // data, or a writeable fd to save to. | 113 // data, or a writeable fd to save to. |
| 113 void NexeFdDidOpen(int32_t pp_error); | 114 void NexeFdDidOpen(int32_t pp_error); |
| 114 // Invoked when a pexe data chunk arrives (when using streaming translation) | |
| 115 void BitcodeStreamGotData(int32_t pp_error, FileStreamData data); | |
| 116 // Invoked when a pexe data chunk is compiled. | 115 // Invoked when a pexe data chunk is compiled. |
| 117 void BitcodeGotCompiled(int32_t pp_error, int64_t bytes_compiled); | 116 void BitcodeGotCompiled(int32_t pp_error, int64_t bytes_compiled); |
| 118 // Invoked when the pexe download finishes (using streaming translation) | |
| 119 void BitcodeStreamDidFinish(int32_t pp_error); | |
| 120 // Once llc and ld nexes have been loaded and the two temporary files have | 117 // Once llc and ld nexes have been loaded and the two temporary files have |
| 121 // been created, this starts the translation. Translation starts two | 118 // been created, this starts the translation. Translation starts two |
| 122 // subprocesses, one for llc and one for ld. | 119 // subprocesses, one for llc and one for ld. |
| 123 void RunTranslate(int32_t pp_error); | 120 void RunTranslate(int32_t pp_error); |
| 124 | 121 |
| 125 // Invoked when translation is finished. | 122 // Invoked when translation is finished. |
| 126 void TranslateFinished(int32_t pp_error); | 123 void TranslateFinished(int32_t pp_error); |
| 127 | 124 |
| 128 // Invoked when the read descriptor for nexe_file_ is created. | 125 // Invoked when the read descriptor for nexe_file_ is created. |
| 129 void NexeReadDidOpen(int32_t pp_error); | 126 void NexeReadDidOpen(int32_t pp_error); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 nacl::string architecture_attributes_; | 170 nacl::string architecture_attributes_; |
| 174 | 171 |
| 175 // Object file, produced by the translator and consumed by the linker. | 172 // Object file, produced by the translator and consumed by the linker. |
| 176 std::vector<TempFile*> obj_files_; | 173 std::vector<TempFile*> obj_files_; |
| 177 nacl::scoped_ptr<nacl::DescWrapper> invalid_desc_wrapper_; | 174 nacl::scoped_ptr<nacl::DescWrapper> invalid_desc_wrapper_; |
| 178 // Number of split modules (threads) for llc | 175 // Number of split modules (threads) for llc |
| 179 int split_module_count_; | 176 int split_module_count_; |
| 180 | 177 |
| 181 // Translated nexe file, produced by the linker. | 178 // Translated nexe file, produced by the linker. |
| 182 nacl::scoped_ptr<TempFile> temp_nexe_file_; | 179 nacl::scoped_ptr<TempFile> temp_nexe_file_; |
| 183 // Passed to the browser, which sets it to true if there is a translation | |
| 184 // cache hit. | |
| 185 PP_Bool is_cache_hit_; | |
| 186 | |
| 187 // Downloader for streaming translation | |
| 188 nacl::scoped_ptr<FileDownloader> streaming_downloader_; | |
| 189 | 180 |
| 190 // Used to report information when errors (PPAPI or otherwise) are reported. | 181 // Used to report information when errors (PPAPI or otherwise) are reported. |
| 191 ErrorInfo error_info_; | 182 ErrorInfo error_info_; |
| 192 | 183 |
| 193 // True if an error was already reported, and translate_notify_callback_ | 184 // True if an error was already reported, and translate_notify_callback_ |
| 194 // was already run/consumed. | 185 // was already run/consumed. |
| 195 bool error_already_reported_; | 186 bool error_already_reported_; |
| 196 | 187 |
| 197 // State for timing and size information for UMA stats. | 188 // State for timing and size information for UMA stats. |
| 198 int64_t pexe_size_; // Count as we stream -- will converge to pexe size. | 189 int64_t pexe_size_; // Count as we stream -- will converge to pexe size. |
| 199 int64_t pexe_bytes_compiled_; // Count as we compile. | 190 int64_t pexe_bytes_compiled_; // Count as we compile. |
| 200 int64_t expected_pexe_size_; // Expected download total (-1 if unknown). | 191 int64_t expected_pexe_size_; // Expected download total (-1 if unknown). |
| 201 | 192 |
| 202 // The helper thread used to do translations via SRPC. | 193 // The helper thread used to do translations via SRPC. |
| 203 // It accesses fields of PnaclCoordinator so it must have a | 194 // It accesses fields of PnaclCoordinator so it must have a |
| 204 // shorter lifetime. | 195 // shorter lifetime. |
| 205 nacl::scoped_ptr<PnaclTranslateThread> translate_thread_; | 196 nacl::scoped_ptr<PnaclTranslateThread> translate_thread_; |
| 206 }; | 197 }; |
| 207 | 198 |
| 208 //---------------------------------------------------------------------- | 199 //---------------------------------------------------------------------- |
| 209 | 200 |
| 210 } // namespace plugin; | 201 } // namespace plugin; |
| 211 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ | 202 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_COORDINATOR_H_ |
| OLD | NEW |