On Fri, Apr 03, 2009 at 05:24:33PM -0700, Avantika Mathur wrote: > > This patch adds the --verbose/-v options to hugeadm. When --verbose <0-99> is > specified, the libhugetlbfs verbosity level is set to that value. The > verbosity > level is increased by one each time -v is specified. If the level is > increased to 99, this sets HUGETLB_DEBUG. > The patch also also adds support for multiple options to hugeadm to be > specified in any order. Without this the verbose option would have to be > specified before any other options. > > Signed-off-by: Avantika Mathur <mat...@us.ibm.com> > --- > > Index: libhugetlbfs-save/hugeadm.c > =================================================================== > --- libhugetlbfs-save.orig/hugeadm.c 2009-04-03 16:43:43.000000000 -0700 > +++ libhugetlbfs-save/hugeadm.c 2009-04-03 16:43:46.000000000 -0700 > @@ -42,6 +42,13 @@ > #include <getopt.h> > > #define REPORT_UTIL "hugeadm" > +#define REPORT(level, prefix, format, ...) > \ > + do { \ > + if (verbose_level >= level) \ > + fprintf(stderr, "hugeadm:" prefix ": " format, \ > + ##__VA_ARGS__); \ > + } while (0); > +
Hmm, was it not possible to do something like #define REPORT_UTIL "hugeadm" #include "libhugetlbfs_internal.h" and use the REPORT macro there? Ahh, I see you were using hugectl as a template. Well, same question applies really, is hugectl redefining REPORT unnecessarily? Also worth checking out if the verbosity functions can be shared between hugectl and hugeadm to reduce duplicated code a little. > #include "libhugetlbfs_internal.h" > #include "hugetlbfs.h" > > @@ -102,11 +109,66 @@ > OPTION("--explain", "Gives a overview of the status of the system"); > CONT("with respect to huge page availability"); > > + OPTION("--verbose <level>, -v", "Increases/sets tracing levels"); > OPTION("--help, -h", "Prints this message"); > } > > int opt_dry_run = 0; > int opt_hard = 0; > +int verbose_level = VERBOSITY_DEFAULT; > + > +void setup_environment(char *var, char *val) > +{ > + setenv(var, val, 1); > + INFO("%s='%s'\n", var, val); > + If you are going to report the verbosity level, make it DEBUG. The current verbosity level is not interesting enough to be INFO. > + if (opt_dry_run) > + printf("%s='%s'\n", var, val); > +} > + > +void verbose_init(void) > +{ > + char *env; > + > + env = getenv("HUGETLB_VERBOSE"); > + if (env) > + verbose_level = atoi(env); > + env = getenv("HUGETLB_DEBUG"); > + if (env) > + verbose_level = VERBOSITY_MAX; > +} > + > +void verbose(char *which) > +{ > + int new_level; > + > + if (which) { > + new_level = atoi(which); > + if (new_level < 0 || new_level > 99) { > + ERROR("%d: verbosity out of range 0-99\n", > + new_level); > + exit(EXIT_FAILURE); > + } > + } else { > + new_level = verbose_level + 1; > + if (new_level == 100) { > + WARNING("verbosity limited to 99\n"); > + new_level--; > + } > + } > + verbose_level = new_level; > +} > + > +void verbose_expose(void) > +{ > + char level[3]; > + > + if (verbose_level == 99) { > + setup_environment("HUGETLB_DEBUG", "yes"); > + } > + snprintf(level, sizeof(level), "%d", verbose_level); > + setup_environment("HUGETLB_VERBOSE", level); > +} > > /* > * getopts return values for options which are long only. > @@ -635,12 +697,17 @@ > int ops; > int has_hugepages = kernel_has_hugepages(); > > - char opts[] = "+hd"; > + char opts[] = "+hdv"; > char base[PATH_MAX]; > - char *opt_min_adj[MAX_POOLS]; > - int ret = 0, index = 0, minadj_count = 0; > + char *opt_min_adj[MAX_POOLS], *opt_max_adj[MAX_POOLS]; > + char *opt_user_mounts = NULL, *opt_group_mounts = NULL; > + int opt_list_mounts = 0, opt_pool_list = 0, opt_create_mounts = 0; > + int opt_global_mounts = 0, opt_pgsizes = 0, opt_pgsizes_all = 0; > + int opt_explain = 0, minadj_count = 0, maxadj_count = 0; > + int ret = 0, index = 0; > struct option long_opts[] = { > {"help", no_argument, NULL, 'h'}, > + {"verbose", required_argument, NULL, 'v' }, > > {"list-all-mounts", no_argument, NULL, LONG_LIST_ALL_MOUNTS}, > {"pool-list", no_argument, NULL, LONG_POOL_LIST}, > @@ -662,6 +729,7 @@ > > hugetlbfs_setup_debug(); > setup_mounts(); > + verbose_init(); > > ops = 0; > while (ret != -1) { > @@ -678,6 +746,10 @@ > print_usage(); > exit(EXIT_SUCCESS); > > + case 'v': > + verbose(optarg); > + continue; > + > case 'd': > opt_dry_run = 1; > continue; > @@ -698,11 +770,11 @@ > continue; > > case LONG_LIST_ALL_MOUNTS: > - mounts_list_all(); > + opt_list_mounts = 1; > break; > > case LONG_POOL_LIST: > - pool_list(); > + opt_pool_list = 1; > break; > > case LONG_POOL_MIN_ADJ: > @@ -715,39 +787,35 @@ > "max cannot be adjusted\n"); > exit(EXIT_FAILURE); > } > - pool_adjust(optarg, POOL_MAX); > - break; > + opt_min_adj[minadj_count++] = optarg; > + break; > > case LONG_CREATE_MOUNTS: > - snprintf(base, PATH_MAX, "%s", MOUNT_DIR); > - create_mounts(NULL, NULL, base, S_IRWXU | S_IRWXG); > + opt_create_mounts = 1; > break; > > case LONG_CREATE_USER_MOUNTS: > - snprintf(base, PATH_MAX, "%s/user", MOUNT_DIR); > - create_mounts(optarg, NULL, base, S_IRWXU); > + opt_user_mounts = optarg; > break; > > case LONG_CREATE_GROUP_MOUNTS: > - snprintf(base, PATH_MAX, "%s/group", MOUNT_DIR); > - create_mounts(NULL, optarg, base, S_IRWXG); > + opt_group_mounts = optarg; > break; > > case LONG_CREATE_GLOBAL_MOUNTS: > - snprintf(base, PATH_MAX, "%s/global", MOUNT_DIR); > - create_mounts(NULL, NULL, base, S_IRWXU | S_IRWXG | > S_IRWXO); > + opt_global_mounts = 1; > break; > > case LONG_PAGE_SIZES: > - page_sizes(0); > + opt_pgsizes = 1; > break; > > case LONG_PAGE_AVAIL: > - page_sizes(1); > + opt_pgsizes_all = 1; > break; > > case LONG_EXPLAIN: > - explain(); > + opt_explain = 1; > break; > > default: > @@ -759,6 +827,14 @@ > ops++; > } > > + verbose_expose(); > + > + if (opt_list_mounts) > + mounts_list_all(); > + > + if (opt_pool_list) > + pool_list(); > + > while (--minadj_count >= 0) { > if (! kernel_has_overcommit()) > pool_adjust(opt_min_adj[minadj_count], POOL_BOTH); > @@ -766,6 +842,39 @@ > pool_adjust(opt_min_adj[minadj_count], POOL_MIN); > } > > + while (--maxadj_count >=0) > + pool_adjust(opt_max_adj[maxadj_count], POOL_MAX); > + > + if (opt_create_mounts) { > + snprintf(base, PATH_MAX, "%s", MOUNT_DIR); > + create_mounts(NULL, NULL, base, S_IRWXU | S_IRWXG); > + } > + > + > + if (opt_user_mounts != NULL) { > + snprintf(base, PATH_MAX, "%s/user", MOUNT_DIR); > + create_mounts(optarg, NULL, base, S_IRWXU); > + } > + > + if (opt_group_mounts) { > + snprintf(base, PATH_MAX, "%s/group", MOUNT_DIR); > + create_mounts(NULL, optarg, base, S_IRWXG); > + } > + > + if (opt_global_mounts) { > + snprintf(base, PATH_MAX, "%s/global", MOUNT_DIR); > + create_mounts(NULL, NULL, base, S_IRWXU | S_IRWXG | S_IRWXO); > + } > + > + if (opt_pgsizes) > + page_sizes(0); > + > + if (opt_pgsizes_all) > + page_sizes(1); > + > + if (opt_explain) > + explain(); > + > index = optind; > > if ((argc - index) != 0 || ops == 0) { > Index: libhugetlbfs-save/man/hugeadm.8 > =================================================================== > --- libhugetlbfs-save.orig/man/hugeadm.8 2009-04-03 16:44:49.000000000 > -0700 > +++ libhugetlbfs-save/man/hugeadm.8 2009-04-03 16:46:02.000000000 -0700 > @@ -126,6 +126,16 @@ > to resize the pool up to 5 times and continues to try if progress is being > made towards the resize. > > +.PP > +The following options affect the verbosity of libhugetlbfs. > + > +.TP > +.B --verbose <level>, -v > +The default value for the verbosity level is 1 and the range of the value can > +be set with --verbose from 0 to 99. The higher the value, the more verbose > the > +library will be. 0 is quiet and 3 will output much debugging information. The > +verbosity level is increased by one each time -v is specified. > + > .SH SEE ALSO > .I oprofile(1), > .I pagesize(1), Functionally, it looks ok. -- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab ------------------------------------------------------------------------------ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel