Skip to content

Commit

Permalink
Merge pull request #949 from Igalia/driver-independence-lwaftr
Browse files Browse the repository at this point in the history
Driver independence
  • Loading branch information
wingo authored Sep 20, 2017
2 parents ff9e2d9 + 79958bd commit 7924779
Show file tree
Hide file tree
Showing 28 changed files with 107 additions and 89 deletions.
8 changes: 2 additions & 6 deletions src/apps/intel/intel10g.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ do
end
end

function M_sf:ingress_packet_drops ()
return self.qs.QPRDC[0]()
end
function M_sf:rxdrop () return self.qs.QPRDC[0]() end

function M_sf:global_reset ()
local reset = bits{LinkReset=3, DeviceReset=26}
Expand Down Expand Up @@ -1004,9 +1002,7 @@ function M_vf:set_tx_rate (limit, priority)
return self
end

function M_vf:ingress_packet_drops ()
return self.pf.qs.QPRDC[self.rxstats]()
end
function M_vf:rxdrop () return self.pf.qs.QPRDC[self.rxstats]() end

rxdesc_t = ffi.typeof [[
union {
Expand Down
11 changes: 8 additions & 3 deletions src/apps/intel/intel_app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Intel82599 = {
rxcounter = {default=0},
txcounter = {default=0},
rate_limit = {default=0},
priority = {default=1.0}
priority = {default=1.0},
ring_buffer_size = {default=intel10g.ring_buffer_size()}
}
}
Intel82599.__index = Intel82599
Expand All @@ -52,6 +53,10 @@ end
function Intel82599:new (conf)
local self = {}

-- FIXME: ring_buffer_size is really a global variable for this
-- driver; taking the parameter as an initarg is just to make the
-- intel_mp transition easier.
intel10g.ring_buffer_size(conf.ring_buffer_size)
if conf.vmdq then
if devices[conf.pciaddr] == nil then
local pf = intel10g.new_pf(conf):open()
Expand Down Expand Up @@ -155,8 +160,8 @@ function Intel82599:pull ()
end
end

function Intel82599:ingress_packet_drops ()
return self.dev:ingress_packet_drops()
function Intel82599:rxdrop ()
return self.dev:rxdrop()
end

function Intel82599:add_receive_buffers ()
Expand Down
14 changes: 8 additions & 6 deletions src/apps/intel_mp/intel_mp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ EEC 0x00010 - RW EEPROM-Mode Control Register
Intel = {
config = {
pciaddr = {required=true},
ndescriptors = {default=2048},
ring_buffer_size = {default=2048},
vmdq = {default=false},
macaddr = {},
poolnum = {},
Expand Down Expand Up @@ -316,7 +316,7 @@ function Intel:new (conf)
r = {},
pciaddress = conf.pciaddr,
path = pci.path(conf.pciaddr),
ndesc = conf.ndescriptors,
ndesc = conf.ring_buffer_size,
txq = conf.txq,
rxq = conf.rxq,
mtu = conf.mtu,
Expand Down Expand Up @@ -482,6 +482,7 @@ function Intel:init_rx_q ()
self.r.RXCTRL:set(bits{ RXEN=0 })
self.r.DCA_RXCTRL:clr(bits{RxCTRL=12})
if self.vmdq then
-- enable packet reception for this pool/VF (4.6.10.1.4)
self.r.PFVFRE[math.floor(self.poolnum/32)]:set(bits{VFRE=self.poolnum%32})
end
elseif self.driver == "Intel1g" then
Expand Down Expand Up @@ -569,12 +570,14 @@ function Intel:push ()
if not self.txq then return end
local li = self.input["input"]
if li == nil then return end
-- assert(li, "intel_mp:push: no input link")

while not empty(li) and self:ringnext(self.tdt) ~= self.tdh do
local p = receive(li)
-- NB: see comment in intel10g for why this is commented out,
-- the rest of the loop body goes in an else branch
-- NB: the comment below is taken from intel_mp.lua, which disables
-- this check for the same reason.
-- We must not send packets that are bigger than the MTU. This
-- check is currently disabled to satisfy some selftests until
-- agreement on this strategy is reached.
--if p.length > self.mtu then
-- packet.free(p)
-- counter.add(self.shm.txdrop)
Expand Down Expand Up @@ -610,7 +613,6 @@ function Intel:pull ()
if not self.rxq then return end
local lo = self.output["output"]
if lo == nil then return end
-- assert(lo, "intel_mp:pull: output link required")

local pkts = 0
while band(self.rxdesc[self.rdt].status, 0x01) == 1 and pkts < engine.pull_npackets do
Expand Down
2 changes: 0 additions & 2 deletions src/apps/intel_mp/testrecv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ function test(pciaddr, qno, vmdq, poolno, macaddr, vlan)
vmdq=true,
poolnum=poolno,
rxq = qno,
ndescriptors = 2048,
wait_for_link=true })
else
config.app(c, "nic", intel.Intel,
{ pciaddr=pciaddr,
rxq = qno,
ndescriptors = 2048,
wait_for_link=true })
end
config.app(c, "sink", basic.Sink)
Expand Down
3 changes: 2 additions & 1 deletion src/apps/intel_mp/testsend.snabb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ local C = require("ffi").C

local c = config.new()
config.app(c, "pcap", pcap.PcapReader, pcapfile)
config.app(c, "nic", intel.Intel, {pciaddr=pciaddr, txq = qno, ndescriptors=2048, wait_for_link = true})
config.app(c, "nic", intel.Intel,
{pciaddr=pciaddr, txq=qno, wait_for_link=true})

if os.getenv("SNABB_SEND_BLAST") then
local basic = require("apps.basic.basic_apps")
Expand Down
3 changes: 1 addition & 2 deletions src/apps/intel_mp/testup.snabb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ local function new_intel (arg)
return intel.Intel:new(parse(arg, intel.Intel.config))
end

local nic = new_intel(
{ pciaddr=pciaddr, rxq = qno, ndescriptors = 2048, wait_for_link = true })
local nic = new_intel({ pciaddr=pciaddr, rxq = qno, wait_for_link = true })
print(nic:link_status())
main.exit(0)
2 changes: 0 additions & 2 deletions src/apps/intel_mp/testvlan.snabb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ config.app(c, "pcap", pcap.PcapReader, pcapfile)
config.app(c, "nic1", intel.Intel,
{pciaddr=pciaddr1,
txq = 0,
ndescriptors=2048,
wait_for_link = true})
config.app(c, "nic2", intel.Intel,
{pciaddr=pciaddr2,
Expand All @@ -32,7 +31,6 @@ config.app(c, "nic2", intel.Intel,
vlan = 1,
poolnum = 0,
rxq = 0,
ndescriptors=2048,
wait_for_link = true})

-- use pflua to filter based on presence of vlan tag
Expand Down
2 changes: 0 additions & 2 deletions src/apps/intel_mp/testvmdqtx.snabb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ config.app(c, "nic1", intel.Intel,
txq = 0,
txcounter = 1,
vlan = 1,
ndescriptors=2048,
wait_for_link = true })

-- nic2 just receives packets so we can check them
config.app(c, "nic2", intel.Intel,
{ pciaddr=pciaddr2,
rxq = 0,
ndescriptors=2048,
wait_for_link = true })

config.app(c, "pcap", pcap.PcapReader, pcapfile)
Expand Down
11 changes: 11 additions & 0 deletions src/lib/hardware/pci.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function device_info (pciaddress)
info.model = which_model(info.vendor, info.device)
info.driver = which_driver(info.vendor, info.device)
if info.driver then
info.rx, info.tx = which_link_names(info.driver)
info.interface = lib.firstfile(p.."/net")
if info.interface then
info.status = lib.firstline(p.."/net/"..info.interface.."/operstate")
Expand Down Expand Up @@ -84,6 +85,12 @@ local cards = {
},
}

local link_names = {
['apps.solarflare.solarflare'] = { "rx", "tx" },
['apps.intel_mp.intel_mp'] = { "input", "output" },
['apps.intel.intel_app'] = { "rx", "tx" }
}

-- Return the name of the Lua module that implements support for this device.
function which_driver (vendor, device)
local card = cards[vendor] and cards[vendor][device]
Expand All @@ -95,6 +102,10 @@ function which_model (vendor, device)
return card and card.model
end

function which_link_names (driver)
return unpack(assert(link_names[driver]))
end

--- ### Device manipulation.

--- Return true if `device` is safely available for use, or false if
Expand Down
6 changes: 3 additions & 3 deletions src/lib/io/virtual_ether_mux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function configure (c, ports, io)
local links
if io and io.pci then
local device = pci.device_info(io.pci)
if device and (device.driver == 'apps.intel.intel_app'
or device.driver == 'apps.solarflare.solarflare') then
if device and device.driver then
links = configureVMDq(c, device, ports)
else
error("Unknown device: "..io.pci)
Expand Down Expand Up @@ -91,7 +90,8 @@ function configureVMDq (c, device, ports)
vmdq = vmdq,
macaddr = port.mac_address,
vlan = port.vlan})
links[i] = {input = NIC..".rx", output = NIC..".tx"}
links[i] = {input = NIC.."."..device.rx,
output = NIC.."."..device.tx}
end
return links
end
4 changes: 2 additions & 2 deletions src/lib/timers/ingress_drop_monitor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function IngressDropMonitor:sample ()
sum[0] = 0
for i = 1, #app_array do
local app = app_array[i]
if app.ingress_packet_drops and not app.dead then
sum[0] = sum[0] + app:ingress_packet_drops()
if app.rxdrop and not app.dead then
sum[0] = sum[0] + app:rxdrop()
end
end
if self.counter then
Expand Down
2 changes: 1 addition & 1 deletion src/lib/virtio/net_device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local invalid_header_id = 0xffff
- VIRTIO_NET_F_CSUM - enables the SG I/O (resulting in
multiple chained data buffers in our TX path(self.rxring))
Required by GSO/TSO/USO. Requires CSUM offload support in the
HW driver (now intel10g)
HW driver (now intel_mp)
- VIRTIO_NET_F_MRG_RXBUF - enables multiple chained buffers in our RX path
(self.txring). Also chnages the virtio_net_hdr to virtio_net_hdr_mrg_rxbuf
Expand Down
4 changes: 2 additions & 2 deletions src/program/ipfix/probe/README
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Available options:
Defaults to 10.0.0.1.
-c, --collector <ipaddr> The IP address of the flow collector.
Defaults to 10.0.0.2.
-i, --input-type <type> One of pcap, raw, tap, or intel10g. Specifies
-i, --input-type <type> One of pcap, raw, tap, or pci. Specifies
how to interpret the <input> argument. Interprets
<input> as a pcap file path, device name, or
PCI address respectively. Defaults to intel10g.
PCI address respectively. Defaults to pci.
-o, --output-type <type> Takes the same values as -i but for <output>.
-D, --duration <seconds> Duration to run (in seconds).
-p, --port <port> The port on the collector to send to. Defaults
Expand Down
13 changes: 7 additions & 6 deletions src/program/ipfix/probe/probe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local link = require("core.link")
local basic = require("apps.basic.basic_apps")
local arp = require("apps.ipv4.arp")
local ipfix = require("apps.ipfix.ipfix")
local pci = require("lib.hardware.pci")
local ipv4 = require("lib.protocol.ipv4")
local ethernet = require("lib.protocol.ethernet")
local numa = require("lib.numa")
Expand Down Expand Up @@ -41,13 +42,13 @@ function in_apps.tap (device)
end
out_apps.tap = in_apps.tap

function in_apps.intel10g (device)
function in_apps.pci (device)
local device_info = pci.device_info(device)
local conf = { pciaddr = device }
return { input = "rx",
output = "tx" },
{ require("apps.intel.intel_app").Intel82599, conf }
return { input = device_info.rx, output = device_info.tx },
{ require(device_info.driver).driver, conf }
end
out_apps.intel10g = in_apps.intel10g
out_apps.pci = in_apps.pci

local long_opts = {
help = "h",
Expand All @@ -67,7 +68,7 @@ local long_opts = {
function run (args)
local duration

local input_type, output_type = "intel10g", "intel10g"
local input_type, output_type = "pci", "pci"

local host_mac
local host_ip = '10.0.0.1' -- Just to have a default.
Expand Down
16 changes: 9 additions & 7 deletions src/program/lisper/dev-env-perftest/baseline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ local ffi = require("ffi")
local app = require("core.app")
local lib = require("core.lib")
local packet = require("core.packet")
local intel = require("apps.intel.intel_app")
local pci = require("lib.hardware.pci")

local c = config.new()

config.app(c, "e0", intel.Intel82599, {
pciaddr = "0000:01:00.0",
local e0, e1 = pci.device_info("01:00.0"), pci.device_info("03:00.0")

config.app(c, "e0", require(e0.driver).driver, {
pciaddr = e0.pciaddress,
macaddr = "00:00:00:00:01:01",
})

config.app(c, "e1", intel.Intel82599, {
pciaddr = "0000:03:00.0",
config.app(c, "e1", require(e1.driver).driver, {
pciaddr = e1.pciaddress,
macaddr = "00:00:00:00:01:02",
})

config.link(c, "e0.tx -> e1.rx")
config.link(c, "e1.tx -> e0.rx")
config.link(c, "e0."..e0.tx.." -> e1."..e1.rx)
config.link(c, "e1."..e1.tx.." -> e0."..e0.rx)

engine.configure(c)
engine.main({report = {showlinks=true}})
10 changes: 6 additions & 4 deletions src/program/lisper/dev-env-perftest/count.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local ffi = require("ffi")
local app = require("core.app")
local lib = require("core.lib")
local packet = require("core.packet")
local intel = require("apps.intel.intel_app")
local pci = require("lib.hardware.pci")

_NAME = ""
local Counter = {}
Expand Down Expand Up @@ -37,12 +37,14 @@ local c = config.new()

config.app(c, "count", Counter)

config.app(c, "eth", intel.Intel82599, {
pciaddr = "0000:03:00.1",
local eth = pci.device_info("03:00.1")

config.app(c, "eth", require(eth.driver).driver, {
pciaddr = eth.pciaddress,
macaddr = "00:00:00:00:02:02",
})

config.link(c, "eth.tx -> count.rx")
config.link(c, "eth."..eth.tx.." -> count.rx")

engine.configure(c)
engine.main({report = {showlinks=true}})
Loading

0 comments on commit 7924779

Please sign in to comment.