login: apply uclamp.min for ui and chrome_renderers cpu cgroup

Chrome applies uclamp values to urgent cpuset cgroup in per thread
basis, this cpu cgroup's settings should be applied to make it possible
to override the effective uclamp.min value from parent group.

BUG=b:159370915
TEST=read /proc/[urgent-tasks]/sched

Change-Id: Id9d6531ad1620e47db0185b4fabaeb2669e34f53
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2517267
Tested-by: Ikjoon Jang <ikjn@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Joel Fernandes <joelaf@google.com>
Commit-Queue: Ikjoon Jang <ikjn@chromium.org>
diff --git a/login_manager/init/scripts/ui-pre-start b/login_manager/init/scripts/ui-pre-start
index 2090df0..7771730 100755
--- a/login_manager/init/scripts/ui-pre-start
+++ b/login_manager/init/scripts/ui-pre-start
@@ -6,6 +6,32 @@
 
 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.
@@ -58,6 +84,16 @@
   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/