Blame src/memkind-hbw-nodes.c

Packit 345191
/*
Packit 345191
 * Copyright (C) 2016 - 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
Packit 345191
#include <numa.h>
Packit 345191
#include <stdio.h>
Packit 345191
Packit 345191
#define MAX_ARG_LEN 8
Packit 345191
Packit 345191
const char *help_message =
Packit 345191
    "\n"
Packit 345191
    "NAME\n"
Packit 345191
    "    memkind-hbw-nodes - Prints comma-separated list of high bandwidth nodes.\n"
Packit 345191
    "\n"
Packit 345191
    "SYNOPSIS\n"
Packit 345191
    "    memkind-hbw-nodes -h | --help\n"
Packit 345191
    "        Prints this help message.\n"
Packit 345191
    "\n"
Packit 345191
    "DESCRIPTION\n"
Packit 345191
    "    Prints a comma-separated list of high bandwidth NUMA nodes\n"
Packit 345191
    "    that can be used with the numactl --membind option.\n"
Packit 345191
    "\n"
Packit 345191
    "EXIT STATUS\n"
Packit 345191
    "    Return code is :\n"
Packit 345191
    "        0 on success\n"
Packit 345191
    "        1 on failure\n"
Packit 345191
    "        2 on invalid argument\n"
Packit 345191
    "\n"
Packit 345191
    "COPYRIGHT\n"
Packit 345191
    "    Copyright 2016 Intel Corporation All Rights Reserved.\n"
Packit 345191
    "\n"
Packit 345191
    "AUTHORS\n"
Packit 345191
    "    Krzysztof Kulakowski\n"
Packit 345191
    "\n"
Packit 345191
    "SEE ALSO\n"
Packit 345191
    "    hbwmalloc(3), memkind(3)\n"
Packit 345191
    "\n";
Packit 345191
Packit 345191
extern unsigned int numa_bitmask_weight(const struct bitmask *bmp );
Packit 345191
Packit 345191
int print_hbw_nodes()
Packit 345191
{
Packit 345191
    int i, j = 0;
Packit 345191
Packit 345191
    nodemask_t nodemask;
Packit 345191
    struct bitmask nodemask_bm = {NUMA_NUM_NODES, nodemask.n};
Packit 345191
Packit 345191
    // ensuring functions in numa library are defined
Packit 345191
    if (numa_available() == -1) {
Packit 345191
        return 3;
Packit 345191
    }
Packit 345191
    numa_bitmask_clearall(&nodemask_bm);
Packit 345191
Packit 345191
    //WARNING: code below is usage of memkind experimental API which may be changed in future
Packit 345191
    if(memkind_hbw_all_get_mbind_nodemask(NULL, nodemask.n, NUMA_NUM_NODES) != 0) {
Packit 345191
        return 1;
Packit 345191
    }
Packit 345191
Packit 345191
    for(i=0; i
Packit 345191
        if(numa_bitmask_isbitset(&nodemask_bm, i)) {
Packit 345191
            printf("%d%s", i, (++j == numa_bitmask_weight(&nodemask_bm)) ? "" : ",");
Packit 345191
        }
Packit 345191
    }
Packit 345191
    printf("\n");
Packit 345191
    return 0;
Packit 345191
}
Packit 345191
Packit 345191
int main(int argc, char *argv[])
Packit 345191
{
Packit 345191
    if(argc == 1) {
Packit 345191
        return print_hbw_nodes();
Packit 345191
    } else if ((argc == 2) && (strncmp(argv[1], "-h", MAX_ARG_LEN) == 0 ||
Packit 345191
                               strncmp(argv[1], "--help", MAX_ARG_LEN) == 0)) {
Packit 345191
        printf("%s", help_message);
Packit 345191
        return 2;
Packit 345191
    }
Packit 345191
Packit 345191
    printf("ERROR: Unknown option %s. More info with \"%s --help\".\n", argv[1],
Packit 345191
           argv[0]);
Packit 345191
    return 2;
Packit 345191
}