aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-06-10 11:10:14 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-06-10 13:40:53 +0000
commit048c640a64fd064361382a8800de05c87ff630cb (patch)
tree2c896c8ed72d1f589472ee034accc21a3183da42 /executor
parent348a48c80275445af03c893a955f29c3db0eb62d (diff)
executor: optimize waiting for child processes exit
Currently we sleep only for 1 ms, which may produce some excessive CPU load (we usually have 6/8 such processes waiting). Make it sleep for 10 ms, but also make the sleep return immediately on child exit. This shuold both improve latency and reduce CPU load.
Diffstat (limited to 'executor')
-rw-r--r--executor/common.h2
-rw-r--r--executor/executor_bsd.h5
-rw-r--r--executor/executor_linux.h5
3 files changed, 11 insertions, 1 deletions
diff --git a/executor/common.h b/executor/common.h
index fdbf4bcb1..3a735a086 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -678,9 +678,9 @@ static void loop(void)
uint32 executed_calls = __atomic_load_n(output_data, __ATOMIC_RELAXED);
#endif
for (;;) {
+ sleep_ms(10);
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
- sleep_ms(1);
#if SYZ_EXECUTOR
// Even though the test process executes exit at the end
// and execution time of each syscall is bounded by syscall_timeout_ms (~50ms),
diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h
index 6c2174360..43c2a19a9 100644
--- a/executor/executor_bsd.h
+++ b/executor/executor_bsd.h
@@ -41,6 +41,11 @@ static void os_init(int argc, char** argv, void* data, size_t data_size)
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = kMaxFd;
setrlimit(RLIMIT_NOFILE, &rlim);
+
+ // A SIGCHLD handler makes sleep in loop exit immediately return with EINTR with a child exits.
+ struct sigaction act = {};
+ act.sa_handler = [](int) {};
+ sigaction(SIGCHLD, &act, nullptr);
}
static intptr_t execute_syscall(const call_t* c, intptr_t a[kMaxArgs])
diff --git a/executor/executor_linux.h b/executor/executor_linux.h
index 3956127cd..bfd81776f 100644
--- a/executor/executor_linux.h
+++ b/executor/executor_linux.h
@@ -67,6 +67,11 @@ static void os_init(int argc, char** argv, char* data, size_t data_size)
got = mmap(data + data_size, SYZ_PAGE_SIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0);
if (data + data_size != got)
failmsg("mmap of right data PROT_NONE page failed", "want %p, got %p", data + data_size, got);
+
+ // A SIGCHLD handler makes sleep in loop exit immediately return with EINTR with a child exits.
+ struct sigaction act = {};
+ act.sa_handler = [](int) {};
+ sigaction(SIGCHLD, &act, nullptr);
}
static intptr_t execute_syscall(const call_t* c, intptr_t a[kMaxArgs])