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

Unified Diff: chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc

Issue 426303002: Fix race condition in CpuInfoProvider::QueryCpuTimePerProcessor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comments and logging Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
diff --git a/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc b/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
index 242226289a7fe0b34dae61e3abd50612dd978f26..1d19549735b4a7de47e1260416cd5d07a5c91415 100644
--- a/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
+++ b/chrome/browser/extensions/api/system_cpu/cpu_info_provider_linux.cc
@@ -37,19 +37,38 @@ bool CpuInfoProvider::QueryCpuTimePerProcessor(
if (line.compare(0, 3, "cpu") != 0)
continue;
+ // Due to a race condition in the kernel, we cannot trust the kernel to
Lei Zhang 2014/08/07 06:19:37 Can you mention the number of CPUs might have chan
+ // always return the same number of entries in /proc/stat as the number of
+ // online processors.
+ //
+ // If the number of /proc/stat is different than the number of online
+ // processors, it is treated as an intermittent problem in the kernel, and
Pawel Osciak 2014/08/04 09:22:54 This is not really an intermittent problem on some
Justin Chuang 2014/08/04 11:55:02 Interesting. Luckily it's not the case. On Nyan, t
+ // this function will return false.
+ //
+ // In addition to the kernel issue, there is another less-likely race
+ // condition that the number of online processors is changed after the value
+ // has been decided in CpuInfoProvider::QueryInfo().
+ if (i == infos->size()) {
Pawel Osciak 2014/08/04 09:22:54 s/==/>=/
Justin Chuang 2014/08/04 09:37:23 'i' won't be greater infos->size() unless std::vec
Pawel Osciak 2014/08/05 07:48:16 Of course, sorry, I misread the code. No need to c
+ LOG(ERROR) << "Got more entries in /proc/stat than online CPUs";
+ return false;
+ }
+
uint64 user = 0, nice = 0, sys = 0, idle = 0;
int vals = sscanf(line.c_str(), "%*s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64,
&user, &nice, &sys, &idle);
DCHECK_EQ(4, vals);
- DCHECK(i < infos->size());
infos->at(i)->usage.kernel = static_cast<double>(sys);
infos->at(i)->usage.user = static_cast<double>(user + nice);
infos->at(i)->usage.idle = static_cast<double>(idle);
infos->at(i)->usage.total = static_cast<double>(sys + user + nice + idle);
++i;
}
- DCHECK_EQ(infos->size(), i);
+ if (i < infos->size()) {
Pawel Osciak 2014/08/04 09:22:54 Is this also an actual issue? Having less CPUs pre
Justin Chuang 2014/08/04 09:37:23 Yes, I have seen both cases on actual nyan device.
+ LOG(ERROR) << "Got fewer entries in /proc/stat than online CPUs";
+ return false;
+ }
+
return true;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698