replace hardcoded hookInterval with bogomips calculator

This commit is contained in:
Adrian Siekierka 2018-07-04 10:48:40 +02:00 committed by payonel
parent be921a2d0f
commit 64035ff0c3

View File

@ -1,4 +1,44 @@
local hookInterval = 100 local hookInterval = 10000
local function calcHookInterval()
local bogomipsDivider = 0.05
local bogomipsDeadline = computer.realTime() + bogomipsDivider
local ipsCount = 0
local bogomipsBusy = true
local function calcBogoMips()
ipsCount = ipsCount + hookInterval
if computer.realTime() > bogomipsDeadline then
bogomipsBusy = false
end
end
-- The following is a bit of nonsensical-seeming code attempting
-- to cover Lua's VM sufficiently for the IPS calculation.
local bogomipsTmpA = {{["b"]=3, ["d"]=9}}
local function c(k)
if k <= 2 then
bogomipsTmpA[1].d = k / 2.0
end
end
debug.sethook(calcBogoMips, "", hookInterval)
while bogomipsBusy do
local st = ""
for k=2,4 do
st = st .. "a" .. k
c(k)
if k >= 3 then
bogomipsTmpA[1].b = bogomipsTmpA[1].b * (k ^ k)
end
end
end
debug.sethook()
return ipsCount / bogomipsDivider
end
local ipsCount = calcHookInterval()
-- Since our IPS might still be too generous (hookInterval needs to run at most
-- every 0.05 seconds), we divide it further by 10 relative to that.
hookInterval = (ipsCount * 0.005)
if hookInterval < 1000 then hookInterval = 1000 end
local deadline = math.huge local deadline = math.huge
local hitDeadline = false local hitDeadline = false
local function checkDeadline() local function checkDeadline()