FIX processor topology length
This commit is contained in:
parent
da5b4d3f2b
commit
564796b81d
|
@ -160,13 +160,14 @@ return function(update_freq, main_state, config, common, width, point)
|
|||
local hwp_paths = cpu.get_hwp_paths(topology)
|
||||
local freq_labels
|
||||
local cpu_group_map = cpu.topology_to_cpu_map(topology)
|
||||
local ngroups = pure.length(topology)
|
||||
local format_label = function(group_id)
|
||||
return __string_format('Ave Freq (%i)', group_id)
|
||||
end
|
||||
if #topology == 1 then
|
||||
if ngroups == 1 then
|
||||
freq_labels = {'Ave Freq'}
|
||||
else
|
||||
freq_labels = pure.map_n(format_label, #topology)
|
||||
freq_labels = pure.map_n(format_label, ngroups)
|
||||
end
|
||||
local cpu_status = common.make_text_rows(
|
||||
point.x,
|
||||
|
@ -193,7 +194,7 @@ return function(update_freq, main_state, config, common, width, point)
|
|||
local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status)
|
||||
return common.mk_acc(
|
||||
width,
|
||||
text_spacing * #topology,
|
||||
text_spacing * ngroups,
|
||||
update,
|
||||
static,
|
||||
dynamic
|
||||
|
|
|
@ -136,6 +136,14 @@ end
|
|||
--------------------------------------------------------------------------------
|
||||
-- random list things
|
||||
|
||||
M.length = function(tbl)
|
||||
local n = 0
|
||||
for _, _ in pairs(tbl) do
|
||||
n = n + 1
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
-- a stupid but composable function
|
||||
M.get = function(key, tbl)
|
||||
return tbl[key]
|
||||
|
|
13
src/sys.lua
13
src/sys.lua
|
@ -172,12 +172,6 @@ end
|
|||
--------------------------------------------------------------------------------
|
||||
-- cpu
|
||||
|
||||
-- ASSUME lscpu will always be available
|
||||
|
||||
M.get_core_number = function()
|
||||
return __tonumber(i_o.read_file('/proc/cpuinfo', 'cpu cores%s+:%s(%d+)'))
|
||||
end
|
||||
|
||||
M.get_cpu_number = function(topology)
|
||||
local n = 0
|
||||
for g, c in pairs(topology) do
|
||||
|
@ -195,6 +189,7 @@ end
|
|||
-- return a table with keys corresponding to physcial core id and values to
|
||||
-- the number of threads of each core (usually 1 or 2)
|
||||
M.get_core_threads = function()
|
||||
i_o.assert_exe_exists('lscpu')
|
||||
local cmd = 'lscpu -y -p=core | grep -v \'^#\' | sort -k1,1n | uniq -c'
|
||||
local flip = function(c) return {__tonumber(c[2]), __tonumber(c[1])} end
|
||||
local make_indexer = pure.compose(
|
||||
|
@ -206,8 +201,8 @@ M.get_core_threads = function()
|
|||
end
|
||||
|
||||
local get_coretemp_mapper = function()
|
||||
local d = get_coretemp_dir()
|
||||
i_o.assert_exe_exists('grep')
|
||||
local d = get_coretemp_dir()
|
||||
local get_labels = pure.compose(
|
||||
i_o.execute_cmd,
|
||||
pure.partial(__string_format, 'grep Core %s/temp*_label', true)
|
||||
|
@ -224,6 +219,9 @@ local get_coretemp_mapper = function()
|
|||
end
|
||||
|
||||
M.get_core_topology = function()
|
||||
i_o.assert_exe_exists('lscpu')
|
||||
i_o.assert_exe_exists('grep')
|
||||
i_o.assert_exe_exists('sort')
|
||||
local coretemp_paths = get_coretemp_mapper()
|
||||
local assign_cpu = function(i, x)
|
||||
return {
|
||||
|
@ -285,6 +283,7 @@ M.read_ave_freqs = function(topology, cpu_group_map)
|
|||
-- scaling_cur_freq in sysfs seems to do the same thing. It appears lscpu
|
||||
-- (which queries /proc/cpuinfo) is much faster and doesn't have this jittery
|
||||
-- problem.
|
||||
i_o.assert_exe_exists('lscpu')
|
||||
local out = i_o.execute_cmd('lscpu -p=MHZ')
|
||||
local init_freqs = function(v)
|
||||
local r = {}
|
||||
|
|
Loading…
Reference in New Issue