From patchwork Wed Sep 2 08:27:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 296051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79E6CC43461 for ; Wed, 2 Sep 2020 08:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FDE420709 for ; Wed, 2 Sep 2020 08:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726310AbgIBI1g (ORCPT ); Wed, 2 Sep 2020 04:27:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:43778 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbgIBI1f (ORCPT ); Wed, 2 Sep 2020 04:27:35 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 67C0FB1DD; Wed, 2 Sep 2020 08:27:34 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests 1/4] cyclicdeadline: Streamline usage output and man page Date: Wed, 2 Sep 2020 10:27:22 +0200 Message-Id: <20200902082725.20037-2-dwagner@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902082725.20037-1-dwagner@suse.de> References: <20200902082725.20037-1-dwagner@suse.de> MIME-Version: 1.0 Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Signed-off-by: Daniel Wagner --- src/sched_deadline/cyclicdeadline.8 | 24 ++++++++--------- src/sched_deadline/cyclicdeadline.c | 41 +++++++++++++++-------------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/sched_deadline/cyclicdeadline.8 b/src/sched_deadline/cyclicdeadline.8 index 91766fb391c4..6df7faf445f9 100644 --- a/src/sched_deadline/cyclicdeadline.8 +++ b/src/sched_deadline/cyclicdeadline.8 @@ -17,7 +17,7 @@ cyclicdeadline \- This program is used to test the deadline scheduler (SCHED_DEA .PP .SH SYNOPSIS .B cyclicdeadline -.RI "[-ha] [-c cpulist] [-i interval] [-s step] [-t nr_threads] [-D duration] +.RI "[-ha] [-c CPUSET] [-D TIME] [-i INTV] [-s STEP] [-t NUM]" .PP .SH DESCRIPTION .B cyclicdeadline @@ -25,28 +25,28 @@ is a cyclictest style program for testing the deadline scheduler .PP .SH OPTIONS .TP -.B \-h -Show this help menu -.TP .B \-a Use all CPUs .TP -.B \-c cpulist +.B \-c CPUSET Comma / hypen separated list of CPUs to run deadline tasks on .TP -.B \-i interval +.B \-D TIME +Specify a length for the test to run +Append 'm', 'h', or 'd' to specify minutes, hours, or days +.TP +.B \-h +Show this help menu +.TP +.B \-i INTV The shortest deadline for the tasks in us. (default 1000us) .TP -.B \-s step +.B \-s STEP The amount to increase the deadline for each task in us. (default 500us) .TP -.B \-t nr_threads +.B \-t NUM The number of threads to run as deadline (default 1) -.TP -.B \-D time -Specify a length for the test to run .br -Append 'm', 'h', or 'd' to specify minutes, hours, or days .SH AUTHOR cyclicdeadline was written by Steven Rostedt .PP diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c index a08e28e73c42..310880805553 100644 --- a/src/sched_deadline/cyclicdeadline.c +++ b/src/sched_deadline/cyclicdeadline.c @@ -630,26 +630,25 @@ static void teardown(void) destroy_cpuset(CPUSET_LOCAL, 1); } -static void usage(char **argv) +static void usage(int error) { - char *arg = argv[0]; - char *p = arg+strlen(arg); - - while (p >= arg && *p != '/') - p--; - p++; - - printf("usage: %s [options]\n" - " -h - Show this help menu\n" - " -a - Use all CPUs\n" - " -c cpulist - Comma/hyphen separated list of CPUs to run deadline tasks on\n" - " -i interval(us) - The shortest deadline for the tasks (default 1000us)\n" - " -s step(us) - The amount to increase the deadline for each task (default 500us)\n" - " -t threads - The number of threads to run as deadline (default 1)\n" - " -D time - Specify a length for the test run\n" - " Append 'm', 'h', or 'd' to specify minutes, hours or days\n" - "\n", p); - exit(-1); + printf("cyclicdeadline V %1.2f\n", VERSION); + printf("Usage:\n" + "cyclicdeadline \n\n" + "-a Use all CPUs\n" + "-c CPUSET Comma/hyphen separated list of CPUs to run deadline\n" + " tasks on.\n" + "-D TIME Specify a length for the test run.\n" + " Append 'm', 'h', or 'd' to specify minutes, hours or\n" + " days\n" + "-h Show this help menu.\n" + "-i INTV The shortest deadline for the tasks in us\n" + " (default 1000us).\n" + "-s STEP The amount to increase the deadline for each task in us\n" + " (default 500us).\n" + "-t NUM The number of threads to run as deadline (default 1).\n" + ); + exit(error); } static int fail; @@ -1057,8 +1056,10 @@ int main (int argc, char **argv) duration = parse_time_string(optarg); break; case 'h': + usage(0); + break; default: - usage(argv); + usage(1); } } From patchwork Wed Sep 2 08:27:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 257093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92124C433E6 for ; Wed, 2 Sep 2020 08:27:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A65620709 for ; Wed, 2 Sep 2020 08:27:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726311AbgIBI1h (ORCPT ); Wed, 2 Sep 2020 04:27:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:43794 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbgIBI1f (ORCPT ); Wed, 2 Sep 2020 04:27:35 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CAA66B579; Wed, 2 Sep 2020 08:27:34 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests 2/4] deadline_test: Streamline usage output and man page Date: Wed, 2 Sep 2020 10:27:23 +0200 Message-Id: <20200902082725.20037-3-dwagner@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902082725.20037-1-dwagner@suse.de> References: <20200902082725.20037-1-dwagner@suse.de> MIME-Version: 1.0 Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Signed-off-by: Daniel Wagner --- src/sched_deadline/deadline_test.8 | 37 ++++++++++++----------- src/sched_deadline/deadline_test.c | 47 +++++++++++++++--------------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/sched_deadline/deadline_test.8 b/src/sched_deadline/deadline_test.8 index 5dc99c0bfc63..8f32c5b6feb6 100644 --- a/src/sched_deadline/deadline_test.8 +++ b/src/sched_deadline/deadline_test.8 @@ -19,45 +19,44 @@ deadline_test \- High resolution test program This program is used to test the deadline scheduler (SCHED_DEADLINE tasks) .SH SYNOPSIS .B deadline_test -.RI "[ \-hb ] [ \-r prio ] [ \-c cpulist ] [ \-i interval ] [ \-p percent ] [ \-P percent ] [ \-t threads ] [ \-s step[us) ]" - +.RI "[ \-hb ] [ \-c CPUSET ] [ \-i INTV ] [ \-p PERCENT ] [ \-P PERCENT ] \ +[ \-r PRIO ] [ \-s STEP ] [ \-t NUM ]" .SH OPTIONS .TP -.B \-h -Show this help menu -.br -.TP .B \-b Bind on the last cpu. (shortcut for -c ) .br .TP -.B \-r prio -Add an RT task with given prio to stress system +.B \-c CPUSET +Comma/hyphen separated list of CPUs to run deadline tasks on .br .TP -.B \-c cpulist -Comma/hyphen separated list of CPUs to run deadline tasks on +.B \-h +Show this help menu .br .TP -.B \-i interval +.B \-i INTV The shortest deadline for the tasks .br .TP -.B \-p percent +.B \-p PERCENT The percent of bandwidth to use (1-90%) .br .TP -.B \-P percent -The percent of runtime for execution completion - (Default 100%) +.B \-P PERCENT +The percent of runtime for execution completion (default 100%) .br .TP -.B \-t threads -The number of threads to run as deadline (default 1) +.B \-r PRIO +Add an RT task with given prio to stress system .br .TP -.B \-s step(us) -The amount to increase the deadline for each task (default 500us) +.B \-s STEP +The amount to increase the deadline for each task in us (default 500us) +.br +.TP +.B \-t NUM +The number of threads to run as deadline (default 1) .br .SH AUTHOR Deadline test was written by Steven Rostedt diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c index 4cef2609912e..060ac896aef2 100644 --- a/src/sched_deadline/deadline_test.c +++ b/src/sched_deadline/deadline_test.c @@ -46,33 +46,30 @@ /** * usage - show the usage of the program and exit. - * @argv: The program passed in args + * @error: Exit error code to be used * - * This is defined here to show people looking at this code how + * This is defined here to show peoplde looking at this code how * to use this program as well. */ -static void usage(char **argv) +static void usage(int error) { - char *arg = argv[0]; - char *p = arg+strlen(arg); - - while (p >= arg && *p != '/') - p--; - p++; - - printf("usage: %s [options]\n" - " -h - Show this help menu\n" - " -b - Bind on the last cpu. (shortcut for -c )\n" - " -r prio - Add an RT task with given prio to stress system\n" - " -c cpulist - Comma/hyphen separated list of CPUs to run deadline tasks on\n" - " -i interval - The shortest deadline for the tasks\n" - " -p percent - The percent of bandwidth to use (1-90%%)\n" - " -P percent - The percent of runtime for execution completion\n" - " (Default 100%%)\n" - " -t threads - The number of threads to run as deadline (default 1)\n" - " -s step(us) - The amount to increase the deadline for each task (default 500us)\n" - "\n", p); - exit(-1); + printf("deadline_test V %1.2f\n", VERSION); + printf("Usage:\n" + "deadline_test \n" + "-b Bind on the last cpu. (shortcut for -c )\n" + "-c CPUSET Comma/hyphen separated list of CPUs to run deadline\n" + " tasks on\n" + "-h Show this help menu\n" + "-i INTV The shortest deadline for the tasks\n" + "-p PERCENT The percent of bandwidth to use (1-90%%)\n" + "-P PERCENT The percent of runtime for execution completion\n" + " (default 100%%)\n" + "-r PRIO Add an RT task with given prio to stress system\n" + "-s STEP The amount to increase the deadline for each task in us\n" + " (default 500us)\n" + "-t NUM The number of threads to run as deadline (default 1)\n" + ); + exit(error); } #define _STR(x) #x @@ -1753,8 +1750,10 @@ int main (int argc, char **argv) rt_task = atoi(optarg); break; case 'h': + usage(0); + break; default: - usage(argv); + usage(1); } } From patchwork Wed Sep 2 08:27:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 296052 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBCDDC433E7 for ; Wed, 2 Sep 2020 08:27:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D480320709 for ; Wed, 2 Sep 2020 08:27:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726193AbgIBI1o (ORCPT ); Wed, 2 Sep 2020 04:27:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:43884 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726247AbgIBI1g (ORCPT ); Wed, 2 Sep 2020 04:27:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 49E80B656; Wed, 2 Sep 2020 08:27:35 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests 3/4] oslat: Streamline usage output and man page Date: Wed, 2 Sep 2020 10:27:24 +0200 Message-Id: <20200902082725.20037-4-dwagner@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902082725.20037-1-dwagner@suse.de> References: <20200902082725.20037-1-dwagner@suse.de> MIME-Version: 1.0 Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Signed-off-by: Daniel Wagner --- src/oslat/oslat.8 | 2 +- src/oslat/oslat.c | 76 +++++++++++++++++++++++------------------------ 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/oslat/oslat.8 b/src/oslat/oslat.8 index 85f2c5bcdf5c..b481d8d82783 100644 --- a/src/oslat/oslat.8 +++ b/src/oslat/oslat.8 @@ -36,7 +36,7 @@ Total memory usage will be this value multiplies 2*N, because there will be src/dst buffers for each thread, and N is the number of processors for testing. .TP -.B \-t, \-\-runtime=SEC +.B \-D, \-\-duration=TIME Specify test duration, e.g., 60, 20m, 2H (m/M: minutes, h/H: hours, d/D: days). By default the unit is s/second. .TP diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c index f1a82f2367d2..79d2b6754461 100644 --- a/src/oslat/oslat.c +++ b/src/oslat/oslat.c @@ -507,42 +507,37 @@ static void handle_alarm(int code) g.cmd = STOP; } -const char *helpmsg = -"Usage: %s [options]\n" -"\n" -"This is an OS latency detector by running busy loops on specified cores.\n" -"Please run this tool using root.\n" -"\n" -"Available options:\n" -"\n" -" -b, --bucket-size Specify the number of the buckets (4-1024)\n" -" -B, --bias Add a bias to all the buckets using the estimated mininum\n" -" -c, --cpu-list Specify CPUs to run on, e.g. '1,3,5,7-15'\n" -" -C, --cpu-main-thread Specify which CPU the main thread runs on. Default is cpu0.\n" -" -f, --rtprio Using SCHED_FIFO priority (1-99)\n" -" -m, --workload-mem Size of the memory to use for the workload (e.g., 4K, 1M).\n" -" Total memory usage will be this value multiplies 2*N,\n" -" because there will be src/dst buffers for each thread, and\n" -" N is the number of processors for testing.\n" -" -s, --single-preheat Use a single thread when measuring latency at preheat stage\n" -" NOTE: please make sure the CPU frequency on all testing cores\n" -" are locked before using this parmater. If you don't know how\n" -" to lock the freq then please don't use this parameter.\n" -" -t, --runtime Specify test duration, e.g., 60, 20m, 2H\n" -" (m/M: minutes, h/H: hours, d/D: days)\n" -" -T, --trace-threshold Stop the test when threshold triggered (in us),\n" -" print a marker in ftrace and stop ftrace too.\n" -" -v, --version Display the version of the software.\n" -" -w, --workload Specify a kind of workload, default is no workload\n" -" (options: no, memmove)\n" -" -z, --zero-omit Don't display buckets in the output histogram if all zeros.\n" -"\n" -; - -static void usage(void) +static void usage(int error) { - printf(helpmsg, g.app_name); - exit(1); + printf("oslat V %1.2f\n", VERSION); + printf("Usage:\n" + "oslat \n\n" + "This is an OS latency detector by running busy loops on specified cores.\n" + "Please run this tool using root.\n\n" + "Available options:\n\n" + "-b, --bucket-size Specify the number of the buckets (4-1024)\n" + "-B, --bias Add a bias to all the buckets using the estimated mininum\n" + "-c, --cpu-list Specify CPUs to run on, e.g. '1,3,5,7-15'\n" + "-C, --cpu-main-thread Specify which CPU the main thread runs on. Default is cpu0.\n" + "-D, --duration Specify test duration, e.g., 60, 20m, 2H\n" + " (m/M: minutes, h/H: hours, d/D: days)\n" + "-f, --rtprio Using SCHED_FIFO priority (1-99)\n" + "-m, --workload-mem Size of the memory to use for the workload (e.g., 4K, 1M).\n" + " Total memory usage will be this value multiplies 2*N,\n" + " because there will be src/dst buffers for each thread, and\n" + " N is the number of processors for testing.\n" + "-s, --single-preheat Use a single thread when measuring latency at preheat stage\n" + " NOTE: please make sure the CPU frequency on all testing cores\n" + " are locked before using this parmater. If you don't know how\n" + " to lock the freq then please don't use this parameter.\n" + "-T, --trace-threshold Stop the test when threshold triggered (in us),\n" + " print a marker in ftrace and stop ftrace too.\n" + "-v, --version Display the version of the software.\n" + "-w, --workload Specify a kind of workload, default is no workload\n" + " (options: no, memmove)\n" + "-z, --zero-omit Don't display buckets in the output histogram if all zeros.\n" + ); + exit(error); } /* TODO: use libnuma? */ @@ -661,7 +656,7 @@ static void parse_options(int argc, char *argv[]) { "bucket-size", required_argument, NULL, 'b' }, { "cpu-list", required_argument, NULL, 'c' }, { "cpu-main-thread", required_argument, NULL, 'C'}, - { "runtime", required_argument, NULL, 't' }, + { "duration", required_argument, NULL, 'D' }, { "rtprio", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "trace-threshold", required_argument, NULL, 'T' }, @@ -673,7 +668,7 @@ static void parse_options(int argc, char *argv[]) { "version", no_argument, NULL, 'v'}, { NULL, 0, NULL, 0 }, }; - int i, c = getopt_long(argc, argv, "b:Bc:C:f:hm:st:w:T:vz", + int i, c = getopt_long(argc, argv, "b:Bc:C:D:f:hm:sw:T:vz", options, NULL); long ncores; @@ -704,7 +699,7 @@ static void parse_options(int argc, char *argv[]) exit(1); } break; - case 't': + case 'D': g.runtime = parse_runtime(optarg); if (!g.runtime) { printf("Illegal runtime: %s\n", optarg); @@ -761,8 +756,11 @@ static void parse_options(int argc, char *argv[]) case 'z': g.output_omit_zero_buckets = 1; break; + case 'h': + usage(0); + break; default: - usage(); + usage(1); break; } } From patchwork Wed Sep 2 08:27:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 257092 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C3B5C433E2 for ; Wed, 2 Sep 2020 08:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73EB22078B for ; Wed, 2 Sep 2020 08:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbgIBI1o (ORCPT ); Wed, 2 Sep 2020 04:27:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:43896 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726268AbgIBI1g (ORCPT ); Wed, 2 Sep 2020 04:27:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BBE0CB65F; Wed, 2 Sep 2020 08:27:35 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests 4/4] oslat: Use string parser utilies Date: Wed, 2 Sep 2020 10:27:25 +0200 Message-Id: <20200902082725.20037-5-dwagner@suse.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902082725.20037-1-dwagner@suse.de> References: <20200902082725.20037-1-dwagner@suse.de> MIME-Version: 1.0 Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Use available parse_time_string() instead locally implemented version. While at it move the mem parser helper to the global utility header. Signed-off-by: Daniel Wagner --- src/include/rt-utils.h | 1 + src/lib/rt-utils.c | 30 +++++++++++++++++++ src/oslat/oslat.c | 67 ++---------------------------------------- 3 files changed, 33 insertions(+), 65 deletions(-) diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h index 4ed1cbc53ece..d7f369cdbb47 100644 --- a/src/include/rt-utils.h +++ b/src/include/rt-utils.h @@ -28,6 +28,7 @@ uint32_t string_to_policy(const char *str); pid_t gettid(void); int parse_time_string(char *val); +int parse_mem_string(char *str, uint64_t *val); void enable_trace_mark(void); void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2))); diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c index f786588706cd..f9cbfb82febb 100644 --- a/src/lib/rt-utils.c +++ b/src/lib/rt-utils.c @@ -362,6 +362,36 @@ int parse_time_string(char *val) return t; } +int parse_mem_string(char *str, uint64_t *val) +{ + char *endptr; + int v = strtol(str, &endptr, 10); + + if (!*endptr) + return v; + + switch (*endptr) { + case 'g': + case 'G': + v *= 1024; + case 'm': + case 'M': + v *= 1024; + case 'k': + case 'K': + v *= 1024; + case 'b': + case 'B': + break; + default: + return -1; + } + + *val = v; + + return 0; +} + void open_tracemark_fd(void) { char path[MAX_PATH]; diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c index 79d2b6754461..3a5acae95c1f 100644 --- a/src/oslat/oslat.c +++ b/src/oslat/oslat.c @@ -570,69 +570,6 @@ static int parse_cpu_list(char *cpu_list, cpu_set_t *cpu_set) return n_cores; } -static int parse_runtime(const char *str) -{ - char *endptr; - int v = strtol(str, &endptr, 10); - - if (!*endptr) - return v; - - switch (*endptr) { - case 'd': - case 'D': - /* Days */ - v *= 24; - case 'h': - case 'H': - /* Hours */ - v *= 60; - case 'm': - case 'M': - /* Minutes */ - v *= 60; - case 's': - case 'S': - /* Seconds */ - break; - default: - printf("Unknown runtime suffix: %s\n", endptr); - v = 0; - break; - } - - return v; -} - -static int parse_mem_size(char *str, uint64_t *val) -{ - char *endptr; - int v = strtol(str, &endptr, 10); - - if (!*endptr) - return v; - - switch (*endptr) { - case 'g': - case 'G': - v *= 1024; - case 'm': - case 'M': - v *= 1024; - case 'k': - case 'K': - v *= 1024; - case 'b': - case 'B': - break; - default: - return -1; - } - - *val = v; - - return 0; -} static int workload_select(char *name) { @@ -700,7 +637,7 @@ static void parse_options(int argc, char *argv[]) } break; case 'D': - g.runtime = parse_runtime(optarg); + g.runtime = parse_time_string(optarg); if (!g.runtime) { printf("Illegal runtime: %s\n", optarg); exit(1); @@ -734,7 +671,7 @@ static void parse_options(int argc, char *argv[]) } break; case 'm': - if (parse_mem_size(optarg, &g.workload_mem_size)) { + if (parse_mem_string(optarg, &g.workload_mem_size)) { printf("Unknown workload memory size '%s'.\n\n", optarg); exit(1); }