Skip to content

Commit

Permalink
Merge PR #1488 (lwAFTR perf regression fix) into max-next
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Oct 12, 2022
2 parents 18d2631 + 4706127 commit 68c338e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
9 changes: 6 additions & 3 deletions src/apps/lwaftr/binding_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,29 @@ psid_map_value_t = ffi.typeof[[

BTLookupQueue = {}

local BTLookupQueue_size = 128
assert(BTLookupQueue_size >= engine.pull_npackets)

-- BTLookupQueue needs a binding table to get softwires and PSID lookup.
function BTLookupQueue.new(binding_table)
local ret = {
binding_table = assert(binding_table),
}
ret.streamer = binding_table.softwires:make_lookup_streamer(32)
ret.packet_queue = ffi.new("struct packet * [32]")
ret.streamer = binding_table.softwires:make_lookup_streamer(BTLookupQueue_size)
ret.packet_queue = ffi.new("struct packet * [?]", BTLookupQueue_size)
ret.length = 0
return setmetatable(ret, {__index=BTLookupQueue})
end

function BTLookupQueue:enqueue_lookup(pkt, ipv4, port)
assert(self.length < BTLookupQueue_size, "BTLookupQueue overflow")
local n = self.length
local streamer = self.streamer
streamer.entries[n].key.ipv4 = ipv4
streamer.entries[n].key.psid = port
self.packet_queue[n] = pkt
n = n + 1
self.length = n
return n == 32
end

function BTLookupQueue:process_queue()
Expand Down
15 changes: 3 additions & 12 deletions src/apps/lwaftr/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -780,16 +780,10 @@ end

function LwAftr:enqueue_encapsulation(pkt, ipv4, port, pkt_src_link)
if pkt_src_link == PKT_FROM_INET then
if self.inet_lookup_queue:enqueue_lookup(pkt, ipv4, port) then
-- Flush the queue right away if enough packets are queued up already.
self:flush_encapsulation()
end
self.inet_lookup_queue:enqueue_lookup(pkt, ipv4, port)
else
assert(pkt_src_link == PKT_HAIRPINNED)
if self.hairpin_lookup_queue:enqueue_lookup(pkt, ipv4, port) then
-- Flush the queue right away if enough packets are queued up already.
self:flush_hairpin()
end
self.hairpin_lookup_queue:enqueue_lookup(pkt, ipv4, port)
end
end

Expand Down Expand Up @@ -977,10 +971,7 @@ function LwAftr:flush_decapsulation()
end

function LwAftr:enqueue_decapsulation(pkt, ipv4, port)
if self.inet_lookup_queue:enqueue_lookup(pkt, ipv4, port) then
-- Flush the queue right away if enough packets are queued up already.
self:flush_decapsulation()
end
self.inet_lookup_queue:enqueue_lookup(pkt, ipv4, port)
end

-- FIXME: Verify that the packet length is big enough?
Expand Down
1 change: 0 additions & 1 deletion src/lib/ctable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ end
function LookupStreamer:stream()
local width = self.width
local entries = self.entries
local keys = self.keys
local pointers = self.pointers
local stream_entries = self.stream_entries
local entries_per_lookup = self.entries_per_lookup
Expand Down
14 changes: 2 additions & 12 deletions src/lib/hash/siphash.dasl
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,6 @@ local function make_hash2(opts)
local hash = make_hash1(opts)
local stride = opts.stride or opts.size
return function(ptr, result)
ptr = ffi.cast('uint8_t*', ptr)
result = ffi.cast('uint32_t*', result)
result[0] = hash(ptr)
result[1] = hash(ptr + stride)
end
Expand All @@ -587,8 +585,6 @@ local function make_hash4(opts)
local hash = make_hash2(opts)
local stride = opts.stride or opts.size
return function(ptr, result)
ptr = ffi.cast('uint8_t*', ptr)
result = ffi.cast('uint32_t*', result)
hash(ptr, result)
hash(ptr + stride*2, result + 2)
end
Expand All @@ -612,19 +608,13 @@ function make_multi_hash(opts)

if width % 4 == 0 then
return function(input, output)
input = ffi.cast('uint8_t*', input)
output = ffi.cast('uint32_t*', output)
for i=1,width,4 do
hash4(input, output)
input = input + stride*4
output = output + 4
for i=0,width-1,4 do
hash4(input + stride*i, output + i)
end
end
end

return function(input, output)
input = ffi.cast('uint8_t*', input)
output = ffi.cast('uint32_t*', output)
for i=1,bit.rshift(width, 2) do
hash4(input, output)
input = input + stride*4
Expand Down

0 comments on commit 68c338e

Please sign in to comment.