Skip to content
Snippets Groups Projects
Commit 188833d3 authored by Martin Teichmann's avatar Martin Teichmann
Browse files

generate backup packages

this doubles the number of packages in the loop, but is an
effective measure against package loss
parent a1b88c27
No related branches found
No related tags found
No related merge requests found
...@@ -228,14 +228,25 @@ class EtherXDP(XDP): ...@@ -228,14 +228,25 @@ class EtherXDP(XDP):
license = "GPL" license = "GPL"
variables = ArrayMap() variables = ArrayMap()
counters = variables.globalVar("64I", write=True) counters = variables.globalVar("64I")
def program(self): def program(self):
with self.packetSize > 24 as p, p.pH[12] == 0xA488, p.pB[16] == 0: with self.packetSize > 24 as p, p.pH[12] == 0xA488, p.pB[16] == 0:
self.r3 = p.pI[18] self.r3 = p.pI[18]
with self.counters.get_address(None, False, False) as (dst, _), \ with self.counters.get_address(None, False, False) as (dst, _), \
self.r3 < FastEtherCat.MAX_PROGS: self.r3 < FastEtherCat.MAX_PROGS:
self.mI[self.r[dst] + 4 * self.r3] += 1 self.mH[self.r[dst] + 4 * self.r3] += 1
p.pB[17] += 2
with p.pB[17] & 1 as is_regular:
self.mB[self.r[dst] + 4 * self.r3 + 3] += 1
self.mB[self.r[dst] + 4 * self.r3 + 2] = 0
with is_regular.Else():
self.mB[self.r[dst] + 4 * self.r3 + 2] += 1
self.mB[self.r[dst] + 4 * self.r3 + 3] = 0
with self.mB[self.r[dst] + 4 * self.r3 + 2] > 3 as exceed:
p.pB[17] += 1 # turn into regular package
with exceed.Else():
self.exit(XDPExitCode.TX)
self.r2 = self.get_fd(self.programs) self.r2 = self.get_fd(self.programs)
self.call(FuncId.tail_call) self.call(FuncId.tail_call)
self.exit(XDPExitCode.PASS) self.exit(XDPExitCode.PASS)
...@@ -271,14 +282,16 @@ class FastEtherCat(SimpleEtherCat): ...@@ -271,14 +282,16 @@ class FastEtherCat(SimpleEtherCat):
return index return index
async def watchdog(self): async def watchdog(self):
lastcounts = [0] * 64
while True: while True:
t0 = time() t0 = time()
self.ebpf.counters = (0,) * self.MAX_PROGS self.ebpf.variables.read()
self.ebpf.variables.readwrite()
counts = self.ebpf.counters counts = self.ebpf.counters
for i, sg in self.sync_groups.items(): for i, sg in self.sync_groups.items():
if counts[i] == 0: if ((counts[i] ^ lastcounts[i]) & 0xffff == 0
or (counts[i] >> 24) > 3):
self.send_packet(sg.assembled) self.send_packet(sg.assembled)
lastcounts[i] = counts[i]
await sleep(0.001) await sleep(0.001)
async def connect(self): async def connect(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment