s390x: Add exit time test
cover s390x: Add exit time test
Sometimes, it is useful to measure the exit time of certain instructions to e.g. identify performance regressions in instructions emulated by the hypervisor.
This series adds a test which executes some instructions and measures their execution time. Since their execution time depends a lot on the environment at hand, all tests are reported as PASS currently.
The point of this series is not so much the instructions which have been chosen here (but your ideas are welcome), but rather the general question whether it makes sense to have a test like this in kvm-unit-tests.
Nico Boehr (2):
lib/s390x: time: add wrapper for stckf
s390x: add exittime tests
lib/s390x/asm/time.h | 9 ++ s390x/Makefile | 1 + s390x/exittime.c | 258 +++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 4 files changed, 272 insertions(+) create mode 100644 s390x/exittime.c
Signature · 1 line
2.36.1
PATCH 1/2 lib/s390x: time: add wrapper for stckf
Upcoming changes will do performance measurements of instructions. Since stck is designed to return unique values even on concurrent calls, it is unsuited for performance measurements. stckf should be used in this case.
Hence, add a nice wrapper for stckf to the time library.
--- lib/s390x/asm/time.h | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/s390x/asm/time.h +9 -0
@@ -14,6 +14,15 @@#define STCK_SHIFT_US (63 - 51)#define STCK_MAX ((1UL << 52) - 1) +static inline uint64_t get_clock_fast (void ) +{ +uint64_t clk; + + asmvolatile (" stckf %0 " : :"Q" (clk) :"memory" ); + +return clk; +} +static inline uint64_t get_clock_us (void ) {uint64_t clk;
Signature · 1 line
2.36.1
Re: [kvm-unit-tests PATCH v1 1/2] lib/s390x: time: add wrapper for stckf
Quoted 18 lines · Nico Boehr
Upcoming changes will do performance measurements of instructions. Since stck is designed to return unique values even on concurrent calls, it is unsuited for performance measurements. stckf should be used in this case.
Hence, add a nice wrapper for stckf to the time library.
Signed-off-by Nico Boehr <[email protected]>--- lib/s390x/asm/time.h | 9 +++++++++ 1 file changed, 9 insertions(+)lib/s390x/asm/time.h +0
-0@@ -14,6 +14,15 @@#define STCK_SHIFT_US (63 - 51)
lib/s390x/asm/time.h line 24
Quoted 10 lines
lib/s390x/asm/time.h +8
-0#define STCK_MAX ((1UL << 52) - 1) +static inline uint64_t get_clock_fast (void ) +{ +uint64_t clk; + + asmvolatile (" stckf %0 " : :"Q" (clk) :"memory" ); + +return clk; +}
Using clk as input parameter together with memory clobbing sounds like a bad solution to me here. The Linux kernel properly uses it as output parameter instead:
static inline unsigned long get_tod_clock_fast(void)
{
unsigned long clk;
asm volatile("stckf %0" : "=Q" (clk) : : "cc");
return clk;
}(see arch/s390/include/asm/timex.h in the kernel sources)
As you can see, also the "cc" should be in the clobber list here.
Thomas
Re: [kvm-unit-tests PATCH v1 1/2] lib/s390x: time: add wrapper for stckf
Quoting Thomas Huth (2022-08-30 14:27:30)
[...]
Quoted 21 lines
Quoted 6 lines
lib/s390x/asm/time.h +0
-0@@ -14,6 +14,15 @@#define STCK_SHIFT_US (63 - 51)lib/s390x/asm/time.h line 24
Quoted 10 lines
lib/s390x/asm/time.h +8
-0#define STCK_MAX ((1UL << 52) - 1) +static inline uint64_t get_clock_fast (void ) +{ +uint64_t clk; + + asmvolatile (" stckf %0 " : :"Q" (clk) :"memory" ); + +return clk; +}Using clk as input parameter together with memory clobbing sounds like a bad solution to me here. The Linux kernel properly uses it as output parameter instead:
Quoted 7 lines
static inline unsigned long
get_tod_clock_fast(void){ unsigned long clk; asm volatile("stckf %0" : "=Q" (clk) : : "cc"); return clk; }
Yes, thanks, it is a better solution. get_clock_us() also does it this way, so while at it let's fix that, too...
PATCH 2/2 s390x: add exittime tests
In reply to Nico BoehrAdd a test to measure the execution time of several instructions. This can be helpful in finding performance regressions in hypervisor code.
All tests are currently reported as PASS, since the baseline for their execution time depends on the respective environment and since needs to be determined on a case-by-case basis.
--- s390x/Makefile | 1 + s390x/exittime.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 3 files changed, 263 insertions(+) create mode 100644 s390x/exittime.c
s390x/Makefile +1 -0
@@ -34,6 +34,7 @@ tests += $(TEST_DIR)/migration.elf tests += $(TEST_DIR)/pv-attest.elf tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf +tests += $(TEST_DIR)/exittime.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/exittime.c new file +258 -0
258 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -185,3 +185,7 @@ groups = migration [migration-skey] file = migration-skey.elf groups = migration + +[exittime] +file = exittime.elf +smp = 2
Signature · 1 line
2.36.1
Re: [kvm-unit-tests PATCH v1 2/2] s390x: add exittime tests
Quoted 52 lines · Nico Boehr
Add a test to measure the execution time of several instructions. This can be helpful in finding performance regressions in hypervisor code.
All tests are currently reported as PASS, since the baseline for their execution time depends on the respective environment and since needs to be determined on a case-by-case basis.
Signed-off-by Nico Boehr <[email protected]>--- s390x/Makefile | 1 + s390x/exittime.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 3 files changed, 263 insertions(+)create mode 100644
s390x/exittime.cs390x/Makefile +1
-0@@ -34,6 +34,7 @@ tests += $(TEST_DIR)/migration.elf tests += $(TEST_DIR)/pv-attest.elf tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf +tests += $(TEST_DIR)/exittime.elf pv-tests += $(TEST_DIR)/pv-diags.elfs390x/exittime.c new file +19
-0@@ -0,0 +1,258 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Measure run time of various instructions. Can be used to find runtime +* regressions of instructions which cause exits. +* +* Copyright IBM Corp. 2022 +* +* Authors: +* Nico Boehr <[email protected]> +*/ +#include <libcflat.h> +#include <smp.h> +#include <sclp.h> +#include <asm/time.h> +#include <asm/sigp.h> +#include <asm/interrupt.h> +#include <asm/page.h> + +char pagebuf[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
s390x/exittime.c line 29
Quoted 10 lines
s390x/exittime.c new file +10
-0+ +static void test_sigp_sense_running (long destcpu) +{ +smp_sigp (destcpu,SIGP_SENSE_RUNNING ,0 ,NULL ); +} + +static void test_nop (long ignore) +{ + asmvolatile ("nop" : : :"memory" ); +}
What's the purpose of testing "nop"? ... it does not trap to the hypervisor... ? Is it just for reference? Then a comment might be helpful here.
Quoted 7 lines
s390x/exittime.c new file +7
-0+static void test_diag9c (long destcpu) +{ + asmvolatile ("diag %[destcpu],0,0x9c" + : + : [destcpu]"d" (destcpu) + : + );
s390x/exittime.c line 47
Quoted 10 lines
s390x/exittime.c new file +10
-0+} + +static long setup_get_this_cpuaddr (long ignore) +{ +return stap (); +} + +static void test_diag44 (long ignore) +{ + asmvolatile ("diag 0,0,0x44" : : : );
Drop the " : : : " please.
s390x/exittime.c line 58
Quoted 11 lines
s390x/exittime.c new file +11
-0+} + +static void test_stnsm (long ignore) +{ +int out; + + asmvolatile ( +"stnsm %[out],0xff" + : [out]"=Q" (out) + : + : "memory"
I don't think you need the "memory" clobber here, do you?
s390x/exittime.c line 70
Quoted 12 lines
s390x/exittime.c new file +12
-0+ ); +} + +static void test_stosm (long ignore) +{ +int out; + + asmvolatile ( +"stosm %[out],0" + : [out]"=Q" (out) + : + : "memory"
dito
Quoted 48 lines
s390x/exittime.c new file +48
-0+ ); +} + +static long setup_ssm (long ignore) +{ +long system_mask =0 ; + + asmvolatile ( +"stosm %[system_mask],0" + : [system_mask]"=Q" (system_mask) + : + :"memory" + ); + +return system_mask; +} + +static void test_ssm (long old_system_mask) +{ + asmvolatile ( +"ssm %[old_system_mask]" + : + : [old_system_mask]"Q" (old_system_mask) + : + ); +} + +static long setup_lctl4 (long ignore) +{ +long ctl4_orig =0 ; + + asmvolatile ( +"stctg 4,4,%[ctl4_orig]" + : [ctl4_orig]"=S" (ctl4_orig) + : + :"memory" + ); + +return ctl4_orig; +} + +static void test_lctl4 (long ctl4_orig) +{ + asmvolatile ( +"lctlg 4,4,%[ctl4_orig]" + : + : [ctl4_orig]"S" (ctl4_orig) + :
s390x/exittime.c line 128
Quoted 10 lines
s390x/exittime.c new file +10
-0+ ); +} + +static void test_stpx (long ignore) +{ +unsigned int prefix; + + asmvolatile ( +"stpx %[prefix]" + : [prefix] "=S" (prefix)
STPX seems to have only a short displacement, so it should have "=Q" instead of "=S" ?
Quoted 46 lines
s390x/exittime.c new file +46
-0+ : + : "memory" + ); +} + +static void test_stfl (long ignore) +{ + asmvolatile ( +"stfl 0" : : :"memory" + ); +} + +static void test_epsw (long ignore) +{ +long r1, r2; + + asmvolatile ( +"epsw %[r1], %[r2]" + : [r1]"=d" (r1), [r2]"=d" (r2) + : + : + ); +} + +static void test_illegal (long ignore) +{ +expect_pgm_int (); + asmvolatile ( +".word 0" + : + : + : + ); +clear_pgm_int (); +} + +static long setup_servc (long arg) +{ +memset (pagebuf,0 ,PAGE_SIZE ); +return arg; +} + +static void test_servc (long ignore) +{ +SCCB *sccb = (SCCB *) pagebuf; + sccb->h.length =8 ;
s390x/exittime.c line 184
Quoted 10 lines
s390x/exittime.c new file +10
-0+servc (0 , (unsigned long ) sccb); +} + +static void test_stsi (long fc) +{ +stsi (pagebuf, fc,2 ,2 ); +} + +struct test { +char name[100 ];
"const char *name" instead of using an array here, please. Otherwise this wastes a lot of space in the binary.
...
s390x/unittests.cfg groups = migration · line 191
Quoted 12 lines
s390x/unittests.cfg +4
-0@@ -185,3 +185,7 @@ groups = migration [migration-skey] file = migration-skey.elf groups = migration + +[exittime] +file = exittime.elf +smp = 2
I wonder whether we should execute this test by default, since nothing can fail here? I assume this is rather something that you want to run manually?
Thomas
Re: [kvm-unit-tests PATCH v1 2/2] s390x: add exittime tests
Quoting Thomas Huth (2022-08-30 14:52:14)
Quoted 2 lines
I wonder whether we should execute this test by default, since nothing can fail here? I assume this is rather something that you want to run manually?
This could be one idea.
My idea was to run it even if it can't fail since the execution times are printed in log files. Collecting them may be interesting to establish a baseline for later measurements. It also is what x86 does with their vmexit tests. In addition, running them doesn't hurt and makes sure the tests don't suddenly break.
I will address your other comments in an upcoming iteration, thank you.
Re: [kvm-unit-tests PATCH v1 2/2] s390x: add exittime tests
In reply to Thomas HuthQuoting Thomas Huth (2022-08-30 14:52:14)
Quoted 2 lines
Quoted 2 lines
s390x/exittime.c new file +0
-0
[...]
Quoted 7 lines
s390x/exittime.c line 29
Quoted 4 lines
s390x/exittime.c new file +4
-0+static void test_nop (long ignore) +{ + asmvolatile ("nop" : : :"memory" ); +}What's the purpose of testing "nop"? ... it does not trap to the hypervisor... ? Is it just for reference? Then a comment might be helpful here.
Yes, the idea is to have some reference for a non-trapping instruction. Added a comment.
[...]
Quoted 5 lines
s390x/exittime.c line 47
Quoted 3 lines
s390x/exittime.c new file +3
-0+static void test_diag44 (long ignore) +{ + asmvolatile ("diag 0,0,0x44" : : : );Drop the " : : : " please.
OK
Quoted 11 lines
s390x/exittime.c line 58
Quoted 9 lines
s390x/exittime.c new file +9
-0+static void test_stnsm (long ignore) +{ +int out; + + asmvolatile ( +"stnsm %[out],0xff" + : [out]"=Q" (out) + : + : "memory"I don't think you need the "memory" clobber here, do you?
Uhm, yes, right. Good thing we have reviews. :-)
[...]
Quoted 10 lines
s390x/exittime.c line 128
Quoted 7 lines
s390x/exittime.c new file +7
-0+static void test_stpx (long ignore) +{ +unsigned int prefix; + + asmvolatile ( +"stpx %[prefix]" + : [prefix] "=S" (prefix)STPX seems to have only a short displacement, so it should have "=Q" instead of "=S" ?
Yes, right, fixed. Also the memory clobber is unneeded. I think I will do through all the clobbers and constraint once more, seems like I messed up a bit there.
[...]
Quoted 5 lines
s390x/exittime.c line 184
Quoted 2 lines
s390x/exittime.c new file +2
-0+struct test { +char name[100 ];"const char *name" instead of using an array here, please. Otherwise this wastes a lot of space in the binary.
Makes sense, thanks.