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

Allow LPM self-tests to complete even if no CPU affinity #1232

Merged
merged 1 commit into from
Nov 10, 2017
Merged
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
21 changes: 14 additions & 7 deletions src/lib/lpm/ip4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,20 @@ function IP4.selftest ()
selftest_get_bit()
selftest_commonlength()
local pmu = require("lib.pmu")
local gbit = IP4.get_bit
pmu.profile(function()
local c = 0
for i = 0,1000000 do
c = c + IP4.commonlength(i,i)
end
end)
local avail, err = pmu.is_available()
if not avail then
print("PMU not available:")
print(" "..err)
print("Skipping benchmark.")
else
local gbit = IP4.get_bit
pmu.profile(function()
local c = 0
for i = 0,1000000 do
c = c + IP4.commonlength(i,i)
end
end)
end
end

return IP4
9 changes: 8 additions & 1 deletion src/lib/lpm/lpm4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ function LPM4:selftest (cfg, millions)
g:verify(f)
C.free(ptr)

self:new(cfg):add_random_entries():benchmark(millions)
local avail, err = require('lib.pmu').is_available()
if not avail then
print("PMU not available:")
print(" "..err)
print("Skipping benchmark.")
else
self:new(cfg):add_random_entries():benchmark(millions)
end
print("selftest complete")
end
15 changes: 11 additions & 4 deletions src/lib/lpm/lpm4_poptrie.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,17 @@ function selftest_get_bits ()
assert(g(p("0.3.128.0"),14) == 56)
assert(g(p("192.0.0.0"),0) == 48)
local pmu = require("lib.pmu")
local n = 0
pmu.profile(function()
for i =0, 1000*1000*1000 do n = n + g(i, 7) end
end)
local avail, err = pmu.is_available()
if not avail then
print("PMU not available:")
print(" "..err)
print("Skipping benchmark.")
else
local n = 0
pmu.profile(function()
for i =0, 1000*1000*1000 do n = n + g(i, 7) end
end)
end
end
function selftest ()
local n = LPM4_poptrie:new()
Expand Down
28 changes: 18 additions & 10 deletions src/lib/lpm/random.dasl
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ Rand.u32 = (function()
end)()

function Rand:selftest()
local pmu = require("lib.pmu")
local v = 0
local million = 1000000
local start = C.get_time_ns()
pmu.profile(function()
for i=0, 500*million do
v = Rand.u32(v)
end
end, {}, { random_u32 = 500*million })
print((C.get_time_ns() - start)/(500*million))
local pmu = require("lib.pmu")
local v = 0
local million = 1000000
local function test()
for i=0, 500*million do
v = Rand.u32(v)
end
end
local avail, err = pmu.is_available()
local start = C.get_time_ns()
if not avail then
print("PMU not available:")
print(" "..err)
test()
else
pmu.profile(test, {}, { random_u32 = 500*million })
end
print(tonumber((C.get_time_ns() - start))/(500*million))
end

return Rand