Re: [rt-tests v2 18/18] hackbench: Streamline usage and man page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Wed, 7 Oct 2020, Daniel Wagner wrote:

> Signed-off-by: Daniel Wagner <dwagner@xxxxxxx>
> ---
>  src/hackbench/hackbench.8 |  70 ++++++++++++++------------
>  src/hackbench/hackbench.c | 102 ++++++++++++++++++--------------------
>  2 files changed, 86 insertions(+), 86 deletions(-)
> 
> diff --git a/src/hackbench/hackbench.8 b/src/hackbench/hackbench.8
> index aaf572359704..4c2c8ad9cb1a 100644
> --- a/src/hackbench/hackbench.8
> +++ b/src/hackbench/hackbench.8
> @@ -1,13 +1,17 @@
> -.TH "hackbench" "8" "February  23, 2010" "" ""
> +.TH "hackbench" "8" "September  19, 2020" "" ""
>  .SH "NAME"
>  hackbench \- scheduler benchmark/stress test
>  .SH "SYNOPSIS"
>  .B hackbench
> -.RI "[\-p|\-\-pipe] [\-s|\-\-datasize " <bytes> "] " 
> -.RI "[\-l|\-\-loops " <num\-loops> "] "
> -.RI "[\-g|\-\-groups "<num\-groups> "] "
> -.RI "[\-f|\-\-fds <num\-fds>] "
> -.RI "[\-T|\-\-threads] [\-P|\-\-process] [\-F|\-\-fifo] [\-\-help]"
> +.RI "[\-f|\-\-fds NUM] "
> +.RI "[\-F|\-\-fifo] "
> +.RI "[\-g|\-\-groups NUM] "
> +.RI "[\-h|\-\-help] "
> +.RI "[\-l|\-\-loops LOOPS] "
> +.RI "[\-p|\-\-pipe] "
> +.RI "[\-s|\-\-datasize SIZE] "
> +.RI "[\-T|\-\-threads]"
> +.RI "[\-P|\-\-process]"
>  
>  .SH "DESCRIPTION"
>  Hackbench is both a benchmark and a stress test for the Linux kernel
> @@ -19,45 +23,45 @@ each pair to send data back and forth.
>  .SH "OPTIONS"
>  These programs follow the usual GNU command line syntax, with long
>  options starting with two dashes ("\-\-").
> -.br 
> +.br
>  A summary of options is included below.
> -.TP 
> +.TP
> +.B \-f, \-\-fds=NUM
> +Defines how many file descriptors each child should use.
> +Note that the effective number will be twice the amount you set here,
> +as the sender and receiver children will each open the given amount of
> +file descriptors.
> +.TP
> +.B \-F,\-\-fifo
> +Change the main thread to SCHED_FIFO after creating workers.
> +This allows the management thread to run after many workers are created.
> +.TP
> +.B \-g, \-\-groups=NUM
> +Defines how many groups of senders and receivers should be started
> +.TP
> +.B \-h, \-\-help
> +.TP
> +.B \-l, \-\-loops=LOOPS
> +How many messages each sender/receiver pair should send
> +.TP
>  .B \-p, \-\-pipe
>  Sends the data via a pipe instead of the socket (default)
> -.TP 
> -.B \-s, \-\-datasize=<size in bytes>
> +.TP
> +.B \-s, \-\-datasize=SIZE
>  Sets the amount of data to send in each message
> -.TP 
> -.B \-l, \-\-loops=<number of loops>
> -How many messages each sender/receiver pair should send
> -.TP 
> -.B \-g, \-\-groups=<number of groups>
> -Defines how many groups of senders and receivers should be started
> -.TP 
> -.B \-f, \-\-fds=<number of file descriptors>
> -Defines how many file descriptors each child should use. 
> -Note that the effective number will be twice the amount you set here,
> -as the sender and receiver children will each open the given amount of 
> -file descriptors.
> -.TP 
> +.TP
>  .B \-T, \-\-threads
>  Each sender/receiver child will be a POSIX thread of the parent.
> -.TP 
> +.TP
>  .B \-P, \-\-process
>  Hackbench will use fork() on all children (default behaviour)
> -.TP
> -.B \-F,\-\-fifo
> -Change the main thread to SCHED_FIFO after creating workers.
> -This allows the management thread to run after many workers are created.
> -.TP 
> -.B \-\-help
> -.br 
> +.br
>  Shows a simple help screen
>  .SH "EXAMPLES"
> -.LP 
> +.LP
>  Running hackbench without any options will give default behaviour,
>  using fork() and sending data between senders and receivers via sockets.
> -.LP 
> +.LP
>  user@host: ~ $ hackbench
>  .br 
>  Running in process mode with 10 groups using 40 file descriptors each (== 400 tasks)
> diff --git a/src/hackbench/hackbench.c b/src/hackbench/hackbench.c
> index 2cddff654df6..268c23233004 100644
> --- a/src/hackbench/hackbench.c
> +++ b/src/hackbench/hackbench.c
> @@ -88,12 +88,22 @@ static void barf(const char *msg)
>  	exit(1);
>  }
>  
> -static void print_usage_exit()
> +static void print_usage_exit(int error)
>  {
> -	printf("Usage: hackbench [-p|--pipe] [-s|--datasize <bytes>] [-l|--loops <num loops>]\n"
> -	       "\t\t [-g|--groups <num groups] [-f|--fds <num fds>]\n"
> -	       "\t\t [-T|--threads] [-P|--process] [-F|--fifo] [--help]\n");
> -	exit(1);
> +	printf("hackbench V %1.2f\n", VERSION);
> +	printf("Usage:\n"
> +	       "hackbench <options>\n\n"
> +	       "-f       --fds=NUM         number of fds\n"
> +	       "-F       --fifo            use SCHED_FIFO for main thread\n"
> +	       "-g       --groups=NUM      number of groups to be used\n"
> +	       "-h       --help            print this message\n"
> +	       "-l       --loops=LOOPS     how many message should be send\n"
> +	       "-p       --pipe            send data via a pipe\n"
> +	       "-s       --datasize=SIZE   message size\n"
> +	       "-T       --threads         use POSIX threads\n"
> +	       "-P       --process         use fork (default)\n"
> +	       );
> +	exit(error);
>  }
>  
>  static void fdpair(int fds[2])
> @@ -342,86 +352,72 @@ static unsigned int group(childinfo_t *child,
>  	return num_fds * 2;
>  }
>  
> -static void process_options (int argc, char *argv[])
> +static void process_options(int argc, char *argv[])
>  {
> -	int error = 0;
> -
> -	while( 1 ) {
> +	for(;;) {
>  		int optind = 0;
>  
>  		static struct option longopts[] = {
> -			{"pipe",      no_argument,	 NULL, 'p'},
> -			{"datasize",  required_argument, NULL, 's'},
> -			{"loops",     required_argument, NULL, 'l'},
> -			{"groups",    required_argument, NULL, 'g'},
> -			{"fds",	      required_argument, NULL, 'f'},
> -			{"threads",   no_argument,	 NULL, 'T'},
> -			{"processes", no_argument,	 NULL, 'P'},
> -			{"fifo",      no_argument,       NULL, 'F'},
> -			{"help",      no_argument,	 NULL, 'h'},
> +			{"fds",		required_argument,	NULL, 'f'},
> +			{"fifo",	no_argument,		NULL, 'F'},
> +			{"groups",	required_argument,	NULL, 'g'},
> +			{"help",	no_argument,		NULL, 'h'},
> +			{"loops",	required_argument,	NULL, 'l'},
> +			{"pipe",	no_argument,		NULL, 'p'},
> +			{"datasize",	required_argument,	NULL, 's'},
> +			{"threads",	no_argument,		NULL, 'T'},
> +			{"processes",	no_argument,		NULL, 'P'},
>  			{NULL, 0, NULL, 0}
>  		};
>  
> -		int c = getopt_long(argc, argv, "ps:l:g:f:TPFh",
> +		int c = getopt_long(argc, argv, "f:Fg:hl:ps:TP",
>  				    longopts, &optind);
>  		if (c == -1) {
>  			break;
>  		}
>  		switch (c) {
> -		case 'p':
> -			use_pipes = 1;
> +		case 'f':
> +			if (!(argv[optind] && (num_fds = atoi(optarg)) > 0)) {
> +				fprintf(stderr, "%s: --fds|-f requires an integer > 0\n", argv[0]);
> +				print_usage_exit(1);
> +			}
>  			break;
> -
> -		case 's':
> -			if (!(argv[optind] && (datasize = atoi(optarg)) > 0)) {
> -				fprintf(stderr, "%s: --datasize|-s requires an integer > 0\n", argv[0]);
> -				error = 1;
> +		case 'F':
> +			fifo = 1;
> +			break;
> +		case 'g':
> +			if (!(argv[optind] && (num_groups = atoi(optarg)) > 0)) {
> +				fprintf(stderr, "%s: --groups|-g requires an integer > 0\n", argv[0]);
> +				print_usage_exit(1);
>  			}
>  			break;
> -
> +		case 'h':
> +			print_usage_exit(0);
>  		case 'l':
>  			if (!(argv[optind] && (loops = atoi(optarg)) > 0)) {
>  				fprintf(stderr, "%s: --loops|-l requires an integer > 0\n", argv[0]);
> -				error = 1;
> +				print_usage_exit(1);
>  			}
>  			break;
> -
> -		case 'g':
> -			if (!(argv[optind] && (num_groups = atoi(optarg)) > 0)) {
> -				fprintf(stderr, "%s: --groups|-g requires an integer > 0\n", argv[0]);
> -				error = 1;
> -			}
> +		case 'p':
> +			use_pipes = 1;
>  			break;
> -
> -		case 'f':
> -			if (!(argv[optind] && (num_fds = atoi(optarg)) > 0)) {
> -				fprintf(stderr, "%s: --fds|-f requires an integer > 0\n", argv[0]);
> -				error = 1;
> +		case 's':
> +			if (!(argv[optind] && (datasize = atoi(optarg)) > 0)) {
> +				fprintf(stderr, "%s: --datasize|-s requires an integer > 0\n", argv[0]);
> +				print_usage_exit(1);
>  			}
>  			break;
> -
>  		case 'T':
>  			process_mode = THREAD_MODE;
>  			break;
>  		case 'P':
>  			process_mode = PROCESS_MODE;
>  			break;
> -
> -		case 'F':
> -			fifo = 1;
> -			break;
> -
> -		case 'h':
> -			print_usage_exit();
> -
>  		default:
> -			error = 1;
> +			print_usage_exit(1);
>  		}
>  	}
> -
> -	if( error ) {
> -		exit(1);
> -	}
>  }
>  
>  void sigcatcher(int sig) {
> -- 
> 2.28.0
> 
> 
Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>



[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux