diff options
author | Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com> | 2023-10-06 16:06:38 +0000 |
---|---|---|
committer | Kamil Konieczny <kamil.konieczny@linux.intel.com> | 2023-10-10 14:17:41 +0200 |
commit | 139fa2fdff99fe5f0048c1f8c95b9fab91259abe (patch) | |
tree | c32f3b46af96f182da819c42f46e8618f3e2839e /benchmarks | |
parent | 22934b9c81e17bdd7ebc2f101deed90cec11088c (diff) |
benchmarks/gem_wsim: extract duration parsing code to new function
Moved code from parse_workload to separate function.
v2:
- keep "field" parameter name (instead of "_desc") (Tvrtko)
- emit error messages from parse_duration, caller returns NULL
on parse_duration failure (Tvrtko)
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/gem_wsim.c | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c index 9d9cbd9c2..91410d42d 100644 --- a/benchmarks/gem_wsim.c +++ b/benchmarks/gem_wsim.c @@ -860,6 +860,44 @@ static long __duration(long dur, double scale) return round(scale * dur); } +static int +parse_duration(unsigned int nr_steps, struct duration *dur, double scale_dur, char *field) +{ + char *sep = NULL; + long tmpl; + + if (field[0] == '*') { + if (intel_gen(intel_get_drm_devid(fd)) < 8) { + wsim_err("Infinite batch at step %u needs Gen8+!\n", nr_steps); + return -1; + } + dur->unbound = true; + } else { + tmpl = strtol(field, &sep, 10); + if (tmpl <= 0 || tmpl == LONG_MIN || tmpl == LONG_MAX) { + wsim_err("Invalid duration at step %u!\n", nr_steps); + return -1; + } + + dur->min = __duration(tmpl, scale_dur); + + if (sep && *sep == '-') { + tmpl = strtol(sep + 1, NULL, 10); + if (tmpl <= 0 || __duration(tmpl, scale_dur) <= dur->min || + tmpl == LONG_MIN || tmpl == LONG_MAX) { + wsim_err("Invalid maximum duration at step %u!\n", nr_steps); + return -1; + } + + dur->max = __duration(tmpl, scale_dur); + } else { + dur->max = dur->min; + } + } + + return 0; +} + #define int_field(_STEP_, _FIELD_, _COND_, _ERR_) \ if ((field = strtok_r(fstart, ".", &fctx))) { \ tmp = atoi(field); \ @@ -1121,38 +1159,10 @@ parse_workload(struct w_arg *arg, unsigned int flags, double scale_dur, } if ((field = strtok_r(fstart, ".", &fctx))) { - char *sep = NULL; - long int tmpl; - fstart = NULL; - if (field[0] == '*') { - check_arg(intel_gen(intel_get_drm_devid(fd)) < 8, - "Infinite batch at step %u needs Gen8+!\n", - nr_steps); - step.duration.unbound = true; - } else { - tmpl = strtol(field, &sep, 10); - check_arg(tmpl <= 0 || tmpl == LONG_MIN || - tmpl == LONG_MAX, - "Invalid duration at step %u!\n", - nr_steps); - step.duration.min = __duration(tmpl, scale_dur); - - if (sep && *sep == '-') { - tmpl = strtol(sep + 1, NULL, 10); - check_arg(tmpl <= 0 || - __duration(tmpl, scale_dur) <= step.duration.min || - tmpl == LONG_MIN || - tmpl == LONG_MAX, - "Invalid maximum duration at step %u!\n", - nr_steps); - step.duration.max = __duration(tmpl, - scale_dur); - } else { - step.duration.max = step.duration.min; - } - } + if (parse_duration(nr_steps, &step.duration, scale_dur, field)) + return NULL; valid++; } |