Skip to content

Commit

Permalink
Enabled the Low Power 5G flag by default and supported changing defau…
Browse files Browse the repository at this point in the history
…lt value of flags.
  • Loading branch information
bb-qq committed Jul 30, 2022
1 parent d84770c commit 605669a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
64 changes: 64 additions & 0 deletions scripts/apply-private-flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

set -eu

SCRIPT=`realpath $0`
ETCDIR=`realpath -m ${SCRIPT}/../../etc`

# flag storage
FLAG_FILE_LOWPOWER="${ETCDIR}/flag-low_power_5g"
FLAG_FILE_THERMALTHROTTLING="${ETCDIR}/flag-thermal_throttling"

# default value
FLAG_DEFAULT_LOWPOWER="on"
FLAG_DEFAULT_THERMALTHROTTLING="on"

DEVNAME=${1:-}

function process_config() {
FLAG_NAME=$1
FLAG_FILE=$2
FLAG_CURRENT=$3
FLAG_DEFAULT=$4

if [ -e "${FLAG_FILE}" ]
then
FLAG_CONFIG=`cat ${FLAG_FILE}`
else
FLAG_CONFIG=${FLAG_DEFAULT}
echo ${FLAG_CONFIG} > ${FLAG_FILE}
fi

if [ "${FLAG_CURRENT}" != "${FLAG_CONFIG}" ]
then
ethtool --set-priv-flags ${DEVNAME} "${FLAG_NAME}" "${FLAG_CONFIG}"
fi
}

if [ -z "${DEVNAME}" ]
then
echo "$0 <ifname>"
exit 1
fi

ethtool --show-priv-flags ${DEVNAME} | {
while read FLAGLINE
do
FLAGVALUE=${FLAGLINE/#*: }
case "${FLAGLINE}" in
"Low Power 5G"*)
FLAG_CURRENT_LOWPOWER=${FLAGVALUE}
;;
"Thermal throttling"*)
FLAG_CURRENT_THERMALTHROTTLING=${FLAGVALUE}
;;
esac
done > /dev/null

process_config "Low Power 5G" \
"${FLAG_FILE_LOWPOWER}" "${FLAG_CURRENT_LOWPOWER}" "${FLAG_DEFAULT_LOWPOWER}"
process_config "Thermal throttling" \
"${FLAG_FILE_THERMALTHROTTLING}" "${FLAG_CURRENT_THERMALTHROTTLING}" "${FLAG_DEFAULT_THERMALTHROTTLING}"
}

ethtool --show-priv-flags ${DEVNAME}
5 changes: 5 additions & 0 deletions scripts/start-stop-status
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ set_interfaces()
synonet --dhcp ovs_$interface_name
fi
fi

if [ "$action" = "up" ]
then
test -e ${script_root}/apply-private-flags && sh ${script_root}/apply-private-flags $interface_name
fi
fi
done
}
Expand Down

0 comments on commit 605669a

Please sign in to comment.