Fix possible crash during array comparison with HackArrCompatCheckCompare
[hiphop-php.git] / hphp / util / numa.h
blob01adbba8d7cb5849225aececda3e943d47da535e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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
19 #include <atomic>
20 #include "stddef.h"
22 #ifdef HAVE_NUMA
24 #include <cstdint>
25 #include <vector>
26 #include <numa.h>
28 namespace HPHP {
30 extern uint32_t numa_node_set;
31 extern uint32_t numa_node_mask;
32 extern uint32_t numa_num_nodes;
33 extern std::vector<bitmask*> node_to_cpu_mask;
34 extern bool use_numa;
36 void initNuma();
39 * Determine the next NUMA node according to state maintained in `curr_node`.
41 int next_numa_node(std::atomic_int& curr_node);
43 * The number of numa nodes in the system
45 inline int num_numa_nodes() {
46 return use_numa ? numa_num_nodes : 1;
49 * Enable numa interleaving for the specified address range
51 void numa_interleave(void* start, size_t size);
53 * Allocate the specified address range on the given node
55 void numa_bind_to(void* start, size_t size, int node);
57 * Return true if node is part of the allowed set of numa nodes
59 inline bool numa_node_allowed(int node) {
60 if (numa_node_set == 0) return true;
61 return numa_node_set & (1u << node);
66 #else // HAVE_NUMA undefined
67 namespace HPHP {
69 inline void initNuma() {}
70 inline constexpr int next_numa_node(std::atomic_int& curr_node) { return 0; }
71 inline constexpr int num_numa_nodes() { return 1; }
72 inline void numa_interleave(void* start, size_t size) {}
73 inline void numa_bind_to(void* start, size_t size, int node) {}
74 inline constexpr bool numa_node_allowed(int node) { return true; }
78 #endif
79 #endif