FIX processor topology length

This commit is contained in:
Nathan Dwarshuis 2023-09-28 17:33:58 -04:00
parent da5b4d3f2b
commit 564796b81d
3 changed files with 18 additions and 10 deletions

View File

@ -160,13 +160,14 @@ return function(update_freq, main_state, config, common, width, point)
local hwp_paths = cpu.get_hwp_paths(topology) local hwp_paths = cpu.get_hwp_paths(topology)
local freq_labels local freq_labels
local cpu_group_map = cpu.topology_to_cpu_map(topology) local cpu_group_map = cpu.topology_to_cpu_map(topology)
local ngroups = pure.length(topology)
local format_label = function(group_id) local format_label = function(group_id)
return __string_format('Ave Freq (%i)', group_id) return __string_format('Ave Freq (%i)', group_id)
end end
if #topology == 1 then if ngroups == 1 then
freq_labels = {'Ave Freq'} freq_labels = {'Ave Freq'}
else else
freq_labels = pure.map_n(format_label, #topology) freq_labels = pure.map_n(format_label, ngroups)
end end
local cpu_status = common.make_text_rows( local cpu_status = common.make_text_rows(
point.x, 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) local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status)
return common.mk_acc( return common.mk_acc(
width, width,
text_spacing * #topology, text_spacing * ngroups,
update, update,
static, static,
dynamic dynamic

View File

@ -136,6 +136,14 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- random list things -- 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 -- a stupid but composable function
M.get = function(key, tbl) M.get = function(key, tbl)
return tbl[key] return tbl[key]

View File

@ -172,12 +172,6 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- cpu -- 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) M.get_cpu_number = function(topology)
local n = 0 local n = 0
for g, c in pairs(topology) do 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 -- return a table with keys corresponding to physcial core id and values to
-- the number of threads of each core (usually 1 or 2) -- the number of threads of each core (usually 1 or 2)
M.get_core_threads = function() 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 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 flip = function(c) return {__tonumber(c[2]), __tonumber(c[1])} end
local make_indexer = pure.compose( local make_indexer = pure.compose(
@ -206,8 +201,8 @@ M.get_core_threads = function()
end end
local get_coretemp_mapper = function() local get_coretemp_mapper = function()
local d = get_coretemp_dir()
i_o.assert_exe_exists('grep') i_o.assert_exe_exists('grep')
local d = get_coretemp_dir()
local get_labels = pure.compose( local get_labels = pure.compose(
i_o.execute_cmd, i_o.execute_cmd,
pure.partial(__string_format, 'grep Core %s/temp*_label', true) pure.partial(__string_format, 'grep Core %s/temp*_label', true)
@ -224,6 +219,9 @@ local get_coretemp_mapper = function()
end end
M.get_core_topology = function() 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 coretemp_paths = get_coretemp_mapper()
local assign_cpu = function(i, x) local assign_cpu = function(i, x)
return { 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 -- 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 -- (which queries /proc/cpuinfo) is much faster and doesn't have this jittery
-- problem. -- problem.
i_o.assert_exe_exists('lscpu')
local out = i_o.execute_cmd('lscpu -p=MHZ') local out = i_o.execute_cmd('lscpu -p=MHZ')
local init_freqs = function(v) local init_freqs = function(v)
local r = {} local r = {}