xref: /spdk/scripts/perf/nvmf/common.py (revision 03e3fc4f5835983a4e6602b4e770922e798ce263)
1import os
2import re
3import json
4from itertools import product, chain
5from subprocess import check_output, Popen
6
7
8def get_used_numa_nodes():
9    used_numa_nodes = set()
10    for bdf in get_nvme_devices_bdf():
11        with open("/sys/bus/pci/devices/%s/numa_node" % bdf, "r") as numa_file:
12            output = numa_file.read()
13        used_numa_nodes.add(int(output))
14    return used_numa_nodes
15
16
17def get_nvme_devices_count():
18    output = get_nvme_devices_bdf()
19    return len(output)
20
21
22def get_nvme_devices_bdf():
23    print("Getting BDFs for NVMe section")
24    output = check_output("rootdir=$PWD; \
25                          source test/common/autotest_common.sh; \
26                          get_nvme_bdfs 01 08 02",
27                          executable="/bin/bash", shell=True)
28    output = [str(x, encoding="utf-8") for x in output.split()]
29    print("Done getting BDFs")
30    return output
31
32
33def get_nvme_devices():
34    print("Getting kernel NVMe names")
35    output = check_output("lsblk -o NAME -nlp", shell=True).decode(encoding="utf-8")
36    output = [x for x in output.split("\n") if "nvme" in x]
37    print("Done getting kernel NVMe names")
38    return output
39
40
41def nvmet_command(nvmet_bin, command):
42    return check_output("%s %s" % (nvmet_bin, command), shell=True).decode(encoding="utf-8")
43