Skip to content

Commit

Permalink
move redundant report() and is_device_suitable() to packetblaster.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Wiget committed Apr 1, 2016
1 parent b994c84 commit 6b0a9ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 42 deletions.
20 changes: 20 additions & 0 deletions src/program/packetblaster/packetblaster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,32 @@
module(..., package.seeall)

local lib = require("core.lib")
local pci = require("lib.hardware.pci")

local function show_usage(exit_code)
print(require("program.packetblaster.README_inc"))
main.exit(exit_code)
end

function report ()
print("Transmissions (last 1 sec):")
engine.report_apps()
end

function is_device_suitable (pcidev, patterns)
if not pcidev.usable or pcidev.driver ~= 'apps.intel.intel_app' then
return false
end
if #patterns == 0 then
return true
end
for _, pattern in ipairs(patterns) do
if pci.qualified(pcidev.pciaddress):gmatch(pattern)() then
return true
end
end
end

function run(args)
if #args == 0 then show_usage(1) end
local command = string.gsub(table.remove(args, 1), "-", "_")
Expand Down
24 changes: 3 additions & 21 deletions src/program/packetblaster/replay/replay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local LoadGen = require("apps.intel.loadgen").LoadGen
local lib = require("core.lib")
local ffi = require("ffi")

local packetblaster = require("program.packetblaster.packetblaster")
local usage = require("program.packetblaster.replay.README_inc")

local long_opts = {
Expand Down Expand Up @@ -46,7 +47,7 @@ function run (args)
local nics = 0
pci.scan_devices()
for _,device in ipairs(pci.devices) do
if is_device_suitable(device, patterns) then
if packetblaster.is_device_suitable(device, patterns) then
nics = nics + 1
local name = "nic"..nics
config.app(c, name, LoadGen, device.pciaddress)
Expand All @@ -57,27 +58,8 @@ function run (args)
engine.busywait = true
intel10g.num_descriptors = 32*1024
engine.configure(c)
local fn = function ()
print("Transmissions (last 1 sec):")
engine.report_apps()
end
local t = timer.new("report", fn, 1e9, 'repeating')
local t = timer.new("report", packetblaster.report, 1e9, 'repeating')
timer.activate(t)
if duration then engine.main({duration=duration})
else engine.main() end
end

function is_device_suitable (pcidev, patterns)
if not pcidev.usable or pcidev.driver ~= 'apps.intel.intel_app' then
return false
end
if #patterns == 0 then
return true
end
for _, pattern in ipairs(patterns) do
if pci.qualified(pcidev.pciaddress):gmatch(pattern)() then
return true
end
end
end

24 changes: 3 additions & 21 deletions src/program/packetblaster/synth/synth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local LoadGen = require("apps.intel.loadgen").LoadGen
local lib = require("core.lib")
local ffi = require("ffi")

local packetblaster = require("program.packetblaster.packetblaster")
local usage = require("program.packetblaster.synth.README_inc")

local long_opts = {
Expand Down Expand Up @@ -55,7 +56,7 @@ function run (args)
local nics = 0
pci.scan_devices()
for _,device in ipairs(pci.devices) do
if is_device_suitable(device, patterns) then
if packetblaster.is_device_suitable(device, patterns) then
nics = nics + 1
local name = "nic"..nics
config.app(c, name, LoadGen, device.pciaddress)
Expand All @@ -66,27 +67,8 @@ function run (args)
engine.busywait = true
intel10g.num_descriptors = 32*1024
engine.configure(c)
local fn = function ()
print("Transmissions (last 1 sec):")
engine.report_apps()
end
local t = timer.new("report", fn, 1e9, 'repeating')
local t = timer.new("report", packetblaster.report, 1e9, 'repeating')
timer.activate(t)
if duration then engine.main({duration=duration})
else engine.main() end
end

function is_device_suitable (pcidev, patterns)
if not pcidev.usable or pcidev.driver ~= 'apps.intel.intel_app' then
return false
end
if #patterns == 0 then
return true
end
for _, pattern in ipairs(patterns) do
if pci.qualified(pcidev.pciaddress):gmatch(pattern)() then
return true
end
end
end

0 comments on commit 6b0a9ca

Please sign in to comment.