libfoedus-core
FOEDUS Core Library
mod_numa_node.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_MOD_NUMA_NODE_HPP_
19 #define FOEDUS_ASSORTED_MOD_NUMA_NODE_HPP_
20 
21 #include <numa.h>
22 
23 namespace foedus {
24 namespace assorted {
25 
31 inline int mod_numa_node(int numa_node) {
32  // if the machine is not a NUMA machine (1-socket), then avoid calling libnuma functions.
33  if (::numa_available() < 0) {
34  return 0;
35  }
36  int hardware_nodes = ::numa_num_configured_nodes();
37  if (numa_node >= 0 && numa_node >= hardware_nodes && hardware_nodes > 0) {
38  numa_node = numa_node % hardware_nodes;
39  }
40  return numa_node;
41 }
42 
43 } // namespace assorted
44 } // namespace foedus
45 
46 #endif // FOEDUS_ASSORTED_MOD_NUMA_NODE_HPP_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
int numa_num_configured_nodes()
int numa_available(void)
int mod_numa_node(int numa_node)
In order to run even on a non-numa machine or a machine with fewer sockets, we allow specifying arbit...