@@ -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)));
@@ -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];
@@ -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);
}
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/include/rt-utils.h | 1 + src/lib/rt-utils.c | 30 +++++++++++++++++++ src/oslat/oslat.c | 67 ++---------------------------------------- 3 files changed, 33 insertions(+), 65 deletions(-)