-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_mode
executable file
·90 lines (78 loc) · 2.24 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
import argparse
import common_bf
def main() -> None:
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",
)
parser.add_argument(
"-n",
"--next_boot",
action="store_true",
help="Get the next_boot mode of the BF",
)
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 -e -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:
if "different from default/current" in e:
save_next = False
continue
k, default, current, next_boot = e.lstrip("*").split()
config = next_boot if args.next_boot else current
settings[k] = config.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()