#!/bin/sh
# Re-enable all offline CPUs after block devices have been probed.

CMDLINE_FILE="${CMDLINE_FILE:-/proc/cmdline}"
SYS_DIR="${SYS_DIR:-/sys}"

if [ ! -f "$CMDLINE_FILE" ] || [ -z "$(grep -Ew "(ocs_1_cpu_udev|maxcpus=1)" "$CMDLINE_FILE" 2>/dev/null)" ]; then
  # Skip if neither ocs_1_cpu_udev nor maxcpus=1 exists.
  exit 0
fi

echo "Enabling SMP-like behavior after udev was started... "
for cpu in "$SYS_DIR"/devices/system/cpu/cpu[1-9]*; do
  if [ -e "$cpu/online" ]; then
    echo -n "$(basename "$cpu"), "
    (echo 1 > "$cpu/online" 2>/dev/null || echo "Failed to enable $(basename "$cpu")") &
  fi
done
echo "done!"
