netdev-dpdk: fix mbuf leaks
[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 #include "list.h"
25
26 #define OVS_CORE_UNSPEC INT_MAX
27 #define OVS_NUMA_UNSPEC INT_MAX
28
29 /* Dump of a list of 'struct ovs_numa_info'. */
30 struct ovs_numa_dump {
31     struct ovs_list dump;
32 };
33
34 /* A numa_id - core_id pair. */
35 struct ovs_numa_info {
36     struct ovs_list list_node;
37     int numa_id;
38     unsigned core_id;
39 };
40
41 #ifdef __linux__
42
43 void ovs_numa_init(void);
44 bool ovs_numa_numa_id_is_valid(int numa_id);
45 bool ovs_numa_core_id_is_valid(unsigned core_id);
46 bool ovs_numa_core_is_pinned(unsigned core_id);
47 int ovs_numa_get_n_numas(void);
48 void ovs_numa_set_cpu_mask(const char *cmask);
49 int ovs_numa_get_n_cores(void);
50 int ovs_numa_get_numa_id(unsigned core_id);
51 int ovs_numa_get_n_cores_on_numa(int numa_id);
52 int ovs_numa_get_n_unpinned_cores_on_numa(int numa_id);
53 bool ovs_numa_try_pin_core_specific(unsigned core_id);
54 unsigned ovs_numa_get_unpinned_core_any(void);
55 unsigned ovs_numa_get_unpinned_core_on_numa(int numa_id);
56 void ovs_numa_unpin_core(unsigned core_id);
57 struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id);
58 void ovs_numa_dump_destroy(struct ovs_numa_dump *);
59
60 #define FOR_EACH_CORE_ON_NUMA(ITER, DUMP)                    \
61     LIST_FOR_EACH((ITER), list_node, &(DUMP)->dump)
62
63 #else
64
65 static inline void
66 ovs_numa_init(void)
67 {
68     /* Nothing */
69 }
70
71 static inline bool
72 ovs_numa_numa_id_is_valid(int numa_id OVS_UNUSED)
73 {
74     return false;
75 }
76
77 static inline bool
78 ovs_numa_core_id_is_valid(unsigned core_id OVS_UNUSED)
79 {
80     return false;
81 }
82
83 static inline bool
84 ovs_numa_core_is_pinned(unsigned core_id OVS_UNUSED)
85 {
86     return false;
87 }
88
89 static inline void
90 ovs_numa_set_cpu_mask(const char *cmask OVS_UNUSED)
91 {
92     /* Nothing */
93 }
94
95 static inline int
96 ovs_numa_get_n_numas(void)
97 {
98     return OVS_NUMA_UNSPEC;
99 }
100
101 static inline int
102 ovs_numa_get_n_cores(void)
103 {
104     return OVS_CORE_UNSPEC;
105 }
106
107 static inline int
108 ovs_numa_get_numa_id(unsigned core_id OVS_UNUSED)
109 {
110     return OVS_NUMA_UNSPEC;
111 }
112
113 static inline int
114 ovs_numa_get_n_cores_on_numa(int numa_id OVS_UNUSED)
115 {
116     return OVS_CORE_UNSPEC;
117 }
118
119 static inline int
120 ovs_numa_get_n_unpinned_cores_on_numa(int numa_id OVS_UNUSED)
121 {
122     return OVS_CORE_UNSPEC;
123 }
124
125 static inline bool
126 ovs_numa_try_pin_core_specific(unsigned core_id OVS_UNUSED)
127 {
128     return false;
129 }
130
131 static inline unsigned
132 ovs_numa_get_unpinned_core_any(void)
133 {
134     return OVS_CORE_UNSPEC;
135 }
136
137 static inline unsigned
138 ovs_numa_get_unpinned_core_on_numa(int numa_id OVS_UNUSED)
139 {
140     return OVS_CORE_UNSPEC;
141 }
142
143 static inline void
144 ovs_numa_unpin_core(unsigned core_id OVS_UNUSED)
145 {
146     /* Nothing */
147 }
148
149 static inline struct ovs_numa_dump *
150 ovs_numa_dump_cores_on_numa(int numa_id OVS_UNUSED)
151 {
152     return NULL;
153 }
154
155 static inline void
156 ovs_numa_dump_destroy(struct ovs_numa_dump *dump OVS_UNUSED)
157 {
158     /* Nothing */
159 }
160
161 /* No loop. */
162 #define FOR_EACH_CORE_ON_NUMA(ITER, DUMP)                    \
163     for ((ITER) = NULL; (ITER);)
164
165 #endif /* __linux__ */
166 #endif /* ovs-thead.h */