On (09/10/08 20:20), Andy Whitcroft didst pronounce: > Add a new utility to list page sizes supported on the system. > > Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
Acked-by: Mel Gorman <[EMAIL PROTECTED]> > --- > Makefile | 8 +++- > pagesize.c | 143 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 150 insertions(+), 1 deletions(-) > create mode 100644 pagesize.c > > diff --git a/Makefile b/Makefile > index 43dff05..5313d44 100644 > --- a/Makefile > +++ b/Makefile > @@ -4,7 +4,7 @@ EXEDIR = /bin > LIBOBJS = hugeutils.o version.o init.o morecore.o debug.o alloc.o shm.o > kernel-features.o > INSTALL_OBJ_LIBS = libhugetlbfs.so libhugetlbfs.a > BIN_OBJ_DIR=obj > -INSTALL_BIN = hugectl hugeedit hpoolcfg > +INSTALL_BIN = hugectl hugeedit hpoolcfg pagesize > INSTALL_HEADERS = hugetlbfs.h > LDSCRIPT_TYPES = B BDT > LDSCRIPT_DIST_ELF = elf32ppclinux elf64ppc elf_i386 elf_x86_64 > @@ -262,6 +262,12 @@ $(BIN_OBJ_DIR)/hpoolcfg: $(foreach > file,$(HPOOLCFG_OBJ),$(BIN_OBJ_DIR)/$(file)) > mkdir -p $(BIN_OBJ_DIR) > $(CC) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ $^ > > +PAGESIZE_OBJ=pagesize.o hugeutils.o debug.o > +$(BIN_OBJ_DIR)/pagesize: $(foreach > file,$(PAGESIZE_OBJ),$(BIN_OBJ_DIR)/$(file)) > + @$(VECHO) LDHOST $@ > + mkdir -p $(BIN_OBJ_DIR) > + $(CC) $(CPPFLAGS) $(CFLAGS) $(LIBPATHS) -o $@ $^ > + > clean: > @$(VECHO) CLEAN > rm -f *~ *.o *.so *.a *.d *.i core a.out $(VERSION) > diff --git a/pagesize.c b/pagesize.c > new file mode 100644 > index 0000000..a40686b > --- /dev/null > +++ b/pagesize.c > @@ -0,0 +1,143 @@ > +/*************************************************************************** > + * User front end for using huge pages Copyright (C) 2008, IBM * > + * * > + * This program is free software; you can redistribute it and/or modify * > + * it under the terms of the Lesser GNU General Public License as * > + * published by the Free Software Foundation; either version 2.1 of the * > + * License, or at your option) any later version. * > + * * > + * This program is distributed in the hope that it will be useful, * > + * but WITHOUT ANY WARRANTY; without even the implied warranty of * > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * > + * GNU Lesser General Public License for more details. * > + * * > + * You should have received a copy of the Lesser GNU General Public * > + * License along with this program; if not, write to the * > + * Free Software Foundation, Inc., * > + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * > + ***************************************************************************/ > + > +/* > + * hugectl is inspired by numactl as a single front end to a large number of > + * options for controlling a very specific environment. Eventually it will > + * have support for controlling the all of the environment variables for > + * libhugetlbfs, but options will only be added after they have been in the > + * library for some time and are throughly tested and stable. > + * > + * This program should be treated as an ABI for using libhugetlbfs. > + */ > + > +#include <stdlib.h> > +#include <stdio.h> > +#include <errno.h> > +#include <string.h> > +#include <limits.h> > + > +#define _GNU_SOURCE /* for getopt_long */ > +#include <unistd.h> > +#include <getopt.h> > + > +#define REPORT_UTIL "pagesize" > +#include "libhugetlbfs_internal.h" > +#include "hugetlbfs.h" > + > +extern int errno; > +extern int optind; > +extern char *optarg; > + > +#define OPTION(opts, text) fprintf(stderr, " %-25s %s\n", opts, text) > +#define CONT(text) fprintf(stderr, " %-25s %s\n", "", text) > + > +void print_usage() > +{ > + fprintf(stderr, "hugectl [options] target\n"); > + fprintf(stderr, "options:\n"); > + > + OPTION("--help, -h", "Prints this message"); > + > + OPTION("--all, -a", "show all supported page sizes"); > + OPTION("--huge-only, -H", "show only huge page sizes"); > +} > + > +static int cmpsizes(const void *p1, const void *p2) > +{ > + return *((long *)p1) > *((long *)p2); > +} > + > +#define MAX_PAGESIZES 32 > + > +int main(int argc, char** argv) > +{ > + int opt_all = 0; > + int opt_huge = 0; > + > + char opts[] = "+haH"; > + int ret = 0, index = 0; > + struct option long_opts[] = { > + {"all", no_argument, NULL, 'a'}, > + {"huge-only", no_argument, NULL, 'H'}, > + > + {0}, > + }; > + > + long pagesizes[MAX_PAGESIZES]; > + int i; > + > + __lh_hugetlbfs_setup_debug(); > + > + while (ret != -1) { > + ret = getopt_long(argc, argv, opts, long_opts, &index); > + switch (ret) { > + case '?': > + print_usage(); > + exit(EXIT_FAILURE); > + > + case 'h': > + print_usage(); > + exit(EXIT_SUCCESS); > + > + case 'a': > + opt_all = 1; > + DEBUG("selecting all page sizes\n"); > + break; > + > + case 'H': > + opt_huge = 1; > + opt_all = 1; > + DEBUG("selecting only huge page sizes\n"); > + break; > + > + case -1: > + break; > + > + default: > + WARNING("unparsed option %08x\n", ret); > + ret = -1; > + break; > + } > + } > + index = optind; > + if ((argc - index) != 0) { > + print_usage(); > + exit(EXIT_FAILURE); > + } > + > + if (!opt_all) { > + pagesizes[0] = sysconf(_SC_PAGESIZE); > + ret = 1; > + } else if (opt_huge) > + ret = gethugepagesizes(pagesizes, MAX_PAGESIZES); > + else > + ret = getpagesizes(pagesizes, MAX_PAGESIZES); > + if (ret < 0) { > + ERROR("failed to get list of supported page sizes\n"); > + exit(EXIT_FAILURE); > + } > + > + qsort(pagesizes, ret, sizeof(long), cmpsizes); > + for (i = 0; i < ret; i++) { > + printf("%ld\n", pagesizes[i]); > + } > + > + exit(EXIT_SUCCESS); > +} > -- > 1.6.0.1.451.gc8d31 > -- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel