Created
October 22, 2024 16:55
-
-
Save mdcallag/de30057bd8f2d9ac2228b67d36e0a980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -u --recursive x/mysql-8.0.40/storage/innobase/include/ut0rnd.h mysql-8.0.40/storage/innobase/include/ut0rnd.h | |
--- orig/mysql-8.0.40/storage/innobase/include/ut0rnd.h 2024-09-18 10:08:24.000000000 +0000 | |
+++ new/mysql-8.0.40/storage/innobase/include/ut0rnd.h 2024-10-22 01:08:07.519857650 +0000 | |
@@ -114,6 +114,9 @@ | |
/** Seed value of ut::random_64() */ | |
extern thread_local uint64_t random_seed; | |
+/** Seed value of utold_rnd_gen_ulint() */ | |
+extern thread_local ulint utold_rnd_ulint_counter; | |
+ | |
/** A helper method, it is used by hash_binary_ib for backward compatibility. | |
NOTE: Do not use this method, it produces results that are not hashed well. | |
Especially for sequences of pairs of <i+n, j+n> over n. */ | |
@@ -160,6 +163,67 @@ | |
} // namespace detail | |
+#define UTOLD_RND1 151117737 | |
+#define UTOLD_RND2 119785373 | |
+#define UTOLD_RND3 85689495 | |
+#define UTOLD_RND4 76595339 | |
+#define UTOLD_SUM_RND2 98781234 | |
+#define UTOLD_SUM_RND3 126792457 | |
+#define UTOLD_SUM_RND4 63498502 | |
+#define UTOLD_XOR_RND1 187678878 | |
+#define UTOLD_XOR_RND2 143537923 | |
+ | |
+/** The following function generates a series of 'random' ulint integers. | |
+ This function is now based on thread local variables. | |
+ @return the next 'random' number */ | |
+static inline ulint utold_rnd_gen_next_ulint( | |
+ ulint rnd) /*!< in: the previous random number value */ | |
+{ | |
+ ulint n_bits; | |
+ n_bits = 8 * sizeof(ulint); | |
+ | |
+ rnd = UTOLD_RND2 * rnd + UTOLD_SUM_RND3; | |
+ rnd = UTOLD_XOR_RND1 ^ rnd; | |
+ rnd = (rnd << 20) + (rnd >> (n_bits - 20)); | |
+ rnd = UTOLD_RND3 * rnd + UTOLD_SUM_RND4; | |
+ rnd = UTOLD_XOR_RND2 ^ rnd; | |
+ rnd = (rnd << 20) + (rnd >> (n_bits - 20)); | |
+ rnd = UTOLD_RND1 * rnd + UTOLD_SUM_RND2; | |
+ return (rnd); | |
+} | |
+ | |
+/** The following function generates 'random' ulint integers which | |
+enumerate the value space of ulint integers in a pseudo random | |
+fashion. Note that the same integer is repeated always after | |
+2 to power 32 calls to the generator (if ulint is 32-bit). | |
+@return pseudo random number */ | |
+static inline ulint utold_rnd_gen_ulint() { | |
+ ulint rnd = detail::utold_rnd_ulint_counter; | |
+ if (rnd == 0) { | |
+ rnd = 65654363; | |
+ } | |
+ | |
+ rnd = UTOLD_RND1 * rnd + UTOLD_RND2; | |
+ detail::utold_rnd_ulint_counter = rnd; | |
+ return (utold_rnd_gen_next_ulint(rnd)); | |
+} | |
+ | |
+/** Generates a random integer from a given interval. | |
+ This function is now based on thread local variables. | |
+ @return the 'random' number */ | |
+static inline ulint utold_rnd_interval( | |
+ ulint low, /*!< in: low limit; can generate also this value */ | |
+ ulint high) /*!< in: high limit; can generate also this value */ | |
+{ | |
+ ulint rnd; | |
+ | |
+ if (low == high) { | |
+ return (low); | |
+ } | |
+ rnd = utold_rnd_gen_ulint(); | |
+ return (low + (rnd % (high - low))); | |
+} | |
+ | |
static inline uint64_t random_64() { | |
detail::random_seed = hash_uint64(detail::random_seed); | |
return detail::random_seed; | |
@@ -183,7 +247,18 @@ | |
} | |
static inline uint64_t random_from_interval_fast(uint64_t low, uint64_t high) { | |
- return random_from_interval_gen<random_64_fast>(low, high); | |
+ // return random_from_interval_gen<random_64>(low, high); | |
+ // return random_from_interval_gen<random_64_fast>(low, high); | |
+ uint64_t r = static_cast<uint64_t>(utold_rnd_interval(low, high)); | |
+ return r; | |
+} | |
+ | |
+inline uint64_t is_inno_hash_crc32() { | |
+#ifndef CRC32_DEFAULT | |
+ if (ut_crc32_cpu_enabled) | |
+ return 1; | |
+#endif | |
+ return 0; | |
} | |
static inline uint64_t hash_uint64(uint64_t value) { | |
diff -u --recursive x/mysql-8.0.40/storage/innobase/srv/srv0start.cc mysql-8.0.40/storage/innobase/srv/srv0start.cc | |
--- orig/mysql-8.0.40/storage/innobase/srv/srv0start.cc 2024-09-18 10:08:24.000000000 +0000 | |
+++ new/mysql-8.0.40/storage/innobase/srv/srv0start.cc 2024-10-21 22:59:19.950832309 +0000 | |
@@ -1655,6 +1655,73 @@ | |
"software polynomial multiplication.") | |
: "software crc32."); | |
+ { | |
+ int alen = srv_spin_wait_delay + 2; | |
+ struct timeval s, e; | |
+ ulint *a = static_cast<ulint*> (malloc(sizeof(ulint) * alen)); | |
+ for (int x=0; x < alen; x++) a[x] = 0; | |
+ | |
+ gettimeofday(&s, NULL); | |
+ for (int x=0; x < 1000; x++) { | |
+ ulint y = ut::random_from_interval(0, srv_spin_wait_delay); | |
+ a[y]++; | |
+ } | |
+ gettimeofday(&e, NULL); | |
+ | |
+ unsigned long long s_usecs = (s.tv_sec * 1000000) + s.tv_usec; | |
+ unsigned long long e_usecs = (e.tv_sec * 1000000) + e.tv_usec; | |
+ unsigned long long t_usecs = e_usecs - s_usecs; | |
+ double usecs_per = (double) t_usecs / 1000.0; | |
+ char usecs_per_str[50]; | |
+ sprintf(usecs_per_str, "%.6f", usecs_per); | |
+ | |
+ ib::info(ER_IB_MSG_1126) | |
+ << " srv_spin_wait_delay = " << srv_spin_wait_delay | |
+ << " usecs/per for ut::random_from_interval = " << usecs_per_str | |
+ << " inno hash uses crc32 = " << ut::is_inno_hash_crc32(); | |
+ for (int x=0; x < alen; x++) { | |
+ ib::info(ER_IB_MSG_1126) | |
+ << "rnd[" << x << "] = " << a[x]; | |
+ a[x] = 0; | |
+ } | |
+ | |
+ gettimeofday(&s, NULL); | |
+ for (int x=0; x < 1000; x++) { | |
+ ulint y = ut::random_from_interval_fast(0, srv_spin_wait_delay); | |
+ a[y]++; | |
+ } | |
+ gettimeofday(&e, NULL); | |
+ | |
+ s_usecs = (s.tv_sec * 1000000) + s.tv_usec; | |
+ e_usecs = (e.tv_sec * 1000000) + e.tv_usec; | |
+ t_usecs = e_usecs - s_usecs; | |
+ usecs_per = (double) t_usecs / 1000.0; | |
+ sprintf(usecs_per_str, "%.6f", usecs_per); | |
+ | |
+ ib::info(ER_IB_MSG_1126) | |
+ << " usecs/per for ut::random_from_interval_fast = " << usecs_per_str; | |
+ for (int x=0; x < alen; x++) { | |
+ ib::info(ER_IB_MSG_1126) | |
+ << "rnd[" << x << "] = " << a[x]; | |
+ } | |
+ | |
+ for (int d=0; d < 10; d++) { | |
+ gettimeofday(&s, NULL); | |
+ for (int x=0; x < 1000; x++) ut_delay(d); | |
+ gettimeofday(&e, NULL); | |
+ s_usecs = (s.tv_sec * 1000000) + s.tv_usec; | |
+ e_usecs = (e.tv_sec * 1000000) + e.tv_usec; | |
+ t_usecs = e_usecs - s_usecs; | |
+ usecs_per = (double) t_usecs / 1000.0; | |
+ sprintf(usecs_per_str, "%.6f", usecs_per); | |
+ ib::info(ER_IB_MSG_1126) | |
+ << " delay = " << d | |
+ << " usecs/per for ut_delay = " << usecs_per_str; | |
+ } | |
+ | |
+ free(a); | |
+ } | |
+ | |
os_create_block_cache(); | |
fil_init(innobase_get_open_files_limit()); | |
diff -u --recursive x/mysql-8.0.40/storage/innobase/ut/ut0rnd.cc mysql-8.0.40/storage/innobase/ut/ut0rnd.cc | |
--- orig/mysql-8.0.40/storage/innobase/ut/ut0rnd.cc 2024-09-18 10:08:24.000000000 +0000 | |
+++ new/mysql-8.0.40/storage/innobase/ut/ut0rnd.cc 2024-10-22 01:08:36.192792769 +0000 | |
@@ -39,6 +39,8 @@ | |
/* Changes for each threads for more different sequences. */ | |
thread_local uint64_t random_seed = ut::this_thread_hash + my_timer_cycles(); | |
+thread_local ulint utold_rnd_ulint_counter = static_cast<ulint>(random_seed); | |
+ | |
/* This is a "precomputed" table of random hash values. */ | |
alignas(ut::INNODB_CACHE_LINE_SIZE) | |
std::array<std::array<uint64_t, 8>, 256> tab_hash_lookup_table = {{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment