Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin <imun@tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 1/2] metrics: add counters for metrics interested in
Date: Wed, 12 Aug 2020 12:39:32 +0300	[thread overview]
Message-ID: <20200812093932.GZ18920@tarantool.org> (raw)
In-Reply-To: <20200727022546.GA11579@root>

Sergey,

On 27.07.20, Sergey Kaplun wrote:
> Igor,
> 
> On 23.07.20, Igor Munkin wrote:
> > Sergey,
> > 
> > Thanks for the patch! Please consider my comments below.
> > 
> > On 21.07.20, Sergey Kaplun wrote:
> > 
> <snipped>
> > 
> > This counter is not incremented if cdata is allocated on trace. Consider
> > the following test:
> > | $ LUA_PATH="$HOME/.luarocks/share/lua/5.1/?.lua;;" ./luajit -joff <<EOF
> > | heredoc> local t = { }
> > | heredoc> for i = 1, 1000 do
> > | heredoc>   table.insert(t, require('ffi').new('uint64_t', i))
> > | heredoc> end
> > | heredoc> t = nil
> > | heredoc> collectgarbage('collect')
> > | heredoc> print(require('inspect')(misc.getmetrics()))
> > | heredoc> EOF
> > | {
> > |   global = {
> > |     cdatanum = 0,
> > |     gc_total = 74722,
> > |     jit_mcode_size = 0,
> > |     jit_trace_num = 0,
> > |     strnum = 534,
> > |     tabnum = 77,
> > |     udatanum = 5
> > |   },
> > |   incremental = {
> > |     gc_allocated = 173092,
> > |     gc_freed = 98370,
> > |     gc_steps_atomic = 1,
> > |     gc_steps_finalize = 0,
> > |     gc_steps_pause = 3,
> > |     gc_steps_propagate = 553,
> > |     gc_steps_sweep = 64,
> > |     gc_steps_sweepstring = 1024,
> > |     jit_snap_restore = 0,
> > |     jit_trace_abort = 0,
> > |     strhash_hit = 4021,
> > |     strhash_miss = 538
> > |   }
> > | }
> > | $ LUA_PATH="$HOME/.luarocks/share/lua/5.1/?.lua;;" ./luajit -jon <<EOF
> > | heredoc> local t = { }
> > | heredoc> for i = 1, 1000 do
> > | heredoc>   table.insert(t, require('ffi').new('uint64_t', i))
> > | heredoc> end
> > | heredoc> t = nil
> > | heredoc> collectgarbage('collect')
> > | heredoc> print(require('inspect')(misc.getmetrics()))
> > | heredoc> EOF
> > | {
> > |   global = {
> > |     cdatanum = -941,
> > |     gc_total = 76561,
> > |     jit_mcode_size = 65536,
> > |     jit_trace_num = 3,
> > |     strnum = 534,
> > |     tabnum = 77,
> > |     udatanum = 5
> > |   },
> > |   incremental = {
> > |     gc_allocated = 145299,
> > |     gc_freed = 68738,
> > |     gc_steps_atomic = 3,
> > |     gc_steps_finalize = 0,
> > |     gc_steps_pause = 2,
> > |     gc_steps_propagate = 505,
> > |     gc_steps_sweep = 64,
> > |     gc_steps_sweepstring = 1024,
> > |     jit_snap_restore = 6,
> > |     jit_trace_abort = 0,
> > |     strhash_hit = 3085,
> > |     strhash_miss = 538
> > |   }
> > | }
> > 
> > As you can see global.cdatanum is negative when JIT is on. You can take
> > a look on the compiled trace by yourself. The root cause is CNEW IR
> > semantics: for VLA/VLS cdata types <lj_cdata_newv> call is emitted and
> > the counters are fine, but for other cdata types JIT compiler emits just
> > a <lj_mem_newgco> call that so this object is not counted. Thereby JIT
> > has to emit the corresponding instructions while assembling CNEW IR.
> > I will elaborate on this later.
> 
> Can we use an approach like this?

Kinda.

> 
> diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h
> index 3e189b1..a32a8c4 100644
> --- a/src/lj_asm_x86.h
> +++ b/src/lj_asm_x86.h
> @@ -1835,6 +1835,12 @@ static void asm_cnew(ASMState *as, IRIns *ir)
>      return;
>    }
>  
> +  /* Global state live longer than given trace.

Global state is a Lua universe, so this line is too obvious.

Typo: s/live/lives/.

> +  ** Increment cdatanum counter by address directly.
> +  */
> +  emit_gmroi(as, XG_ARITHi(XOg_ADD), RID_NONE,
> +        ptr2addr(&J2G(as->J)->gc.cdatanum), (int32_t)1);

I see no reason for explicit cast here:
* the parameter is <int32_t> type
* IIRC, integral literals are 32 bit integer types

There is also an additional check within <emit_gmroi> and imm8 addition
is emitted for your case.

Besides, other emitters are still left unpatched.

> +
>    /* Combine initialization of marked, gct and ctypeid. */
>    emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked));
>    emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX,
> 
> > 
> <snipped>
> > 
> > -- 
> > Best regards,
> > IM
> 
> I've fixed your other comments in [1].

Great, thanks!

> 
> [1]: https://lists.tarantool.org/pipermail/tarantool-patches/2020-July/018866.html
> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

  reply	other threads:[~2020-08-12  9:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21 11:34 [Tarantool-patches] [PATCH 0/2] Implement LuaJIT platform metrics Sergey Kaplun
2020-07-21 11:34 ` [Tarantool-patches] [PATCH 1/2] metrics: add counters for metrics interested in Sergey Kaplun
2020-07-23 20:12   ` Igor Munkin
2020-07-24 12:00     ` Sergey Kaplun
2020-07-24 20:05       ` Igor Munkin
2020-07-25 10:00         ` Sergey Kaplun
2020-07-27  2:25     ` Sergey Kaplun
2020-08-12  9:39       ` Igor Munkin [this message]
2020-07-21 11:34 ` [Tarantool-patches] [PATCH 2/2] metrics: add C and Lua API Sergey Kaplun
2020-07-21 11:37 ` [Tarantool-patches] [RFC] rfc: luajit metrics Sergey Kaplun
2020-07-23 10:15   ` Sergey Ostanevich
2020-07-24 11:18     ` Sergey Kaplun
2020-07-24 11:22       ` Sergey Kaplun
2020-07-24 17:20       ` Sergey Ostanevich
2020-07-27  2:18         ` Sergey Kaplun
2020-08-11 20:13         ` Igor Munkin

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=20200812093932.GZ18920@tarantool.org \
    --to=imun@tarantool.org \
    --cc=skaplun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/2] metrics: add counters for metrics interested in' \
    /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