qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	Richard Henderson <richard.henderson@linaro.org>,
	clg@kaod.org, david@gibson.dropbear.id.au
Subject: Re: [PATCH 0/3] Reorg ppc64 pmu insn counting
Date: Mon, 3 Jan 2022 15:06:18 -0300	[thread overview]
Message-ID: <328302bb-b916-8d13-70e6-e6f88b0745db@gmail.com> (raw)
In-Reply-To: <87fsq4dfck.fsf@linaro.org>



On 1/3/22 12:07, Alex Bennée wrote:
> 
> Daniel Henrique Barboza <danielhb413@gmail.com> writes:
> 
>> On 12/23/21 00:01, Richard Henderson wrote:
>>> In contrast to Daniel's version, the code stays in power8-pmu.c,
>>> but is better organized to not take so much overhead.
>>> Before:
>>>       32.97%  qemu-system-ppc  qemu-system-ppc64   [.] pmc_get_event
>>>       20.22%  qemu-system-ppc  qemu-system-ppc64   [.] helper_insns_inc
>>>        4.52%  qemu-system-ppc  qemu-system-ppc64   [.] hreg_compute_hflags_value
>>>        3.30%  qemu-system-ppc  qemu-system-ppc64   [.] helper_lookup_tb_ptr
>>>        2.68%  qemu-system-ppc  qemu-system-ppc64   [.] tcg_gen_code
>>>        2.28%  qemu-system-ppc  qemu-system-ppc64   [.] cpu_exec
>>>        1.84%  qemu-system-ppc  qemu-system-ppc64   [.] pmu_insn_cnt_enabled
>>> After:
>>>        8.42%  qemu-system-ppc  qemu-system-ppc64   [.]
>>> hreg_compute_hflags_value
>>>        6.65%  qemu-system-ppc  qemu-system-ppc64   [.] cpu_exec
>>>        6.63%  qemu-system-ppc  qemu-system-ppc64   [.] helper_insns_inc
>>>
>>
>> Thanks for looking this up. I had no idea the original C code was that slow.
>>
> <snip>
>>
>> With that in mind I decided to post a new version of my TCG rework, with less repetition and
>> a bit more concise, to have an alternative that can be used upstream to fix the Avocado tests.
>> Meanwhile I'll see if I can get your reorg working with all EBB tests we need. All things
>> equal - similar performance, all EBB tests passing - I'd rather stay with your C code than my
>> TCG rework since yours doesn't rely on TCG Ops knowledge to maintain
>> it.
> 
> Reading this series did make me wonder if we need a more generic service
> from the TCG for helping with "internal" instrumentation needed for
> things like decent PMU emulation. We haven't gone as much for it in ARM
> yet but it would be nice to. It would be even nicer if such a facility
> could be used by stuff like icount as well so we don't end up doing the
> same thing twice.

Back in May 2021 when I first starting working on this code I tried to base myself in the
ARM PMU code. In fact, the cycle and insn calculation done in the very first version of
this work was based on what ARM does in target/arm/helper.c, cycles_get_count() and
instructions_get_count(). The cycle calculation got simplified because our PPC64 CPU
has a 1Ghz clock so it's easier to just consider 1ns = 1 cycle.

For instruction count, aside from my 2-3 weeks of spectacular failures trying to count
instructions inside translate.c, I also looked into how TCG plugins work and tried to do
something similar to what plugin_gen_tb_end() does at the end of the translator_loop()
in accel/tcg/translator.c. For some reason I wasn't able to replicate the same behavior
that I would have if I used the TCG plugin framework in the 'canonical' way.

I ended up doing something similar to what instructions_get_count() from ARM does, which
relies on icount. Richard then aided me in figuring out that I could count instructions
directly by tapping into the end of each TB.

So, for a generic service of sorts I believe it would be nice to re-use the TCG plugins
API in the internal instrumentation (I tried it once, failed, not sure if I messed up
or it's not possible ATM). That would be a good start to try to get all this logic in a
generic code for internal translate code to use.



Thanks,


Daniel



> 
>>
>>
>> Thanks,
>>
>>
>> Daniel
>>
>>
>> [1] https://github.com/torvalds/linux/tree/master/tools/testing/selftests/powerpc/pmu/ebb
>> [2] https://lists.gnu.org/archive/html/qemu-devel/2021-12/msg00073.html
>>
>>> r~
>>> Richard Henderson (3):
>>>     target/ppc: Cache per-pmc insn and cycle count settings
>>>     target/ppc: Rewrite pmu_increment_insns
>>>     target/ppc: Use env->pnc_cyc_cnt
>>>    target/ppc/cpu.h         |   3 +
>>>    target/ppc/power8-pmu.h  |  14 +--
>>>    target/ppc/cpu_init.c    |   1 +
>>>    target/ppc/helper_regs.c |   2 +-
>>>    target/ppc/machine.c     |   2 +
>>>    target/ppc/power8-pmu.c  | 230 ++++++++++++++++-----------------------
>>>    6 files changed, 108 insertions(+), 144 deletions(-)
>>>
> 
> 


  reply	other threads:[~2022-01-03 18:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23  3:01 [PATCH 0/3] Reorg ppc64 pmu insn counting Richard Henderson
2021-12-23  3:01 ` [PATCH 1/3] target/ppc: Cache per-pmc insn and cycle count settings Richard Henderson
2021-12-23  3:01 ` [PATCH 2/3] target/ppc: Rewrite pmu_increment_insns Richard Henderson
2021-12-23  3:01 ` [PATCH 3/3] target/ppc: Use env->pnc_cyc_cnt Richard Henderson
2021-12-23 20:36 ` [PATCH 0/3] Reorg ppc64 pmu insn counting Daniel Henrique Barboza
2021-12-23 21:19   ` Richard Henderson
2021-12-23 22:47     ` Daniel Henrique Barboza
2021-12-30 22:12     ` Daniel Henrique Barboza
2022-01-03  6:48       ` Cédric Le Goater
2022-01-03 11:10         ` Daniel Henrique Barboza
2022-01-03 15:07   ` Alex Bennée
2022-01-03 18:06     ` Daniel Henrique Barboza [this message]
2022-01-04 10:32       ` Alex Bennée
2022-01-04 19:56         ` Daniel Henrique Barboza

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=328302bb-b916-8d13-70e6-e6f88b0745db@gmail.com \
    --to=danielhb413@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).