|
|
513694 |
From 1edbd8aad68ea5ddd729e1cbd307c84b1386459a Mon Sep 17 00:00:00 2001
|
|
|
513694 |
From: Noah Goldstein <goldstein.w.n@gmail.com>
|
|
|
513694 |
Date: Wed, 27 Apr 2022 15:13:02 -0500
|
|
|
513694 |
Subject: [PATCH] sysdeps: Add 'get_fast_jitter' interace in fast-jitter.h
|
|
|
513694 |
|
|
|
513694 |
'get_fast_jitter' is meant to be used purely for performance
|
|
|
513694 |
purposes. In all cases it's used it should be acceptable to get no
|
|
|
513694 |
randomness (see default case). An example use case is in setting
|
|
|
513694 |
jitter for retries between threads at a lock. There is a
|
|
|
513694 |
performance benefit to having jitter, but only if the jitter can
|
|
|
513694 |
be generated very quickly and ultimately there is no serious issue
|
|
|
513694 |
if no jitter is generated.
|
|
|
513694 |
|
|
|
513694 |
The implementation generally uses 'HP_TIMING_NOW' iff it is
|
|
|
513694 |
inlined (avoid any potential syscall paths).
|
|
|
513694 |
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
513694 |
|
|
|
513694 |
(cherry picked from commit 911c63a51c690dd1a97dfc587097277029baf00f)
|
|
|
513694 |
---
|
|
|
513694 |
sysdeps/generic/fast-jitter.h | 42 +++++++++++++++++++++++++++++++++++
|
|
|
513694 |
1 file changed, 42 insertions(+)
|
|
|
513694 |
create mode 100644 sysdeps/generic/fast-jitter.h
|
|
|
513694 |
|
|
|
513694 |
diff --git a/sysdeps/generic/fast-jitter.h b/sysdeps/generic/fast-jitter.h
|
|
|
513694 |
new file mode 100644
|
|
|
513694 |
index 00000000..4dd53e34
|
|
|
513694 |
--- /dev/null
|
|
|
513694 |
+++ b/sysdeps/generic/fast-jitter.h
|
|
|
513694 |
@@ -0,0 +1,42 @@
|
|
|
513694 |
+/* Fallback for fast jitter just return 0.
|
|
|
513694 |
+ Copyright (C) 2019-2022 Free Software Foundation, Inc.
|
|
|
513694 |
+ This file is part of the GNU C Library.
|
|
|
513694 |
+
|
|
|
513694 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
513694 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
513694 |
+ License as published by the Free Software Foundation; either
|
|
|
513694 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
513694 |
+
|
|
|
513694 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
513694 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
513694 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
513694 |
+ Lesser General Public License for more details.
|
|
|
513694 |
+
|
|
|
513694 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
513694 |
+ License along with the GNU C Library; if not, see
|
|
|
513694 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
513694 |
+
|
|
|
513694 |
+#ifndef _FAST_JITTER_H
|
|
|
513694 |
+# define _FAST_JITTER_H
|
|
|
513694 |
+
|
|
|
513694 |
+# include <stdint.h>
|
|
|
513694 |
+# include <hp-timing.h>
|
|
|
513694 |
+
|
|
|
513694 |
+/* Baseline just return 0. We could create jitter using a clock or
|
|
|
513694 |
+ 'random_bits' but that may imply a syscall and the goal of
|
|
|
513694 |
+ 'get_fast_jitter' is minimal overhead "randomness" when such
|
|
|
513694 |
+ randomness helps performance. Adding high overhead the function
|
|
|
513694 |
+ defeats the purpose. */
|
|
|
513694 |
+static inline uint32_t
|
|
|
513694 |
+get_fast_jitter (void)
|
|
|
513694 |
+{
|
|
|
513694 |
+# if HP_TIMING_INLINE
|
|
|
513694 |
+ hp_timing_t jitter;
|
|
|
513694 |
+ HP_TIMING_NOW (jitter);
|
|
|
513694 |
+ return (uint32_t) jitter;
|
|
|
513694 |
+# else
|
|
|
513694 |
+ return 0;
|
|
|
513694 |
+# endif
|
|
|
513694 |
+}
|
|
|
513694 |
+
|
|
|
513694 |
+#endif
|
|
|
513694 |
--
|
|
|
513694 |
GitLab
|
|
|
513694 |
|