Skip to content

Commit

Permalink
mellanox benchmark: add forwarding mode
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Feb 1, 2022
1 parent 0ab555f commit 312b740
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/apps/mellanox/benchmark-tx-fwd-queues-sizes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

sizes_fine="64
66
70
74
78
84
90
96
104
114
126
140
156
174
196
222
254
292
338
392
456
534
628
740
874
1034
1226
1456"

sizes_coarse="64
128
256
512
1024"

echo i,workers,queues,pktsize,txrate,txdrop,txerror,rxrate,rxdrop,rxerror,fwrate,fwdrop,fwerror
for i in `seq 1 3`; do
for w in `seq 1 6`; do
for q in `seq 1 4`; do
for s in $sizes_coarse; do
out=$(./snabb snsh apps/mellanox/benchmark.snabb -a 81:00.0 -b 81:00.1 -A 6-11 -B 12-17 \
-m source-fwd -w $w -q $q -s $s -n 100e6)
txrate=$(echo "$out" | grep "Tx Rate is" | cut -d " " -f 4)
txdrop=$(echo "$out" | grep "Tx Drop Rate is" | cut -d " " -f 5)
txerror=$(echo "$out" | grep "Tx Error Rate is" | cut -d " " -f 5)
rxrate=$(echo "$out" | grep "Rx Rate is" | cut -d " " -f 4)
rxdrop=$(echo "$out" | grep "Rx Drop Rate is" | cut -d " " -f 5)
rxerror=$(echo "$out" | grep "Rx Error Rate is" | cut -d " " -f 5)
fwrate=$(echo "$out" | grep "Fw Rate is" | cut -d " " -f 4)
fwdrop=$(echo "$out" | grep "Fw Drop Rate is" | cut -d " " -f 5)
fwerror=$(echo "$out" | grep "Fw Error Rate is" | cut -d " " -f 5)
echo "$i,$w,$q,$s,$txrate,$txdrop,$txerror,$rxrate,$rxdrop,$rxerror,$fwrate,$fwdrop,$fwerror"
#echo $out
done
done
done
done
112 changes: 112 additions & 0 deletions src/apps/mellanox/benchmark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,118 @@ function Source:pull ()
self.cursor = band(cursor, mask)
end

function fwd (pci, cores, nworkers, nqueues, macs, vlans, opt, npackets)
local cores = cpu_set(cores)
local macs = make_set(macs)
local vlans = make_set(vlans)

local cfg = mlxconf(pci, nworkers*nqueues, macs, vlans, opt)

local c = config.new()
config.app(c, "ConnectX", connectx.ConnectX, cfg)
engine.configure(c)

for w=1, nworkers do
worker.start(
"sink"..w,
('require("apps.mellanox.benchmark").fwd_worker(%q, %s, %d, %d)')
:format(pci, take(cores), nqueues, 1+(w-1)*nqueues)
)
end

local stats = engine.app_table.ConnectX.stats

local startline = npackets/10
engine.main{no_report=true, done=function () -- warmup
return counter.read(stats.rxpackets) >= startline
end}

local rxpackets_start = counter.read(stats.rxpackets)
local rxdrop_start = counter.read(stats.rxdrop)
local rxerrors_start = counter.read(stats.rxerrors)
local txpackets_start = counter.read(stats.txpackets)
local txdrop_start = counter.read(stats.txdrop)
local txerrors_start = counter.read(stats.txerrors)

local goal = rxpackets_start + npackets
local start = engine.now()
engine.main{no_report=true, done=function ()
return counter.read(stats.rxpackets) >= goal
end}

local duration = engine.now() - start
local rxpackets = counter.read(stats.rxpackets) - rxpackets_start
local rxdrop = counter.read(stats.rxdrop) - rxdrop_start
local rxerrors = counter.read(stats.rxerrors) - rxerrors_start
print(("Received %s packets in %.2f seconds"):format(lib.comma_value(rxpackets), duration))
print(("Rx Rate is %.3f Mpps"):format(tonumber(rxpackets) / duration / 1e6))
print(("Rx Drop Rate is %.3f Mpps"):format(tonumber(rxdrop) / duration / 1e6))
print(("Rx Error Rate is %.3f Mpps"):format(tonumber(rxerrors) / duration / 1e6))
local txpackets = counter.read(stats.txpackets) - txpackets_start
local txdrop = counter.read(stats.txdrop) - txdrop_start
local txerrors = counter.read(stats.txerrors) - txerrors_start
print(("Forwarded %s packets in %.2f seconds"):format(lib.comma_value(txpackets), duration))
print(("Fw Rate is %.3f Mpps"):format(tonumber(txpackets) / duration / 1e6))
print(("Fw Drop Rate is %.3f Mpps"):format(tonumber(txdrop) / duration / 1e6))
print(("Fw Error Rate is %.3f Mpps"):format(tonumber(txerrors) / duration / 1e6))
io.stdout:flush()

engine.main()
end

function fwd_worker (pci, core, nqueues, idx)
if core then numa.bind_to_cpu(core, 'skip') end
engine.busywait = true

local c = config.new()
config.app(c, "Forward", Forward)
local q = idx
for _=1, nqueues do
config.app(c, "IO"..q, connectx.IO, {pciaddress=pci, queue="q"..q})
config.link(c, "IO"..q..".output -> Forward.input"..q)
config.link(c, "Forward.output"..q.." -> IO"..q..".input")
q = q + 1
end
engine.configure(c)

while true do
engine.main{no_report=true, duration=1}
end
end

Forward = {}

local ethernet = require("lib.protocol.ethernet")

function Forward:new (conf)
local self = setmetatable({}, {__index=Forward})
self.eth = ethernet:new{}
return self
end

function Forward:link ()
self.input_links, self.output_links = {}, {}
for name, input in pairs(self.input) do
if type(name) == 'string' then
local q = name:match("input([0-9]+)")
self.input_links[#self.input_links+1] = input
self.output_links[#self.output_links+1] = self.output["output"..q]
end
end
end

function Forward:push ()
for i = 1, #self.input_links do
local input, output = self.input_links[i], self.output_links[i]
while not link.empty(input) do
local p = link.receive(input)
local eth = self.eth:new_from_mem(p.data, p.length)
eth:swap()
link.transmit(output, p)
end
end
end


function mlxconf (pci, nqueues, macs, vlans, opt)
local opt = opt or {}
Expand Down
12 changes: 12 additions & 0 deletions src/apps/mellanox/benchmark.snabb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ if mode == 'source-sink' then
return not worker.status()["source"].alive
end}

elseif mode == 'source-fwd' then

worker.start("forward", ('require("apps.mellanox.benchmark").fwd(%q, %q, %d, %d, nil, nil, %s, %d)')
:format(pci0, cores0, nworkers, nqueues, mlxopts, npackets))

worker.start("source", ('require("apps.mellanox.benchmark").source(%q, %q, %d, %d, nil, nil, %s, %d, %d)')
:format(pci1, cores1, nworkers, nqueues, mlxopts, npackets, pktsize))

engine.main{done = function ()
return not worker.status()["source"].alive
end}

elseif mode == 'source' then

worker.start("source", ('require("apps.mellanox.benchmark").source(%q, %q, %d, %d, nil, nil, %s, %d, %d)')
Expand Down

0 comments on commit 312b740

Please sign in to comment.