From 45baa5c1d3793d15d7ff4143e6f169973125ae64 Mon Sep 17 00:00:00 2001 From: Jonathan Albrecht Date: Mon, 23 Oct 2023 13:42:22 -0400 Subject: [PATCH] On s390x, use the stckf instruction to get the cycles timer value. The test ut0rnd.random_from_interval_fast from test suite merge_innodb_tests-t is failing on s390x because the stck (Store Clock) instruction in the my_timer_cycles() function is not very good when used as a source of randomness in random_64_fast(). The stckf (Store Clock Fast) instruction works much better as a source of randomness and is less expensive to call as well. Compared to stck, stckf may store the same clock value twice but according to the Additional Comments comment in mysys/my_rdtsc.cc that should be fine. All 'make test' tests pass with this change. The stckf instruction was added to the Z Architecture in z9 and all of the s390x versions of distros MySQL supports are compiled for z9 or newer so we don't need to check if it is available. --- mysys/my_rdtsc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysys/my_rdtsc.cc b/mysys/my_rdtsc.cc index 537e53ec32e2..73b64343a725 100644 --- a/mysys/my_rdtsc.cc +++ b/mysys/my_rdtsc.cc @@ -173,7 +173,7 @@ ulonglong my_timer_cycles(void) { #elif defined(__GNUC__) && defined(__s390x__) { uint64_t result; - __asm __volatile__("stck %0" : "=Q"(result) : : "cc"); + __asm __volatile__("stckf %0" : "=Q"(result) : : "cc"); return result; } #elif defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME)