Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba8a4753 authored by Todd Kjos's avatar Todd Kjos
Browse files

Actively mangage EAS schedtune nodes

Move foreground tasks to /sys/fs/cgroup/stune/boost/tasks (boosted
weight in EAS scheduler). Move background tasks to
/sys/fs/cgroup/stune/tasks (default weight). For services started
with init, set "foreground" services to boosted.

Change-Id: I0e489fad9510727c13e6754dabaf311c2391f395
parent 2a3024f9
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -115,6 +115,9 @@ LOCAL_STATIC_LIBRARIES := liblog
ifneq ($(ENABLE_CPUSETS),)
ifneq ($(ENABLE_CPUSETS),)
LOCAL_CFLAGS += -DUSE_CPUSETS
LOCAL_CFLAGS += -DUSE_CPUSETS
endif
endif
ifneq ($(ENABLE_SCHEDBOOST),)
LOCAL_CFLAGS += -DUSE_SCHEDBOOST
endif
LOCAL_CFLAGS += -Werror -Wall -Wextra -std=gnu90
LOCAL_CFLAGS += -Werror -Wall -Wextra -std=gnu90
LOCAL_CLANG := true
LOCAL_CLANG := true
LOCAL_SANITIZE := integer
LOCAL_SANITIZE := integer
@@ -129,6 +132,9 @@ LOCAL_SHARED_LIBRARIES := liblog
ifneq ($(ENABLE_CPUSETS),)
ifneq ($(ENABLE_CPUSETS),)
LOCAL_CFLAGS += -DUSE_CPUSETS
LOCAL_CFLAGS += -DUSE_CPUSETS
endif
endif
ifneq ($(ENABLE_SCHEDBOOST),)
LOCAL_CFLAGS += -DUSE_SCHEDBOOST
endif
LOCAL_CFLAGS += -Werror -Wall -Wextra
LOCAL_CFLAGS += -Werror -Wall -Wextra
LOCAL_C_INCLUDES := $(libcutils_c_includes)
LOCAL_C_INCLUDES := $(libcutils_c_includes)
LOCAL_CLANG := true
LOCAL_CLANG := true
+17 −1
Original line number Original line Diff line number Diff line
@@ -64,6 +64,8 @@ static int fg_cgroup_fd = -1;
// File descriptors open to /dev/cpuset/../tasks, setup by initialize, or -1 on error
// File descriptors open to /dev/cpuset/../tasks, setup by initialize, or -1 on error
static int bg_cpuset_fd = -1;
static int bg_cpuset_fd = -1;
static int fg_cpuset_fd = -1;
static int fg_cpuset_fd = -1;
static int bg_schedboost_fd = -1;
static int fg_schedboost_fd = -1;
#endif
#endif


/* Add tid to the scheduling group defined by the policy */
/* Add tid to the scheduling group defined by the policy */
@@ -128,6 +130,12 @@ static void __initialize(void) {
        fg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
        fg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
        filename = "/dev/cpuset/background/tasks";
        filename = "/dev/cpuset/background/tasks";
        bg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
        bg_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
#ifdef USE_SCHEDBOOST
        filename = "/sys/fs/cgroup/stune/foreground/tasks";
        fg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
        filename = "/sys/fs/cgroup/stune/tasks";
        bg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
#endif
    }
    }
#endif
#endif


@@ -253,17 +261,20 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
    pthread_once(&the_once, __initialize);
    pthread_once(&the_once, __initialize);


    int fd;
    int fd;
    int boost_fd;
    switch (policy) {
    switch (policy) {
    case SP_BACKGROUND:
    case SP_BACKGROUND:
        fd = bg_cpuset_fd;
        fd = bg_cpuset_fd;
        boost_fd = bg_schedboost_fd;
        break;
        break;
    case SP_FOREGROUND:
    case SP_FOREGROUND:
    case SP_AUDIO_APP:
    case SP_AUDIO_APP:
    case SP_AUDIO_SYS:
    case SP_AUDIO_SYS:
        fd = fg_cpuset_fd;
        fd = fg_cpuset_fd;
        boost_fd = fg_schedboost_fd;
        break;
        break;
    default:
    default:
        fd = -1;
        boost_fd = fd = -1;
        break;
        break;
    }
    }


@@ -272,6 +283,11 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
            return -errno;
            return -errno;
    }
    }


    if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) {
        if (errno != ESRCH && errno != ENOENT)
            return -errno;
    }

    return 0;
    return 0;
#endif
#endif
}
}
+14 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,17 @@ on init
    chown root system /sys/fs/cgroup/memory/sw/tasks
    chown root system /sys/fs/cgroup/memory/sw/tasks
    chmod 0660 /sys/fs/cgroup/memory/sw/tasks
    chmod 0660 /sys/fs/cgroup/memory/sw/tasks


    # Create energy-aware scheduler tuning nodes
    mkdir /sys/fs/cgroup/stune
    mount cgroup none /sys/fs/cgroup/stune schedtune
    mkdir /sys/fs/cgroup/stune/foreground
    chown system system /sys/fs/cgroup/stune
    chown system system /sys/fs/cgroup/stune/foreground
    chown system system /sys/fs/cgroup/stune/tasks
    chown system system /sys/fs/cgroup/stune/foreground/tasks
    chmod 0664 /sys/fs/cgroup/stune/tasks
    chmod 0664 /sys/fs/cgroup/stune/foreground/tasks

    # Mount staging areas for devices managed by vold
    # Mount staging areas for devices managed by vold
    # See storage config details at http://source.android.com/tech/storage/
    # See storage config details at http://source.android.com/tech/storage/
    mount tmpfs tmpfs /mnt mode=0755,uid=0,gid=1000
    mount tmpfs tmpfs /mnt mode=0755,uid=0,gid=1000
@@ -163,13 +174,16 @@ on init
    chown system system /dev/cpuset/foreground
    chown system system /dev/cpuset/foreground
    chown system system /dev/cpuset/foreground/boost
    chown system system /dev/cpuset/foreground/boost
    chown system system /dev/cpuset/background
    chown system system /dev/cpuset/background
    chown system system /dev/cpuset/system-background
    chown system system /dev/cpuset/tasks
    chown system system /dev/cpuset/tasks
    chown system system /dev/cpuset/foreground/tasks
    chown system system /dev/cpuset/foreground/tasks
    chown system system /dev/cpuset/foreground/boost/tasks
    chown system system /dev/cpuset/foreground/boost/tasks
    chown system system /dev/cpuset/background/tasks
    chown system system /dev/cpuset/background/tasks
    chown system system /dev/cpuset/system-background/tasks
    chmod 0664 /dev/cpuset/foreground/tasks
    chmod 0664 /dev/cpuset/foreground/tasks
    chmod 0664 /dev/cpuset/foreground/boost/tasks
    chmod 0664 /dev/cpuset/foreground/boost/tasks
    chmod 0664 /dev/cpuset/background/tasks
    chmod 0664 /dev/cpuset/background/tasks
    chmod 0664 /dev/cpuset/system-background/tasks
    chmod 0664 /dev/cpuset/tasks
    chmod 0664 /dev/cpuset/tasks




+1 −1
Original line number Original line Diff line number Diff line
@@ -5,4 +5,4 @@ service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-sys
    onrestart write /sys/power/state on
    onrestart write /sys/power/state on
    onrestart restart media
    onrestart restart media
    onrestart restart netd
    onrestart restart netd
    writepid /dev/cpuset/foreground/tasks
    writepid /dev/cpuset/foreground/tasks /sys/fs/cgroup/stune/foreground/tasks
+2 −2
Original line number Original line Diff line number Diff line
@@ -5,10 +5,10 @@ service zygote /system/bin/app_process32 -Xzygote /system/bin --zygote --start-s
    onrestart write /sys/power/state on
    onrestart write /sys/power/state on
    onrestart restart media
    onrestart restart media
    onrestart restart netd
    onrestart restart netd
    writepid /dev/cpuset/foreground/tasks
    writepid /dev/cpuset/foreground/tasks /sys/fs/cgroup/stune/foreground/tasks


service zygote_secondary /system/bin/app_process64 -Xzygote /system/bin --zygote --socket-name=zygote_secondary
service zygote_secondary /system/bin/app_process64 -Xzygote /system/bin --zygote --socket-name=zygote_secondary
    class main
    class main
    socket zygote_secondary stream 660 root system
    socket zygote_secondary stream 660 root system
    onrestart restart zygote
    onrestart restart zygote
    writepid /dev/cpuset/foreground/tasks
    writepid /dev/cpuset/foreground/tasks /sys/fs/cgroup/stune/foreground/tasks
 No newline at end of file
Loading