From 0cb256c03de278cf34b6f5df56d0436306b74c29 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Tue, 23 Mar 2021 21:30:57 +0100 Subject: [PATCH] scripts: Add helper script for looking up PMR info under qemu Added mainly to verify if the PMR setup on the VM is correct. Example of an output with PMR device size of 32M configured for two nvme devices, and one nvme device with 128M CMB. [root@fedora31-cloud-1614680581-9ba06c102 ~]# /tmp/get-pmr nvme0:0000:00:04.0:64-bit:prefetchable:0xf0000000:0xf7ffffff:0x08000000:cmb nvme1:0000:00:05.0:64-bit:prefetchable:0xf8000000:0xf9ffffff:0x02000000:pmr nvme2:0000:00:06.0:64-bit:prefetchable:0xfa000000:0xfbffffff:0x02000000:pmr Signed-off-by: Michal Berger Change-Id: I522cebd8b5a16f8a37c6e0e01a0288fb310467fb Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7019 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki Reviewed-by: Ben Walker --- scripts/get-pmr | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 scripts/get-pmr diff --git a/scripts/get-pmr b/scripts/get-pmr new file mode 100755 index 0000000000..76fd186623 --- /dev/null +++ b/scripts/get-pmr @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# We simply check if BAR2 is present as that's where PMR or CMB is +# meant to be located under qemu. If found, print some stats then exit. + +[[ $(uname -s) == Linux ]] || exit 0 +# Use MSR instead? +[[ $(< /sys/class/dmi/id/chassis_vendor) == QEMU ]] || exit 0 + +get_bar2() { + echo "0x$(setpci -s "$1" 0x18.L)" +} + +get_size() { + local addr=$1 + local start end type + + while IFS="- " read -r start end type; do + start=0x$start end=0x$end + if ((start == addr)) && [[ $type == *"$pci"* ]]; then + printf '0x%08x:0x%08x:0x%08x\n' \ + "$start" "$end" $((end - start + 1)) + return 0 + fi + done < /proc/iomem + echo "unknown" +} + +info() { + local bar=$1 + + local pref loc + + pref[0]=non-prefetchable + pref[1]=prefetchable + + loc[0]=32-bit + loc[1]="<1MiB" + loc[2]=64-bit + + echo "${loc[(bar >> 1) & 0x3]}:${pref[bar & 1 << 3 ? 1 : 0]}:$(get_size $((bar & ~0xf)))" +} + +for nvme in /sys/class/nvme/nvme*; do + pci=$(readlink -f "$nvme/device") pci=${pci##*/} + bar2=$(get_bar2 "$pci") || continue + ((bar2 != 0x0)) || continue + bar=pmr + [[ -e $nvme/cmb ]] && bar=cmb + echo "${nvme##*/}:$pci:$(info "$bar2"):$bar" +done