1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#!/bin/bash -e
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2019-2020 Intel Corporation. All rights reserved.
KERNEL=${KERNEL:-$(uname -r)}
ROOT_IMAGE=${ROOT_IMAGE:-root.img}
INITIATORS=4
TARGETS=128
TARGET_SIZE_MB=128
TARGET_SIZE="$((TARGET_SIZE_MB * 1024 * 1024))"
QEMU_MEM="$((TARGET_SIZE_MB * TARGETS))"
for i in $(seq 0 $((TARGETS - 1))); do
qemu-img create -f raw "dimm-$i" "${TARGET_SIZE}"
done;
# Address Range Structures
cat <<EOF > hmat.dsl
Signature : "HMAT" [Heterogeneous Memory Attributes Table]
Table Length : 00000200
Revision : 01
Checksum : F4
Oem ID : "BOCHS "
Oem Table ID : "BXPCHMAT"
Oem Revision : 00000001
Asl Compiler ID : "INTL"
Asl Compiler Revision : 20170929
Reserved : 00000000
Structure Type : 0000 [Memory Subystem Address Range]
Reserved : 0000
Length : 00000028
Flags (decoded below) : 0003
Processor Proximity Domain Valid : 1
Memory Proximity Domain Valid : 1
Reservation Hint : 0
Reserved1 : 0000
Processor Proximity Domain : 00000000
Memory Proximity Domain : 00000000
Reserved2 : 00000000
Physical Address Range Base : 0000000000000000
Physical Address Range Size : 00000000000A0000
Structure Type : 0000 [Memory Subystem Address Range]
Reserved : 0000
Length : 00000028
Flags (decoded below) : 0003
Processor Proximity Domain Valid : 1
Memory Proximity Domain Valid : 1
Reservation Hint : 0
Reserved1 : 0000
Processor Proximity Domain : 00000000
Memory Proximity Domain : 00000000
Reserved2 : 00000000
Physical Address Range Base : 0000000000100000
Physical Address Range Size : 0000000007F00000
EOF
for i in $(seq 1 $((TARGETS - 1))); do
BASE=$(printf "%016x" $((0x8000000 * i)))
cat <<EOF >> hmat.dsl
Structure Type : 0000 [Memory Subystem Address Range]
Reserved : 0000
Length : 00000028
Flags (decoded below) : 0003
Processor Proximity Domain Valid : 1
Memory Proximity Domain Valid : 1
Reservation Hint : 0
Reserved1 : 0000
Processor Proximity Domain : $(printf "%08x" $((i % INITIATORS)))
Memory Proximity Domain : $(printf "%08x" "${i}")
Reserved2 : 00000000
Physical Address Range Base : ${BASE}
Physical Address Range Size : 0000000008000000
EOF
done
# System Locality Latency
TABLE_SIZE="$(printf "%08x" $((40 + 4 * INITIATORS + 4 * TARGETS + 2 * INITIATORS * TARGETS)))"
cat <<EOF >> hmat.dsl
Structure Type : 0001 [System Locality Latency and Bandwidth Information]
Reserved : 0000
Length : ${TABLE_SIZE}
Flags (decoded below) : 00
Memory Hierarchy : 0
Data Type : 00
Reserved1 : 0000
Initiator Proximity Domains # : $(printf "%08x" ${INITIATORS})
Target Proximity Domains # : $(printf "%08x" ${TARGETS})
Reserved2 : 00000000
Entry Base Unit : 0000000000000001
EOF
for i in $(seq 0 $((INITIATORS - 1))); do
cat <<EOF >> hmat.dsl
Initiator Proximity Domain List : $(printf "%08x" "${i}")
EOF
done
for i in $(seq 0 $((TARGETS - 1))); do
cat <<EOF >> hmat.dsl
Target Proximity Domain List : $(printf "%08x" "${i}")
EOF
done
LOCAL_START=0x10
REMOTE_START=0x20
for i in $(seq 0 $((INITIATORS - 1))); do
for j in $(seq 0 $((TARGETS - 1))); do
if [ "$((j % INITIATORS))" -eq "${i}" ]; then
cat <<EOF >> hmat.dsl
Entry : $(printf "%04x" $((LOCAL_START + j * 10)))
EOF
else
cat <<EOF >> hmat.dsl
Entry : $(printf "%04x" $((REMOTE_START + j * 10)))
EOF
fi
done
done
# System Locality Bandwidth
TABLE_SIZE=$(printf "%08x" $((40 + 4 * INITIATORS + 4 * TARGETS + 2 * INITIATORS * TARGETS)))
cat <<EOF >> hmat.dsl
Structure Type : 0001 [System Locality Latency and Bandwidth Information]
Reserved : 0000
Length : ${TABLE_SIZE}
Flags (decoded below) : 00
Memory Hierarchy : 0
Data Type : 03
Reserved1 : 0000
Initiator Proximity Domains # : $(printf "%08x" ${INITIATORS})
Target Proximity Domains # : $(printf "%08x" ${TARGETS})
Reserved2 : 00000000
Entry Base Unit : 0000000000000400
EOF
for i in $(seq 0 $((INITIATORS - 1))); do
cat <<EOF >> hmat.dsl
Initiator Proximity Domain List : $(printf "%08x" "${i}")
EOF
done
for i in $(seq 0 $((TARGETS - 1))); do
cat <<EOF >> hmat.dsl
Target Proximity Domain List : $(printf "%08x" "${i}")
EOF
done
LOCAL_START=0x2000
REMOTE_START=0x1000
for i in $(seq 0 $((INITIATORS - 1))); do
for j in $(seq 0 $((TARGETS - 1))); do
if [ "$((j % INITIATORS))" -eq "${i}" ]; then
cat <<EOF >> hmat.dsl
Entry : $(printf "%04x" $((LOCAL_START - j * 32)))
EOF
else
cat <<EOF >> hmat.dsl
Entry : $(printf "%04x" $((REMOTE_START - j * 32)))
EOF
fi
done
done
# Side Caches
for i in $(seq 0 ${TARGETS}); do
cat <<EOF >> hmat.dsl
Structure Type : 0002 [Memory Side Cache Information Structure]
Reserved : 0000
Length : 00000020
Memory Proximity Domain : $(printf "%08x" "${i}")
Reserved1 : 00000000
Memory Side Cache Size : 0000000000100000
Cache Attributes (decoded below) : 01001113
Total Cache Levels : 1
Cache Level : 1
Cache Associativity : 1
Write Policy : 1
Cache Line Size : 0100
Reserved2 : 0000
SMBIOS Handle # : 0000
EOF
done
# Generate injected initrd
iasl ./*dsl
mkdir -p kernel/firmware/acpi/
rm -f kernel/firmware/acpi/*.aml hmat-initramfs
cp ./*aml kernel/firmware/acpi/
find kernel | cpio -c -o > hmat-initramfs
cat "/boot/initramfs-${KERNEL}.img" >> hmat-initramfs
# Build and evaluate QEMU command line
QEMU="qemu-system-x86_64 -m ${QEMU_MEM} -smp 8,sockets=${INITIATORS},maxcpus=8 -machine pc,accel=kvm "
QEMU+="-enable-kvm -display none -nographic -snapshot -hda ${ROOT_IMAGE} "
QEMU+="-kernel /boot/vmlinuz-${KERNEL} -initrd ./hmat-initramfs "
QEMU+="-append \"console=tty0 console=ttyS0 root=/dev/sda rw\" "
for i in $(seq 0 $((TARGETS - 1))); do
QEMU+="-object memory-backend-file,id=mem${i},share,mem-path=dimm-${i},size=${TARGET_SIZE_MB}M "
QEMU+="-numa node,nodeid=${i},memdev=mem${i} "
done
eval "${QEMU}"
|