Example #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)
Example #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")
Example #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 []
Example #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)
Example #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)
Example #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)
Example #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")
Example #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")
Example #9
0
def set_preferred_node(node: int) -> None:
    LIBNUMA.numa_set_preferred(node)
Example #10
0
def get_preferred_node() -> int:
    return LIBNUMA.numa_preferred()
Example #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
Example #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)
Example #13
0
def get_max_node() -> int:
    return LIBNUMA.numa_max_node()
Example #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)))
Example #15
0
def set_local_alloc() -> None:
    LIBNUMA.numa_set_localalloc()
Example #16
0
def cpu_to_node(cpu: int) -> int:
    return LIBNUMA.numa_node_of_cpu(cpu)
Example #17
0
def numa_distance(node1: int, node2: int) -> int:
    return LIBNUMA.numa_distance(node1, node2)
Example #18
0
def get_num_configured_cpus() -> int:
    return LIBNUMA.numa_num_configured_cpus()
Example #19
0
def get_max_possible_node() -> int:
    return LIBNUMA.numa_max_possible_node()
Example #20
0
def get_allowed_cpus_num() -> int:
    return LIBNUMA.numa_num_task_cpus()
Example #21
0
def get_allowed_nodes_num() -> int:
    return LIBNUMA.numa_num_task_nodes()
Example #22
0
def numa_available() -> bool:
    return LIBNUMA.numa_available() != -1