-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDefaultsConfigurator.hpp
139 lines (120 loc) · 4.22 KB
/
DefaultsConfigurator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
**/
#ifndef QUICKSTEP_CLI_DEFAULTS_CONFIGURATOR_HPP_
#define QUICKSTEP_CLI_DEFAULTS_CONFIGURATOR_HPP_
#include "storage/StorageConfig.h" // For QUICKSTEP_HAVE_LIBNUMA.
#ifdef QUICKSTEP_HAVE_LIBNUMA
#include <numa.h>
#endif // QUICKSTEP_HAVE_LIBNUMA
#include <cstddef>
#include <string>
#include <thread> // NOLINT(build/c++11)
#ifdef QUICKSTEP_HAVE_LIBNUMA
#include <unordered_map>
#endif // QUICKSTEP_HAVE_LIBNUMA
#include <vector>
#include "utility/Macros.hpp"
namespace quickstep {
/** \addtogroup CLI
* @{
**/
/**
* @brief A static class for setting the default configuration parameters in
* Quickstep.
**/
class DefaultsConfigurator {
public:
/**
* @brief Get the number of concurrent threads supported by the hardware,
*
* @note This function will return 0, if it fails (which it may on some
* machines/environments).
**/
static std::size_t GetNumHardwareThreads() {
return std::thread::hardware_concurrency();
}
/**
* @brief Get the number of available numa sockets.
*
* @return Number of available numa sockets. Always 1 if the system doesn't
* have libnuma.
**/
static std::size_t GetNumNUMANodes() {
#ifdef QUICKSTEP_HAVE_LIBNUMA
// Id of the maximum node.
return numa_max_node() + 1;
#else
return 1;
#endif // QUICKSTEP_HAVE_LIBNUMA
}
/**
* @brief Get the number of NUMA nodes covered by the given worker affinities
* to the CPU cores.
*
* @param worker_cpu_affinities A vector V where V[i] is the CPU core to which
* worker with index i is affinitized.
*
* @return The number of NUMA nodes that are covered by the given set of
* workers.
**/
static std::size_t GetNumNUMANodesCoveredByWorkers(const std::vector<int> &worker_cpu_affinities) {
if (!worker_cpu_affinities.empty()) {
#ifdef QUICKSTEP_HAVE_LIBNUMA
// Key = NUMA node, value = whether there is at least one worker whose
// affinity is set to a core on the given NUMA node.
std::unordered_map<int, bool> any_worker_on_numa_node;
for (const int curr_cpu_core_id : worker_cpu_affinities) {
const int curr_numa_node_id = numa_node_of_cpu(curr_cpu_core_id);
if (curr_numa_node_id >= 0) {
// Note - For the purpose of this function, the value is always true.
// Therefore, we can rely on the size of the map to get the count.
any_worker_on_numa_node[curr_numa_node_id] = true;
}
}
return any_worker_on_numa_node.size();
#endif // QUICKSTEP_HAVE_LIBNUMA
}
// When libnuma is not available, or worker affinities are not specified,
// the default return value is 1.
return 1;
}
/**
* @brief Initialize the default database with no relations.
*
* @param storage_path The filesystem directory to store catalog.
* @param catalog_path The full path of the catalog file.
**/
static void InitializeDefaultDatabase(const std::string &storage_path,
const std::string &catalog_path);
/**
* @brief Create the directory.
*
* @param storage_path The filesystem directory for StorageManager.
**/
static void CreateDirectory(const std::string &storage_path);
private:
/**
* @brief Private constructor to disable instantiation of the class.
**/
DefaultsConfigurator();
DISALLOW_COPY_AND_ASSIGN(DefaultsConfigurator);
};
/** @} */
} // namespace quickstep
#endif // QUICKSTEP_CLI_DEFAULTS_CONFIGURATOR_HPP_