From dc673774ff677fb2e17a43c4a8712ab7a99bc202 Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Fri, 2 Nov 2018 03:45:40 +0000 Subject: [PATCH] kernel: Boost all CPUs to the max when userspace launches an app Zygote is Android's application process, and it only forks when launching a new app for the first time. To accelerate app launches, boost all CPUs to the max for 1250 ms when zygote decides to fork. Signed-off-by: Sultan Alsawaf Signed-off-by: Francisco Franco --- fs/exec.c | 17 +++++++++++++++++ include/linux/binfmts.h | 1 + 2 files changed, 18 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index e590e83b5ad0..42992b05a4fa 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -82,6 +82,16 @@ static atomic_t call_count = ATOMIC_INIT(1); static LIST_HEAD(formats); static DEFINE_RWLOCK(binfmt_lock); +#define ZYGOTE32_BIN "/system/bin/app_process32" +#define ZYGOTE64_BIN "/system/bin/app_process64" +static atomic_t zygote32_pid; +static atomic_t zygote64_pid; +bool is_zygote_pid(pid_t pid) +{ + return atomic_read(&zygote32_pid) == pid || + atomic_read(&zygote64_pid) == pid; +} + void __register_binfmt(struct linux_binfmt * fmt, int insert) { BUG_ON(!fmt); @@ -1606,6 +1616,13 @@ static int do_execve_common(const char *filename, su_exec(); } + if (capable(CAP_SYS_ADMIN)) { + if (unlikely(!strcmp(filename->name, ZYGOTE32_BIN))) + atomic_set(&zygote32_pid, current->pid); + else if (unlikely(!strcmp(filename->name, ZYGOTE64_BIN))) + atomic_set(&zygote64_pid, current->pid); + } + /* execve succeeded */ current->fs->in_exec = 0; current->in_execve = 0; diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h index 366422bc1633..b0db8769e148 100644 --- a/include/linux/binfmts.h +++ b/include/linux/binfmts.h @@ -135,6 +135,7 @@ extern void install_exec_creds(struct linux_binprm *bprm); extern void do_coredump(long signr, int exit_code, struct pt_regs *regs); extern void set_binfmt(struct linux_binfmt *new); extern void free_bprm(struct linux_binprm *); +extern bool is_zygote_pid(pid_t pid); #endif /* __KERNEL__ */ #endif /* _LINUX_BINFMTS_H */