2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_UTIL_NUMA_H
17 #define incl_HPHP_UTIL_NUMA_H
28 // numa_num_nodes and numa_node_set are always defined. They are initialized to
29 // 1 (which is the value when libnuma isn't used).
30 extern uint32_t numa_num_nodes
;
31 extern uint32_t numa_node_set
;
35 extern uint32_t numa_node_mask
;
36 extern std::vector
<bitmask
*> node_to_cpu_mask
;
40 * init_numa() is called very early during process initialization, before
41 * parsing runtime options. It initializes `numa_num_nodes`, `numa_node_set`,
42 * and `numa_node_mask`, when NUMA APIs are usable.
47 * enable_numa() is called after parsing runtime options. It initializes
48 * `use_numa`, which is used to decide whether we actually call NUMA APIs. Note
49 * that on single-node systems, we don't set use_numa.
54 * Determine the next NUMA node according to state maintained in `curr_node`.
56 uint32_t next_numa_node(std::atomic
<uint32_t>& curr_node
);
58 * The number of numa nodes in the system
60 inline uint32_t num_numa_nodes() {
61 return use_numa
? numa_num_nodes
: 1;
64 * Enable numa interleaving for the specified address range
66 void numa_interleave(void* start
, size_t size
);
68 * Allocate the specified address range on the given node
70 void numa_bind_to(void* start
, size_t size
, uint32_t node
);
72 * Return true if node is part of the allowed set of numa nodes
74 inline bool numa_node_allowed(uint32_t node
) {
75 if (numa_node_set
== 0) return true;
76 return numa_node_set
& (1u << node
);
79 #else // HAVE_NUMA undefined
81 inline void init_numa() {}
82 inline void enable_numa() {}
83 inline constexpr uint32_t next_numa_node(std::atomic
<uint32_t>& curr_node
) {
86 inline constexpr uint32_t num_numa_nodes() { return 1; }
87 inline void numa_interleave(void* start
, size_t size
) {}
88 inline void numa_bind_to(void* start
, size_t size
, uint32_t node
) {}
89 inline constexpr bool numa_node_allowed(int node
) { return true; }