From 7ae76356440a542b132286f733ca195212d6cefe Mon Sep 17 00:00:00 2001 From: Anton Todorov Date: Fri, 22 Nov 2019 11:08:07 +0200 Subject: [PATCH] B #3972: normalize the list of cpus (#3973) following the description in CPUSET(7) man page: List format The List Format for cpus and mems is a comma-separated list of CPU or memory-node numbers and ranges of numbers, in ASCII decimal. Examples of the List Format: 0-4,9 # bits 0, 1, 2, 3, 4, and 9 set 0-2,7,12-14 # bits 0, 1, 2, 7, 12, 13, and 14 set Signed-off-by: Anton Todorov --- src/im_mad/remotes/node-probes.d/numa.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/im_mad/remotes/node-probes.d/numa.rb b/src/im_mad/remotes/node-probes.d/numa.rb index ac6719a957..284a96c8a0 100755 --- a/src/im_mad/remotes/node-probes.d/numa.rb +++ b/src/im_mad/remotes/node-probes.d/numa.rb @@ -109,6 +109,21 @@ def huge_pages(nodes, node_id) end end +def normalize_list(list_format) + list = [] + list_format.split(',').each do |range| + arr = range.split('-') + if arr.length > 1 + for entry in arr[0]..arr[1] do + list << entry + end + else + list.concat(arr) + end + end + list +end + # ------------------------------------------------------------------------------ # CPU topology # ------------------------------------------------------------------------------ @@ -134,7 +149,7 @@ def cpu_topology(nodes, node_id) core_path = "#{cpu_path}/#{cp}/topology" siblings = File.read("#{core_path}/thread_siblings_list").chomp - siblings = siblings.split(',') + siblings = normalize_list(siblings) cpu_visited.concat(siblings)