| 1 |
|
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
local tonumber = tonumber |
| 22 |
local io = { open = io.open } |
| 23 |
local setmetatable = setmetatable |
| 24 |
local helpers = require("vicious.helpers") |
| 25 |
local string = { |
| 26 |
sub = string.sub, |
| 27 |
match = string.match, |
| 28 |
gmatch = string.gmatch |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
local ati_linux = {} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
local _units = { clock = { ["khz"] = 1, ["mhz"] = 1000 }, |
| 40 |
voltage = { ["v"] = 1, ["mv"] = 1000 } } |
| 41 |
local _reps = { |
| 42 |
["sclk"] = { name = "engine_clock", units = _units.clock, mul = 10 }, |
| 43 |
["mclk"] = { name = "memory_clock", units = _units.clock, mul = 10 }, |
| 44 |
["vddc"] = { name = "voltage", units = _units.voltage }, |
| 45 |
["voltage"] = { name = "voltage", units = _units.voltage }, |
| 46 |
["current engine clock"] = { name = "engine_clock", units = _units.clock }, |
| 47 |
["current memory clock"] = { name = "memory_clock", units = _units.clock } |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
local function worker(format, warg) |
| 53 |
if not warg then return end |
| 54 |
|
| 55 |
local pm = helpers.pathtotable("/sys/class/drm/"..warg.."/device") |
| 56 |
local _data = {} |
| 57 |
|
| 58 |
|
| 59 |
_data["{method}"] = |
| 60 |
pm.power_method and string.sub(pm.power_method, 1, -2) or "N/A" |
| 61 |
_data["{dpm_state}"] = |
| 62 |
pm.power_dpm_state and string.sub(pm.power_dpm_state, 1, -2) or "N/A" |
| 63 |
_data["{dpm_perf_level}"] = |
| 64 |
pm.power_dpm_force_performance_level and |
| 65 |
string.sub(pm.power_dpm_force_performance_level, 1, -2) or "N/A" |
| 66 |
_data["{profile}"] = |
| 67 |
pm.power_profile and string.sub(pm.power_profile, 1, -2) or "N/A" |
| 68 |
|
| 69 |
local f = io.open("/sys/kernel/debug/dri/64/radeon_pm_info", "r") |
| 70 |
if f then |
| 71 |
for line in f:lines() do |
| 72 |
for k, unit in string.gmatch(line, "(%a+[%a%s]*):[%s]+([%d]+)") do |
| 73 |
unit = tonumber(unit) |
| 74 |
|
| 75 |
_data["{dpm_power_level}"] = |
| 76 |
tonumber(string.match(line, "power level ([%d])")) or "N/A" |
| 77 |
|
| 78 |
if _reps[k] then |
| 79 |
for u, v in pairs(_reps[k].units) do |
| 80 |
_data["{".._reps[k].name.." "..u.."}"] = |
| 81 |
(unit * (_reps[k].mul or 1)) / v |
| 82 |
end |
| 83 |
end |
| 84 |
end |
| 85 |
end |
| 86 |
f:close() |
| 87 |
end |
| 88 |
|
| 89 |
return _data |
| 90 |
end |
| 91 |
|
| 92 |
|
| 93 |
return setmetatable(ati_linux, { __call = function(_, ...) return worker(...) end }) |