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 Munson <[EMAIL PROTECTED]>

---

 hugectl.c |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/hugectl.c b/hugectl.c
new file mode 100644
index 0000000..d9aa35f
--- /dev/null
+++ b/hugectl.c
@@ -0,0 +1,113 @@
+/***************************************************************************
+ *   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
+ *   --heap Backs malloc (morecore) with huge pages
+ * The last three switches plus the --stack switch 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;
+
+void print_usage()
+{
+       fprintf(stderr, "hugectl [options] target\n");
+       fprintf(stderr, "options:\n");
+       fprintf(stderr, " --help,  -h   Prints this message\n");
+       fprintf(stderr,
+               " --stack, -s   Attempts to execute target program with a huge 
page backed stack\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);
+       }
+}
+
+int main(int argc, char** argv)
+{
+       char opts [] = "+hs";
+       int ret = 0, index = 0;
+       struct option long_opts [] = {
+               {"help",  0, 0, 'h'},
+               {"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 's':
+                               set_huge_stack();
+                       case -1:
+                               break;
+
+                       case 'h':
+                               print_usage();
+                               return 0;
+
+                       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;
+}
+

Attachment: 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

Reply via email to