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