Skip to content

Commit

Permalink
Merge pull request #173 from virtualopensystems/performance-v1
Browse files Browse the repository at this point in the history
Performance improvements
  • Loading branch information
lukego committed May 20, 2014
2 parents 3a5fb9d + b8126e1 commit b110f87
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/apps/intel/intel_app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local basic_apps = require("apps.basic.basic_apps")
local lib = require("core.lib")
local register = require("lib.hardware.register")
local intel10g = require("apps.intel.intel10g")
local freelist = require("core.freelist")

Intel82599 = {}
Intel82599.__index = Intel82599
Expand Down
4 changes: 2 additions & 2 deletions src/apps/vhost/vhost_user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ function VhostUser:set_mem_table (msg, fds, nfds)
C.mmap_memory(pointer, size, ffi.cast("uint64_t",pointer), true, true)
local guest = msg.memory.regions[i].guest_phys_addr
local qemu = msg.memory.regions[i].userspace_addr
table.insert(mem_table, { guest = guest,
mem_table[i] = { guest = guest,
qemu = qemu,
snabb = ffi.cast("int64_t", pointer),
size = tonumber(size) })
size = tonumber(size) }
end
self.dev:set_mem_table(mem_table)
end
Expand Down
10 changes: 9 additions & 1 deletion src/core/memory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ huge_page_size = get_huge_page_size()
--- ### Physical address translation

-- Convert from virtual address (pointer) to physical address (uint64_t).
-- Use local caching of virtual to physical page translation. This will work
-- only if the mlockall was called.
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 = C.phys_page(virt_page)
local phys_page = virt_page_cache[virt_page]
if not phys_page then
phys_page = C.phys_page(virt_page)
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)
end

Expand Down
2 changes: 1 addition & 1 deletion src/designs/nfv/nfv.lua → src/designs/nfv/nfv
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module(...,package.seeall)
#!/usr/bin/env snabb

local app = require("core.app")
local basic_apps = require("apps.basic.basic_apps")
Expand Down
9 changes: 6 additions & 3 deletions src/lib/virtio/net_device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ end

-- Address space remapping.
function VirtioNetDevice:map_to_guest (addr)
for _,m in ipairs(self.mem_table) do
for i = 0, table.getn(self.mem_table) do
local m = self.mem_table[i]
if addr >= m.snabb and addr < m.snabb + m.size then
return addr + m.guest - m.snabb
end
Expand All @@ -250,7 +251,8 @@ function VirtioNetDevice:map_to_guest (addr)
end

function VirtioNetDevice:map_from_guest (addr)
for _,m in ipairs(self.mem_table) do
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
return addr + m.snabb - m.guest
end
Expand All @@ -259,7 +261,8 @@ function VirtioNetDevice:map_from_guest (addr)
end

function VirtioNetDevice:map_from_qemu (addr)
for _,m in ipairs(self.mem_table) do
for i = 0, table.getn(self.mem_table) do
local m = self.mem_table[i]
if addr >= m.qemu and addr < m.qemu + m.size then
return addr + m.snabb - m.qemu
end
Expand Down

0 comments on commit b110f87

Please sign in to comment.