| 1 | // Licensed to the .NET Foundation under one or more agreements. | 
|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license. | 
|---|
| 3 | // See the LICENSE file in the project root for more information. | 
|---|
| 4 |  | 
|---|
| 5 | // Enable calling numa functions through shims to make it a soft | 
|---|
| 6 | // runtime dependency. | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef __NUMASHIM_H__ | 
|---|
| 9 | #define __NUMASHIM_H__ | 
|---|
| 10 |  | 
|---|
| 11 | #if HAVE_NUMA_H | 
|---|
| 12 |  | 
|---|
| 13 | #include <numa.h> | 
|---|
| 14 | #include <numaif.h> | 
|---|
| 15 |  | 
|---|
| 16 | #define numa_free_cpumask numa_bitmask_free | 
|---|
| 17 |  | 
|---|
| 18 | // List of all functions from the numa library that are used | 
|---|
| 19 | #define FOR_ALL_NUMA_FUNCTIONS \ | 
|---|
| 20 | PER_FUNCTION_BLOCK(numa_available) \ | 
|---|
| 21 | PER_FUNCTION_BLOCK(mbind) \ | 
|---|
| 22 | PER_FUNCTION_BLOCK(numa_num_possible_cpus) \ | 
|---|
| 23 | PER_FUNCTION_BLOCK(numa_max_node) \ | 
|---|
| 24 | PER_FUNCTION_BLOCK(numa_allocate_cpumask) \ | 
|---|
| 25 | PER_FUNCTION_BLOCK(numa_node_to_cpus) \ | 
|---|
| 26 | PER_FUNCTION_BLOCK(numa_bitmask_weight) \ | 
|---|
| 27 | PER_FUNCTION_BLOCK(numa_bitmask_isbitset) \ | 
|---|
| 28 | PER_FUNCTION_BLOCK(numa_bitmask_free) | 
|---|
| 29 |  | 
|---|
| 30 | // Declare pointers to all the used numa functions | 
|---|
| 31 | #define PER_FUNCTION_BLOCK(fn) extern decltype(fn)* fn##_ptr; | 
|---|
| 32 | FOR_ALL_NUMA_FUNCTIONS | 
|---|
| 33 | #undef PER_FUNCTION_BLOCK | 
|---|
| 34 |  | 
|---|
| 35 | // Redefine all calls to numa functions as calls through pointers that are set | 
|---|
| 36 | // to the functions of libnuma in the initialization. | 
|---|
| 37 | #define numa_available() numa_available_ptr() | 
|---|
| 38 | #define mbind(...) mbind_ptr(__VA_ARGS__) | 
|---|
| 39 | #define numa_num_possible_cpus() numa_num_possible_cpus_ptr() | 
|---|
| 40 | #define numa_max_node() numa_max_node_ptr() | 
|---|
| 41 | #define numa_allocate_cpumask() numa_allocate_cpumask_ptr() | 
|---|
| 42 | #define numa_node_to_cpus(...) numa_node_to_cpus_ptr(__VA_ARGS__) | 
|---|
| 43 | #define numa_bitmask_weight(...) numa_bitmask_weight_ptr(__VA_ARGS__) | 
|---|
| 44 | #define numa_bitmask_isbitset(...) numa_bitmask_isbitset_ptr(__VA_ARGS__) | 
|---|
| 45 | #define numa_bitmask_free(...) numa_bitmask_free_ptr(__VA_ARGS__) | 
|---|
| 46 |  | 
|---|
| 47 | #endif // HAVE_NUMA_H | 
|---|
| 48 |  | 
|---|
| 49 | #endif // __NUMASHIM_H__ | 
|---|
| 50 |  | 
|---|