Debian Codegraph @

storage/innobase/include/ut0cpu_cache.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2020, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /** @file include/ut0cpu_cache.h
29 Utilities related to CPU cache. */
30
31 #ifndef ut0cpu_cache_h
32 #define ut0cpu_cache_h
33
34 #include "ut0ut.h"
35 namespace ut {
36
37 /** CPU cache line size */
38 #ifdef __powerpc__
39 constexpr size_t INNODB_CACHE_LINE_SIZE = 128;
40 #else
41 constexpr size_t INNODB_CACHE_LINE_SIZE = 64;
42 #endif /* __powerpc__ */
43
44 /** Default kernel page size (not assuming huge pages support). */
45 constexpr size_t INNODB_KERNEL_PAGE_SIZE_DEFAULT = 4 * 1024;
46
47 /**
48 A utility wrapper class, which adds padding at the end of the wrapped structure,
49 so that the next object after it is guaranteed to be in the next cache line.
50 This is to avoid false-sharing.
51 Use this, as opposed to alignas(), to avoid problems with allocators which do
52 not handle over-aligned types.
53 */
54 template <typename T>
55 struct Cacheline_padded : public T {
56 char pad[INNODB_CACHE_LINE_SIZE];
57 // "Inherit" constructors
58 using T::T;
59 };
60
61 /**
62 A utility wrapper class, which aligns T to cacheline boundary.
63 This is to avoid false-sharing.
64 */
65 template <typename T>
66 struct alignas(INNODB_CACHE_LINE_SIZE) Cacheline_aligned : public T {
67 // "Inherit" constructors
68 using T::T;
69 };
70
71 } /* namespace ut */
72
73 #endif /* ut0cpu_cache_h */