diff mbox series

[v1,12/22] plugins: stxp test case from Aaron (!upstream)

Message ID 20220124201608.604599-13-alex.bennee@linaro.org
State New
Headers show
Series testing and plugin updates | expand

Commit Message

Alex Bennée Jan. 24, 2022, 8:15 p.m. UTC
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
Message-ID: <YXCA62xdRDeueQR6@strawberry.localdomain>

---
[AJB] this was for testing, I think you can show the same stuff with
the much more complete execlog now.
---
 contrib/plugins/stxp-plugin.c     | 50 +++++++++++++++++++++++++++++++
 tests/tcg/aarch64/stxp.c          | 28 +++++++++++++++++
 contrib/plugins/Makefile          |  1 +
 tests/tcg/aarch64/Makefile.target |  3 ++
 4 files changed, 82 insertions(+)
 create mode 100644 contrib/plugins/stxp-plugin.c
 create mode 100644 tests/tcg/aarch64/stxp.c

Comments

Thomas Huth Jan. 25, 2022, 8:17 a.m. UTC | #1
On 24/01/2022 21.15, Alex Bennée wrote:
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
> Message-ID: <YXCA62xdRDeueQR6@strawberry.localdomain>
> 
> ---
> [AJB] this was for testing, I think you can show the same stuff with
> the much more complete execlog now.
> ---
>   contrib/plugins/stxp-plugin.c     | 50 +++++++++++++++++++++++++++++++
>   tests/tcg/aarch64/stxp.c          | 28 +++++++++++++++++
>   contrib/plugins/Makefile          |  1 +
>   tests/tcg/aarch64/Makefile.target |  3 ++
>   4 files changed, 82 insertions(+)
>   create mode 100644 contrib/plugins/stxp-plugin.c
>   create mode 100644 tests/tcg/aarch64/stxp.c
> 
> diff --git a/contrib/plugins/stxp-plugin.c b/contrib/plugins/stxp-plugin.c
> new file mode 100644
> index 0000000000..432cf8c1ed
> --- /dev/null
> +++ b/contrib/plugins/stxp-plugin.c
> @@ -0,0 +1,50 @@
> +#include <stdio.h>
> +#include <stdarg.h>
> +#include <qemu-plugin.h>
> +
> +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
> +
> +void qemu_logf(const char *str, ...)
> +{
> +    char message[1024];
> +    va_list args;
> +    va_start(args, str);
> +    vsnprintf(message, 1023, str, args);
> +
> +    qemu_plugin_outs(message);
> +
> +    va_end(args);
> +}
> +
> +void before_insn_cb(unsigned int cpu_index, void *udata)
> +{
> +    uint64_t pc = (uint64_t)udata;
> +    qemu_logf("Executing PC: 0x%" PRIx64 "\n", pc);
> +}
> +
> +static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t va, void *udata)

Could you please break the line to avoid checkpatch errors:

ERROR: line over 90 characters
#63: FILE: contrib/plugins/stxp-plugin.c:25:
+static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, 
uint64_t va, void *udata)

ERROR: line over 90 characters
#77: FILE: contrib/plugins/stxp-plugin.c:39:
+        qemu_plugin_register_vcpu_insn_exec_cb(insn, before_insn_cb, 
QEMU_PLUGIN_CB_R_REGS, (void *)pc);

ERROR: line over 90 characters
#78: FILE: contrib/plugins/stxp-plugin.c:40:
+        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb, 
QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);

ERROR: "(foo*)" should be "(foo *)"
#78: FILE: contrib/plugins/stxp-plugin.c:40:
+        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb, 
QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);

total: 4 errors, 1 warnings, 92 lines checked

  Thanks,
   Thomas
Aaron Lindsay Feb. 1, 2022, 2:58 p.m. UTC | #2
On Jan 25 09:17, Thomas Huth wrote:
> On 24/01/2022 21.15, Alex Bennée wrote:
> > Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> > Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
> > Message-ID: <YXCA62xdRDeueQR6@strawberry.localdomain>
> > 
> > ---
> > [AJB] this was for testing, I think you can show the same stuff with
> > the much more complete execlog now.
> > ---
> >   contrib/plugins/stxp-plugin.c     | 50 +++++++++++++++++++++++++++++++
> >   tests/tcg/aarch64/stxp.c          | 28 +++++++++++++++++
> >   contrib/plugins/Makefile          |  1 +
> >   tests/tcg/aarch64/Makefile.target |  3 ++
> >   4 files changed, 82 insertions(+)
> >   create mode 100644 contrib/plugins/stxp-plugin.c
> >   create mode 100644 tests/tcg/aarch64/stxp.c
> > 
> > diff --git a/contrib/plugins/stxp-plugin.c b/contrib/plugins/stxp-plugin.c
> > new file mode 100644
> > index 0000000000..432cf8c1ed
> > --- /dev/null
> > +++ b/contrib/plugins/stxp-plugin.c
> > @@ -0,0 +1,50 @@
> > +#include <stdio.h>
> > +#include <stdarg.h>
> > +#include <qemu-plugin.h>
> > +
> > +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
> > +
> > +void qemu_logf(const char *str, ...)
> > +{
> > +    char message[1024];
> > +    va_list args;
> > +    va_start(args, str);
> > +    vsnprintf(message, 1023, str, args);
> > +
> > +    qemu_plugin_outs(message);
> > +
> > +    va_end(args);
> > +}
> > +
> > +void before_insn_cb(unsigned int cpu_index, void *udata)
> > +{
> > +    uint64_t pc = (uint64_t)udata;
> > +    qemu_logf("Executing PC: 0x%" PRIx64 "\n", pc);
> > +}
> > +
> > +static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t va, void *udata)
> 
> Could you please break the line to avoid checkpatch errors:
> 
> ERROR: line over 90 characters
> #63: FILE: contrib/plugins/stxp-plugin.c:25:
> +static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
> uint64_t va, void *udata)
> 
> ERROR: line over 90 characters
> #77: FILE: contrib/plugins/stxp-plugin.c:39:
> +        qemu_plugin_register_vcpu_insn_exec_cb(insn, before_insn_cb,
> QEMU_PLUGIN_CB_R_REGS, (void *)pc);
> 
> ERROR: line over 90 characters
> #78: FILE: contrib/plugins/stxp-plugin.c:40:
> +        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb,
> QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);
> 
> ERROR: "(foo*)" should be "(foo *)"
> #78: FILE: contrib/plugins/stxp-plugin.c:40:
> +        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb,
> QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);
> 
> total: 4 errors, 1 warnings, 92 lines checked

For whatever it's worth, I don't think Alex's intention is to upstream
this code.

-Aaron
Aaron Lindsay Feb. 1, 2022, 3 p.m. UTC | #3
On Jan 24 20:15, Alex Bennée wrote:
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
> Message-ID: <YXCA62xdRDeueQR6@strawberry.localdomain>
> 
> ---
> [AJB] this was for testing, I think you can show the same stuff with
> the much more complete execlog now.

Is it true that execlog can also reproduce the duplicate loads which are
still an outstanding issue?

-Aaron

> ---
>  contrib/plugins/stxp-plugin.c     | 50 +++++++++++++++++++++++++++++++
>  tests/tcg/aarch64/stxp.c          | 28 +++++++++++++++++
>  contrib/plugins/Makefile          |  1 +
>  tests/tcg/aarch64/Makefile.target |  3 ++
>  4 files changed, 82 insertions(+)
>  create mode 100644 contrib/plugins/stxp-plugin.c
>  create mode 100644 tests/tcg/aarch64/stxp.c
> 
> diff --git a/contrib/plugins/stxp-plugin.c b/contrib/plugins/stxp-plugin.c
> new file mode 100644
> index 0000000000..432cf8c1ed
> --- /dev/null
> +++ b/contrib/plugins/stxp-plugin.c
> @@ -0,0 +1,50 @@
> +#include <stdio.h>
> +#include <stdarg.h>
> +#include <qemu-plugin.h>
> +
> +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
> +
> +void qemu_logf(const char *str, ...)
> +{
> +    char message[1024];
> +    va_list args;
> +    va_start(args, str);
> +    vsnprintf(message, 1023, str, args);
> +
> +    qemu_plugin_outs(message);
> +
> +    va_end(args);
> +}
> +
> +void before_insn_cb(unsigned int cpu_index, void *udata)
> +{
> +    uint64_t pc = (uint64_t)udata;
> +    qemu_logf("Executing PC: 0x%" PRIx64 "\n", pc);
> +}
> +
> +static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t va, void *udata)
> +{
> +    uint64_t pc = (uint64_t)udata;
> +    qemu_logf("PC 0x%" PRIx64 " accessed memory at 0x%" PRIx64 "\n", pc, va);
> +}
> +
> +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
> +{
> +    size_t n = qemu_plugin_tb_n_insns(tb);
> +
> +    for (size_t i = 0; i < n; i++) {
> +        struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
> +        uint64_t pc = qemu_plugin_insn_vaddr(insn);
> +
> +        qemu_plugin_register_vcpu_insn_exec_cb(insn, before_insn_cb, QEMU_PLUGIN_CB_R_REGS, (void *)pc);
> +        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb, QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);
> +    }
> +}
> +
> +QEMU_PLUGIN_EXPORT
> +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
> +                        int argc, char **argv)
> +{
> +    qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
> +    return 0;
> +}
> diff --git a/tests/tcg/aarch64/stxp.c b/tests/tcg/aarch64/stxp.c
> new file mode 100644
> index 0000000000..fb8ef6a46d
> --- /dev/null
> +++ b/tests/tcg/aarch64/stxp.c
> @@ -0,0 +1,28 @@
> +
> +
> +void stxp_issue_demo(void *arr)
> +{
> +    asm(".align 8\n\t"
> +        "    mov x0, %[in]\n\t"
> +        "    mov x18, 0x1000\n\t"
> +        "    mov x2, 0x0\n\t"
> +        "    mov x3, 0x0\n\t"
> +        "loop:\n\t"
> +        "    prfm  pstl1strm, [x0]\n\t"
> +        "    ldxp  x16, x17, [x0]\n\t"
> +        "    stxp  w16, x2, x3, [x0]\n\t"
> +        "\n\t"
> +        "    subs x18, x18, 1\n\t"
> +        "    beq done\n\t"
> +        "    b loop\n\t"
> +        "done:\n\t"
> +        : /* none out */
> +        : [in] "r" (arr) /* in */
> +        : "x0", "x2", "x3", "x16", "x17", "x18"); /* clobbers */
> +}
> +
> +int main()
> +{
> +    char arr[16];
> +    stxp_issue_demo(&arr);
> +}
> diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
> index 54ac5ccd9f..576ed5875a 100644
> --- a/contrib/plugins/Makefile
> +++ b/contrib/plugins/Makefile
> @@ -20,6 +20,7 @@ NAMES += howvec
>  NAMES += lockstep
>  NAMES += hwprofile
>  NAMES += cache
> +NAMES += stxp-plugin
>  
>  SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
>  
> diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
> index 1d967901bd..54b2e90d00 100644
> --- a/tests/tcg/aarch64/Makefile.target
> +++ b/tests/tcg/aarch64/Makefile.target
> @@ -72,4 +72,7 @@ endif
>  
>  endif
>  
> +# Load/Store exclusive test
> +AARCH64_TESTS += stxp
> +
>  TESTS += $(AARCH64_TESTS)
> -- 
> 2.30.2
>
Alex Bennée Feb. 1, 2022, 3:29 p.m. UTC | #4
Aaron Lindsay <aaron@os.amperecomputing.com> writes:

> On Jan 24 20:15, Alex Bennée wrote:
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
>> Message-ID: <YXCA62xdRDeueQR6@strawberry.localdomain>
>> 
>> ---
>> [AJB] this was for testing, I think you can show the same stuff with
>> the much more complete execlog now.
>
> Is it true that execlog can also reproduce the duplicate loads which are
> still an outstanding issue?

Are we still seeing duplicate loads? I thought that had been fixed.

>
> -Aaron
>
>> ---
>>  contrib/plugins/stxp-plugin.c     | 50 +++++++++++++++++++++++++++++++
>>  tests/tcg/aarch64/stxp.c          | 28 +++++++++++++++++
>>  contrib/plugins/Makefile          |  1 +
>>  tests/tcg/aarch64/Makefile.target |  3 ++
>>  4 files changed, 82 insertions(+)
>>  create mode 100644 contrib/plugins/stxp-plugin.c
>>  create mode 100644 tests/tcg/aarch64/stxp.c
>> 
>> diff --git a/contrib/plugins/stxp-plugin.c b/contrib/plugins/stxp-plugin.c
>> new file mode 100644
>> index 0000000000..432cf8c1ed
>> --- /dev/null
>> +++ b/contrib/plugins/stxp-plugin.c
>> @@ -0,0 +1,50 @@
>> +#include <stdio.h>
>> +#include <stdarg.h>
>> +#include <qemu-plugin.h>
>> +
>> +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
>> +
>> +void qemu_logf(const char *str, ...)
>> +{
>> +    char message[1024];
>> +    va_list args;
>> +    va_start(args, str);
>> +    vsnprintf(message, 1023, str, args);
>> +
>> +    qemu_plugin_outs(message);
>> +
>> +    va_end(args);
>> +}
>> +
>> +void before_insn_cb(unsigned int cpu_index, void *udata)
>> +{
>> +    uint64_t pc = (uint64_t)udata;
>> +    qemu_logf("Executing PC: 0x%" PRIx64 "\n", pc);
>> +}
>> +
>> +static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t va, void *udata)
>> +{
>> +    uint64_t pc = (uint64_t)udata;
>> +    qemu_logf("PC 0x%" PRIx64 " accessed memory at 0x%" PRIx64 "\n", pc, va);
>> +}
>> +
>> +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>> +{
>> +    size_t n = qemu_plugin_tb_n_insns(tb);
>> +
>> +    for (size_t i = 0; i < n; i++) {
>> +        struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
>> +        uint64_t pc = qemu_plugin_insn_vaddr(insn);
>> +
>> +        qemu_plugin_register_vcpu_insn_exec_cb(insn, before_insn_cb, QEMU_PLUGIN_CB_R_REGS, (void *)pc);
>> +        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb, QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);
>> +    }
>> +}
>> +
>> +QEMU_PLUGIN_EXPORT
>> +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
>> +                        int argc, char **argv)
>> +{
>> +    qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
>> +    return 0;
>> +}
>> diff --git a/tests/tcg/aarch64/stxp.c b/tests/tcg/aarch64/stxp.c
>> new file mode 100644
>> index 0000000000..fb8ef6a46d
>> --- /dev/null
>> +++ b/tests/tcg/aarch64/stxp.c
>> @@ -0,0 +1,28 @@
>> +
>> +
>> +void stxp_issue_demo(void *arr)
>> +{
>> +    asm(".align 8\n\t"
>> +        "    mov x0, %[in]\n\t"
>> +        "    mov x18, 0x1000\n\t"
>> +        "    mov x2, 0x0\n\t"
>> +        "    mov x3, 0x0\n\t"
>> +        "loop:\n\t"
>> +        "    prfm  pstl1strm, [x0]\n\t"
>> +        "    ldxp  x16, x17, [x0]\n\t"
>> +        "    stxp  w16, x2, x3, [x0]\n\t"
>> +        "\n\t"
>> +        "    subs x18, x18, 1\n\t"
>> +        "    beq done\n\t"
>> +        "    b loop\n\t"
>> +        "done:\n\t"
>> +        : /* none out */
>> +        : [in] "r" (arr) /* in */
>> +        : "x0", "x2", "x3", "x16", "x17", "x18"); /* clobbers */
>> +}
>> +
>> +int main()
>> +{
>> +    char arr[16];
>> +    stxp_issue_demo(&arr);
>> +}
>> diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
>> index 54ac5ccd9f..576ed5875a 100644
>> --- a/contrib/plugins/Makefile
>> +++ b/contrib/plugins/Makefile
>> @@ -20,6 +20,7 @@ NAMES += howvec
>>  NAMES += lockstep
>>  NAMES += hwprofile
>>  NAMES += cache
>> +NAMES += stxp-plugin
>>  
>>  SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
>>  
>> diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
>> index 1d967901bd..54b2e90d00 100644
>> --- a/tests/tcg/aarch64/Makefile.target
>> +++ b/tests/tcg/aarch64/Makefile.target
>> @@ -72,4 +72,7 @@ endif
>>  
>>  endif
>>  
>> +# Load/Store exclusive test
>> +AARCH64_TESTS += stxp
>> +
>>  TESTS += $(AARCH64_TESTS)
>> -- 
>> 2.30.2
>>
Aaron Lindsay Feb. 2, 2022, 2:17 p.m. UTC | #5
On Feb 01 15:29, Alex Bennée wrote:
> 
> Aaron Lindsay <aaron@os.amperecomputing.com> writes:
> 
> > On Jan 24 20:15, Alex Bennée wrote:
> >> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> >> Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
> >> Message-ID: <YXCA62xdRDeueQR6@strawberry.localdomain>
> >> 
> >> ---
> >> [AJB] this was for testing, I think you can show the same stuff with
> >> the much more complete execlog now.
> >
> > Is it true that execlog can also reproduce the duplicate loads which are
> > still an outstanding issue?
> 
> Are we still seeing duplicate loads? I thought that had been fixed.

I have not explicitly tested for the duplicate loads on atomics lately
(though I have seen some transient behavior related to atomics that I
have struggled to reliably reproduce, but I believe that's a different
issue). I hadn't seen a subsequent fix come through after the initial
fix for stores and assumed it was still an issue. Sorry for my
assumption, particularly if I just missed it.

-Aaron

> >> ---
> >>  contrib/plugins/stxp-plugin.c     | 50 +++++++++++++++++++++++++++++++
> >>  tests/tcg/aarch64/stxp.c          | 28 +++++++++++++++++
> >>  contrib/plugins/Makefile          |  1 +
> >>  tests/tcg/aarch64/Makefile.target |  3 ++
> >>  4 files changed, 82 insertions(+)
> >>  create mode 100644 contrib/plugins/stxp-plugin.c
> >>  create mode 100644 tests/tcg/aarch64/stxp.c
> >> 
> >> diff --git a/contrib/plugins/stxp-plugin.c b/contrib/plugins/stxp-plugin.c
> >> new file mode 100644
> >> index 0000000000..432cf8c1ed
> >> --- /dev/null
> >> +++ b/contrib/plugins/stxp-plugin.c
> >> @@ -0,0 +1,50 @@
> >> +#include <stdio.h>
> >> +#include <stdarg.h>
> >> +#include <qemu-plugin.h>
> >> +
> >> +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
> >> +
> >> +void qemu_logf(const char *str, ...)
> >> +{
> >> +    char message[1024];
> >> +    va_list args;
> >> +    va_start(args, str);
> >> +    vsnprintf(message, 1023, str, args);
> >> +
> >> +    qemu_plugin_outs(message);
> >> +
> >> +    va_end(args);
> >> +}
> >> +
> >> +void before_insn_cb(unsigned int cpu_index, void *udata)
> >> +{
> >> +    uint64_t pc = (uint64_t)udata;
> >> +    qemu_logf("Executing PC: 0x%" PRIx64 "\n", pc);
> >> +}
> >> +
> >> +static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t va, void *udata)
> >> +{
> >> +    uint64_t pc = (uint64_t)udata;
> >> +    qemu_logf("PC 0x%" PRIx64 " accessed memory at 0x%" PRIx64 "\n", pc, va);
> >> +}
> >> +
> >> +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
> >> +{
> >> +    size_t n = qemu_plugin_tb_n_insns(tb);
> >> +
> >> +    for (size_t i = 0; i < n; i++) {
> >> +        struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
> >> +        uint64_t pc = qemu_plugin_insn_vaddr(insn);
> >> +
> >> +        qemu_plugin_register_vcpu_insn_exec_cb(insn, before_insn_cb, QEMU_PLUGIN_CB_R_REGS, (void *)pc);
> >> +        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb, QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);
> >> +    }
> >> +}
> >> +
> >> +QEMU_PLUGIN_EXPORT
> >> +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
> >> +                        int argc, char **argv)
> >> +{
> >> +    qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
> >> +    return 0;
> >> +}
> >> diff --git a/tests/tcg/aarch64/stxp.c b/tests/tcg/aarch64/stxp.c
> >> new file mode 100644
> >> index 0000000000..fb8ef6a46d
> >> --- /dev/null
> >> +++ b/tests/tcg/aarch64/stxp.c
> >> @@ -0,0 +1,28 @@
> >> +
> >> +
> >> +void stxp_issue_demo(void *arr)
> >> +{
> >> +    asm(".align 8\n\t"
> >> +        "    mov x0, %[in]\n\t"
> >> +        "    mov x18, 0x1000\n\t"
> >> +        "    mov x2, 0x0\n\t"
> >> +        "    mov x3, 0x0\n\t"
> >> +        "loop:\n\t"
> >> +        "    prfm  pstl1strm, [x0]\n\t"
> >> +        "    ldxp  x16, x17, [x0]\n\t"
> >> +        "    stxp  w16, x2, x3, [x0]\n\t"
> >> +        "\n\t"
> >> +        "    subs x18, x18, 1\n\t"
> >> +        "    beq done\n\t"
> >> +        "    b loop\n\t"
> >> +        "done:\n\t"
> >> +        : /* none out */
> >> +        : [in] "r" (arr) /* in */
> >> +        : "x0", "x2", "x3", "x16", "x17", "x18"); /* clobbers */
> >> +}
> >> +
> >> +int main()
> >> +{
> >> +    char arr[16];
> >> +    stxp_issue_demo(&arr);
> >> +}
> >> diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
> >> index 54ac5ccd9f..576ed5875a 100644
> >> --- a/contrib/plugins/Makefile
> >> +++ b/contrib/plugins/Makefile
> >> @@ -20,6 +20,7 @@ NAMES += howvec
> >>  NAMES += lockstep
> >>  NAMES += hwprofile
> >>  NAMES += cache
> >> +NAMES += stxp-plugin
> >>  
> >>  SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
> >>  
> >> diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
> >> index 1d967901bd..54b2e90d00 100644
> >> --- a/tests/tcg/aarch64/Makefile.target
> >> +++ b/tests/tcg/aarch64/Makefile.target
> >> @@ -72,4 +72,7 @@ endif
> >>  
> >>  endif
> >>  
> >> +# Load/Store exclusive test
> >> +AARCH64_TESTS += stxp
> >> +
> >>  TESTS += $(AARCH64_TESTS)
> >> -- 
> >> 2.30.2
> >> 
> 
> 
> -- 
> Alex Bennée
diff mbox series

Patch

diff --git a/contrib/plugins/stxp-plugin.c b/contrib/plugins/stxp-plugin.c
new file mode 100644
index 0000000000..432cf8c1ed
--- /dev/null
+++ b/contrib/plugins/stxp-plugin.c
@@ -0,0 +1,50 @@ 
+#include <stdio.h>
+#include <stdarg.h>
+#include <qemu-plugin.h>
+
+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
+
+void qemu_logf(const char *str, ...)
+{
+    char message[1024];
+    va_list args;
+    va_start(args, str);
+    vsnprintf(message, 1023, str, args);
+
+    qemu_plugin_outs(message);
+
+    va_end(args);
+}
+
+void before_insn_cb(unsigned int cpu_index, void *udata)
+{
+    uint64_t pc = (uint64_t)udata;
+    qemu_logf("Executing PC: 0x%" PRIx64 "\n", pc);
+}
+
+static void mem_cb(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t va, void *udata)
+{
+    uint64_t pc = (uint64_t)udata;
+    qemu_logf("PC 0x%" PRIx64 " accessed memory at 0x%" PRIx64 "\n", pc, va);
+}
+
+static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
+{
+    size_t n = qemu_plugin_tb_n_insns(tb);
+
+    for (size_t i = 0; i < n; i++) {
+        struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
+        uint64_t pc = qemu_plugin_insn_vaddr(insn);
+
+        qemu_plugin_register_vcpu_insn_exec_cb(insn, before_insn_cb, QEMU_PLUGIN_CB_R_REGS, (void *)pc);
+        qemu_plugin_register_vcpu_mem_cb(insn, mem_cb, QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, (void*)pc);
+    }
+}
+
+QEMU_PLUGIN_EXPORT
+int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
+                        int argc, char **argv)
+{
+    qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
+    return 0;
+}
diff --git a/tests/tcg/aarch64/stxp.c b/tests/tcg/aarch64/stxp.c
new file mode 100644
index 0000000000..fb8ef6a46d
--- /dev/null
+++ b/tests/tcg/aarch64/stxp.c
@@ -0,0 +1,28 @@ 
+
+
+void stxp_issue_demo(void *arr)
+{
+    asm(".align 8\n\t"
+        "    mov x0, %[in]\n\t"
+        "    mov x18, 0x1000\n\t"
+        "    mov x2, 0x0\n\t"
+        "    mov x3, 0x0\n\t"
+        "loop:\n\t"
+        "    prfm  pstl1strm, [x0]\n\t"
+        "    ldxp  x16, x17, [x0]\n\t"
+        "    stxp  w16, x2, x3, [x0]\n\t"
+        "\n\t"
+        "    subs x18, x18, 1\n\t"
+        "    beq done\n\t"
+        "    b loop\n\t"
+        "done:\n\t"
+        : /* none out */
+        : [in] "r" (arr) /* in */
+        : "x0", "x2", "x3", "x16", "x17", "x18"); /* clobbers */
+}
+
+int main()
+{
+    char arr[16];
+    stxp_issue_demo(&arr);
+}
diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile
index 54ac5ccd9f..576ed5875a 100644
--- a/contrib/plugins/Makefile
+++ b/contrib/plugins/Makefile
@@ -20,6 +20,7 @@  NAMES += howvec
 NAMES += lockstep
 NAMES += hwprofile
 NAMES += cache
+NAMES += stxp-plugin
 
 SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
 
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index 1d967901bd..54b2e90d00 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -72,4 +72,7 @@  endif
 
 endif
 
+# Load/Store exclusive test
+AARCH64_TESTS += stxp
+
 TESTS += $(AARCH64_TESTS)