Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for regressions in max-next headed for Octarina release #1466

Merged
merged 8 commits into from
Jan 21, 2022
16 changes: 7 additions & 9 deletions src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,17 @@ local function getvmprofile (name)
end

function setvmprofile (name)
if vmprofile_enabled then
C.vmprofile_set_profile(getvmprofile(name))
end
C.vmprofile_set_profile(getvmprofile(name))
end

function clearvmprofiles ()
jit.vmprofile.stop()
for name, profile in pairs(vmprofiles) do
shm.unmap(profile)
shm.unlink("vmprofile/"..name..".vmprofile")
vmprofiles[name] = nil
end
if vmprofile_enabled then
jit.vmprofile.stop()
for name, profile in pairs(vmprofiles) do
shm.unmap(profile)
shm.unlink("vmprofile/"..name..".vmprofile")
vmprofiles[name] = nil
end
jit.vmprofile.start()
end
end
Expand Down
12 changes: 6 additions & 6 deletions src/core/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package.path = ''

local STP = require("lib.lua.StackTracePlus")
local ffi = require("ffi")
local vmprofile = require("jit.vmprofile")
local jit = require("jit")
local lib = require("core.lib")
local shm = require("core.shm")
local C = ffi.C
Expand Down Expand Up @@ -47,7 +47,10 @@ function main ()
error("fatal: "..ffi.os.."/"..ffi.arch.." is not a supported platform\n")
end
initialize()
vmprofile.start()
-- Setup audit.log, vmprofile
engine.enable_auditlog()
engine.setvmprofile("program")
jit.vmprofile.start()
if lib.getenv("SNABB_PROGRAM_LUACODE") then
-- Run the given Lua code instead of the command-line
local expr = lib.getenv("SNABB_PROGRAM_LUACODE")
Expand All @@ -67,7 +70,7 @@ function main ()
require(modulename(program)).run(args)
end
end
vmprofile.stop()
jit.vmprofile.stop()
end

-- Take the program name from the first argument, unless the first
Expand Down Expand Up @@ -162,9 +165,6 @@ function initialize ()
_G.packet = require("core.packet"); _G.packet.initialize()
_G.timer = require("core.timer")
_G.main = getfenv()
-- Setup audit.log, vmprofile
engine.enable_auditlog()
engine.setvmprofile("program")
end

function handler (reason)
Expand Down
6 changes: 6 additions & 0 deletions src/core/packet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ default_headroom = 256
-- things aligned at least this much.
minimum_alignment = 2

-- Copy read-only constants to locals
local max_payload, packet_alignment, default_headroom, minimum_alignment =
max_payload, packet_alignment, default_headroom, minimum_alignment

local function get_alignment (addr, alignment)
-- Precondition: alignment is a power of 2.
return bit.band(addr, alignment - 1)
Expand Down Expand Up @@ -273,6 +277,8 @@ function account_free (p)
counter.add(engine.freebits, (12 + 8 + math.max(p.length, 60) + 4) * 8)
end

local free_internal, account_free =
free_internal, account_free
function free (p)
account_free(p)
free_internal(p)
Expand Down
2 changes: 0 additions & 2 deletions src/lib/ptree/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ local worker_config_spec = {
duration = {},
measure_latency = {default=true},
measure_memory = {default=true},
profile = {default=true},
no_report = {default=false},
report = {default={showapps=true,showlinks=true}},
Hz = {default=1000},
Expand All @@ -47,7 +46,6 @@ function new_worker (conf)
if conf.measure_memory then
timer.activate(memory_info.HeapSizeMonitor.new():timer())
end
engine.vmprofile_enabled = conf.profile
return ret
end

Expand Down
4 changes: 2 additions & 2 deletions src/lib/scheduling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ end

function sched_apply.profile (profile)
engine.vmprofile_enabled = profile
local vmprofile = require('jit.vmprofile')
if profile then vmprofile.start() else vmprofile.stop() end
local jit = require('jit')
if profile then jit.vmprofile.start() else jit.vmprofile.stop() end
end

function sched_apply.eval (str)
Expand Down
51 changes: 44 additions & 7 deletions src/program/lwaftr/migrate_configuration/migrate_configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local yang = require('lib.yang.yang')
local binding_table = require("apps.lwaftr.binding_table")
local Parser = require("program.lwaftr.migrate_configuration.conf_parser").Parser
local data = require('lib.yang.data')
local schema = require('lib.yang.schema')

local br_address_t = ffi.typeof('uint8_t[16]')
local SOFTWIRE_TABLE_LOAD_FACTOR = 0.4
Expand Down Expand Up @@ -436,13 +437,38 @@ local function remove_psid_map(conf)
return conf
end

local function v3_migration(src, conf_file)
local v2_schema = yang.load_schema_by_name("snabb-softwire-v2")
local v3_schema = yang.load_schema_by_name("snabb-softwire-v3")
local conf = yang.load_config_for_schema(
v2_schema, mem.open_input_string(src, conf_file))

-- Move leaf external-interface/device up as external-device.
for device, instance in pairs(conf.softwire_config.instance) do
for id, queue in pairs(instance.queue) do
if queue.external_interface.device then
if instance.external_device then
io.stderr:write('Multiple external devices detected; '..
'manual verification needed.\n')
io.stderr:flush()
end
instance.external_device = queue.external_interface.device
queue.external_interface.device = nil
end
end
end

return config_to_string(v3_schema, conf)
end

local function multiprocess_migration(src, conf_file)
local device = "IPv6 PCI Address"
local ex_device = "IPv4 PCI address"

-- We should build up a hybrid schema from parts of v1 and v2.
local v1_schema = yang.load_schema_by_name("snabb-softwire-v1")
local hybridscm = yang.load_schema_by_name("snabb-softwire-v3")
-- Make sure we load a fresh schema, as not to mutate a memoized copy
local hybridscm = schema.load_schema(schema.load_schema_source_by_name("snabb-softwire-v2"))
local v1_external = v1_schema.body["softwire-config"].body["external-interface"]
local v1_internal = v1_schema.body["softwire-config"].body["internal-interface"]
local external = hybridscm.body["softwire-config"].body["external-interface"]
Expand Down Expand Up @@ -473,9 +499,9 @@ local function multiprocess_migration(src, conf_file)

-- Build up the instance list
local instance = {
[device] = {queue = cltable.new({ key_type = queue_key }),},
[device] = {queue={}},
}
local key = ffi.new(queue_key, 0)
local key = 0
local value = {
external_interface = {
device = ex_device,
Expand Down Expand Up @@ -508,7 +534,7 @@ local function multiprocess_migration(src, conf_file)
else
error("One or both of next-hop values must be provided.")
end
cltable.set(instance[device].queue, key, value)
instance[device].queue[key] = value
conf.softwire_config.instance = instance

-- Remove the fields which no longer should exist
Expand All @@ -521,15 +547,17 @@ local function multiprocess_migration(src, conf_file)
conf.softwire_config.external_interface.next_hop = nil
conf.softwire_config.external_interface.vlan_tag = nil

return config_to_string('snabb-softwire-v3', conf)
return config_to_string(hybridscm, conf)
end

local function v2_migration(src, conf_file)
-- Lets create a custom schema programmatically as an intermediary so we can
-- switch over to v2 of snabb-softwire config.
local v1_schema = yang.load_schema_by_name("snabb-softwire-v1")
local v1_binding_table = v1_schema.body["softwire-config"].body["binding-table"]
local hybridscm = yang.load_schema_by_name("snabb-softwire-v3")

-- Make sure we load a fresh schema, as not to mutate a memoized copy
local hybridscm = schema.load_schema(schema.load_schema_source_by_name("snabb-softwire-v2"))
local binding_table = hybridscm.body["softwire-config"].body["binding-table"]

-- Add the schema from v1 that we need to convert them.
Expand All @@ -547,6 +575,9 @@ local function v2_migration(src, conf_file)
-- Remove the mandatory requirement on softwire.br-address for the migration
binding_table.body["softwire"].body["br-address"].mandatory = false

-- Remove the mandatory requirement on softwire.port-set.psid-length for the migration
binding_table.body["softwire"].body["port-set"].body["psid-length"].mandatory = false

local conf = yang.load_config_for_schema(
hybridscm, mem.open_input_string(src, conf_file))

Expand Down Expand Up @@ -590,13 +621,18 @@ local function migrate_2017_07_01(conf_file, src)
return multiprocess_migration(src, conf_file)
end

local function migrate_2022_01_19(conf_file, src)
return v3_migration(src, conf_file)
end


local migrations = {
{version='legacy', migrator=migrate_legacy},
{version='3.0.1', migrator=migrate_3_0_1},
{version='3.0.1.1', migrator=migrate_3_0_1bis},
{version='3.2.0', migrator=migrate_3_2_0},
{version='2017.07.01',migrator=migrate_2017_07_01}
{version='2017.07.01',migrator=migrate_2017_07_01},
{version='2022.01.19',migrator=migrate_2022_01_19},
}


Expand All @@ -617,6 +653,7 @@ function run(args)

local conf = io.open(conf_file, "r"):read("*a")
for _, migration in next,migrations,start do
io.stderr:write(("-> %s migration\n"):format(migration.version))
conf = migration.migrator(conf_file, conf)
-- Prompt the garbage collection to do a full collect after each migration
collectgarbage()
Expand Down
4 changes: 2 additions & 2 deletions src/program/lwaftr/tests/config-migrations/selftest.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

# Attempt to migration from legacy to latest
LEGACY_OUT=`./snabb lwaftr migrate-configuration -f legacy \
Expand All @@ -19,4 +19,4 @@ if [[ "$?" -ne "0" ]]; then
echo "3.2.0 configuration migration failed (status code != 0)"
echo "$V320_OUT"
exit 1
fi
fi
2 changes: 0 additions & 2 deletions src/program/snabbnfv/traffic/traffic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local ffi = require("ffi")
local C = ffi.C
local timer = require("core.timer")
local pci = require("lib.hardware.pci")
local ingress_drop_monitor = require("lib.timers.ingress_drop_monitor")
local counter = require("core.counter")

local long_opts = {
Expand Down Expand Up @@ -91,7 +90,6 @@ function traffic (pciaddr, confpath, sockpath)
timer.activate(timer.new("reconf", check_for_reconfigure, 1e9, 'repeating'))
-- Flush logs every second.
timer.activate(timer.new("flush", io.flush, 1e9, 'repeating'))
timer.activate(ingress_drop_monitor.new({action='warn'}):timer())
while true do
needs_reconfigure = false
print("Loading " .. confpath)
Expand Down