Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This scripts sets the DPTF profile to ADAPTIVE_PERFORMANCE under linux and enables the relevant thermal zone. Requires ROOT and a fairly recent kernel (likely 5.3+)
#!/bin/bash
# DISCLAIMER
# This script is not officially created nor endorsed by the manufacturer(s) of your software, hardware or parts of it.
# Apply/use at your own discretion considering all possible consequences (bricked devices, dead machine, thermonuclear war, etc.).
# LICENCE
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# USAGE and PURPOSE
# The objective of this script is to the set the ADAPTIVE_PERFORMANCE DPTF profile and enable the relevant thermal zone so that the
# firmware/EC allows TCC Offset lower than 20
# based on https://forums.lenovo.com/t5/Other-Linux-Discussions/X1C6-T480s-low-cTDP-and-trip-temperature-in-Linux/m-p/4447831/highlight/true#M13343
# which in turn is based on https://www.reddit.com/r/linux/comments/9n5ajg/first_part_of_the_real_fix_for_ultrabook_cpu/
# NOTE: this script requires ROOT
FORCE=false
if [[ "$1" == "-f" ]]; then
FORCE=true
fi
# initial TCC Offset
INITIAL_TCC_OFFSET=$(rdmsr -f 29:24 -d 0x1a2)
echo Current TCC Offset: $(expr 100 - $INITIAL_TCC_OFFSET )C
if [[ $INITIAL_TCC_OFFSET -le 5 ]] && [ $FORCE == "false" ]; then
echo "TCC Offset already set. Aborting. (Hint: Use the -f flag to override)"
exit 1
fi
#Profile UUID to NAME tables: https://elixir.bootlin.com/linux/latest/source/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
ADAPTIVE_PERFORMANCE=63BE270F-1C11-48FD-A6F7-3AF253FF3E2D
CURRENT_UUID=$(cat /sys/devices/platform/INT3400:00/uuids/current_uuid)
#echo Current DTPF Profile UUID: $CURRENT_UUID
if [[ $CURRENT_UUID == $ADAPTIVE_PERFORMANCE ]] && [ $FORCE == "false" ]; then
echo "Current DPTF profile is already set to ADAPTIVE PERFORMANCE [$ADAPTIVE_PERFORMANCE]. (Hint: Use the -f flag to override)"
exit 0
fi
AVAILABLE_PROFILES=$(cat /sys/devices/platform/INT3400:00/uuids/available_uuids)
#echo Available DTPF Profile UUIDs : $AVAILABLE_PROFILES
if [[ $AVAILABLE_PROFILES != *$ADAPTIVE_PERFORMANCE* ]]; then
echo "ERROR: ADAPTIVE_PERFORMANCE [$ADAPTIVE_PERFORMANCE] DPTF profile not supported by this system. Aborting."
exit 1
fi
# looking for something like /sys/class/thermal/thermal_zone1/type:INT3400 Thermal
zoneId=$(grep INT3400 /sys/class/thermal/thermal_zone*/type | grep Thermal | sed '/\/sys\/class\/thermal\/thermal_zone/ s/\/type.*//')
if [[ $zoneId == '' ]]; then
echo "ERROR: Could not find thermal zone with id INT3400 and type 'Thermal'. Aborting."
exit 1
fi
#echo Found INT3400 Thermal zone: $zoneId
echo disabled > "$zone/mode"
THERMAL_ZONE_MODE=$(cat $zoneId/mode)
if [[ $THERMAL_ZONE_MODE == 'enabled' ]] && [ $FORCE == "false" ]; then
echo "Could not disable thermal zone $zoneId (temporarily). (Hint: Use the -f flag to override)"
else
echo Activating ADAPTIVE_PERFORMANCE PROFILE
echo $ADAPTIVE_PERFORMANCE >/sys/devices/platform/INT3400:00/uuids/current_uuid
echo Enabling zone $zoneId ...
echo enabled >$zoneId/mode
echo New mode of thermal zone: $(cat $zoneId/mode)
fi
echo Current TCC Offset: $(expr 100 - $(rdmsr -f 29:24 -d 0x1a2) )C
echo Finished.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.