|
Packit |
2d622a |
/***************************************************************************
|
|
Packit |
2d622a |
* User front end for using huge pages Copyright (C) 2008, IBM *
|
|
Packit |
2d622a |
* *
|
|
Packit |
2d622a |
* This program is free software; you can redistribute it and/or modify *
|
|
Packit |
2d622a |
* it under the terms of the Lesser GNU General Public License as *
|
|
Packit |
2d622a |
* published by the Free Software Foundation; either version 2.1 of the *
|
|
Packit |
2d622a |
* License, or at your option) any later version. *
|
|
Packit |
2d622a |
* *
|
|
Packit |
2d622a |
* This program is distributed in the hope that it will be useful, *
|
|
Packit |
2d622a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
Packit |
2d622a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
Packit |
2d622a |
* GNU Lesser General Public License for more details. *
|
|
Packit |
2d622a |
* *
|
|
Packit |
2d622a |
* You should have received a copy of the Lesser GNU General Public *
|
|
Packit |
2d622a |
* License along with this program; if not, write to the *
|
|
Packit |
2d622a |
* Free Software Foundation, Inc., *
|
|
Packit |
2d622a |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
Packit |
2d622a |
***************************************************************************/
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
/*
|
|
Packit |
2d622a |
* pagesize exposes the available and hardware supported page sizes on
|
|
Packit |
2d622a |
* the system.
|
|
Packit |
2d622a |
*
|
|
Packit |
2d622a |
* This program should be treated as an ABI for using libhugetlbfs.
|
|
Packit |
2d622a |
*/
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
#include <stdlib.h>
|
|
Packit |
2d622a |
#include <stdio.h>
|
|
Packit |
2d622a |
#include <errno.h>
|
|
Packit |
2d622a |
#include <string.h>
|
|
Packit |
2d622a |
#include <limits.h>
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
#define _GNU_SOURCE /* for getopt_long */
|
|
Packit |
2d622a |
#include <unistd.h>
|
|
Packit |
2d622a |
#include <getopt.h>
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
#define REPORT_UTIL "pagesize"
|
|
Packit |
2d622a |
#include "libhugetlbfs_internal.h"
|
|
Packit |
2d622a |
#include "hugetlbfs.h"
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
extern int errno;
|
|
Packit |
2d622a |
extern int optind;
|
|
Packit |
2d622a |
extern char *optarg;
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
#define OPTION(opts, text) fprintf(stderr, " %-25s %s\n", opts, text)
|
|
Packit |
2d622a |
#define CONT(text) fprintf(stderr, " %-25s %s\n", "", text)
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
void print_usage()
|
|
Packit |
2d622a |
{
|
|
Packit |
2d622a |
fprintf(stderr, "pagesize [options] target\n");
|
|
Packit |
2d622a |
fprintf(stderr, "options:\n");
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
OPTION("--help, -h", "Prints this message");
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
OPTION("--all, -a", "show all supported page sizes");
|
|
Packit |
2d622a |
OPTION("--huge-only, -H", "show only huge page sizes");
|
|
Packit |
2d622a |
}
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
static int cmpsizes(const void *p1, const void *p2)
|
|
Packit |
2d622a |
{
|
|
Packit |
2d622a |
return *((long *)p1) > *((long *)p2);
|
|
Packit |
2d622a |
}
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
#define MAX_PAGESIZES 32
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
int main(int argc, char** argv)
|
|
Packit |
2d622a |
{
|
|
Packit |
2d622a |
int opt_all = 0;
|
|
Packit |
2d622a |
int opt_huge = 0;
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
char opts[] = "+haH";
|
|
Packit |
2d622a |
int ret = 0, index = 0;
|
|
Packit |
2d622a |
struct option long_opts[] = {
|
|
Packit |
2d622a |
{"all", no_argument, NULL, 'a'},
|
|
Packit |
2d622a |
{"huge-only", no_argument, NULL, 'H'},
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
{0},
|
|
Packit |
2d622a |
};
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
long pagesizes[MAX_PAGESIZES];
|
|
Packit |
2d622a |
int i;
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
hugetlbfs_setup_debug();
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
while (ret != -1) {
|
|
Packit |
2d622a |
ret = getopt_long(argc, argv, opts, long_opts, &index);
|
|
Packit |
2d622a |
switch (ret) {
|
|
Packit |
2d622a |
case '?':
|
|
Packit |
2d622a |
print_usage();
|
|
Packit |
2d622a |
exit(EXIT_FAILURE);
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
case 'h':
|
|
Packit |
2d622a |
print_usage();
|
|
Packit |
2d622a |
exit(EXIT_SUCCESS);
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
case 'a':
|
|
Packit |
2d622a |
opt_all = 1;
|
|
Packit |
2d622a |
INFO("selecting all page sizes\n");
|
|
Packit |
2d622a |
break;
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
case 'H':
|
|
Packit |
2d622a |
opt_huge = 1;
|
|
Packit |
2d622a |
opt_all = 1;
|
|
Packit |
2d622a |
INFO("selecting only huge page sizes\n");
|
|
Packit |
2d622a |
break;
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
case -1:
|
|
Packit |
2d622a |
break;
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
default:
|
|
Packit |
2d622a |
WARNING("unparsed option %08x\n", ret);
|
|
Packit |
2d622a |
ret = -1;
|
|
Packit |
2d622a |
break;
|
|
Packit |
2d622a |
}
|
|
Packit |
2d622a |
}
|
|
Packit |
2d622a |
index = optind;
|
|
Packit |
2d622a |
if ((argc - index) != 0) {
|
|
Packit |
2d622a |
print_usage();
|
|
Packit |
2d622a |
exit(EXIT_FAILURE);
|
|
Packit |
2d622a |
}
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
if (!opt_all) {
|
|
Packit |
2d622a |
pagesizes[0] = sysconf(_SC_PAGESIZE);
|
|
Packit |
2d622a |
ret = 1;
|
|
Packit |
2d622a |
} else if (opt_huge)
|
|
Packit |
2d622a |
ret = gethugepagesizes(pagesizes, MAX_PAGESIZES);
|
|
Packit |
2d622a |
else
|
|
Packit |
2d622a |
ret = getpagesizes(pagesizes, MAX_PAGESIZES);
|
|
Packit |
2d622a |
if (ret < 0) {
|
|
Packit |
2d622a |
ERROR("failed to get list of supported page sizes\n");
|
|
Packit |
2d622a |
exit(EXIT_FAILURE);
|
|
Packit |
2d622a |
}
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
qsort(pagesizes, ret, sizeof(long), cmpsizes);
|
|
Packit |
2d622a |
for (i = 0; i < ret; i++) {
|
|
Packit |
2d622a |
printf("%ld\n", pagesizes[i]);
|
|
Packit |
2d622a |
}
|
|
Packit |
2d622a |
|
|
Packit |
2d622a |
exit(EXIT_SUCCESS);
|
|
Packit |
2d622a |
}
|