Skip to content

Commit

Permalink
Merge pull request snabbco#973 from Igalia/multiqueue-fixes
Browse files Browse the repository at this point in the history
Multiqueue fixes
  • Loading branch information
wingo authored Sep 27, 2017
2 parents e2e25f9 + e29810f commit edfb477
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/apps/config/leader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ local function path_adder_for_grammar(grammar, path)
return function(config, subconfig)
local tab = getter(config)
for k,_ in pairs(subconfig) do
if tab[k] ~= nil then error('already-existing entry', k) end
if tab[k] ~= nil then error('already-existing entry') end
end
for k,v in pairs(subconfig) do tab[k] = v end
return config
Expand Down
10 changes: 3 additions & 7 deletions src/apps/lwaftr/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,11 @@ local function select_instance(conf)
for k,v in pairs(t2) do ret[k] = v end
return ret
end
local device = next(conf.softwire_config.instance)
local device, id, queue = lwutil.parse_instance(conf)
conf.softwire_config.external_interface = table_merge(
conf.softwire_config.external_interface,
conf.softwire_config.instance[device].queue.values[1].external_interface
)
conf.softwire_config.external_interface, queue.external_interface)
conf.softwire_config.internal_interface = table_merge(
conf.softwire_config.internal_interface,
conf.softwire_config.instance[device].queue.values[1].internal_interface
)
conf.softwire_config.internal_interface, queue.internal_interface)
return conf
end

Expand Down
18 changes: 18 additions & 0 deletions src/apps/lwaftr/lwutil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local S = require("syscall")
local bit = require("bit")
local ffi = require("ffi")
local lib = require("core.lib")
local cltable = require("lib.cltable")

local band = bit.band
local cast = ffi.cast
Expand All @@ -18,6 +19,23 @@ local ehs = constants.ethernet_header_size
local o_ipv4_flags = constants.o_ipv4_flags
local ntohs = lib.ntohs

-- Return device PCI address, queue ID, and queue configuration.
function parse_instance(conf)
local device, instance
for k, v in pairs(conf.softwire_config.instance) do
assert(device == nil, "configuration has more than one instance")
device, instance = k, v
end
assert(device ~= nil, "configuration has no instance")
local id, queue
for k, v in cltable.pairs(instance.queue) do
assert(id == nil, "configuration has more than one RSS queue")
id, queue = k.id, v
end
assert(id ~= nil, "configuration has no RSS queues")
return device, id, queue
end

function get_ihl_from_offset(pkt, offset)
local ver_and_ihl = pkt.data[offset]
return band(ver_and_ihl, 0xf) * 4
Expand Down
5 changes: 3 additions & 2 deletions src/lib/cltable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ function set(cltable, key, value)
cltable.values[entry.value] = value
if value == nil then cltable.keys:remove_ptr(entry) end
elseif value ~= nil then
table.insert(cltable.values, value)
cltable.keys:add(key, #cltable.values)
local idx = #cltable.values + 1
cltable.values[idx] = value
cltable.keys:add(key, idx)
end
end

Expand Down
17 changes: 13 additions & 4 deletions src/lib/yang/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local ctable = require('lib.ctable')
local cltable = require('lib.cltable')

local MAGIC = "yangconf"
local VERSION = 0x00005000
local VERSION = 0x00008000

local header_t = ffi.typeof([[
struct {
Expand Down Expand Up @@ -102,6 +102,8 @@ local function table_size(tab)
return size
end

local SPARSE_ARRAY_END = 0xffffffff

local function data_emitter(production)
local handlers = {}
local translators = {}
Expand Down Expand Up @@ -216,8 +218,11 @@ local function data_emitter(production)
return function(data, stream)
stream:write_stringref('cltable')
emit_keys(data.keys, stream)
stream:write_uint32(#data.values)
for i=1,#data.values do emit_value(data.values[i], stream) end
for i, value in pairs(data.values) do
stream:write_uint32(i)
emit_value(value, stream)
end
stream:write_uint32(SPARSE_ARRAY_END)
end
else
local emit_key = visit1({type='struct', members=production.keys,
Expand Down Expand Up @@ -410,7 +415,11 @@ local function read_compiled_data(stream, strtab)
function readers.cltable()
local keys = read1()
local values = {}
for i=1,stream:read_uint32() do table.insert(values, read1()) end
while true do
local i = stream:read_uint32()
if i == SPARSE_ARRAY_END then break end
values[i] = read1()
end
return cltable.build(keys, values)
end
function readers.lltable()
Expand Down
9 changes: 4 additions & 5 deletions src/program/lwaftr/run/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ end
-- Requires a V4V6 splitter if running in on-a-stick mode and VLAN tag values
-- are the same for the internal and external interfaces.
local function requires_splitter (opts, conf)
local device, id, queue = lwutil.parse_instance(conf)
if opts["on-a-stick"] then
local _, instance = next(conf.softwire_config.instance)
local internal_interface = instance.queue.values[1].internal_interface
local external_interface = instance.queue.values[1].external_interface
local internal_interface = queue.internal_interface
local external_interface = queue.external_interface
return internal_interface.vlan_tag == external_interface.vlan_tag
end
return false
Expand All @@ -161,8 +161,7 @@ function run(args)

-- If instance has external-interface.device configure as bump-in-the-wire
-- otherwise configure it in on-a-stick mode.
local name, instance = next(lwconfig.softwire_config.instance)
local queue = instance.queue.values[1]
local device, id, queue = lwutil.parse_instance(lwconfig)
if queue.external_interface.device then
return setup.load_phy(graph, lwconfig, 'inetNic', 'b4sideNic',
opts.ring_buffer_size)
Expand Down
38 changes: 10 additions & 28 deletions src/program/lwaftr/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ local ipv4 = require("lib.protocol.ipv4")
local ethernet = require("lib.protocol.ethernet")
local ipv4_ntop = require("lib.yang.util").ipv4_ntop
local binary = require("lib.yang.binary")
local cltable = require("lib.cltable")
local S = require("syscall")
local engine = require("core.app")
local lib = require("core.lib")
Expand Down Expand Up @@ -60,23 +59,6 @@ local function validate_pci_devices(devices)
end
end

-- Return device PCI address, queue ID, and queue configuration.
local function parse_instance(conf)
local device, instance
for k, v in pairs(conf.softwire_config.instance) do
assert(device == nil, "configuration has more than one instance")
device, instance = k, v
end
assert(device ~= nil, "configuration has no instance")
local id, queue
for k, v in cltable.pairs(instance.queue) do
assert(id == nil, "configuration has more than one RSS queue")
id, queue = k.id, v
end
assert(id ~= nil, "configuration has no RSS queues")
return device, id, queue
end

function lwaftr_app(c, conf)
assert(type(conf) == 'table')

Expand All @@ -101,7 +83,7 @@ function lwaftr_app(c, conf)
end
switch_names(conf)

local device, id, queue = parse_instance(conf)
local device, id, queue = lwutil.parse_instance(conf)

-- Global interfaces
local gexternal_interface = conf.softwire_config.external_interface
Expand Down Expand Up @@ -237,7 +219,7 @@ local function link_sink(c, v4_out, v6_out)
end

function load_phy(c, conf, v4_nic_name, v6_nic_name, ring_buffer_size)
local v4_pci, id, queue = parse_instance(conf)
local v4_pci, id, queue = lwutil.parse_instance(conf)
local v6_pci = queue.external_interface.device
local v4_info = pci.device_info(v4_pci)
local v6_info = pci.device_info(v6_pci)
Expand Down Expand Up @@ -268,7 +250,7 @@ function load_phy(c, conf, v4_nic_name, v6_nic_name, ring_buffer_size)
end

function load_on_a_stick(c, conf, args)
local pciaddr, id, queue = parse_instance(conf)
local pciaddr, id, queue = lwutil.parse_instance(conf)
local device = pci.device_info(pciaddr)
local driver = require(device.driver).driver
validate_pci_devices({pciaddr})
Expand Down Expand Up @@ -326,7 +308,7 @@ function load_on_a_stick(c, conf, args)
end

function load_virt(c, conf, v4_nic_name, v6_nic_name)
local v4_pci, id, queue = parse_instance(conf)
local v4_pci, id, queue = lwutil.parse_instance(conf)
local v6_pci = queue.external_device.device
lwaftr_app(c, conf, device)

Expand All @@ -345,7 +327,7 @@ function load_virt(c, conf, v4_nic_name, v6_nic_name)
end

function load_bench(c, conf, v4_pcap, v6_pcap, v4_sink, v6_sink)
local device, id, queue = parse_instance(conf)
local device, id, queue = lwutil.parse_instance(conf)
lwaftr_app(c, conf, device)

config.app(c, "capturev4", pcap.PcapReader, v4_pcap)
Expand Down Expand Up @@ -380,7 +362,7 @@ function load_bench(c, conf, v4_pcap, v6_pcap, v4_sink, v6_sink)
end

function load_check_on_a_stick (c, conf, inv4_pcap, inv6_pcap, outv4_pcap, outv6_pcap)
local device, id, queue = parse_instance(conf)
local device, id, queue = lwutil.parse_instance(conf)
lwaftr_app(c, conf, device)

config.app(c, "capturev4", pcap.PcapReader, inv4_pcap)
Expand Down Expand Up @@ -432,7 +414,7 @@ function load_check_on_a_stick (c, conf, inv4_pcap, inv6_pcap, outv4_pcap, outv6
end

function load_check(c, conf, inv4_pcap, inv6_pcap, outv4_pcap, outv6_pcap)
local device, id, queue = parse_instance(conf)
local device, id, queue = lwutil.parse_instance(conf)
lwaftr_app(c, conf, device)

config.app(c, "capturev4", pcap.PcapReader, inv4_pcap)
Expand Down Expand Up @@ -470,7 +452,7 @@ function load_check(c, conf, inv4_pcap, inv6_pcap, outv4_pcap, outv6_pcap)
end

function load_soak_test(c, conf, inv4_pcap, inv6_pcap)
local device, id, queue = parse_instance(conf)
local device, id, queue = lwutil.parse_instance(conf)
lwaftr_app(c, conf, device)

config.app(c, "capturev4", pcap.PcapReader, inv4_pcap)
Expand Down Expand Up @@ -512,7 +494,7 @@ function load_soak_test(c, conf, inv4_pcap, inv6_pcap)
end

function load_soak_test_on_a_stick (c, conf, inv4_pcap, inv6_pcap)
local device, id, queue = parse_instance(conf)
local device, id, queue = lwutil.parse_instance(conf)
lwaftr_app(c, conf, device)

config.app(c, "capturev4", pcap.PcapReader, inv4_pcap)
Expand Down Expand Up @@ -692,6 +674,7 @@ local function compute_worker_configs(conf)
local make_copy = copier(conf)
for device, queues in pairs(conf.softwire_config.instance) do
for k, _ in cltable.pairs(queues.queue) do
local worker_id = string.format('%s/%s', device, k.id)
local worker_config = make_copy()
local instance = worker_config.softwire_config.instance
for other_device, queues in pairs(conf.softwire_config.instance) do
Expand All @@ -705,7 +688,6 @@ local function compute_worker_configs(conf)
end
end
end
local worker_id = string.format('%s/%s', device, k.id)
ret[worker_id] = worker_config
end
end
Expand Down
22 changes: 2 additions & 20 deletions src/program/snabbvmx/lwaftr/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ local lwaftr = require("apps.lwaftr.lwaftr")
local lwutil = require("apps.lwaftr.lwutil")
local constants = require("apps.lwaftr.constants")
local nh_fwd = require("apps.lwaftr.nh_fwd")
local cltable = require("lib.cltable")
local pci = require("lib.hardware.pci")
local raw = require("apps.socket.raw")
local tap = require("apps.tap.tap")
Expand All @@ -45,26 +44,9 @@ local function load_driver (pciaddr)
return require(device_info.driver).driver, device_info.rx, device_info.tx
end

-- Return device PCI address, queue ID, and queue configuration.
local function parse_instance(conf)
local device, instance
for k, v in pairs(conf.softwire_config.instance) do
assert(device == nil, "configuration has more than one instance")
device, instance = k, v
end
assert(device ~= nil, "configuration has no instance")
local id, queue
for k, v in cltable.pairs(instance.queue) do
assert(id == nil, "configuration has more than one RSS queue")
id, queue = k.id, v
end
assert(id ~= nil, "configuration has no RSS queues")
return device, id, queue
end

local function load_virt (c, nic_id, lwconf, interface)
-- Validate the lwaftr and split the interfaces into global and instance.
local device, id, queue = parse_instance(lwconf)
local device, id, queue = lwutil.parse_instance(lwconf)

local gexternal_interface = lwconf.softwire_config.external_interface
local ginternal_interface = lwconf.softwire_config.internal_interface
Expand Down Expand Up @@ -161,7 +143,7 @@ function lwaftr_app(c, conf, lwconf, sock_path)
assert(type(lwconf) == 'table')

-- Validate the lwaftr and split the interfaces into global and instance.
local device, id, queue = parse_instance(lwconf)
local device, id, queue = lwutil.parse_instance(lwconf)

local gexternal_interface = lwconf.softwire_config.external_interface
local ginternal_interface = lwconf.softwire_config.internal_interface
Expand Down

0 comments on commit edfb477

Please sign in to comment.