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

Performance v2 #186

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local ffi = require("ffi")
local C = ffi.C
require("core.packet_h")

debug = false
test_skipped_code = 43

-- The set of all active apps and links in the system.
Expand Down Expand Up @@ -128,10 +129,13 @@ end

-- Call this to "run snabb switch".
function main (options)
local done = nil
options = options or {}
local done = options.done
local no_timers = options.no_timers
if options.duration then done = lib.timer(options.duration * 1e9) end
if options.duration then
assert(not done, "You can not have both 'duration' and 'done'")
done = lib.timer(options.duration * 1e9)
end
repeat
breathe()
if not no_timers then timer.run() end
Expand All @@ -144,7 +148,9 @@ function breathe ()
-- Inhale: pull work into the app network
for _, app in ipairs(app_array) do
if app.pull then
zone(app.zone) app:pull() zone()
if debug then zone(app.zone) end
app:pull()
if debug then zone() end
end
end
-- Exhale: push work out through the app network
Expand All @@ -157,7 +163,9 @@ function breathe ()
link.has_new_data = false
local receiver = app_array[link.receiving_app]
if receiver.push then
zone(receiver.zone) receiver:push() zone()
if debug then zone(receiver.zone) end
receiver:push()
if debug then zone() end
progress = true
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/core/freelist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

function add (freelist, element)
-- Safety check
assert(freelist.nfree < freelist.max, "freelist overflow")
if freelist.nfree == freelist.max then assert(freelist.nfree < freelist.max, "freelist overflow") end
freelist.list[freelist.nfree] = element
freelist.nfree = freelist.nfree + 1
end
Expand Down
4 changes: 2 additions & 2 deletions src/core/link.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(...,package.seeall)

local debug = true
local debug = false

local ffi = require("ffi")
local C = ffi.C
Expand All @@ -26,7 +26,7 @@ function receive (r)
end

function transmit (r, p)
assert(p)
if debug then assert(p) end
if full(r) then
r.stats.txdrop = r.stats.txdrop + 1
else
Expand Down
5 changes: 2 additions & 3 deletions src/core/memory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,16 @@ local virt_page_cache = {}
function virtual_to_physical (virt_addr)
virt_addr = ffi.cast("uint64_t", virt_addr)
local virt_page = tonumber(virt_addr / base_page_size)
local offset = tonumber(virt_addr % base_page_size)
local phys_page = virt_page_cache[virt_page]
if not phys_page then
phys_page = C.phys_page(virt_page)
phys_page = C.phys_page(virt_page) * base_page_size
virt_page_cache[virt_page] = phys_page
end
if phys_page == 0 then
error("Failed to resolve physical address of "..tostring(virt_addr))
end
--assert(phys_page == C.phys_page(virt_page))
return ffi.cast("uint64_t", phys_page * base_page_size + offset)
return ffi.cast("uint64_t", phys_page + virt_addr % base_page_size)
end

--- ### selftest
Expand Down
6 changes: 4 additions & 2 deletions src/core/packet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ packets = ffi.new("struct packet[?]", max_packets)
local packet_size = ffi.sizeof("struct packet")

function module_init ()
ffi.fill(packets, max_packets * packet_size)
for i = 0, max_packets-1 do
free(packets[i])
end
Expand Down Expand Up @@ -184,7 +185,7 @@ end
function deref (p, n)
n = n or 1
if p.refcount > 0 then
assert(p.refcount >= n)
if debug then assert(p.refcount >= n) end
if n == p.refcount then
free(p)
else
Expand All @@ -203,9 +204,10 @@ function free (p)
for i = 0, p.niovecs-1 do
buffer.free(p.iovecs[i].buffer)
end
ffi.fill(p, packet_size, 0)
p.refcount = 1
p.fuel = initial_fuel
p.niovecs = 0
p.length = 0
freelist.add(packets_fl, p)
end

Expand Down
7 changes: 3 additions & 4 deletions src/designs/bench/basic1
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ function run (npackets)
config.link(c, "Tee.tx2 -> Sink.rx2")
engine.configure(c)
local start = C.get_monotonic_time()
timer.init()
timer.activate(timer.new("null", function () end, 1e6, 'repeating'))
while engine.app_table.Source.output.tx.stats.txpackets < npackets do
engine.main({duration = 0.01, no_report = true})
local done = function ()
return engine.app_table.Source.output.tx.stats.txpackets >= npackets
end
engine.main({done = done, no_report = true})
local finish = C.get_monotonic_time()
local runtime = finish - start
local packets = engine.app_table.Source.output.tx.stats.txpackets
Expand Down
4 changes: 4 additions & 0 deletions src/lib/virtio/net_device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ function VirtioNetDevice:map_from_guest (addr)
for i = 0, table.getn(self.mem_table) do
local m = self.mem_table[i]
if addr >= m.guest and addr < m.guest + m.size then
if i ~= 0 then
self.mem_table[i] = self.mem_table[0]
self.mem_table[0] = m
end
return addr + m.snabb - m.guest
end
end
Expand Down