|
Packit |
345191 |
/*
|
|
Packit |
345191 |
* Copyright (C) 2014 - 2019 Intel Corporation.
|
|
Packit |
345191 |
* All rights reserved.
|
|
Packit |
345191 |
*
|
|
Packit |
345191 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
345191 |
* modification, are permitted provided that the following conditions are met:
|
|
Packit |
345191 |
* 1. Redistributions of source code must retain the above copyright notice(s),
|
|
Packit |
345191 |
* this list of conditions and the following disclaimer.
|
|
Packit |
345191 |
* 2. Redistributions in binary form must reproduce the above copyright notice(s),
|
|
Packit |
345191 |
* this list of conditions and the following disclaimer in the documentation
|
|
Packit |
345191 |
* and/or other materials provided with the distribution.
|
|
Packit |
345191 |
*
|
|
Packit |
345191 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
|
|
Packit |
345191 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
Packit |
345191 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
Packit |
345191 |
* EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit |
345191 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
Packit |
345191 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
Packit |
345191 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
Packit |
345191 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
Packit |
345191 |
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
Packit |
345191 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
345191 |
*/
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include <memkind/internal/memkind_hbw.h>
|
|
Packit |
345191 |
#include <memkind/internal/memkind_default.h>
|
|
Packit |
345191 |
#include <memkind/internal/memkind_hugetlb.h>
|
|
Packit |
345191 |
#include <memkind/internal/memkind_bandwidth.h>
|
|
Packit |
345191 |
#include <memkind/internal/memkind_arena.h>
|
|
Packit |
345191 |
#include <memkind/internal/memkind_private.h>
|
|
Packit |
345191 |
#include <memkind/internal/memkind_log.h>
|
|
Packit |
345191 |
#include <memkind/internal/heap_manager.h>
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include <stdlib.h>
|
|
Packit |
345191 |
#include <stdio.h>
|
|
Packit |
345191 |
#include <unistd.h>
|
|
Packit |
345191 |
#include <limits.h>
|
|
Packit |
345191 |
#include <pthread.h>
|
|
Packit |
345191 |
#include <numa.h>
|
|
Packit |
345191 |
#include <numaif.h>
|
|
Packit |
345191 |
#include <errno.h>
|
|
Packit |
345191 |
#include <sys/types.h>
|
|
Packit |
345191 |
#include <sys/stat.h>
|
|
Packit |
345191 |
#include <utmpx.h>
|
|
Packit |
345191 |
#include <sched.h>
|
|
Packit |
345191 |
#include <stdint.h>
|
|
Packit |
345191 |
#include <assert.h>
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT struct memkind_ops MEMKIND_HBW_OPS = {
|
|
Packit |
345191 |
.create = memkind_arena_create,
|
|
Packit |
345191 |
.destroy = memkind_default_destroy,
|
|
Packit |
345191 |
.malloc = memkind_arena_malloc,
|
|
Packit |
345191 |
.calloc = memkind_arena_calloc,
|
|
Packit |
345191 |
.posix_memalign = memkind_arena_posix_memalign,
|
|
Packit |
345191 |
.realloc = memkind_arena_realloc,
|
|
Packit |
345191 |
.free = memkind_arena_free,
|
|
Packit |
345191 |
.check_available = memkind_hbw_check_available,
|
|
Packit |
345191 |
.mbind = memkind_default_mbind,
|
|
Packit |
345191 |
.get_mmap_flags = memkind_default_get_mmap_flags,
|
|
Packit |
345191 |
.get_mbind_mode = memkind_default_get_mbind_mode,
|
|
Packit |
345191 |
.get_mbind_nodemask = memkind_hbw_get_mbind_nodemask,
|
|
Packit |
345191 |
.get_arena = memkind_thread_get_arena,
|
|
Packit |
345191 |
.init_once = memkind_hbw_init_once,
|
|
Packit |
345191 |
.malloc_usable_size = memkind_default_malloc_usable_size,
|
|
Packit |
345191 |
.finalize = memkind_arena_finalize,
|
|
Packit |
345191 |
.get_stat = memkind_arena_get_kind_stat,
|
|
Packit |
345191 |
.defrag_reallocate = memkind_arena_defrag_reallocate
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT struct memkind_ops MEMKIND_HBW_ALL_OPS = {
|
|
Packit |
345191 |
.create = memkind_arena_create,
|
|
Packit |
345191 |
.destroy = memkind_default_destroy,
|
|
Packit |
345191 |
.malloc = memkind_arena_malloc,
|
|
Packit |
345191 |
.calloc = memkind_arena_calloc,
|
|
Packit |
345191 |
.posix_memalign = memkind_arena_posix_memalign,
|
|
Packit |
345191 |
.realloc = memkind_arena_realloc,
|
|
Packit |
345191 |
.free = memkind_arena_free,
|
|
Packit |
345191 |
.check_available = memkind_hbw_check_available,
|
|
Packit |
345191 |
.mbind = memkind_default_mbind,
|
|
Packit |
345191 |
.get_mmap_flags = memkind_default_get_mmap_flags,
|
|
Packit |
345191 |
.get_mbind_mode = memkind_default_get_mbind_mode,
|
|
Packit |
345191 |
.get_mbind_nodemask = memkind_hbw_all_get_mbind_nodemask,
|
|
Packit |
345191 |
.get_arena = memkind_thread_get_arena,
|
|
Packit |
345191 |
.init_once = memkind_hbw_all_init_once,
|
|
Packit |
345191 |
.malloc_usable_size = memkind_default_malloc_usable_size,
|
|
Packit |
345191 |
.finalize = memkind_arena_finalize,
|
|
Packit |
345191 |
.get_stat = memkind_arena_get_kind_stat,
|
|
Packit |
345191 |
.defrag_reallocate = memkind_arena_defrag_reallocate
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT struct memkind_ops MEMKIND_HBW_HUGETLB_OPS = {
|
|
Packit |
345191 |
.create = memkind_arena_create,
|
|
Packit |
345191 |
.destroy = memkind_default_destroy,
|
|
Packit |
345191 |
.malloc = memkind_arena_malloc,
|
|
Packit |
345191 |
.calloc = memkind_arena_calloc,
|
|
Packit |
345191 |
.posix_memalign = memkind_arena_posix_memalign,
|
|
Packit |
345191 |
.realloc = memkind_arena_realloc,
|
|
Packit |
345191 |
.free = memkind_arena_free,
|
|
Packit |
345191 |
.check_available = memkind_hbw_hugetlb_check_available,
|
|
Packit |
345191 |
.mbind = memkind_default_mbind,
|
|
Packit |
345191 |
.get_mmap_flags = memkind_hugetlb_get_mmap_flags,
|
|
Packit |
345191 |
.get_mbind_mode = memkind_default_get_mbind_mode,
|
|
Packit |
345191 |
.get_mbind_nodemask = memkind_hbw_get_mbind_nodemask,
|
|
Packit |
345191 |
.get_arena = memkind_thread_get_arena,
|
|
Packit |
345191 |
.init_once = memkind_hbw_hugetlb_init_once,
|
|
Packit |
345191 |
.malloc_usable_size = memkind_default_malloc_usable_size,
|
|
Packit |
345191 |
.finalize = memkind_arena_finalize,
|
|
Packit |
345191 |
.get_stat = memkind_arena_get_kind_stat,
|
|
Packit |
345191 |
.defrag_reallocate = memkind_arena_defrag_reallocate
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT struct memkind_ops MEMKIND_HBW_ALL_HUGETLB_OPS = {
|
|
Packit |
345191 |
.create = memkind_arena_create,
|
|
Packit |
345191 |
.destroy = memkind_default_destroy,
|
|
Packit |
345191 |
.malloc = memkind_arena_malloc,
|
|
Packit |
345191 |
.calloc = memkind_arena_calloc,
|
|
Packit |
345191 |
.posix_memalign = memkind_arena_posix_memalign,
|
|
Packit |
345191 |
.realloc = memkind_arena_realloc,
|
|
Packit |
345191 |
.free = memkind_arena_free,
|
|
Packit |
345191 |
.check_available = memkind_hbw_hugetlb_check_available,
|
|
Packit |
345191 |
.mbind = memkind_default_mbind,
|
|
Packit |
345191 |
.get_mmap_flags = memkind_hugetlb_get_mmap_flags,
|
|
Packit |
345191 |
.get_mbind_mode = memkind_default_get_mbind_mode,
|
|
Packit |
345191 |
.get_mbind_nodemask = memkind_hbw_all_get_mbind_nodemask,
|
|
Packit |
345191 |
.get_arena = memkind_thread_get_arena,
|
|
Packit |
345191 |
.init_once = memkind_hbw_all_hugetlb_init_once,
|
|
Packit |
345191 |
.malloc_usable_size = memkind_default_malloc_usable_size,
|
|
Packit |
345191 |
.finalize = memkind_arena_finalize,
|
|
Packit |
345191 |
.get_stat = memkind_arena_get_kind_stat,
|
|
Packit |
345191 |
.defrag_reallocate = memkind_arena_defrag_reallocate
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT struct memkind_ops MEMKIND_HBW_PREFERRED_OPS = {
|
|
Packit |
345191 |
.create = memkind_arena_create,
|
|
Packit |
345191 |
.destroy = memkind_default_destroy,
|
|
Packit |
345191 |
.malloc = memkind_arena_malloc,
|
|
Packit |
345191 |
.calloc = memkind_arena_calloc,
|
|
Packit |
345191 |
.posix_memalign = memkind_arena_posix_memalign,
|
|
Packit |
345191 |
.realloc = memkind_arena_realloc,
|
|
Packit |
345191 |
.free = memkind_arena_free,
|
|
Packit |
345191 |
.check_available = memkind_hbw_check_available,
|
|
Packit |
345191 |
.mbind = memkind_default_mbind,
|
|
Packit |
345191 |
.get_mmap_flags = memkind_default_get_mmap_flags,
|
|
Packit |
345191 |
.get_mbind_mode = memkind_preferred_get_mbind_mode,
|
|
Packit |
345191 |
.get_mbind_nodemask = memkind_hbw_get_mbind_nodemask,
|
|
Packit |
345191 |
.get_arena = memkind_thread_get_arena,
|
|
Packit |
345191 |
.init_once = memkind_hbw_preferred_init_once,
|
|
Packit |
345191 |
.malloc_usable_size = memkind_default_malloc_usable_size,
|
|
Packit |
345191 |
.finalize = memkind_arena_finalize,
|
|
Packit |
345191 |
.get_stat = memkind_arena_get_kind_stat,
|
|
Packit |
345191 |
.defrag_reallocate = memkind_arena_defrag_reallocate
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT struct memkind_ops MEMKIND_HBW_PREFERRED_HUGETLB_OPS = {
|
|
Packit |
345191 |
.create = memkind_arena_create,
|
|
Packit |
345191 |
.destroy = memkind_default_destroy,
|
|
Packit |
345191 |
.malloc = memkind_arena_malloc,
|
|
Packit |
345191 |
.calloc = memkind_arena_calloc,
|
|
Packit |
345191 |
.posix_memalign = memkind_arena_posix_memalign,
|
|
Packit |
345191 |
.realloc = memkind_arena_realloc,
|
|
Packit |
345191 |
.free = memkind_arena_free,
|
|
Packit |
345191 |
.check_available = memkind_hbw_hugetlb_check_available,
|
|
Packit |
345191 |
.mbind = memkind_default_mbind,
|
|
Packit |
345191 |
.get_mmap_flags = memkind_hugetlb_get_mmap_flags,
|
|
Packit |
345191 |
.get_mbind_mode = memkind_preferred_get_mbind_mode,
|
|
Packit |
345191 |
.get_mbind_nodemask = memkind_hbw_get_mbind_nodemask,
|
|
Packit |
345191 |
.get_arena = memkind_thread_get_arena,
|
|
Packit |
345191 |
.init_once = memkind_hbw_preferred_hugetlb_init_once,
|
|
Packit |
345191 |
.malloc_usable_size = memkind_default_malloc_usable_size,
|
|
Packit |
345191 |
.finalize = memkind_arena_finalize,
|
|
Packit |
345191 |
.get_stat = memkind_arena_get_kind_stat,
|
|
Packit |
345191 |
.defrag_reallocate = memkind_arena_defrag_reallocate
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT struct memkind_ops MEMKIND_HBW_INTERLEAVE_OPS = {
|
|
Packit |
345191 |
.create = memkind_arena_create,
|
|
Packit |
345191 |
.destroy = memkind_default_destroy,
|
|
Packit |
345191 |
.malloc = memkind_arena_malloc,
|
|
Packit |
345191 |
.calloc = memkind_arena_calloc,
|
|
Packit |
345191 |
.posix_memalign = memkind_arena_posix_memalign,
|
|
Packit |
345191 |
.realloc = memkind_arena_realloc,
|
|
Packit |
345191 |
.free = memkind_arena_free,
|
|
Packit |
345191 |
.check_available = memkind_hbw_check_available,
|
|
Packit |
345191 |
.mbind = memkind_default_mbind,
|
|
Packit |
345191 |
.madvise = memkind_nohugepage_madvise,
|
|
Packit |
345191 |
.get_mmap_flags = memkind_default_get_mmap_flags,
|
|
Packit |
345191 |
.get_mbind_mode = memkind_interleave_get_mbind_mode,
|
|
Packit |
345191 |
.get_mbind_nodemask = memkind_hbw_all_get_mbind_nodemask,
|
|
Packit |
345191 |
.get_arena = memkind_thread_get_arena,
|
|
Packit |
345191 |
.init_once = memkind_hbw_interleave_init_once,
|
|
Packit |
345191 |
.malloc_usable_size = memkind_default_malloc_usable_size,
|
|
Packit |
345191 |
.finalize = memkind_arena_finalize,
|
|
Packit |
345191 |
.get_stat = memkind_arena_get_kind_stat,
|
|
Packit |
345191 |
.defrag_reallocate = memkind_arena_defrag_reallocate
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
struct hbw_closest_numanode_t {
|
|
Packit |
345191 |
int init_err;
|
|
Packit |
345191 |
int num_cpu;
|
|
Packit |
345191 |
struct vec_cpu_node *closest_numanode;
|
|
Packit |
345191 |
};
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static struct hbw_closest_numanode_t memkind_hbw_closest_numanode_g;
|
|
Packit |
345191 |
static pthread_once_t memkind_hbw_closest_numanode_once_g = PTHREAD_ONCE_INIT;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void memkind_hbw_closest_numanode_init(void);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
// This declaration is necessary, cause it's missing in headers from libnuma 2.0.8
|
|
Packit |
345191 |
extern unsigned int numa_bitmask_weight(const struct bitmask *bmp );
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static int fill_bandwidth_values_heuristically (int *bandwidth);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT int memkind_hbw_check_available(struct memkind *kind)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
return kind->ops->get_mbind_nodemask(kind, NULL, 0);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT int memkind_hbw_hugetlb_check_available(struct memkind *kind)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
int err = memkind_hbw_check_available(kind);
|
|
Packit |
345191 |
if (!err) {
|
|
Packit |
345191 |
err = memkind_hugetlb_check_available_2mb(kind);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
return err;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT int memkind_hbw_get_mbind_nodemask(struct memkind *kind,
|
|
Packit |
345191 |
unsigned long *nodemask,
|
|
Packit |
345191 |
unsigned long maxnode)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
struct hbw_closest_numanode_t *g = &memkind_hbw_closest_numanode_g;
|
|
Packit |
345191 |
pthread_once(&memkind_hbw_closest_numanode_once_g,
|
|
Packit |
345191 |
memkind_hbw_closest_numanode_init);
|
|
Packit |
345191 |
if (MEMKIND_LIKELY(!g->init_err)) {
|
|
Packit |
345191 |
g->init_err = set_bitmask_for_current_closest_numanode(nodemask, maxnode,
|
|
Packit |
345191 |
g->closest_numanode, g->num_cpu);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
return g->init_err;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT int memkind_hbw_all_get_mbind_nodemask(struct memkind *kind,
|
|
Packit |
345191 |
unsigned long *nodemask,
|
|
Packit |
345191 |
unsigned long maxnode)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
struct hbw_closest_numanode_t *g = &memkind_hbw_closest_numanode_g;
|
|
Packit |
345191 |
pthread_once(&memkind_hbw_closest_numanode_once_g,
|
|
Packit |
345191 |
memkind_hbw_closest_numanode_init);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
if (MEMKIND_LIKELY(!g->init_err)) {
|
|
Packit |
345191 |
set_bitmask_for_all_closest_numanodes(nodemask, maxnode, g->closest_numanode,
|
|
Packit |
345191 |
g->num_cpu);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
return g->init_err;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
typedef struct registers_t {
|
|
Packit |
345191 |
uint32_t eax;
|
|
Packit |
345191 |
uint32_t ebx;
|
|
Packit |
345191 |
uint32_t ecx;
|
|
Packit |
345191 |
uint32_t edx;
|
|
Packit |
345191 |
} registers_t;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
inline static void cpuid_asm(int leaf, int subleaf, registers_t *registers)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
#ifdef __x86_64__
|
|
Packit |
345191 |
asm volatile("cpuid":"=a"(registers->eax),
|
|
Packit |
345191 |
"=b"(registers->ebx),
|
|
Packit |
345191 |
"=c"(registers->ecx),
|
|
Packit |
345191 |
"=d"(registers->edx):"0"(leaf), "2"(subleaf));
|
|
Packit |
345191 |
#else
|
|
Packit |
345191 |
// Non-x86 can't possibly be Knight's Landing nor Knight's Mill.
|
|
Packit |
345191 |
registers->eax = 0;
|
|
Packit |
345191 |
#endif
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#define CPUID_MODEL_SHIFT (4)
|
|
Packit |
345191 |
#define CPUID_MODEL_MASK (0xf)
|
|
Packit |
345191 |
#define CPUID_EXT_MODEL_MASK (0xf)
|
|
Packit |
345191 |
#define CPUID_EXT_MODEL_SHIFT (16)
|
|
Packit |
345191 |
#define CPUID_FAMILY_MASK (0xf)
|
|
Packit |
345191 |
#define CPUID_FAMILY_SHIFT (8)
|
|
Packit |
345191 |
#define CPU_MODEL_KNL (0x57)
|
|
Packit |
345191 |
#define CPU_MODEL_KNM (0x85)
|
|
Packit |
345191 |
#define CPU_FAMILY_INTEL (0x06)
|
|
Packit |
345191 |
|
|
Packit |
345191 |
typedef struct {
|
|
Packit |
345191 |
uint32_t model;
|
|
Packit |
345191 |
uint32_t family;
|
|
Packit |
345191 |
} cpu_model_data_t;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static cpu_model_data_t get_cpu_model_data()
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
registers_t registers;
|
|
Packit |
345191 |
cpuid_asm(1, 0, ®isters);
|
|
Packit |
345191 |
uint32_t model = (registers.eax >> CPUID_MODEL_SHIFT) & CPUID_MODEL_MASK;
|
|
Packit |
345191 |
uint32_t model_ext = (registers.eax >> CPUID_EXT_MODEL_SHIFT) &
|
|
Packit |
345191 |
CPUID_EXT_MODEL_MASK;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
cpu_model_data_t data;
|
|
Packit |
345191 |
data.model = model | (model_ext << 4);
|
|
Packit |
345191 |
data.family = (registers.eax >> CPUID_FAMILY_SHIFT) & CPUID_FAMILY_MASK;
|
|
Packit |
345191 |
return data;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static bool is_hbm_supported(cpu_model_data_t cpu)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
return cpu.family == CPU_FAMILY_INTEL &&
|
|
Packit |
345191 |
(cpu.model == CPU_MODEL_KNL || cpu.model == CPU_MODEL_KNM);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static int get_high_bandwidth_nodes(struct bitmask *hbw_node_mask)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
int nodes_num = numa_num_configured_nodes();
|
|
Packit |
345191 |
// Check if NUMA configuration is supported.
|
|
Packit |
345191 |
if(nodes_num == 2 || nodes_num == 4 || nodes_num == 8) {
|
|
Packit |
345191 |
struct bitmask *node_cpus = numa_allocate_cpumask();
|
|
Packit |
345191 |
|
|
Packit |
345191 |
assert(hbw_node_mask->size >= nodes_num);
|
|
Packit |
345191 |
assert(node_cpus->size >= nodes_num);
|
|
Packit |
345191 |
int i;
|
|
Packit |
345191 |
for(i=0; i
|
|
Packit |
345191 |
numa_node_to_cpus(i, node_cpus);
|
|
Packit |
345191 |
if(numa_bitmask_weight(node_cpus) == 0) {
|
|
Packit |
345191 |
//NUMA nodes without CPU are HBW nodes.
|
|
Packit |
345191 |
numa_bitmask_setbit(hbw_node_mask, i);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
numa_bitmask_free(node_cpus);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
if(2*numa_bitmask_weight(hbw_node_mask) == nodes_num) {
|
|
Packit |
345191 |
return 0;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
return MEMKIND_ERROR_UNAVAILABLE;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
///This function tries to fill bandwidth array based on knowledge about known CPU models
|
|
Packit |
345191 |
static int fill_bandwidth_values_heuristically(int *bandwidth)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
cpu_model_data_t cpu = get_cpu_model_data();
|
|
Packit |
345191 |
|
|
Packit |
345191 |
if(!is_hbm_supported(cpu)) {
|
|
Packit |
345191 |
log_err("High Bandwidth Memory is not supported by this CPU.");
|
|
Packit |
345191 |
return MEMKIND_ERROR_UNAVAILABLE;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
switch(cpu.model) {
|
|
Packit |
345191 |
case CPU_MODEL_KNL:
|
|
Packit |
345191 |
case CPU_MODEL_KNM: {
|
|
Packit |
345191 |
int ret = bandwidth_fill(bandwidth, get_high_bandwidth_nodes);
|
|
Packit |
345191 |
if(ret == 0) {
|
|
Packit |
345191 |
log_info("Detected High Bandwidth Memory.");
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
return ret;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
default:
|
|
Packit |
345191 |
return MEMKIND_ERROR_UNAVAILABLE;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
static void memkind_hbw_closest_numanode_init(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
struct hbw_closest_numanode_t *g = &memkind_hbw_closest_numanode_g;
|
|
Packit |
345191 |
g->num_cpu = numa_num_configured_cpus();
|
|
Packit |
345191 |
g->closest_numanode = NULL;
|
|
Packit |
345191 |
g->init_err = set_closest_numanode(fill_bandwidth_values_heuristically,
|
|
Packit |
345191 |
"MEMKIND_HBW_NODES", &g->closest_numanode, g->num_cpu, true);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT void memkind_hbw_init_once(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
memkind_init(MEMKIND_HBW, true);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT void memkind_hbw_all_init_once(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
memkind_init(MEMKIND_HBW_ALL, true);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT void memkind_hbw_hugetlb_init_once(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
memkind_init(MEMKIND_HBW_HUGETLB, true);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT void memkind_hbw_all_hugetlb_init_once(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
memkind_init(MEMKIND_HBW_ALL_HUGETLB, true);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT void memkind_hbw_preferred_init_once(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
memkind_init(MEMKIND_HBW_PREFERRED, true);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT void memkind_hbw_preferred_hugetlb_init_once(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
memkind_init(MEMKIND_HBW_PREFERRED_HUGETLB, true);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
MEMKIND_EXPORT void memkind_hbw_interleave_init_once(void)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
memkind_init(MEMKIND_HBW_INTERLEAVE, true);
|
|
Packit |
345191 |
}
|