[igt-dev] [PATCH i-g-t 04/17] benchmarks/gem_wsim: extract duration parsing code to new function
Marcin Bernatowicz
marcin.bernatowicz at linux.intel.com
Fri Oct 6 16:06:38 UTC 2023
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 at intel.com>
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
---
benchmarks/gem_wsim.c | 70 ++++++++++++++++++++++++-------------------
1 file 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++;
}
--
2.42.0
More information about the igt-dev
mailing list