Skip to content

Commit

Permalink
test: fix fix-mips64-spare-side-exit-patching
Browse files Browse the repository at this point in the history
This test may be flaky due to a sparse filling of the vector with
traces. Hence, `misc.getmetrics().jit_trace_num` (which is the total
number of traces) is not the last trace number, so there is no mcode for
it.

This patch fixes flakyness from two sides:
* The `fillmcode()` function now starts a search from the given trace
  itself, so there is no possible inconsistency with the growing vector.
* The finding of the last trace number in the aforementioned test is now
  more bulletproof: we scan all numbers from the metrics value to the
  maxtrace value. The last number with an existing mcode is chosen as
  the resulting last trace number.

Reviewed-by: Maxim Kokryashkin <[email protected]>
Reviewed-by: Igor Munkin <[email protected]>
Signed-off-by: Igor Munkin <[email protected]>
  • Loading branch information
Buristan authored and igormunkin committed Sep 26, 2023
1 parent bb93182 commit 7d5901d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
22 changes: 19 additions & 3 deletions test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@ local test = tap.test('fix-mips64-spare-side-exit-patching'):skipcond({

local generators = require('utils').jit.generators
local frontend = require('utils').frontend
local jutil = require('jit.util')

-- Allow compilation of up to 2000 traces to avoid flushes.
local MAXTRACE = 2000;

test:plan(1)

local function find_last_trace()
local candidate = misc.getmetrics().jit_trace_num
for traceno = candidate, MAXTRACE do
-- There is no need for heavy calls here. Just use the
-- simplest one to invoke `lj_checktrace()`.
if jutil.tracemc(traceno) then
candidate = traceno
end
end
assert(jutil.tracemc(candidate), 'tracenum candidate is invalid')
return candidate
end

-- Make compiler work hard.
jit.opt.start(
-- No optimizations at all to produce more mcode.
0,
-- Try to compile all compiled paths as early as JIT can.
'hotloop=1',
'hotexit=1',
-- Allow compilation of up to 2000 traces to avoid flushes.
'maxtrace=2000',
('maxtrace=%d'):format(MAXTRACE),
-- Allow to compile 8Mb of mcode to be sure the issue occurs.
'maxmcode=8192',
-- Use big mcode area for traces to avoid usage of different
Expand Down Expand Up @@ -59,7 +75,7 @@ for i = 1, MAX_SPARE_SLOT + 1 do
parent(i)
parent(i)
parent(i)
last_traceno = misc.getmetrics().jit_trace_num
last_traceno = find_last_trace()
end

test:ok(true, 'all traces executed correctly')
Expand Down
5 changes: 2 additions & 3 deletions test/tarantool-tests/utils/jit/generators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ function M.fillmcode(trace_from, size)
-- Marker to check that traces are not flushed.
local maxtraceno = getlast_traceno()
local FLUSH_ERR = 'Traces are flushed, check your maxtrace, maxmcode options'

local _, last_addr = jutil.tracemc(maxtraceno)
last_addr = canonicalize_address(last_addr)
local last_addr = addr_from

-- Addresses of traces may increase or decrease depending on OS,
-- so use absolute diff.
Expand Down Expand Up @@ -104,6 +102,7 @@ function M.fillmcode(trace_from, size)

-- Calculate the address of the last trace start.
maxtraceno = last_traceno
local _
_, last_addr = jutil.tracemc(last_traceno)
if not last_addr then
error(FLUSH_ERR)
Expand Down

0 comments on commit 7d5901d

Please sign in to comment.