libfoedus-core
FOEDUS Core Library
cacheline.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_ASSORTED_CACHELINE_HPP_
19 #define FOEDUS_ASSORTED_CACHELINE_HPP_
20 
21 #include <stdint.h>
22 
23 #include "foedus/compiler.hpp"
24 
31 namespace foedus {
32 namespace assorted {
33 
42 const uint16_t kCachelineSize = 64;
43 
49 inline void prefetch_cacheline(const void* address) {
50 #if defined(__GNUC__)
51 #if defined(__aarch64__)
52  ::__builtin_prefetch(address, 1, 3);
53 #else // defined(__aarch64__)
54  ::__builtin_prefetch(address, 1, 3);
55  // ::_mm_prefetch(address, ::_MM_HINT_T0);
56 #endif // defined(__aarch64__)
57 #endif // defined(__GNUC__)
58 }
59 
66 inline void prefetch_cachelines(const void* address, int cacheline_count) {
67  for (int i = 0; i < cacheline_count; ++i) {
68  const void* shifted = reinterpret_cast<const char*>(address) + kCachelineSize * cacheline_count;
69  prefetch_cacheline(shifted);
70  }
71 }
72 
79 inline void prefetch_l2(const void* address, int cacheline_count) {
80  for (int i = 0; i < cacheline_count; ++i) {
81  const void* shifted = reinterpret_cast<const char*>(address) + kCachelineSize * cacheline_count;
82  prefetch_cacheline(shifted); // this also works for L2/L3
83  }
84 }
85 
86 } // namespace assorted
87 } // namespace foedus
88 
89 #endif // FOEDUS_ASSORTED_CACHELINE_HPP_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
void prefetch_cacheline(const void *address)
Prefetch one cacheline to L1 cache.
Definition: cacheline.hpp:49
void prefetch_cachelines(const void *address, int cacheline_count)
Prefetch multiple contiguous cachelines to L1 cache.
Definition: cacheline.hpp:66
const uint16_t kCachelineSize
Byte count of one cache line.
Definition: cacheline.hpp:42
void prefetch_l2(const void *address, int cacheline_count)
Prefetch multiple contiguous cachelines to L2/L3 cache.
Definition: cacheline.hpp:79