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