Esempio n. 1
0
def bind(*nodes):
    nodes = list(set(nodes))
    res = ",".join(list(map(str, nodes)))
    c_string = bytes(res, "ascii")
    bitmask = LIBNUMA.numa_parse_nodestring(c_string)
    LIBNUMA.numa_run_on_node_mask(bitmask)
    LIBNUMA.numa_set_membind(bitmask)
Esempio n. 2
0
def set_membind_nodes(*nodes) -> None:
    nodes = list(set(nodes))
    res = ",".join(list(map(str, nodes)))
    c_string = bytes(res, "ascii")
    bitmask = LIBNUMA.numa_parse_nodestring(c_string)
    op_res = LIBNUMA.numa_set_membind(bitmask)
    if op_res == -1:
        raise Exception(f"set membind nodes {res} failed")
Esempio n. 3
0
def node_to_cpus(node: int) -> List[int]:
    cpu_mask = LIBNUMA.numa_allocate_cpumask()
    LIBNUMA.numa_bitmask_clearall(cpu_mask)
    res = LIBNUMA.numa_node_to_cpus(node, cpu_mask)
    if res == 0:
        return numa_utils.get_bitset_list(cpu_mask)
    else:
        return []
Esempio n. 4
0
def get_allocation_allowed_nodes() -> List[int]:
    result_nodes_pointer = LIBNUMA.numa_get_mems_allowed()
    try:
        result_nodes_pointer.contents
    except ValueError:
        raise Exception(f"get allocation allowed nodes info failed")
    return numa_utils.get_bitset_list(result_nodes_pointer)
Esempio n. 5
0
def get_interleave_nodes() -> List[int]:
    result_nodes_pointer = LIBNUMA.numa_get_interleave_mask()
    try:
        result_nodes_pointer.contents
    except ValueError:
        raise Exception(f"get interleave nodes info failed")
    return numa_utils.get_bitset_list(result_nodes_pointer)
Esempio n. 6
0
def get_affinitive_nodes() -> List[int]:
    result_mask_pointer = LIBNUMA.numa_get_run_node_mask()
    try:
        result_mask_pointer.contents
    except ValueError:
        raise Exception(f"get run nodes info failed")
    return numa_utils.get_bitset_list(result_mask_pointer)
Esempio n. 7
0
def run_on_nodes(*nodes):
    """
    :param nodes: numa node to run
    :return:
    """
    nodes = list(set(nodes))
    if len(nodes) == 0:
        bitmask = LIBNUMA.numa_parse_nodestring(b"all")
        op_res = LIBNUMA.numa_run_on_node_mask(bitmask)
        if op_res == -1:
            raise Exception("attempt to run on all nodes failed")
    else:
        res = ",".join(list(map(str, nodes)))
        c_string = bytes(res, "ascii")
        bitmask = LIBNUMA.numa_parse_nodestring(c_string)
        op_res = LIBNUMA.numa_run_on_node_mask(bitmask)
        if op_res == -1:
            raise Exception(f"attempt to run on {res} failed")
Esempio n. 8
0
def run_on_cpus(pid: int, *cpus):
    """
    :param cpus: cpu list
    :param pid: process id
    :return:
    """
    cpus = list(set(cpus))
    if len(cpus) == 0:
        bitmask = LIBNUMA.numa_parse_cpustring(b"all")
        op_res = LIBNUMA.numa_sched_setaffinity(pid, bitmask)
        if op_res == -1:
            raise Exception("attempt to run on all nodes failed")
    else:
        res = ",".join(list(map(str, cpus)))
        c_string = bytes(res, "ascii")
        bitmask = LIBNUMA.numa_parse_cpustring(c_string)
        op_res = LIBNUMA.numa_sched_setaffinity(pid, bitmask)
        if op_res == -1:
            raise Exception(f"attempt to run on {res} failed")
Esempio n. 9
0
def set_preferred_node(node: int) -> None:
    LIBNUMA.numa_set_preferred(node)
Esempio n. 10
0
def get_preferred_node() -> int:
    return LIBNUMA.numa_preferred()
Esempio n. 11
0
def node_memory_info(node: int) -> tuple:
    free_size = c_longlong()
    total_size = LIBNUMA.numa_node_size64(node, free_size)
    return total_size, free_size.value
Esempio n. 12
0
def get_affinitive_cpus(pid: int) -> List[int]:
    cpu_mask = LIBNUMA.numa_allocate_cpumask()
    LIBNUMA.numa_bitmask_clearall(cpu_mask)
    LIBNUMA.numa_sched_getaffinity(pid, cpu_mask)
    return numa_utils.get_bitset_list(cpu_mask)
Esempio n. 13
0
def get_max_node() -> int:
    return LIBNUMA.numa_max_node()
Esempio n. 14
0
def get_bitset_list(bitmask: bitmask_t) -> List[int]:
    return list(
        filter(lambda node: LIBNUMA.numa_bitmask_isbitset(bitmask, node) != 0,
               range(bitmask.contents.size)))
Esempio n. 15
0
def set_local_alloc() -> None:
    LIBNUMA.numa_set_localalloc()
Esempio n. 16
0
def cpu_to_node(cpu: int) -> int:
    return LIBNUMA.numa_node_of_cpu(cpu)
Esempio n. 17
0
def numa_distance(node1: int, node2: int) -> int:
    return LIBNUMA.numa_distance(node1, node2)
Esempio n. 18
0
def get_num_configured_cpus() -> int:
    return LIBNUMA.numa_num_configured_cpus()
Esempio n. 19
0
def get_max_possible_node() -> int:
    return LIBNUMA.numa_max_possible_node()
Esempio n. 20
0
def get_allowed_cpus_num() -> int:
    return LIBNUMA.numa_num_task_cpus()
Esempio n. 21
0
def get_allowed_nodes_num() -> int:
    return LIBNUMA.numa_num_task_nodes()
Esempio n. 22
0
def numa_available() -> bool:
    return LIBNUMA.numa_available() != -1