summaryrefslogtreecommitdiffstats
path: root/module/zfs/cityhash.c
diff options
context:
space:
mode:
authorPaul Dagnelie <[email protected]>2017-05-25 11:32:40 -0700
committerBrian Behlendorf <[email protected]>2018-06-06 09:35:59 -0700
commit37fb3e431845b934df9771d7bcca5fbef79f4c1e (patch)
tree352e34819910486a9a5ff9cb8870f4256c90afff /module/zfs/cityhash.c
parentf0ed6c744872ec6dc4838947ffc597f4d141864a (diff)
OpenZFS 8484 - Implement aggregate sum and use for arc counters
In pursuit of improving performance on multi-core systems, we should implements fanned out counters and use them to improve the performance of some of the arc statistics. These stats are updated extremely frequently, and can consume a significant amount of CPU time. Authored by: Paul Dagnelie <[email protected]> Reviewed by: Pavel Zakharov <[email protected]> Reviewed by: Matthew Ahrens <[email protected]> Approved by: Dan McDonald <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Ported-by: Paul Dagnelie <[email protected]> OpenZFS-issue: https://www.illumos.org/issues/8484 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/7028a8b92b7 Issue #3752 Closes #7462
Diffstat (limited to 'module/zfs/cityhash.c')
-rw-r--r--module/zfs/cityhash.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/module/zfs/cityhash.c b/module/zfs/cityhash.c
new file mode 100644
index 000000000..2b62edad0
--- /dev/null
+++ b/module/zfs/cityhash.c
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 Google, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+/*
+ * Copyright (c) 2017 by Delphix. All rights reserved.
+ */
+
+#include <sys/cityhash.h>
+
+#define HASH_K1 0xb492b66fbe98f273ULL
+#define HASH_K2 0x9ae16a3b2f90404fULL
+
+/*
+ * Bitwise right rotate. Normally this will compile to a single
+ * instruction.
+ */
+static inline uint64_t
+rotate(uint64_t val, int shift)
+{
+ // Avoid shifting by 64: doing so yields an undefined result.
+ return (shift == 0 ? val : (val >> shift) | (val << (64 - shift)));
+}
+
+static inline uint64_t
+cityhash_helper(uint64_t u, uint64_t v, uint64_t mul)
+{
+ uint64_t a = (u ^ v) * mul;
+ a ^= (a >> 47);
+ uint64_t b = (v ^ a) * mul;
+ b ^= (b >> 47);
+ b *= mul;
+ return (b);
+}
+
+uint64_t
+cityhash4(uint64_t w1, uint64_t w2, uint64_t w3, uint64_t w4)
+{
+ uint64_t mul = HASH_K2 + 64;
+ uint64_t a = w1 * HASH_K1;
+ uint64_t b = w2;
+ uint64_t c = w4 * mul;
+ uint64_t d = w3 * HASH_K2;
+ return (cityhash_helper(rotate(a + b, 43) + rotate(c, 30) + d,
+ a + rotate(b + HASH_K2, 18) + c, mul));
+
+}