ovs-numa: Add function for getting numa node id from core id.
[cascardo/ovs.git] / lib / ovs-numa.h
1 /*
2  * Copyright (c) 2014 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OVS_NUMA_H
18 #define OVS_NUMA_H 1
19
20 #include <limits.h>
21 #include <stdbool.h>
22
23 #include "compiler.h"
24
25 #define OVS_CORE_UNSPEC INT_MAX
26 #define OVS_NUMA_UNSPEC INT_MAX
27
28 #ifdef __linux__
29
30 void ovs_numa_init(void);
31 bool ovs_numa_numa_id_is_valid(int numa_id);
32 bool ovs_numa_core_id_is_valid(int core_id);
33 int ovs_numa_get_n_numas(void);
34 int ovs_numa_get_n_cores(void);
35 int ovs_numa_get_numa_id(int core_id);
36 int ovs_numa_get_n_cores_on_numa(int numa_id);
37 int ovs_numa_get_n_unpinned_cores_on_numa(int numa_id);
38 bool ovs_numa_try_pin_core_specific(int core_id);
39 int ovs_numa_get_unpinned_core_any(void);
40 int ovs_numa_get_unpinned_core_on_numa(int numa_id);
41 void ovs_numa_unpin_core(int core_id);
42
43 #else
44
45 static inline void
46 ovs_numa_init(void)
47 {
48     /* Nothing */
49 }
50
51 static inline bool
52 ovs_numa_numa_id_is_valid(int numa_id OVS_UNUSED)
53 {
54     return false;
55 }
56
57 static inline bool
58 ovs_numa_core_id_is_valid(int core_id OVS_UNUSED)
59 {
60     return false;
61 }
62
63 static inline int
64 ovs_numa_get_n_numas(void)
65 {
66     return OVS_NUMA_UNSPEC;
67 }
68
69 static inline int
70 ovs_numa_get_n_cores(void)
71 {
72     return OVS_CORE_UNSPEC;
73 }
74
75 static inline int
76 ovs_numa_get_numa_id(int core_id OVS_UNUSED)
77 {
78     return OVS_NUMA_UNSPEC;
79 }
80
81 static inline int
82 ovs_numa_get_n_cores_on_numa(int numa_id OVS_UNUSED)
83 {
84     return OVS_CORE_UNSPEC;
85 }
86
87 static inline int
88 ovs_numa_get_n_unpinned_cores_on_numa(int numa_id OVS_UNUSED)
89 {
90     return OVS_CORE_UNSPEC;
91 }
92
93 static inline bool
94 ovs_numa_try_pin_core_specific(int core_id OVS_UNUSED)
95 {
96     return false;
97 }
98
99 static inline int
100 ovs_numa_get_unpinned_core_any(void)
101 {
102     return OVS_CORE_UNSPEC;
103 }
104
105 static inline int
106 ovs_numa_get_unpinned_core_on_numa(int numa_id OVS_UNUSED)
107 {
108     return OVS_CORE_UNSPEC;
109 }
110
111 static inline void
112 ovs_numa_unpin_core(int core_id OVS_UNUSED)
113 {
114     /* Nothing */
115 }
116
117 #endif /* __linux__ */
118 #endif /* ovs-thead.h */