Skip to content

Commit

Permalink
Merge #1329 branch 'snabbco/wingo-next' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Apr 25, 2018
2 parents 964a8b7 + 78276a5 commit 636a6cb
Show file tree
Hide file tree
Showing 62 changed files with 1,878 additions and 1,068 deletions.
1 change: 1 addition & 0 deletions lib/ljsyscall/syscall/bsd/syscalls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if C.getdirentries then
basep = basep or t.long1()
local ret, err = C.getdirentries(getfd(fd), buf, size, basep)
if ret == -1 then return nil, t.error(err or errno()) end
if ret == 0 then return nil, nil end
return t.dirents(buf, ret)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/ljsyscall/syscall/syscalls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ if C.getdents then
buf = buf or t.buffer(size)
local ret, err = C.getdents(getfd(fd), buf, size)
if ret == -1 then return nil, t.error(err or errno()) end
if ret == 0 then return nil, nil end
return t.dirents(buf, ret)
end
end
Expand Down
9 changes: 2 additions & 7 deletions lib/ljsyscall/syscall/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -601,15 +601,10 @@ if bsdtypes then types = bsdtypes.init(c, types) end
-- define dents type if dirent is defined
if t.dirent then
t.dirents = function(buf, size) -- buf should be char*
local d, i = nil, 0
local i = 0
return function() -- TODO work out if possible to make stateless
if size > 0 and not d then
d = pt.dirent(buf)
i = i + d.d_reclen
return d
end
while i < size do
d = pt.dirent(pt.char(d) + d.d_reclen)
local d = pt.dirent(buf + i)
i = i + d.d_reclen
if d.ino ~= 0 then return d end -- some systems use ino = 0 for deleted files before removed eg OSX; it is never valid
end
Expand Down
25 changes: 11 additions & 14 deletions lib/ljsyscall/syscall/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,19 @@ function util.ls(name, buf, size)
if err then return nil, err end
local di
return function()
local d, first
repeat
while true do
if di then
local d = di()
if d then return d.name, d end
end
-- Fetch more entries.
local err
di, err = fd:getdents(buf, size)
if not di then
local err
di, err = fd:getdents(buf, size)
if not di then
fd:close()
error(err)
end
first = true
fd:close()
if err then error(err) else return nil end
end
d = di()
if not d then di = nil end
if not d and first then return nil end
until d
return d.name, d
end
end
end

Expand Down
4 changes: 0 additions & 4 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,6 @@ Returns the filename of the first file in *directory*.

Returns the first line of file at *filename* as a string.

— Function **lib.files_in_directory** *directory*

Returns an array of filenames in *directory*.

— Function **lib.load_string** *string*

Evaluates and returns the value of the Lua expression in *string*.
Expand Down
2 changes: 1 addition & 1 deletion src/apps/ipsec/selftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

SKIPPED_CODE=43

if [ "$SNABB_IPSEC_SKIP_E2E_TEST" = yes ]; then
if [ -z "$SNABB_IPSEC_ENABLE_E2E_TEST" ]; then
exit $SKIPPED_CODE
fi

Expand Down
9 changes: 1 addition & 8 deletions src/core/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ end

function firstline (filename) return readfile(filename, "*l") end

function files_in_directory (dir)
local files = {}
for line in assert(io.popen('ls -1 "'..dir..'" 2>/dev/null')):lines() do
table.insert(files, line)
end
return files
end

-- Load Lua value from string.
function load_string (string)
return loadstring("return "..string)()
Expand Down Expand Up @@ -726,6 +718,7 @@ function random_bytes_from_dev_urandom (count)
while written < count do
written = written + assert(f:read(bytes, count-written))
end
f:close()
return bytes
end

Expand Down
13 changes: 7 additions & 6 deletions src/lib/ctable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local lib = require("core.lib")
local binary_search = require("lib.binary_search")
local multi_copy = require("lib.multi_copy")
local siphash = require("lib.hash.siphash")
local max, floor, ceil = math.max, math.floor, math.ceil
local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil

CTable = {}
LookupStreamer = {}
Expand Down Expand Up @@ -154,6 +154,7 @@ end
local try_huge_pages = true
local huge_page_threshold = 1e6
local function calloc(t, count)
if count == 0 then return 0, 0 end
local byte_size = ffi.sizeof(t) * count
local mem, err
if try_huge_pages and byte_size > huge_page_threshold then
Expand Down Expand Up @@ -204,6 +205,7 @@ end

function CTable:resize(size)
assert(size >= (self.occupancy / self.max_occupancy_rate))
assert(size == floor(size))
local old_entries = self.entries
local old_size = self.size
local old_max_displacement = self.max_displacement
Expand Down Expand Up @@ -280,7 +282,7 @@ function CTable:add(key, value, updates_allowed)
if self.occupancy + 1 > self.occupancy_hi then
-- Note that resizing will invalidate all hash keys, so we need
-- to hash the key after resizing.
self:resize(self.size * 2)
self:resize(max(self.size * 2, 1)) -- Could be current size is 0.
end

local hash = self.hash_fn(key)
Expand Down Expand Up @@ -402,7 +404,7 @@ function CTable:remove_ptr(entry)
end

if self.occupancy < self.occupancy_lo then
self:resize(self.size / 2)
self:resize(max(ceil(self.size / 2), 1))
end
end

Expand Down Expand Up @@ -589,7 +591,7 @@ function CTable:next_entry(offset, limit)
elseif limit == nil then
limit = self.size + self.max_displacement
else
limit = math.min(limit, self.size + self.max_displacement)
limit = min(limit, self.size + self.max_displacement)
end
for offset=offset, limit-1 do
if self.entries[offset].hash ~= HASH_MAX then
Expand All @@ -612,7 +614,6 @@ function selftest()
initial_size = ceil(occupancy / 0.4)
}
local ctab = new(params)
ctab:resize(occupancy / 0.4 + 1)

-- Fill with {i} -> { bnot(i), ... }.
local k = ffi.new('uint32_t[1]');
Expand Down Expand Up @@ -707,7 +708,7 @@ function selftest()
repeat
local streamer = ctab:make_lookup_streamer(width)
for i = 1, occupancy, width do
local n = math.min(width, occupancy-i+1)
local n = min(width, occupancy-i+1)
for j = 0, n-1 do
streamer.entries[j].key[0] = i + j
end
Expand Down
8 changes: 5 additions & 3 deletions src/lib/hardware/pci.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ devices = {}

--- Initialize (or re-initialize) the `devices` table.
function scan_devices ()
for _,device in ipairs(lib.files_in_directory("/sys/bus/pci/devices")) do
local info = device_info(device)
if info.driver then table.insert(devices, info) end
for device in assert(S.util.ls("/sys/bus/pci/devices")) do
if device ~= '.' and device ~= '..' then
local info = device_info(device)
if info.driver then table.insert(devices, info) end
end
end
end

Expand Down
3 changes: 3 additions & 0 deletions src/lib/ptree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ Optional entries that may be present in the *parameters* table include:
address being used by the worker.
* `Hz`: Frequency at which to poll the config socket. Default is
1000.
* `rpc_trace_file`: File to which to write a trace of incoming RPCs
from "snabb config". The trace is written in a format that can later
be piped to "snabb config listen" to replay the trace.

The return value is a ptree manager object, whose public methods are as
follows:
Expand Down
2 changes: 1 addition & 1 deletion src/program/config/json.lua → src/lib/ptree/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function write_json_object(output, obj)
end

function selftest ()
print('selftest: program.config.json')
print('selftest: lib.ptree.json')
local equal = require('core.lib').equal
local function test_json(str, obj)
local tmp = os.tmpname()
Expand Down
Loading

0 comments on commit 636a6cb

Please sign in to comment.