aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/includes/hicn/transport/portability/cache.h
diff options
context:
space:
mode:
authorLuca Muscariello <lumuscar@cisco.com>2022-06-09 21:34:09 +0200
committerLuca Muscariello <muscariello@ieee.org>2022-06-30 10:47:50 +0200
commit6b94663b2455e212009a544ae23bb6a8c55407f8 (patch)
tree0af780ce5eeb1009fd24b8af8af08e8368eda3bd /libtransport/includes/hicn/transport/portability/cache.h
parenta1ac96f497719b897793ac14b287cb8d840651c1 (diff)
refactor(lib, hicn-light, vpp, hiperf): HICN-723
- move infra data structure into the shared lib - new packet cache using double hashing and lookup on prefix suffix - testing updates - authenticated requests using interest manifests Co-authored-by: Mauro Sardara <msardara@cisco.com> Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com> Co-authored-by: Michele Papalini <micpapal@cisco.com> Co-authored-by: Olivier Roques <oroques+fdio@cisco.com> Co-authored-by: Enrico Loparco <eloparco@cisco.com> Change-Id: Iaddebfe6aa5279ea8553433b0f519578f6b9ccd9 Signed-off-by: Luca Muscariello <muscariello@ieee.org>
Diffstat (limited to 'libtransport/includes/hicn/transport/portability/cache.h')
-rw-r--r--libtransport/includes/hicn/transport/portability/cache.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/libtransport/includes/hicn/transport/portability/cache.h b/libtransport/includes/hicn/transport/portability/cache.h
new file mode 100644
index 000000000..ae113c7d6
--- /dev/null
+++ b/libtransport/includes/hicn/transport/portability/cache.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2022 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/portability/platform.h>
+
+namespace transport {
+namespace portability {
+namespace cache {
+
+/**
+ * @Prefetch utilities
+ */
+
+/* Default cache line size of 64 bytes. */
+#ifndef LOG2_CACHE_LINE_BYTES
+static constexpr const std::size_t klog2_cache_line_bytes = 6;
+#else
+static constexpr const std::size_t klog2_cache_line_bytes =
+ LOG2_CACHE_LINE_BYTES;
+#endif
+
+/* How much data prefetch instruction prefetches */
+#ifndef LOG2_CACHE_PREFETCH_BYTES
+static constexpr const std::size_t klog2_cache_prefetch_bytes =
+ klog2_cache_line_bytes;
+#else
+static constexpr const std::size_t klog2_cache_prefetch_bytes =
+ LOG2_CACHE_PREFETCH_BYTES;
+#endif
+
+/* Default cache line fill buffers. */
+#ifndef N_PREFETCHES
+static constexpr const std::size_t kn_prefetches = 16;
+#else
+static constexpr const std::size_t kn_prefetches = N_PREFETCHES;
+#endif
+
+static constexpr const std::size_t kcache_line_bytes =
+ (1 << klog2_cache_line_bytes);
+static constexpr const std::size_t kcache_prefetch_bytes =
+ (1 << klog2_cache_prefetch_bytes);
+
+static constexpr const int READ = 0;
+static constexpr const int LOAD = 0; /* alias for read */
+static constexpr const int WRITE = 1;
+static constexpr const int STORE = 1; /* alias for write */
+
+#if defined(__GNUC__) || defined(__clang__)
+// Clang & GCC
+
+template <int type>
+static inline void _prefetch(uint8_t *addr, std::size_t n, std::size_t size) {
+ if (size > n * kcache_prefetch_bytes) {
+ __builtin_prefetch(addr + n * kcache_prefetch_bytes, type,
+ /* locality */ 3);
+ }
+}
+
+template <typename T, int type>
+static inline void prefetch(T *addr, std::size_t size) {
+ uint8_t *_addr = reinterpret_cast<uint8_t *>(addr);
+
+ _prefetch<type>(_addr, 0, size);
+ _prefetch<type>(_addr, 1, size);
+ _prefetch<type>(_addr, 2, size);
+ _prefetch<type>(_addr, 3, size);
+}
+#endif
+
+} // namespace cache
+} // namespace portability
+} // namespace transport \ No newline at end of file