blob: 7771730d3d7501387aeda2335e69cd8242e7e089 [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
JOB=$(basename "$0")
# Read chrome OS configurations
read_cros_config_int() {
local path="$1"
local key="$2"
local def="$3"
local v
# cros_config exits with non-zero when a key isn't existed,
v=$(cros_config "${path}" "${key}" || echo "${def}")
# config value should be an integer
case "${v}" in
''|*[!0-9]*)
logger -t "${JOB}" -p warn \
"cros_config ${path}/${key} is not an integer! "\
"Let me use ${def} instead of ${v}."
echo "${def}"
;;
*)
echo "${v}"
;;
esac
}
# Setup drm log tracing if available. This will allow us to access more verbose
# logs to debug display connectivity issues when they arise. The traces are
# accessible via chrome://system and included in feedback/crash reports.
#
# As configured, we won't have a lot of volume in these traces, they will only
# be written in cases where the display configuration changes, or an error
# occurs. As such, there is no performance impact during steady-state operation.
#
# TODO(seanpaul): Once we've finished moving over to the upstream tracefs
# implementation, remove the block initializing the downstream
# debugfs code. Tracked in b/163580546.
DRM_TRACE_DIR="/sys/kernel/debug/dri"
DRM_TRACE_MASK="${DRM_TRACE_DIR}/trace_mask"
if [ -w "${DRM_TRACE_MASK}" ]; then
# 64kB per-cpu of drm logs.
echo 64 > "${DRM_TRACE_DIR}/trace_size_kb"
# 0x106 corresponds to (DRM_UT_DRIVER | DRM_UT_KMS | DRM_UT_DP).
echo 0x106 > "${DRM_TRACE_MASK}"
fi
DRM_TRACEFS_INSTANCE="/sys/kernel/debug/tracing/instances/drm"
DRM_TRACEFS_BUF_SIZE="${DRM_TRACEFS_INSTANCE}/buffer_size_kb"
if [ -w "${DRM_TRACEFS_BUF_SIZE}" ]; then
# 64kB per-cpu of drm logs.
echo 64 > "${DRM_TRACEFS_BUF_SIZE}"
fi
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
# apply ui and chrome foreground cgroup's uclamp.min, default 20%,
v=$(read_cros_config_int "/scheduler-tune" "boost-urgent" "20")
for knob in "${UI_CPU_CGROUP_DIR}/cpu.uclamp.min" \
"${CHROME_CPU_CGROUP_DIR}/cpu.uclamp.min" \
"${CHROME_CPU_CGROUP_DIR}/foreground/cpu.uclamp.min"; do
if [ -f "${knob}" ]; then
echo "${v}" > "${knob}"
fi
done
# Set up a folder on the stateful partition for ephemeral encrypted swap
# files.
USERSPACE_SWAP_DIR=/mnt/stateful_partition/unencrypted/userspace_swap.tmp/
if [ ! -d "${USERSPACE_SWAP_DIR}" ]; then
mkdir -p "${USERSPACE_SWAP_DIR}"
chown -R chronos "${USERSPACE_SWAP_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"
echo "-1" > "${CONTAINER_CGROUP_DIR}/cpu.cfs_quota_us"
if [ -f "${CONTAINER_CGROUP_DIR}/cpu.uclamp.min" ]; then
echo "100" > "${CONTAINER_CGROUP_DIR}/cpu.uclamp.min"
fi
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