Skip to content

Commit

Permalink
kernel: Boost whenever a zygote-forked process becomes a top app
Browse files Browse the repository at this point in the history
Boost the CPU to the max for 1000 ms whenever the top app changes, which
improves app launch speeds and addresses jitter when switching between
apps. A check to make sure that the top-app's parent is zygote ensures
that a user-facing app is indeed what's added to the top app task group,
since app processes are forked from zygote.

Signed-off-by: Sultan Alsawaf <[email protected]>
Signed-off-by: celtare21 <[email protected]>
Signed-off-by: UtsavBalar1231 <[email protected]>
  • Loading branch information
kerneltoast authored and UtsavBalar1231 committed Aug 17, 2020
1 parent ab25cbf commit 1237497
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ int suid_dumpable = 0;
static LIST_HEAD(formats);
static DEFINE_RWLOCK(binfmt_lock);

#define ZYGOTE32_BIN "/system/bin/app_process32"
#define ZYGOTE64_BIN "/system/bin/app_process64"
static struct signal_struct *zygote32_sig;
static struct signal_struct *zygote64_sig;

bool task_is_zygote(struct task_struct *p)
{
return p->signal == zygote32_sig || p->signal == zygote64_sig;
}

void __register_binfmt(struct linux_binfmt * fmt, int insert)
{
BUG_ON(!fmt);
Expand Down Expand Up @@ -1799,6 +1809,13 @@ static int do_execveat_common(int fd, struct filename *filename,
if (retval < 0)
goto out;

if (is_global_init(current->parent)) {
if (unlikely(!strcmp(filename->name, ZYGOTE32_BIN)))
zygote32_sig = current->signal;
else if (unlikely(!strcmp(filename->name, ZYGOTE64_BIN)))
zygote64_sig = current->signal;
}

/* execve succeeded */
current->fs->in_exec = 0;
current->in_execve = 0;
Expand Down
1 change: 1 addition & 0 deletions include/linux/binfmts.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ extern int prepare_bprm_creds(struct linux_binprm *bprm);
extern void install_exec_creds(struct linux_binprm *bprm);
extern void set_binfmt(struct linux_binfmt *new);
extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
extern bool task_is_zygote(struct task_struct *p);

extern int do_execve(struct filename *,
const char __user * const __user *,
Expand Down
7 changes: 7 additions & 0 deletions kernel/cgroup/cgroup-v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <linux/delayacct.h>
#include <linux/pid_namespace.h>
#include <linux/cgroupstats.h>
#include <linux/binfmts.h>
#include <linux/cpu_input_boost.h>

#include <trace/events/cgroup.h>

Expand Down Expand Up @@ -551,6 +553,11 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of,

ret = cgroup_attach_task(cgrp, task, threadgroup);

/* This covers boosting for app launches and app transitions */
if (!ret && !threadgroup && !strcmp(of->kn->parent->name, "top-app") &&
task_is_zygote(task->parent))
cpu_input_boost_kick_max(1000);

out_finish:
cgroup_procs_write_finish(task);
out_unlock:
Expand Down

0 comments on commit 1237497

Please sign in to comment.