* limitations under the License.
*/
-/* On non-Linux, these functions are defined inline in ovs-numa.h. */
-#ifdef __linux__
-
#include <config.h>
#include "ovs-numa.h"
#include <ctype.h>
-#include <dirent.h>
#include <errno.h>
+#ifdef __linux__
+#include <dirent.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
+#endif /* __linux__ */
#include "hash.h"
#include "hmap.h"
/* True if numa node and core info are correctly extracted. */
static bool found_numa_and_core;
+#ifdef __linux__
/* Returns true if 'str' contains all digits. Returns false otherwise. */
static bool
contain_all_digits(const char *str)
{
return str[strspn(str, "0123456789")] == '\0';
}
+#endif /* __linux__ */
/* Discovers all numa nodes and the corresponding cpu cores.
* Constructs the 'struct numa_node' and 'struct cpu_core'. */
static void
discover_numa_and_core(void)
{
+#ifdef __linux__
int n_cpus = 0;
int i;
DIR *dir;
if (hmap_count(&all_numa_nodes) && hmap_count(&all_cpu_cores)) {
found_numa_and_core = true;
}
+#endif /* __linux__ */
}
/* Gets 'struct cpu_core' by 'core_id'. */
struct ovs_numa_dump *
ovs_numa_dump_cores_on_numa(int numa_id)
{
- struct ovs_numa_dump *dump = NULL;
+ struct ovs_numa_dump *dump = xmalloc(sizeof *dump);
struct numa_node *numa = get_numa_by_numa_id(numa_id);
+ ovs_list_init(&dump->dump);
+
if (numa) {
struct cpu_core *core;
- dump = xmalloc(sizeof *dump);
- ovs_list_init(&dump->dump);
LIST_FOR_EACH(core, list_node, &numa->cores) {
struct ovs_numa_info *info = xmalloc(sizeof *info);
{
struct ovs_numa_info *iter;
+ if (!dump) {
+ return;
+ }
+
LIST_FOR_EACH_POP (iter, list_node, &dump->dump) {
free(iter);
}
core->available = false;
}
}
-
-#endif /* __linux__ */
unsigned core_id;
};
-#ifdef __linux__
-
void ovs_numa_init(void);
bool ovs_numa_numa_id_is_valid(int numa_id);
bool ovs_numa_core_id_is_valid(unsigned core_id);
#define FOR_EACH_CORE_ON_NUMA(ITER, DUMP) \
LIST_FOR_EACH((ITER), list_node, &(DUMP)->dump)
-#else
-
-static inline void
-ovs_numa_init(void)
-{
- /* Nothing */
-}
-
-static inline bool
-ovs_numa_numa_id_is_valid(int numa_id OVS_UNUSED)
-{
- return false;
-}
-
-static inline bool
-ovs_numa_core_id_is_valid(unsigned core_id OVS_UNUSED)
-{
- return false;
-}
-
-static inline bool
-ovs_numa_core_is_pinned(unsigned core_id OVS_UNUSED)
-{
- return false;
-}
-
-static inline void
-ovs_numa_set_cpu_mask(const char *cmask OVS_UNUSED)
-{
- /* Nothing */
-}
-
-static inline int
-ovs_numa_get_n_numas(void)
-{
- return OVS_NUMA_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_n_cores(void)
-{
- return OVS_CORE_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_numa_id(unsigned core_id OVS_UNUSED)
-{
- return OVS_NUMA_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_n_cores_on_numa(int numa_id OVS_UNUSED)
-{
- return OVS_CORE_UNSPEC;
-}
-
-static inline int
-ovs_numa_get_n_unpinned_cores_on_numa(int numa_id OVS_UNUSED)
-{
- return OVS_CORE_UNSPEC;
-}
-
-static inline bool
-ovs_numa_try_pin_core_specific(unsigned core_id OVS_UNUSED)
-{
- return false;
-}
-
-static inline unsigned
-ovs_numa_get_unpinned_core_any(void)
-{
- return OVS_CORE_UNSPEC;
-}
-
-static inline unsigned
-ovs_numa_get_unpinned_core_on_numa(int numa_id OVS_UNUSED)
-{
- return OVS_CORE_UNSPEC;
-}
-
-static inline void
-ovs_numa_unpin_core(unsigned core_id OVS_UNUSED)
-{
- /* Nothing */
-}
-
-static inline struct ovs_numa_dump *
-ovs_numa_dump_cores_on_numa(int numa_id OVS_UNUSED)
-{
- return NULL;
-}
-
-static inline void
-ovs_numa_dump_destroy(struct ovs_numa_dump *dump OVS_UNUSED)
-{
- /* Nothing */
-}
-
-/* No loop. */
-#define FOR_EACH_CORE_ON_NUMA(ITER, DUMP) \
- for ((ITER) = NULL; (ITER);)
-
-#endif /* __linux__ */
-#endif /* ovs-thead.h */
+#endif /* ovs-numa.h */