Skip to content

Commit

Permalink
优化gpu路径获取
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Sep 1, 2023
1 parent d3ac696 commit f102855
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
4 changes: 3 additions & 1 deletion backend/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import subprocess
import glob
import os
from helpers import get_homebrew_path,get_home_path,get_user

Expand All @@ -20,7 +21,8 @@
HOMEBREW_PATH = get_homebrew_path(get_home_path(get_user()))
SH_PATH="{}/plugins/PowerControl/backend/sh_tools.sh".format(HOMEBREW_PATH)
RYZENADJ_PATH="{}/plugins/PowerControl/bin/ryzenadj".format(HOMEBREW_PATH)
GPUFREQ_PATH = "/sys/class/drm/card0/device/pp_od_clk_voltage"
GPU_DEVICE_PATH = glob.glob("/sys/class/drm/card?/device")[0]
GPUFREQ_PATH = "{}/pp_od_clk_voltage".format(GPU_DEVICE_PATH)
except Exception as e:
logging.error(f"路径配置异常|{e}")

Expand Down
1 change: 1 addition & 0 deletions backend/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def Check_gpuFreq(self, freqMin:int, freqMax:int):
global gpu_freqMax
global gpu_freqMin
try:
logging.debug(f"GPUFREQ_PATH = {GPUFREQ_PATH}")
#可查询gpu设置频率时,判断当前设置是否与系统相同
if os.path.exists(GPUFREQ_PATH):
lines = open(GPUFREQ_PATH,"r")
Expand Down
51 changes: 32 additions & 19 deletions backend/sh_tools.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/bin/bash

function get_gpu_device()
{
for gpu_device in /sys/class/drm/card?/device; do
if [ -d "$gpu_device" ]; then
echo "$gpu_device"
return
fi
done
}

gpu_device=$(get_gpu_device)


function set_cpu_Freq()
{
cpu_index=$1
Expand Down Expand Up @@ -67,54 +80,54 @@ function set_clock_limits()
let min=$1
let max=$2
if(($min==0 || $max==0));then
sudo echo "auto">/sys/class/drm/card0/device/power_dpm_force_performance_level
sudo echo "auto" > "${gpu_device}/power_dpm_force_performance_level"
else
sudo echo "manual">/sys/class/drm/card0/device/power_dpm_force_performance_level
sudo echo "s 0 ${min}" > /sys/class/drm/card0/device/pp_od_clk_voltage
sudo echo "s 1 ${max}" > /sys/class/drm/card0/device/pp_od_clk_voltage
sudo echo "c" > /sys/class/drm/card0/device/pp_od_clk_voltage
sudo echo "manual" > "${gpu_device}/power_dpm_force_performance_level"
sudo echo "s 0 ${min}" > "${gpu_device}/pp_od_clk_voltage"
sudo echo "s 1 ${max}" > "${gpu_device}/pp_od_clk_voltage"
sudo echo "c" > "${gpu_device}/pp_od_clk_voltage"
fi
sudo echo "gpu_clock_limit "$1 $2 >> /tmp/powerControl_sh.log
}

function get_gpuFreqMin()
{
sudo echo "manual">/sys/class/drm/card0/device/power_dpm_force_performance_level
echo "$(sudo cat /sys/class/drm/card0/device/pp_od_clk_voltage|grep -a "SCLK:"|awk '{print $2}'|sed -e 's/Mhz//g'|xargs)"
sudo echo "manual"> "${gpu_device}/power_dpm_force_performance_level"
echo "$(sudo cat ${gpu_device}/pp_od_clk_voltage|grep -a "SCLK:"|awk '{print $2}'|sed -e 's/Mhz//g'|xargs)"
}

function get_gpuFreqMax()
{
sudo echo "manual">/sys/class/drm/card0/device/power_dpm_force_performance_level
echo "$(sudo cat /sys/class/drm/card0/device/pp_od_clk_voltage|grep -a "SCLK:"|awk '{print $3}'|sed -e 's/Mhz//g'|xargs)"
sudo echo "manual" > "${gpu_device}/power_dpm_force_performance_level"
echo "$(sudo cat ${gpu_device}/pp_od_clk_voltage|grep -a "SCLK:"|awk '{print $3}'|sed -e 's/Mhz//g'|xargs)"
}

function set_gpu_flk()
{
flk=$1
index=$(((1600-$flk)/400))
now_mode=$(cat /sys/class/drm/card0/device/power_dpm_force_performance_level)
now_mode=$(cat ${gpu_device}/power_dpm_force_performance_level)
if [[ "$now_mode"!="manual" ]];then
sudo echo "manual" >/sys/class/drm/card0/device/power_dpm_force_performance_level
sudo echo "$index" >/sys/class/drm/card0/device/pp_dpm_fclk
sudo echo "manual" > "${gpu_device}/power_dpm_force_performance_level"
sudo echo "$index" > "${gpu_device}/pp_dpm_fclk"
else
sudo echo "$index" > /sys/class/drm/card0/device/pp_dpm_fclk
sudo echo "$index" > "${gpu_device}/pp_dpm_fclk"
fi
sudo echo "gpu_flk_limit " $index >> /tmp/powerControl_sh.log
}

function check_clock_limits()
{
mode=$1
now_mode=$(cat /sys/class/drm/card0/device/power_dpm_force_performance_level)
now_mode=$(cat ${gpu_device}/power_dpm_force_performance_level)
if [[ "$now_mode"!="$mode" ]];then
if(( "$1" == "manual"));then
sudo echo "manual" >/sys/class/drm/card0/device/power_dpm_force_performance_level
sudo echo "s 0 $2" > /sys/class/drm/card0/device/pp_od_clk_voltage
sudo echo "s 1 $3" > /sys/class/drm/card0/device/pp_od_clk_voltage
sudo echo "c" > /sys/class/drm/card0/device/pp_od_clk_voltage
sudo echo "manual" > "${gpu_device}/power_dpm_force_performance_level"
sudo echo "s 0 $2" > "${gpu_device}/pp_od_clk_voltage"
sudo echo "s 1 $3" > "${gpu_device}/pp_od_clk_voltage"
sudo echo "c" > "${gpu_device}/pp_od_clk_voltage"
else
sudo echo "auto" >/sys/class/drm/card0/device/power_dpm_force_performance_level
sudo echo "auto" > "${gpu_device}/power_dpm_force_performance_level"
fi
fi
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "PowerControl",
"version": "2.0.3",
"version": "2.0.4",
"description": "PowerControl plugin.",
"scripts": {
"build": "shx rm -rf dist && rollup -c",
Expand Down

0 comments on commit f102855

Please sign in to comment.