#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)

# Minimal OS variable loading for performance
. /etc/profile.d/001-functions
. /etc/profile.d/030-powerfunctions
. /etc/profile.d/099-freqfunctions

#tocon "Setting performance mode..."

### Enable the desired number of threads.
#tocon "Restoring cpu threads..."
NUMTHREADS=$(get_setting "system.threads")
if [ -n "${NUMTHREADS}" ]
then
        onlinethreads ${NUMTHREADS} 0
else
        onlinethreads all 1
fi

### If we don't have a default governor set, set it
### to schedutil if the device supports it, otherwise
### set to performance, but don't enable it.
if [ -z "$(get_setting system.cpugovernor)" ]
then
  GOVTEST="$(awk '/schedutil/ {print $1}' /sys/devices/system/cpu/cpufreq/policy0/scaling_available_governors)"
  if [ -n "${GOVTEST}" ]
  then
    set_setting system.cpugovernor schedutil
  else
    set_setting system.cpugovernor performance
  fi
fi

### Set the default GPU performance mode
GPUPERF=$(get_setting system.gpuperf)
if [ -n "${GPUPERF}" ]
then
  gpu_performance_level ${GPUPERF}
fi
