Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
	Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 3/3] test: fix fix-mips64-spare-side-exit-patching
Date: Mon,  4 Sep 2023 18:50:26 +0300	[thread overview]
Message-ID: <fcbf5fc49bcbcaf9ad962717a620fbebf9438185.1693840653.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1693840653.git.skaplun@tarantool.org>

This test may be flaky due to a non-monotonic 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.
---
 ...x-mips64-spare-side-exit-patching.test.lua | 22 ++++++++++++++++---
 test/tarantool-tests/utils/jit/generators.lua |  5 ++---
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua b/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua
index 62933df9..703d8e69 100644
--- a/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua
+++ b/test/tarantool-tests/fix-mips64-spare-side-exit-patching.test.lua
@@ -8,9 +8,26 @@ 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.
@@ -18,8 +35,7 @@ jit.opt.start(
   -- 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
@@ -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')
diff --git a/test/tarantool-tests/utils/jit/generators.lua b/test/tarantool-tests/utils/jit/generators.lua
index 0189cd2a..14e0e3c3 100644
--- a/test/tarantool-tests/utils/jit/generators.lua
+++ b/test/tarantool-tests/utils/jit/generators.lua
@@ -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.
@@ -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)
-- 
2.42.0


  parent reply	other threads:[~2023-09-04 15:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04 15:50 [Tarantool-patches] [PATCH luajit 0/3] Fix fix-mips64-spare-side-exit-patching Sergey Kaplun via Tarantool-patches
2023-09-04 15:50 ` [Tarantool-patches] [PATCH luajit 1/3] MIPS: Fix "bad FP FLOAD" assertion Sergey Kaplun via Tarantool-patches
2023-09-05  7:05   ` Maxim Kokryashkin via Tarantool-patches
2023-09-26 18:58   ` Igor Munkin via Tarantool-patches
2023-09-04 15:50 ` [Tarantool-patches] [PATCH luajit 2/3] test: fix `fillmcode()` generator helper Sergey Kaplun via Tarantool-patches
2023-09-05  7:06   ` Maxim Kokryashkin via Tarantool-patches
2023-09-26 18:58   ` Igor Munkin via Tarantool-patches
2023-09-04 15:50 ` Sergey Kaplun via Tarantool-patches [this message]
2023-09-05  8:56   ` [Tarantool-patches] [PATCH luajit 3/3] test: fix fix-mips64-spare-side-exit-patching Maxim Kokryashkin via Tarantool-patches
2023-09-05 11:16     ` Sergey Kaplun via Tarantool-patches
2023-09-26 18:59   ` Igor Munkin via Tarantool-patches
2023-09-27 12:33 ` [Tarantool-patches] [PATCH luajit 0/3] Fix fix-mips64-spare-side-exit-patching Igor Munkin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fcbf5fc49bcbcaf9ad962717a620fbebf9438185.1693840653.git.skaplun@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.kokryashkin@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 3/3] test: fix fix-mips64-spare-side-exit-patching' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox