| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# SPDX-License-Identifier: BSD-3-Clause |
| 4 |
# Copyright © 2016-2017 Inria. All rights reserved. |
| 5 |
# See COPYING in top-level directory. |
| 6 |
|
| 7 |
# This tool exports a topology as a Linux sysfs filesystem inside the |
| 8 |
# output directory given as the first argument. |
| 9 |
# The goal is to test the Linux import code back from there. |
| 10 |
# |
| 11 |
# It may be used to export from XML by setting HWLOC_XMLFILE=file.xml in the environment, |
| 12 |
# or from synthetic by setting HWLOC_SYNTHETIC="node:4 core:4 pu:2". |
| 13 |
# |
| 14 |
# The export isn't complete. It lacks /proc/cpuinfo and several other files (see below). |
| 15 |
# But at least it takes care of generating the annoying files (bitmasks for each cpu and node). |
| 16 |
|
| 17 |
if test "x$1" = "x"; then |
| 18 |
echo "Missing output directory argument." |
| 19 |
exit 1 |
| 20 |
fi |
| 21 |
|
| 22 |
outdir="$1" |
| 23 |
|
| 24 |
Ppus=$(hwloc-calc -I pu --po --sep " " root) |
| 25 |
|
| 26 |
for Ppu in $Ppus; do |
| 27 |
Lpu=$(hwloc-calc --pi --lo -I pu pu:$Ppu) |
| 28 |
echo "Exporting PU L#${Lpu} = P#${Ppu}..." |
| 29 |
mkdir -p "$outdir/sys/devices/system/cpu/cpu${Ppu}/topology" |
| 30 |
|
| 31 |
Lcore=$(hwloc-calc -I core pu:$Lpu) |
| 32 |
Pcore=$(hwloc-calc --po -I core pu:$Lpu) |
| 33 |
if test "x$Lcore" != x; then |
| 34 |
echo " Adding core L#${Lcore} = P#${Pcore}..." |
| 35 |
echo $Pcore > "$outdir/sys/devices/system/cpu/cpu${Ppu}/topology/core_id" |
| 36 |
hwloc-calc core:$Lcore | sed -e 's/0x//g' -e 's/,,/,00000000,/g' > "$outdir/sys/devices/system/cpu/cpu${Ppu}/topology/thread_siblings" |
| 37 |
# FIXME: thread_siblings_list isn't used so far |
| 38 |
else |
| 39 |
echo " No core." |
| 40 |
fi |
| 41 |
|
| 42 |
Lpack=$(hwloc-calc -I pack pu:$Lpu) |
| 43 |
Ppack=$(hwloc-calc --po -I pack pu:$Lpu) |
| 44 |
if test "x$Lpack" != x; then |
| 45 |
echo " Adding package L#${Lpack} = P#${Ppack}..." |
| 46 |
echo $Ppack > "$outdir/sys/devices/system/cpu/cpu${Ppu}/topology/physical_package_id" |
| 47 |
hwloc-calc pack:$Lpack | sed -e 's/0x//g' -e 's/,,/,00000000,/g' > "$outdir/sys/devices/system/cpu/cpu${Ppu}/topology/core_siblings" |
| 48 |
# FIXME: core_siblings_list isn't used so far |
| 49 |
else |
| 50 |
echo "No package." |
| 51 |
fi |
| 52 |
|
| 53 |
Lnumas=$(hwloc-calc -I numanode pu:$Lpu --sep " ") |
| 54 |
if test "x$Lnumas" != x; then |
| 55 |
# 2.0 with always NUMA node but possibly multiple of them |
| 56 |
for Lnuma in $Lnumas; do |
| 57 |
Pnuma=$(hwloc-calc --po -I numanode numa:$Lnuma) |
| 58 |
echo " Adding NUMAnode L#${Lnuma} = P#${Pnuma}..." |
| 59 |
mkdir -p "$outdir/sys/devices/system/node/node${Pnuma}" |
| 60 |
hwloc-calc numanode:$Lnuma | sed -e 's/0x//g' -e 's/,,/,00000000,/g' > "$outdir/sys/devices/system/node/node${Pnuma}/cpumap" |
| 61 |
bytes=$(hwloc-info numanode:$Lnuma | sed -rn -e 's/^ local memory = //p') |
| 62 |
echo "Node $Pnuma MemTotal: "$((bytes/1024))" kB" > "$outdir/sys/devices/system/node/node${Pnuma}/meminfo" |
| 63 |
done |
| 64 |
else |
| 65 |
# 1.x with single local NUMA node but possibly none |
| 66 |
echo " Adding single NUMAnode L#0 = P#0..." |
| 67 |
mkdir -p "$outdir/sys/devices/system/node/node0" |
| 68 |
hwloc-calc all | sed -e 's/0x//g' -e 's/,,/,00000000,/g' > "$outdir/sys/devices/system/node/node0/cpumap" |
| 69 |
bytes=$(hwloc-info root | sed -rn -e 's/^ local memory = //p') |
| 70 |
echo "Node 0 MemTotal: "$((bytes/1024))" kB" > "$outdir/sys/devices/system/node/node0/meminfo" |
| 71 |
fi |
| 72 |
# FIXME: symlinks between cpu and node aren't needed so far |
| 73 |
|
| 74 |
cachetypes=$(hwloc-info --ancestors pu:$Lpu | sed -nre 's/^ full type = //p' | grep -i Cache) |
| 75 |
index=0 |
| 76 |
for cachetype in $cachetypes; do |
| 77 |
mkdir -p "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}" |
| 78 |
hwloc-info --ancestor $cachetype pu:${Lpu} | sed -rn -e 's/^ cpuset = //p' | sed -e 's/0x//g' -e 's/,,/,00000000,/g' > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/shared_cpu_map" |
| 79 |
hwloc-info --ancestor $cachetype pu:${Lpu} | sed -rn -e 's/^ attr cache depth = //p' > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/level" |
| 80 |
hwloc-info --ancestor $cachetype pu:${Lpu} | sed -rn -e 's/^ attr cache type = //p' > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/type" |
| 81 |
bytes=$(hwloc-info --ancestor $cachetype pu:${Lpu} | sed -rn -e 's/^ attr cache size = //p') |
| 82 |
echo $((bytes/1024))K > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/size" |
| 83 |
hwloc-info --ancestor $cachetype pu:${Lpu} | sed -rn -e 's/^ attr cache line size = //p' > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/coherency_line_size" |
| 84 |
ways=$(hwloc-info --ancestor $cachetype pu:${Lpu} | sed -rn -e 's/^ attr cache ways = //p') |
| 85 |
echo 1 > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/physical_line_partition" |
| 86 |
echo $((bytes/ways)) > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/number_of_sets" |
| 87 |
echo $ways > "$outdir/sys/devices/system/cpu/cpu${Ppu}/cache/index${index}/ways_of_associativity" |
| 88 |
index=$((index+1)) |
| 89 |
done |
| 90 |
done |
| 91 |
|
| 92 |
# FIXME: /sys/devices/system/cpu/{online,offline,possible,present,kernel_max} |
| 93 |
|
| 94 |
# command-line tools look for /proc to autoguess that -i means fake fsroot |
| 95 |
mkdir -p "$outdir/proc" |
| 96 |
# FIXME: /proc/cpuinfo |