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

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

Issue 308013002: Pepper: Narrow locking at llc subprocess start. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_translate_thread.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
10 #include "ppapi/cpp/var.h" 10 #include "ppapi/cpp/var.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 for (Args::const_iterator arg(args.begin()); arg != args.end(); ++arg) { 47 for (Args::const_iterator arg(args.begin()); arg != args.end(); ++arg) {
48 std::copy(arg->begin(), arg->end(), std::back_inserter(*split_args)); 48 std::copy(arg->begin(), arg->end(), std::back_inserter(*split_args));
49 split_args->push_back('\x00'); 49 split_args->push_back('\x00');
50 } 50 }
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false), 55 PnaclTranslateThread::PnaclTranslateThread() : llc_subprocess_active_(false),
56 ld_subprocess_active_(false), 56 ld_subprocess_active_(false),
57 subprocesses_aborted_(false),
57 done_(false), 58 done_(false),
58 compile_time_(0), 59 compile_time_(0),
59 obj_files_(NULL), 60 obj_files_(NULL),
60 nexe_file_(NULL), 61 nexe_file_(NULL),
61 coordinator_error_info_(NULL), 62 coordinator_error_info_(NULL),
62 resources_(NULL), 63 resources_(NULL),
63 coordinator_(NULL), 64 coordinator_(NULL),
64 plugin_(NULL) { 65 plugin_(NULL) {
65 NaClXMutexCtor(&subprocess_mu_); 66 NaClXMutexCtor(&subprocess_mu_);
66 NaClXMutexCtor(&cond_mu_); 67 NaClXMutexCtor(&cond_mu_);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ErrorInfo error_info; 154 ErrorInfo error_info;
154 SrpcParams params; 155 SrpcParams params;
155 std::vector<nacl::DescWrapper*> llc_out_files; 156 std::vector<nacl::DescWrapper*> llc_out_files;
156 size_t i; 157 size_t i;
157 for (i = 0; i < obj_files_->size(); i++) 158 for (i = 0; i < obj_files_->size(); i++)
158 llc_out_files.push_back((*obj_files_)[i]->write_wrapper()); 159 llc_out_files.push_back((*obj_files_)[i]->write_wrapper());
159 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) 160 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++)
160 llc_out_files.push_back(invalid_desc_wrapper_); 161 llc_out_files.push_back(invalid_desc_wrapper_);
161 162
162 pp::Core* core = pp::Module::Get()->core(); 163 pp::Core* core = pp::Module::Get()->core();
164 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds();
165 PP_FileHandle llc_file_handle = resources_->TakeLlcFileHandle();
166 NaClSubprocess* llc_subprocess = plugin_->LoadHelperNaClModule(
167 resources_->GetLlcUrl(), llc_file_handle, &error_info);
168 if (llc_subprocess == NULL) {
169 if (llc_file_handle != PP_kInvalidFileHandle)
170 CloseFileHandle(llc_file_handle);
171 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP,
172 "Compile process could not be created: " +
173 error_info.message());
174 return;
175 }
176 core->CallOnMainThread(0,
177 coordinator_->GetUMATimeCallback(
178 "NaCl.Perf.PNaClLoadTime.LoadCompiler",
bbudge 2014/05/30 17:53:19 nit: indent arguments
179 NaClGetTimeOfDayMicroseconds() - llc_start_time),
180 PP_OK);
181
163 { 182 {
164 nacl::MutexLocker ml(&subprocess_mu_); 183 nacl::MutexLocker ml(&subprocess_mu_);
165 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds(); 184 // If we received a call to AbortSubprocesses() before we had a chance to
166 PP_FileHandle llc_file_handle = resources_->TakeLlcFileHandle(); 185 // set llc_subprocess_, shut down and clean up the subprocess started here.
167 186 if (subprocesses_aborted_) {
168 // On success, ownership of llc_file_handle is transferred. 187 llc_subprocess->service_runtime()->Shutdown();
169 llc_subprocess_.reset(plugin_->LoadHelperNaClModule( 188 delete llc_subprocess;
170 resources_->GetLlcUrl(), llc_file_handle, &error_info));
171 if (llc_subprocess_.get() == NULL) {
172 if (llc_file_handle != PP_kInvalidFileHandle)
173 CloseFileHandle(llc_file_handle);
174 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP,
175 "Compile process could not be created: " +
176 error_info.message());
177 return; 189 return;
178 } 190 }
179 191 llc_subprocess_.reset(llc_subprocess);
192 llc_subprocess = NULL;
180 llc_subprocess_active_ = true; 193 llc_subprocess_active_ = true;
181 core->CallOnMainThread(0,
182 coordinator_->GetUMATimeCallback(
183 "NaCl.Perf.PNaClLoadTime.LoadCompiler",
184 NaClGetTimeOfDayMicroseconds() - llc_start_time),
185 PP_OK);
186 } 194 }
187 195
188 int64_t compile_start_time = NaClGetTimeOfDayMicroseconds(); 196 int64_t compile_start_time = NaClGetTimeOfDayMicroseconds();
189 bool init_success; 197 bool init_success;
190 198
191 std::vector<char> split_args; 199 std::vector<char> split_args;
192 GetLlcCommandLine(plugin_, 200 GetLlcCommandLine(plugin_,
193 &split_args, 201 &split_args,
194 obj_files_->size(), 202 obj_files_->size(),
195 pnacl_options_->opt_level, 203 pnacl_options_->opt_level,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 PLUGIN_PRINTF(("PnaclTranslateThread::AbortSubprocesses\n")); 427 PLUGIN_PRINTF(("PnaclTranslateThread::AbortSubprocesses\n"));
420 NaClXMutexLock(&subprocess_mu_); 428 NaClXMutexLock(&subprocess_mu_);
421 if (llc_subprocess_ != NULL && llc_subprocess_active_) { 429 if (llc_subprocess_ != NULL && llc_subprocess_active_) {
422 llc_subprocess_->service_runtime()->Shutdown(); 430 llc_subprocess_->service_runtime()->Shutdown();
423 llc_subprocess_active_ = false; 431 llc_subprocess_active_ = false;
424 } 432 }
425 if (ld_subprocess_ != NULL && ld_subprocess_active_) { 433 if (ld_subprocess_ != NULL && ld_subprocess_active_) {
426 ld_subprocess_->service_runtime()->Shutdown(); 434 ld_subprocess_->service_runtime()->Shutdown();
427 ld_subprocess_active_ = false; 435 ld_subprocess_active_ = false;
428 } 436 }
437 subprocesses_aborted_ = true;
429 NaClXMutexUnlock(&subprocess_mu_); 438 NaClXMutexUnlock(&subprocess_mu_);
430 nacl::MutexLocker ml(&cond_mu_); 439 nacl::MutexLocker ml(&cond_mu_);
431 done_ = true; 440 done_ = true;
432 // Free all buffered bitcode chunks 441 // Free all buffered bitcode chunks
433 data_buffers_.clear(); 442 data_buffers_.clear();
434 NaClXCondVarSignal(&buffer_cond_); 443 NaClXCondVarSignal(&buffer_cond_);
435 } 444 }
436 445
437 PnaclTranslateThread::~PnaclTranslateThread() { 446 PnaclTranslateThread::~PnaclTranslateThread() {
438 PLUGIN_PRINTF(("~PnaclTranslateThread (translate_thread=%p)\n", this)); 447 PLUGIN_PRINTF(("~PnaclTranslateThread (translate_thread=%p)\n", this));
439 AbortSubprocesses(); 448 AbortSubprocesses();
440 if (translate_thread_ != NULL) 449 if (translate_thread_ != NULL)
441 NaClThreadJoin(translate_thread_.get()); 450 NaClThreadJoin(translate_thread_.get());
442 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); 451 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n"));
443 NaClCondVarDtor(&buffer_cond_); 452 NaClCondVarDtor(&buffer_cond_);
444 NaClMutexDtor(&cond_mu_); 453 NaClMutexDtor(&cond_mu_);
445 NaClMutexDtor(&subprocess_mu_); 454 NaClMutexDtor(&subprocess_mu_);
446 } 455 }
447 456
448 } // namespace plugin 457 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698