Debian Codegraph @

modules/hwloc/contrib/misc/hwloc-export-sysfs

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