blob: 486cab57c701b4a141c01090aaf44ed91be13170 [file] [log] [blame]
#!/bin/sh
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
mkdir -p $UI_LOG_DIR
ln -sf ui.$(date +%Y%m%d-%H%M%S) $UI_LOG_DIR/$UI_LOG_FILE
mkdir -p $CONTAINER_ROOT_DIR
# Create a top-level cpu cgroup for ui tasks. This will be used to share cpu
# resources with tasks not managed by the UI. Android will be placed in a
# parallel cgroup allowing priority to be given to one or the other depending
# on what the user is doing at the time.
if [ ! -d $UI_CPU_CGROUP_DIR ]; then
mkdir -p ${UI_CPU_CGROUP_DIR}
fi
# Set up cgroups for chrome. We create two task groups, one for at most one
# foreground renderer and one for all the background renderers and set the
# background group to a very low priority. We specifically do not set it to
# the lowest "2" such that other processes like the update-engine can be even
# lower. The default value is 1024.
CHROME_CPU_CGROUP_DIR=/sys/fs/cgroup/cpu/chrome_renderers
if [ ! -d $CHROME_CPU_CGROUP_DIR ]; then
mkdir -p ${CHROME_CPU_CGROUP_DIR}/foreground
mkdir -p ${CHROME_CPU_CGROUP_DIR}/background
echo "10" > ${CHROME_CPU_CGROUP_DIR}/background/cpu.shares
chown -R chronos ${CHROME_CPU_CGROUP_DIR}
fi
# Set up the renderer freezer. This is used during the suspend/resume cycle
# to freeze all the chrome renderers so that they don't take up a lot of power
# when the system comes up in dark resume
if [ ! -d $CHROME_FREEZER_CGROUP_DIR ]; then
mkdir -p ${CHROME_FREEZER_CGROUP_DIR}
mkdir -p "${CHROME_FREEZER_CGROUP_DIR}/to_be_frozen"
chown -R chronos ${CHROME_FREEZER_CGROUP_DIR}
fi
# Set up a cgroup for containers(Android) started by session manager. To
# start, limit the cpu shares of Android. This will be reset to the default
# once the user clicks on an Android app. Keeping the usage low prevents
# Android boot from slowing the login process.
CONTAINER_CGROUP_DIR=/sys/fs/cgroup/cpu/session_manager_containers
if [ -d $CONTAINER_CGROUP_DIR ]; then
echo "32" > ${CONTAINER_CGROUP_DIR}/cpu.shares
fi
if crossystem "cros_debug?1"; then
# Set up the alt-syscall kernel module (on systems with kernel 3.14 or later)
# to allow developer mode only system calls to be exposed to Android
# containers (and potentially other containers) when the system is in
# developer mode.
DEVMODE_SYSCALL=/proc/sys/kernel/chromiumos/alt_syscall/allow_devmode_syscalls
if [ -e "${DEVMODE_SYSCALL}" ]; then
echo "1" > "${DEVMODE_SYSCALL}"
fi
# /proc/sys/kernel/perf_event_paranoid controls the use of kernel perf events
# system by users without the CAP_SYS_ADMIN capability (see
# kernel/Documentation/sysctl/kernel.txt for details). On systems with kernel
# 3.14 or later, we enable CONFIG_SECURITY_PERF_EVENTS_RESTRICT in kernel,
# which sets the default value of perf_event_paranoid to a more restrictive
# level "3", instead of "1". As alt-syscall exposes perf_event_open() to
# Android containers when the system is in developer mode, restore
# perf_event_paranoid to the less restrictive level "1".
PERF_EVENT_PARANOID=/proc/sys/kernel/perf_event_paranoid
if [ -e "${PERF_EVENT_PARANOID}" ]; then
echo "1" > "${PERF_EVENT_PARANOID}"
fi
fi
# Set up the lucid sleep debug flag. This file only exists on devices that
# use kernel 3.14. When this sysfs entry is set to 1, the kernel will treat
# all resumes as dark resumes, relying on chrome and powerd to detect any user
# activity and to transition out of dark resume into regular resume. Since we
# are currently unable to distinguish the source that woke up the system, this
# is a temporary workaround to allow for apps and extensions to test lucid
# sleep functionality. Chrome will write 1 to this file only if the
# wake-on-packets flag is set.
#
# TODO(chirantan): Remove this once the firmware change and corresponding
# kernel change for querying the wakeup source is ready (crbug.com/414949).
DARK_RESUME_ALWAYS_FILE=/sys/power/dark_resume_always
if [ -e "${DARK_RESUME_ALWAYS_FILE}" ]; then
chown chronos "${DARK_RESUME_ALWAYS_FILE}"
fi