|
Packit Service |
7f3b24 |
// SPDX-License-Identifier: BSD-2-Clause
|
|
Packit Service |
7f3b24 |
/* Copyright (C) 2019 - 2020 Intel Corporation. */
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include <memkind/internal/memkind_dax_kmem.h>
|
|
Packit |
345191 |
#include <memkind.h>
|
|
Packit |
345191 |
#include <numa.h>
|
|
Packit |
345191 |
#include <stdio.h>
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#define MAX_ARG_LEN 8
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static const char *const help_message =
|
|
Packit |
345191 |
"\n"
|
|
Packit |
345191 |
"NAME\n"
|
|
Packit |
345191 |
" memkind-auto-dax-kmem-nodes - prints comma-separated list of automatically detected persistent memory NUMA nodes.\n"
|
|
Packit |
345191 |
"\n"
|
|
Packit |
345191 |
"SYNOPSIS\n"
|
|
Packit |
345191 |
" memkind-auto-dax-kmem-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 automatically detected persistent memory 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 if automatic detection is disabled (memkind wasn't build with suitable libdaxctl-devel version)\n"
|
|
Packit |
345191 |
" 2 on invalid argument\n"
|
|
Packit |
345191 |
" 3 on other failure\n"
|
|
Packit |
345191 |
"\n"
|
|
Packit |
345191 |
"COPYRIGHT\n"
|
|
Packit Service |
7f3b24 |
" Copyright 2019 - 2020 Intel Corporation All Rights Reserved.\n"
|
|
Packit |
345191 |
"\n"
|
|
Packit |
345191 |
"AUTHORS\n"
|
|
Packit |
345191 |
" Michal Biesek\n"
|
|
Packit |
345191 |
"\n"
|
|
Packit |
345191 |
"SEE ALSO\n"
|
|
Packit |
345191 |
" memkind(3)\n"
|
|
Packit |
345191 |
"\n";
|
|
Packit |
345191 |
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static int print_dax_kmem_nodes()
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
unsigned i, j = 0;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
nodemask_t nodemask;
|
|
Packit |
345191 |
struct bitmask nodemask_dax_kmem = {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_dax_kmem);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
//WARNING: code below is usage of memkind experimental API which may be changed in future
|
|
Packit |
345191 |
int status = memkind_dax_kmem_all_get_mbind_nodemask(NULL, nodemask.n,
|
|
Packit |
345191 |
NUMA_NUM_NODES);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
if (status == MEMKIND_ERROR_OPERATION_FAILED ) {
|
|
Packit |
345191 |
return 1;
|
|
Packit |
345191 |
} else if (status != MEMKIND_SUCCESS ) {
|
|
Packit |
345191 |
return 3;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
for(i = 0; i
|
|
Packit |
345191 |
if(numa_bitmask_isbitset(&nodemask_dax_kmem, i)) {
|
|
Packit |
345191 |
printf("%u%s", i, (++j == numa_bitmask_weight(&nodemask_dax_kmem)) ? "" : ",");
|
|
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_dax_kmem_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 0;
|
|
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 |
}
|