All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] target/arm: replace cp_regs hashtable lookup with direct array index
Date: Wed, 03 Jun 2026 09:00:57 +0100	[thread overview]
Message-ID: <877boguk7a.fsf@draig.linaro.org> (raw)
In-Reply-To: <fff37ec8-1242-4c45-b2bb-d17c672757db@linaro.org> (Richard Henderson's message of "Tue, 2 Jun 2026 15:18:05 -0700")

Richard Henderson <richard.henderson@linaro.org> writes:

> On 6/2/26 08:19, abdelrahman elbehery wrote:
>> Ping
>> On Mon, 18 May 2026, 12:58 pm Abdelrahman Elbehery,
>> <elbeheri95@gmail.com <mailto:elbeheri95@gmail.com>> wrote:
>>     Profiling showed g_hash_table_lookup as a hot spot when running
>> TCG
>>     plugins that log all CPU registers (e.g. execlog with reg=*).
>>     Replace it with a direct array index to avoid lookup overhead.
>>     Signed-off-by: Abdelrahman Elbehery <elbeheri95@gmail.com
>> <mailto:elbeheri95@gmail.com>>
>>     ---
>>     While profiling (via callgrind) a TCG plugin that logs all the CPU registers
>>     (very identical to execlog with reg=*) i noticed that arm_gdb_get_sysreg is a hot spot,
>>     mostly while calling g_hash_table_lookup. Probably this is due to some hashtable collision
>>     that is handleded by glib internally.
>>     Currently each DynamicGDBFeatureInfo item holds keys for
>> cp_regs, and the keys are always
>>     used to retrieve the ARMCPRegInfo pointer.
>>     By replacing the keys array with a GPtrArray, we now just access
>> reg info directly from
>>     the given index.
>>     The benchmarking was done on c2d-highcpu-16 (16 vCPUs, 32 GB
>> memory) GCP
>>     Setup was to run qemu-system-aarch64 against a buildroot kernel
>> and rootfs
>>     with and without the patch mostly using:
>>          --plugin contrib/plugins/libstoptrigger.so,icount=2000000
>>          --plugin contrib/plugins/libexeclog.so,reg=*
>>          -M virt -cpu cortex-a710 -smp 1
>>     Benchmark showed ~15% performance gain when hashtable is not
>> used.
>>     For benchmarking, i used hyperfine with 3 warmup rounds and 10 iterations each.
>>     ---
>>       target/arm/cpu.h     |  6 +++---
>>       target/arm/gdbstub.c | 28 ++++++++++++++++------------
>>       2 files changed, 19 insertions(+), 15 deletions(-)
>>     diff --git a/target/arm/cpu.h b/target/arm/cpu.h
>>     index
>>     15a13b929276dad161032b61ba51ebbce7eeebc6..8816e94e3f8271ad403e77f6182fdb8cee31c527 100644
>>     --- a/target/arm/cpu.h
>>     +++ b/target/arm/cpu.h
>>     @@ -121,15 +121,15 @@
>>        * DynamicGDBFeatureInfo:
>>        * @desc: Contains the feature descriptions.
>>        * @data: A union with data specific to the set of registers
>>     - *    @cpregs_keys: Array that contains the corresponding Key of
>>     - *                  a given cpreg with the same order of the cpreg
>>     + *    @cpregs_regs: Array that contains the corresponding Register info pointer
>>     + *                  of a given cpreg with the same order of the cpreg
>>        *                  in the XML description.
>
> This will not work, because each ARMCPU has separate cpreg info
> structures, and these structures only have the lifetime of the ARMCPU
> struct.  We create and destroy these at runtime, so at some point you
> may end up with pointers to freed memory.

Shouldn't it be the same set for each CPU though?

>
>
> r~

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2026-06-03  8:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18  9:58 [PATCH] target/arm: replace cp_regs hashtable lookup with direct array index Abdelrahman Elbehery
2026-06-02 15:19 ` abdelrahman elbehery
2026-06-02 22:18   ` Richard Henderson
2026-06-03  8:00     ` Alex Bennée [this message]
2026-06-03 14:22       ` Richard Henderson
2026-06-03 15:35         ` Alex Bennée
2026-06-02 16:28 ` Alex Bennée
2026-06-03  9:55   ` abdelrahman elbehery

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=877boguk7a.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=qemu-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.