public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Wagner <dwagner@suse.de>
To: Clark Williams <williams@redhat.com>, John Kacur <jkacur@redhat.com>
Cc: linux-rt-users@vger.kernel.org, Daniel Wagner <dwagner@suse.de>
Subject: [rt-tests v1 2/6] oslat: Use string parser utilies
Date: Fri, 13 Nov 2020 22:09:06 +0100	[thread overview]
Message-ID: <20201113210910.21807-3-dwagner@suse.de> (raw)
In-Reply-To: <20201113210910.21807-1-dwagner@suse.de>

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 <dwagner@suse.de>
---
 src/oslat/oslat.c | 67 ++---------------------------------------------
 1 file changed, 2 insertions(+), 65 deletions(-)

diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index 0018c472e0c1..b2aa15001be2 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -572,69 +572,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)
 {
@@ -702,7 +639,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);
@@ -736,7 +673,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);
 			}
-- 
2.29.2


  parent reply	other threads:[~2020-11-13 21:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 21:09 [rt-tests v1 0/6] Move common code to helper libraries Daniel Wagner
2020-11-13 21:09 ` [rt-tests v1 1/6] rt-utils: Introduce parse_mem_string() Daniel Wagner
2020-11-18 20:59   ` John Kacur
2020-11-13 21:09 ` Daniel Wagner [this message]
2020-11-18 21:00   ` [rt-tests v1 2/6] oslat: Use string parser utilies John Kacur
2020-11-13 21:09 ` [rt-tests v1 3/6] cyclictest: Remove deadcode checking for NUMA Daniel Wagner
2020-11-18 21:01   ` John Kacur
2020-11-13 21:09 ` [rt-tests v1 4/6] rt-numa: Introduce NUMA helpers Daniel Wagner
2020-11-18 21:09   ` John Kacur
2020-11-19  8:21     ` Daniel Wagner
2020-11-13 21:09 ` [rt-tests v1 5/6] cyclictest: Use parse_cpumask() from rt-numa.h Daniel Wagner
2020-11-18 21:10   ` John Kacur
2020-11-18 21:17   ` John Kacur
2020-11-13 21:09 ` [rt-tests v1 6/6] oslat: " Daniel Wagner
2020-11-18 21:18   ` John Kacur
2021-02-10 16:07   ` Peter Xu
2021-02-10 16:29     ` Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201113210910.21807-3-dwagner@suse.de \
    --to=dwagner@suse.de \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox