forked from bn222/dpu-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_mode
executable file
·61 lines (53 loc) · 1.8 KB
/
get_mode
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
#!/usr/bin/env python3
import common_bf
import argparse
def main():
parser = argparse.ArgumentParser(description='Reads the current mode of the BF.')
parser.add_argument('-i', '--id', dest='id', default=0,
action='store', type=int, help='Specify the id of the BF.')
parser.add_argument('-v', '--verbose', dest='verbose',
default=False, action='store', type=bool,
help='Enable verbose output. This will show the settings')
args = parser.parse_args()
bf = common_bf.find_bf_pci_addresses_or_quit(args.id)
cfg = [
"INTERNAL_CPU_MODEL",
"INTERNAL_CPU_PAGE_SUPPLIER",
"INTERNAL_CPU_ESWITCH_MANAGER",
"INTERNAL_CPU_IB_VPORT0",
"INTERNAL_CPU_OFFLOAD_ENGINE"
]
all_cfg = " ".join(cfg)
ret = common_bf.run(f"mstconfig -d {bf} q {all_cfg}").out
save_next = False
settings = {}
for e in ret.split("\n"):
if not e:
continue
if e.startswith("Configurations:"):
save_next = True
elif save_next:
k, v = e.split()
settings[k] = v.split("(")[1].split(")")[0]
dpu_mode = {
'INTERNAL_CPU_MODEL': '1',
'INTERNAL_CPU_PAGE_SUPPLIER': '0',
'INTERNAL_CPU_ESWITCH_MANAGER': '0',
'INTERNAL_CPU_IB_VPORT0': '0',
'INTERNAL_CPU_OFFLOAD_ENGINE': '0'}
nic_mode = {
'INTERNAL_CPU_MODEL': '1',
'INTERNAL_CPU_PAGE_SUPPLIER': '1',
'INTERNAL_CPU_ESWITCH_MANAGER': '1',
'INTERNAL_CPU_IB_VPORT0': '1',
'INTERNAL_CPU_OFFLOAD_ENGINE': '1'}
if dpu_mode == settings:
print("dpu")
elif nic_mode == settings:
print("nic")
else:
print("unknown")
if args.verbose:
print(settings)
if __name__ == "__main__":
main()