Debian Codegraph @

vicious/contrib/ati_linux.lua

raw symbols SCIP
1 -- contrib/ati_linux.lua
2 -- Copyright (C) 2013 NormalRa <normalrawr gmail com>
3 -- Copyright (C) 2017 Jörg Thalheim <[email protected]>
4 --
5 -- This file is part of Vicious.
6 --
7 -- Vicious is free software: you can redistribute it and/or modify
8 -- it under the terms of the GNU General Public License as
9 -- published by the Free Software Foundation, either version 2 of the
10 -- License, or (at your option) any later version.
11 --
12 -- Vicious is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
19
20 -- {{{ Grab environment
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 -- ATI: provides various info about ATI GPU status
34 -- vicious.contrib.ati
35 local ati_linux = {}
36
37
38 -- {{{ Define variables
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 -- {{{ ATI widget type
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 -- Get power info
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 -- Get ATI info from the debug filesystem
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}"] = -- DPM active?
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 })