Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 6ebd85e

Browse files
bnoordhuistrevnorris
authored andcommitted
v8: don't busy loop in cpu profiler thread
Reduce the overhead of the CPU profiler by replacing sched_yield() with nanosleep() in V8's tick event processor thread. The former only yields the CPU when there is another process scheduled on the same CPU. Before this commit, the thread would effectively busy loop and consume 100% CPU time. By forcing a one nanosecond sleep period rounded up to the task scheduler's granularity (about 50 us on Linux), CPU usage for the processor thread now hovers around 10-20% for a busy application. PR-URL: #8789 Ref: strongloop/strong-agent#3 Reviewed-by: Trevor Norris <[email protected]>
1 parent fe20196 commit 6ebd85e

7 files changed

+7
-26
lines changed

deps/v8/src/platform-freebsd.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,6 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
539539
}
540540

541541

542-
void Thread::YieldCPU() {
543-
sched_yield();
544-
}
545-
546-
547542
class FreeBSDMutex : public Mutex {
548543
public:
549544
FreeBSDMutex() {

deps/v8/src/platform-linux.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,6 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
812812
}
813813

814814

815-
void Thread::YieldCPU() {
816-
sched_yield();
817-
}
818-
819-
820815
class LinuxMutex : public Mutex {
821816
public:
822817
LinuxMutex() {

deps/v8/src/platform-macos.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,6 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
640640
}
641641

642642

643-
void Thread::YieldCPU() {
644-
sched_yield();
645-
}
646-
647-
648643
class MacOSMutex : public Mutex {
649644
public:
650645
MacOSMutex() {

deps/v8/src/platform-openbsd.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,6 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
593593
}
594594

595595

596-
void Thread::YieldCPU() {
597-
sched_yield();
598-
}
599-
600-
601596
class OpenBSDMutex : public Mutex {
602597
public:
603598
OpenBSDMutex() {

deps/v8/src/platform-posix.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
392392
}
393393

394394

395+
void Thread::YieldCPU() {
396+
const timespec delay = { 0, 1 };
397+
nanosleep(&delay, NULL);
398+
}
399+
400+
395401
// ----------------------------------------------------------------------------
396402
// POSIX socket support.
397403
//

deps/v8/src/platform-solaris.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,6 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
527527
}
528528

529529

530-
void Thread::YieldCPU() {
531-
sched_yield();
532-
}
533-
534-
535530
class SolarisMutex : public Mutex {
536531
public:
537532
SolarisMutex() {

deps/v8/tools/gyp/v8.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@
715715
['OS=="solaris"', {
716716
'link_settings': {
717717
'libraries': [
718-
'-lsocket -lnsl',
718+
'-lsocket -lnsl -lrt',
719719
]},
720720
'sources': [
721721
'../../src/platform-solaris.cc',

0 commit comments

Comments
 (0)