xref: /spdk/scripts/perf/nvmf/common.py (revision ae7b5890ef728af40bd233a5011b924c482603bf)
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("source scripts/common.sh; iter_pci_class_code 01 08 02",
25                          executable="/bin/bash", shell=True)
26    output = [str(x, encoding="utf-8") for x in output.split()]
27    print("Done getting BDFs")
28    return output
29
30
31def get_nvme_devices():
32    print("Getting kernel NVMe names")
33    output = check_output("lsblk -o NAME -nlp", shell=True).decode(encoding="utf-8")
34    output = [x for x in output.split("\n") if "nvme" in x]
35    print("Done getting kernel NVMe names")
36    return output
37
38
39def nvmet_command(nvmet_bin, command):
40    return check_output("%s %s" % (nvmet_bin, command), shell=True).decode(encoding="utf-8")
41