Skip to content

Commit 976fb08

Browse files
committed
fix: NUMA check
1 parent 5696384 commit 976fb08

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

scripts/pin_cpus.sh

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,43 @@ if ! [[ $CPU_SET_RANGE =~ ^[0-9,-]+$ ]]; then
3232
exit 1
3333
fi
3434

35-
# --- minimal NUMA check ---
36-
# nodes_used=$(for cpu in $(echo "$CPU_SET_RANGE" | sed 's/,/ /g'); do
37-
# for node_dir in /sys/devices/system/node/node*; do
38-
# grep -qE "(^|,)$cpu($|,|-)" "$node_dir/cpulist" && echo $(basename $node_dir | sed 's/node//')
39-
# done
40-
# done | sort -u)
41-
#
42-
# if [[ $(wc -w <<< "$nodes_used") -gt 1 ]]; then
43-
# echo "error: requested CPUs span multiple NUMA nodes. nodes [$nodes_used]"
44-
# exit 1
45-
# fi
46-
# echo "requested CPUs are within NUMA node. node [$nodes_used]"
47-
# --- end minimal NUMA check ---
35+
# --- NUMA check ---
36+
expand_cpu_range() {
37+
local range=$1
38+
local cpus=()
39+
IFS=',' read -ra parts <<< "$range"
40+
for part in "${parts[@]}"; do
41+
if [[ $part == *-* ]]; then
42+
IFS='-' read -r start end <<< "$part"
43+
for ((i=start; i<=end; i++)); do
44+
cpus+=("$i")
45+
done
46+
else
47+
cpus+=("$part")
48+
fi
49+
done
50+
echo "${cpus[@]}"
51+
}
52+
# determine NUMA nodes used by requested CPUs
53+
nodes_used=$(for cpu in $(expand_cpu_range "$CPU_SET_RANGE"); do
54+
for node_dir in /sys/devices/system/node/node*; do
55+
cpulist_file="$node_dir/cpulist"
56+
[[ -f $cpulist_file ]] || continue
57+
if grep -qE "(^|,)$cpu($|,|-)" "$cpulist_file"; then
58+
echo "$(basename "$node_dir" | sed 's/node//')"
59+
fi
60+
done
61+
done | sort -u)
62+
if [[ -z "$nodes_used" ]]; then
63+
echo "error: could not determine NUMA nodes. CPUs [$CPU_SET_RANGE]"
64+
exit 1
65+
fi
66+
if [[ $(wc -w <<< "$nodes_used") -gt 1 ]]; then
67+
echo "error: requested CPUs span multiple NUMA nodes. CPUs [$CPU_SET_RANGE] nodes [$nodes_used]"
68+
exit 1
69+
fi
70+
echo "requested CPUs are within NUMA node. CPUs [$CPU_SET_RANGE] node [$nodes_used]"
71+
# --- end NUMA check ---
4872

4973
# build path based on cgroup version
5074
if [[ -f /sys/fs/cgroup/cgroup.controllers ]]; then

0 commit comments

Comments
 (0)