V2 As environment variables are added and/or change meaning it will become more complicated for end users to remember how to properly invoke their program using libhugetlbfs. This front-end will be updated to setup and run programs with libhugetlbfs without relying on the caller to remember how the environment should be configured.
Signed-off-by: Eric B Munson <[EMAIL PROTECTED]>
---
Changes from V1:
Update hugectl to handle the environment variables currently in libhugetlbfs
Comment out huge page backed stack helper, functionality not yet in kernel
hugectl.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 228 insertions(+), 0 deletions(-)
diff --git a/hugectl.c b/hugectl.c
new file mode 100644
index 0000000..a002d4e
--- /dev/null
+++ b/hugectl.c
@@ -0,0 +1,228 @@
+/***************************************************************************
+ * 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. *
+ ***************************************************************************/
+
+/*
+ * This program is going to be expanded to be a front end for using
+ * libhugetlbfs as well as controlling certain process behavior.
+ * Ideas for future implementation:
+ * --report-page-sizes Gives all valid huge page sizes for this machine
+ * --report-mounts Gives all mounts for libhugetlbfs (and their page size?)
+ * --text-remap Puts the text section of target binary in huge pages
+ * --bss-remap Puts the bss section of target binary in huge pages
+ * --stack Backs process stack with huge pages (when available in kernel)
+ * The last four switches could be extended to take an optional argument
+ * that specifies which huge page size to use.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#define _GNU_SOURCE /* for getopt_long */
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/personality.h>
+
+/* Peronsality bit for huge page backed stack */
+#ifndef HUGE_PAGE_STACK
+#define HUGE_PAGE_STACK 0x0020000
+#endif
+
+extern int errno;
+extern int optind;
+extern char *optarg;
+
+#define HUGETLB_MORECORE "HUGETLB_MORECORE"
+#define HUGETLB_MORECORE_SHRINK "HUGETLB_MORECORE_SHRINK"
+#define HUGETLB_MORECORE_HEAPBASE "HUGETLB_MORECORE_HEAPBASE"
+#define HUGETLB_NO_PREFAULT "HUGETLB_NO_PREFAULT"
+#define HUGETLB_ELFMAP "HUGETLB_ELFMAP"
+#define HUGETLB_MINIMAL_COPY "HUGETLB_MINIMAL_COPY"
+#define HUGETLB_FORCE_ELFMAP "HUGETLB_FORCE_ELFMAP"
+#define HUGETLB_VERBOSE "HUGETLB_VERBOSE"
+#define HUGETLB_PATH "HUGETLB_PATH"
+#define HUGETLB_SHARE "HUGETLB_SHARE"
+#define HUGETLB_DEBUG "HUGETLB_DEBUG"
+#define LD_PRELOAD "LD_PRELOAD"
+
+void print_usage()
+{
+ fprintf(stderr, "hugectl [options] target\n");
+ fprintf(stderr, "options:\n");
+ fprintf(stderr, " --help, -h Prints this
message.\n");
+ fprintf(stderr,
+ " --debug=[0*|1], -D[0*|1] Sets HUGETLB_DEBUG to
specified value.\n");
+ fprintf(stderr,
+ " --force-elfmap=[yes|no*], -E[yes|no*] Sets
HUGETLB_FORCE_ELFMAP to specified value.\n");
+ fprintf(stderr,
+ " --heap=[yes|no], -H[yes|no] Sets HUGETLB_MORECORE
to specified value.\n");
+ fprintf(stderr,
+ " --ld-preload=VALUE, -LVALUE Sets LD_PRELOAD to
VALUE.\n");
+ fprintf(stderr,
+ " --shrink=[yes|no*], -S[yes|no*] Sets
HUGETLB_MORECORE_SHRINK to specified value.\n");
+ fprintf(stderr,
+ " --verbose=LEVEL, -VLEVEL Sets HUGETLB_VERBOSE to
LEVEL [1*-99].\n");
+ fprintf(stderr,
+ " --heap-base=ADDR, -bADDR Sets
HUGETLB_MORECORE_HEAPBASE to ADDR.\n");
+ fprintf(stderr,
+ " --elf-map=[yes*|no], -e[yes*|no] Sets HUGETLB_ELFMAP to
specified value.\n");
+ fprintf(stderr,
+ " --minimal-copy=[yes*|no], -m[yes*|no] Sets
HUGETLB_MINIMAL_COPY to specified value.\n");
+ fprintf(stderr,
+ " --no-prefault=[yes|no*], -n[yes|no*] Sets
HUGETLB_NO_PREFAULT to specified value.\n");
+ fprintf(stderr,
+ " --path=PATH, -pPATH Sets HUGETLB_PATH to
PATH.\n");
+ fprintf(stderr,
+ " --share-segment=[0*|1], -r[0*|1] Sets HUGETLB_SHARE to
specified value.\n");
+ /*fprintf(stderr,
+ " --stack, -s Attempts to execute
target program with a huge page backed stack.\n");*/
+ fprintf(stderr, "* denotes default value\n\n");
+ fprintf(stderr,
+ "For an explanation of each of these environment variables,
please see the libhugetlbfs HOWTO file.\n\n");
+}
+
+void set_huge_stack()
+{
+ char * err;
+ unsigned long curr_per = personality(0xffffffff);
+ if (personality(curr_per | HUGE_PAGE_STACK | ADDR_NO_RANDOMIZE) == -1) {
+ err = strerror(errno);
+ fprintf(stderr,
+ "Error setting HUGE_STACK personality flag: '%s'\n",
+ err);
+ exit(-1);
+ }
+}
+
+void set_env_val(char *var, char *val)
+{
+ if (setenv(var, val, 1) < 0) {
+ fprintf(stderr,
+ "Error setting %s environment variable to '%s'.\n",
+ var, val);
+ exit(-1);
+ }
+}
+
+int main(int argc, char** argv)
+{
+ char opts [] = "+D:E:H:L:S:V:b:e:hm:n:p:r:s";
+ int ret = 0, index = 0;
+ struct option long_opts [] = {
+ {"debug", 1, 0, 'D'},
+ {"force-elfmap", 1, 0, 'E'},
+ {"heap", 1, 0, 'H'},
+ {"ld-preload", 1, 0, 'L'},
+ {"shrink", 1, 0, 'S'},
+ {"verbose", 1, 0, 'V'},
+ {"heap-base", 1, 0, 'b'},
+ {"elf-map", 1, 0, 'e'},
+ {"help", 0, 0, 'h'},
+ {"minimal-copy", 1, 0, 'm'},
+ {"no-prefault", 1, 0, 'n'},
+ {"path", 1, 0, 'p'},
+ {"share-segment", 1, 0, 'r'},
+ {"stack", 0, 0, 's'},
+ {0, 0, 0, 0},
+ };
+
+ if (argc < 2) {
+ print_usage();
+ return 0;
+ }
+
+ while (ret != -1) {
+ ret = getopt_long(argc, argv, opts, long_opts, &index);
+ switch (ret) {
+ case 'D':
+ set_env_val(HUGETLB_DEBUG, optarg);
+ break;
+
+ case 'E':
+ set_env_val(HUGETLB_FORCE_ELFMAP, optarg);
+ break;
+
+ case 'H':
+ set_env_val(HUGETLB_MORECORE, optarg);
+ break;
+
+ case 'L':
+ set_env_val(LD_PRELOAD, optarg);
+ break;
+
+ case 'S':
+ set_env_val(HUGETLB_MORECORE_SHRINK, optarg);
+ break;
+
+ case 'V':
+ set_env_val(HUGETLB_VERBOSE, optarg);
+ break;
+
+ case 'b':
+ set_env_val(HUGETLB_MORECORE_HEAPBASE, optarg);
+ break;
+
+ case 'e':
+ set_env_val(HUGETLB_ELFMAP, optarg);
+ break;
+
+ case 'm':
+ set_env_val(HUGETLB_MINIMAL_COPY, optarg);
+ break;
+
+ case 'n':
+ set_env_val(HUGETLB_NO_PREFAULT, optarg);
+ break;
+
+ case 'p':
+ set_env_val(HUGETLB_PATH, optarg);
+ break;
+
+ case 'r':
+ set_env_val(HUGETLB_SHARE, optarg);
+ break;
+
+ case 's':
+ /*set_huge_stack();*/
+ /*break;*/
+ case '?':
+ case 'h':
+ print_usage();
+ return 0;
+
+ case -1:
+ break;
+
+ default:
+ ret = -1;
+ break;
+ }
+ }
+ index = optind;
+
+ if (execvp(argv[index], &argv[index]) == -1) {
+ ret = errno;
+ fprintf(stderr, "Error calling execvp: '%s'\n", strerror(ret));
+ return ret;
+ }
+
+ return 0;
+}
+
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Libhugetlbfs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel
