[PATCH 3/3] tests/tcg/s390x: Test SET CLOCK COMPARATOR

Ilya Leoshkevich posted 3 patches 1 month ago
Maintainers: Thomas Huth <thuth@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>
There is a newer version of this series
[PATCH 3/3] tests/tcg/s390x: Test SET CLOCK COMPARATOR
Posted by Ilya Leoshkevich 1 month ago
Add a small test to prevent regressions.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tests/tcg/s390x/Makefile.softmmu-target |  1 +
 tests/tcg/s390x/sckc.S                  | 53 +++++++++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 tests/tcg/s390x/sckc.S

diff --git a/tests/tcg/s390x/Makefile.softmmu-target b/tests/tcg/s390x/Makefile.softmmu-target
index 8cd4667c63b..a4425d3184a 100644
--- a/tests/tcg/s390x/Makefile.softmmu-target
+++ b/tests/tcg/s390x/Makefile.softmmu-target
@@ -28,6 +28,7 @@ ASM_TESTS =                                                                    \
     mc                                                                         \
     per                                                                        \
     precise-smc-softmmu                                                        \
+    sckc                                                                       \
     ssm-early                                                                  \
     stosm-early                                                                \
     stpq                                                                       \
diff --git a/tests/tcg/s390x/sckc.S b/tests/tcg/s390x/sckc.S
new file mode 100644
index 00000000000..0fadec0dd65
--- /dev/null
+++ b/tests/tcg/s390x/sckc.S
@@ -0,0 +1,53 @@
+/*
+ * Test clock comparator.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+    .org 0x130
+ext_old_psw:
+    .org 0x1b0
+ext_new_psw:
+    .quad 0x180000000, _ext            /* 64-bit mode */
+    .org 0x200                         /* lowcore padding */
+
+    .globl _start
+_start:
+    lpswe start31_psw
+_start31:
+    stctg %c0,%c0,c0
+    oi c0+6,8                          /* set clock-comparator subclass mask */
+    lctlg %c0,%c0,c0
+0:
+    cghsi ext_counter,0x1000
+    jnz 0b
+    lpswe success_psw
+
+_ext:
+    stg %r0,ext_saved_r0
+
+    lg %r0,ext_counter
+    aghi %r0,1
+    stg %r0,ext_counter
+
+    stck clock
+    lg %r0,clock
+    agfi %r0,0x40000                   /* 64us * 0x1000 =~ 0.25s */
+    stg %r0,clock
+    sckc clock
+
+    lg %r0,ext_saved_r0
+    lpswe ext_old_psw
+
+    .align 8
+start31_psw:
+    .quad 0x100000080000000,_start31   /* EX, 31-bit mode */
+success_psw:
+    .quad 0x2000000000000,0xfff        /* see is_special_wait_psw() */
+c0:
+    .skip 8
+clock:
+    .quad 0
+ext_counter:
+    .quad 0
+ext_saved_r0:
+    .skip 8
-- 
2.51.0
Re: [PATCH 3/3] tests/tcg/s390x: Test SET CLOCK COMPARATOR
Posted by Ilya Leoshkevich 1 month ago
On Tue, 2025-10-14 at 18:05 +0200, Ilya Leoshkevich wrote:
> Add a small test to prevent regressions.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tests/tcg/s390x/Makefile.softmmu-target |  1 +
>  tests/tcg/s390x/sckc.S                  | 53
> +++++++++++++++++++++++++
>  2 files changed, 54 insertions(+)
>  create mode 100644 tests/tcg/s390x/sckc.S

[...]

> diff --git a/tests/tcg/s390x/sckc.S b/tests/tcg/s390x/sckc.S
> new file mode 100644
> index 00000000000..0fadec0dd65
> --- /dev/null
> +++ b/tests/tcg/s390x/sckc.S
> @@ -0,0 +1,53 @@
> +/*
> + * Test clock comparator.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +    .org 0x130
> +ext_old_psw:
> +    .org 0x1b0
> +ext_new_psw:
> +    .quad 0x180000000, _ext            /* 64-bit mode */
> +    .org 0x200                         /* lowcore padding */
> +
> +    .globl _start
> +_start:
> +    lpswe start31_psw
> +_start31:
> +    stctg %c0,%c0,c0
> +    oi c0+6,8                          /* set clock-comparator
> subclass mask */
> +    lctlg %c0,%c0,c0
> +0:
> +    cghsi ext_counter,0x1000
> +    jnz 0b

It's better to move this check to the interrupt handler, otherwise
there is a risk we get two interrupts and the counter moves from
0xfff to 0x1001, causing an infinite loop. I will fix this in v2.

> +    lpswe success_psw
> +
> +_ext:
> +    stg %r0,ext_saved_r0
> +
> +    lg %r0,ext_counter
> +    aghi %r0,1
> +    stg %r0,ext_counter

[...]