qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Xingtao Yao" <yaoxt.fnst@fujitsu.com>
Subject: Re: [PATCH v6 7/7] tests/tcg/x86_64: add test for plugin memory access
Date: Thu, 18 Jul 2024 18:01:55 -0700	[thread overview]
Message-ID: <f4042995-cf2e-473e-9d8b-78a263684fb7@linaro.org> (raw)
In-Reply-To: <2c7e5d0a-7f75-4c3e-9127-695787622599@linaro.org>

On 7/12/24 10:14, Pierrick Bouvier wrote:
> On 7/12/24 07:51, Alex Bennée wrote:
>> Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:
>>
>>> On 7/8/24 12:15, Alex Bennée wrote:
>>>> Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:
>>>>
>>>>> Add an explicit test to check expected memory values are read/written.
>>>>> For sizes 8, 16, 32, 64 and 128, we generate a load/store operation.
>>>>> For size 8 -> 64, we generate an atomic __sync_val_compare_and_swap too.
>>>>> For 128bits memory access, we rely on SSE2 instructions.
>>>>>
>>>>> By default, atomic accesses are non atomic if a single cpu is running,
>>>>> so we force creation of a second one by creating a new thread first.
>>>>>
>>>>> load/store helpers code path can't be triggered easily in user mode (no
>>>>> softmmu), so we can't test it here.
>>>>>
>>>>> Can be run with:
>>>>> make -C build/tests/tcg/x86_64-linux-user run-plugin-test-plugin-mem-access-with-libmem.so
>>>>>
>>>>> Tested-by: Xingtao Yao <yaoxt.fnst@fujitsu.com>
>>>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>>>> ---
>>>>>     tests/tcg/x86_64/test-plugin-mem-access.c   | 89 +++++++++++++++++++++
>>>>>     tests/tcg/x86_64/Makefile.target            |  7 ++
>>>>>     tests/tcg/x86_64/check-plugin-mem-access.sh | 48 +++++++++++
>>>>>     3 files changed, 144 insertions(+)
>>>>>     create mode 100644 tests/tcg/x86_64/test-plugin-mem-access.c
>>>>>     create mode 100755 tests/tcg/x86_64/check-plugin-mem-access.sh
>>>>>
>>>>> diff --git a/tests/tcg/x86_64/test-plugin-mem-access.c b/tests/tcg/x86_64/test-plugin-mem-access.c
>>>>> new file mode 100644
>>>>> index 00000000000..7fdd6a55829
>>>>> --- /dev/null
>>>>> +++ b/tests/tcg/x86_64/test-plugin-mem-access.c
>>>>> @@ -0,0 +1,89 @@
>>>>> +#include <emmintrin.h>
>>>>> +#include <pthread.h>
>>>>> +#include <stdint.h>
>>>>> +#include <stdlib.h>
>>>>> +
>>>>> +static void *data;
>>>>> +
>>>>> +#define DEFINE_STORE(name, type, value) \
>>>>> +static void store_##name(void)          \
>>>>> +{                                       \
>>>>> +    *((type *)data) = value;            \
>>>>> +}
>>>>> +
>>>>> +#define DEFINE_ATOMIC_OP(name, type, value)                 \
>>>>> +static void atomic_op_##name(void)                          \
>>>>> +{                                                           \
>>>>> +    *((type *)data) = 0x42;                                 \
>>>>> +    __sync_val_compare_and_swap((type *)data, 0x42, value); \
>>>> Should we exercise the other compare and swap ops? Do they all come
>>>> through the same rwm path?
>>>>
>>>
>>> There are definitely several paths depending on the generated atomic op.
>>> However, the code is pretty straightforward (and implemented in a
>>> single function), so my thought was that one way to trigger this was
>>> enough.
>>
>> If they all come through the same path I guess that's OK.
>>
>>>>> +}
>>>>> +
>>>>> +#define DEFINE_LOAD(name, type)                         \
>>>>> +static void load_##name(void)                           \
>>>>> +{                                                       \
>>>>> +    register type var asm("eax") = *((type *) data);    \
>>>>> +    (void)var;                                          \
>>>> This is a bit weird. It's the only inline asm needed that makes this
>>>> a
>>>> non-multiarch test. Why?
>>>>
>>>
>>> I'll answer here about why this test is arch specific, and not a multi arch.
>>>
>>> The problem I met is that all target architecture do not have native
>>> 64/128 bits types, and depending how code is compiled with gcc, you
>>> may or not generated expected vector instructions for 128bits
>>> operation. Same for atomic operations.
>>
>> So we do handle this with the sha512 test, building variants of it with
>> various compiler flags to trigger the use of vectors. So the code is
>> multiarch but we have arch specific variants as dictated by the
>> Makefiles, i.e.:
>>
>>     sha512-sve: CFLAGS=-O3 -march=armv8.1-a+sve
>>     sha512-sve: sha512.c
>>             $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
>>
>>     TESTS += sha512-sve
>>
> 
> I suspect this is gonna need several iterations to try all arch, and see
> which ones have native 64/128 bits and which ones have atomic
> instructions. Is that really where we want to spend our (precious) time?
> I'm not convinced of the value of that. We try to test plugins
> implementation, not how QEMU handles memory accesses in general.
> 
> The specificity of this test, is what we don't test the correct output
> of a program, but we observe an expected behavior, via the plugins
> trace. So it's a bit different from sha512 example.
> 
>>> Thus, I chose to specialize this test for x86_64, and use sse2
>>> directly for 128 bits integers.
>>>
>>> You might say "How about adding ifdef for this". Yes sure, but the
>>> check script would become complicated too, and I just wanted to keep
>>> it simple.
>>
>> We can keep the check-script per arch if we have to.
>>
> 
> I would add a target arch param, but not duplicate this to be honest.
> Will be a pain to update if needed.
> My goal was to replace this with LLVM filecheck in a following series.
> 
>>> Our interest here is not to check that memory accesses are
>>> correctly implemented in QEMU, but to check that a specific behavior
>>> on one arch is the one expected.
>>
>> So the problem with not being multiarch is we don't build all targets in
>> all combinations. To limit CI time we often build a subset and now this
>> particular subset won't test the plugin paths.
>>
> 
> Ok. Is linux-user-x86_64 frequently skipped?
> I could add support for aarch64 too, if you think it's worth it. I
> suspect we always have at least one of the two arch that is running in CI.
> 
>>>
>>> Does it make more sense for you?
>>>
>> <snip>
>>

After discussing with Alex, our goal will be to have a multiarch test. 
I'll do this for the next version.

      reply	other threads:[~2024-07-19  1:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-06 19:13 [PATCH v6 0/7] plugins: access values during a memory read/write Pierrick Bouvier
2024-07-06 19:13 ` [PATCH v6 1/7] plugins: fix mem callback array size Pierrick Bouvier
2024-07-08  9:27   ` Alex Bennée
2024-07-16 13:53   ` Alex Bennée
2024-07-06 19:13 ` [PATCH v6 2/7] plugins: save value during memory accesses Pierrick Bouvier
2024-07-08 10:55   ` Alex Bennée
2024-07-06 19:13 ` [PATCH v6 3/7] plugins: extend API to get latest memory value accessed Pierrick Bouvier
2024-07-08 10:56   ` Alex Bennée
2024-07-06 19:13 ` [PATCH v6 4/7] tests/tcg: add mechanism to run specific tests with plugins Pierrick Bouvier
2024-07-08 11:00   ` Alex Bennée
2024-07-12  0:24     ` Pierrick Bouvier
2024-07-06 19:13 ` [PATCH v6 5/7] tests/tcg: allow to check output of plugins Pierrick Bouvier
2024-07-08 16:06   ` Alex Bennée
2024-07-12  0:36     ` Pierrick Bouvier
2024-07-06 19:13 ` [PATCH v6 6/7] tests/plugin/mem: add option to print memory accesses Pierrick Bouvier
2024-07-06 19:13 ` [PATCH v6 7/7] tests/tcg/x86_64: add test for plugin memory access Pierrick Bouvier
2024-07-07 18:25   ` Richard Henderson
2024-07-12  0:41     ` Pierrick Bouvier
2024-07-08 19:15   ` Alex Bennée
2024-07-12  0:48     ` Pierrick Bouvier
2024-07-12 14:51       ` Alex Bennée
2024-07-12 17:14         ` Pierrick Bouvier
2024-07-19  1:01           ` Pierrick Bouvier [this message]

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=f4042995-cf2e-473e-9d8b-78a263684fb7@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=eduardo@habkost.net \
    --cc=erdnaxe@crans.org \
    --cc=ma.mandourr@gmail.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=wangyanan55@huawei.com \
    --cc=yaoxt.fnst@fujitsu.com \
    /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).