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
|
#!/usr/bin/env python3
# runbook.py - watch for the GR0 channel ring registration, hand the pair to
# sema_pdb_discover, then (after the pdb anchor) issue bounded
# sema_chan_rewind calls so entries skipped before the anchor re-decode.
import re, subprocess, sys, time
PDB = "/sys/module/vgsp/parameters/sema_pdb_discover"
REW = "/sys/module/vgsp/parameters/sema_chan_rewind"
def dmesg_tail(n=150):
out = subprocess.run(["sudo", "dmesg"], capture_output=True).stdout.decode(errors="ignore")
return out.splitlines()[-n:]
def main():
dur = float(sys.argv[1]) if len(sys.argv) > 1 else 180
end = time.time() + dur
fired = set()
rewinds = {}
print("# runbook start (%.0fs)" % dur, flush=True)
while time.time() < end:
for ln in dmesg_tail():
m = re.search(r"sema-chan: h=0x([0-9a-f]+) eng=\d+ cid=\d+ gpfifo=0x([0-9a-f]+) ent=\d+ userd=0x[0-9a-f]+ as=\d+ put=\d+ get=\d+ ring rc=0 pa=0x([0-9a-f]+)", ln)
if not m:
continue
h = int(m.group(1), 16)
gv = int(m.group(2), 16)
rp = int(m.group(3), 16)
key = (h, gv, rp)
if key in fired:
# after the anchor has had time to land, rewind this channel
if h == 0xbeec0100:
t0 = rewinds.setdefault(key, time.time())
n = int((time.time() - t0) // 8)
done = rewinds.get(("done", key), 0)
if n > done:
subprocess.run(["sudo", "sh", "-c",
"echo all > %s" % REW], capture_output=True)
rewinds[("done", key)] = n
print("[%s] REWIND all (h=0x%x, n=%d)" % (
time.strftime("%H:%M:%S"), h, n), flush=True)
continue
fired.add(key)
r = subprocess.run(["sudo", "sh", "-c",
"echo 0x%x,0x%x > %s" % (gv, rp, PDB)],
capture_output=True)
print("[%s] TRIGGER h=0x%x va=0x%x pa=0x%x rc=%d" % (
time.strftime("%H:%M:%S"), h, gv, rp, r.returncode), flush=True)
# report decodes/releases
out = subprocess.run(["sudo", "dmesg"], capture_output=True).stdout.decode(errors="ignore")
for ln in out.splitlines()[-8:]:
if ("sema-push: h=0xbeec0100" in ln and "have_rel=1" in ln) or \
"registered after verified" in ln or "rewind" in ln or \
("sema-push: h=0xbeec0100" in ln and "len=1432" in ln):
print("LOG %s" % ln.strip()[-170:], flush=True)
time.sleep(0.4)
print("# runbook end", flush=True)
main()
|