diff options
author | Tvrtko Ursulin <tvrtko.ursulin@intel.com> | 2019-05-22 16:57:08 +0100 |
---|---|---|
committer | Tvrtko Ursulin <tvrtko.ursulin@intel.com> | 2019-05-23 15:12:13 +0100 |
commit | 3b4677f3a5f736be0b34776dfad569f991e7d987 (patch) | |
tree | c176ead1fb3dd28b5c1e366917df15494d0b6338 /benchmarks | |
parent | 4366acd059b99b08cc7a6cc6bdfef66101edb9bf (diff) |
gem_wsim: Compact int command parsing with a macro
Parsing an integer workload descriptor field is a common pattern which we
can extract to a helper macro and by doing so further improve the
readability of the main parsing loop.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/gem_wsim.c | 80 |
1 files changed, 25 insertions, 55 deletions
diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c index baa389c3..66832f74 100644 --- a/benchmarks/gem_wsim.c +++ b/benchmarks/gem_wsim.c @@ -376,6 +376,15 @@ static int parse_engine_map(struct w_step *step, const char *_str) return 0; } +#define int_field(_STEP_, _FIELD_, _COND_, _ERR_) \ + if ((field = strtok_r(fstart, ".", &fctx))) { \ + tmp = atoi(field); \ + check_arg(_COND_, _ERR_, nr_steps); \ + step.type = _STEP_; \ + step._FIELD_ = tmp; \ + goto add_step; \ + } \ + static struct workload * parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) { @@ -403,25 +412,11 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) fstart = NULL; if (!strcmp(field, "d")) { - if ((field = strtok_r(fstart, ".", &fctx))) { - tmp = atoi(field); - check_arg(tmp <= 0, - "Invalid delay at step %u!\n", - nr_steps); - step.type = DELAY; - step.delay = tmp; - goto add_step; - } + int_field(DELAY, delay, tmp <= 0, + "Invalid delay at step %u!\n"); } else if (!strcmp(field, "p")) { - if ((field = strtok_r(fstart, ".", &fctx))) { - tmp = atoi(field); - check_arg(tmp <= 0, - "Invalid period at step %u!\n", - nr_steps); - step.type = PERIOD; - step.period = tmp; - goto add_step; - } + int_field(PERIOD, period, tmp <= 0, + "Invalid period at step %u!\n"); } else if (!strcmp(field, "P")) { unsigned int nr = 0; while ((field = strtok_r(fstart, ".", &fctx))) { @@ -444,46 +439,21 @@ parse_workload(struct w_arg *arg, unsigned int flags, struct workload *app_w) step.type = CTX_PRIORITY; goto add_step; } else if (!strcmp(field, "s")) { - if ((field = strtok_r(fstart, ".", &fctx))) { - tmp = atoi(field); - check_arg(tmp >= 0 || - ((int)nr_steps + tmp) < 0, - "Invalid sync target at step %u!\n", - nr_steps); - step.type = SYNC; - step.target = tmp; - goto add_step; - } + int_field(SYNC, target, + tmp >= 0 || ((int)nr_steps + tmp) < 0, + "Invalid sync target at step %u!\n"); } else if (!strcmp(field, "t")) { - if ((field = strtok_r(fstart, ".", &fctx))) { - tmp = atoi(field); - check_arg(tmp < 0, - "Invalid throttle at step %u!\n", - nr_steps); - step.type = THROTTLE; - step.throttle = tmp; - goto add_step; - } + int_field(THROTTLE, throttle, + tmp < 0, + "Invalid throttle at step %u!\n"); } else if (!strcmp(field, "q")) { - if ((field = strtok_r(fstart, ".", &fctx))) { - tmp = atoi(field); - check_arg(tmp < 0, - "Invalid qd throttle at step %u!\n", - nr_steps); - step.type = QD_THROTTLE; - step.throttle = tmp; - goto add_step; - } + int_field(QD_THROTTLE, throttle, + tmp < 0, + "Invalid qd throttle at step %u!\n"); } else if (!strcmp(field, "a")) { - if ((field = strtok_r(fstart, ".", &fctx))) { - tmp = atoi(field); - check_arg(tmp >= 0, - "Invalid sw fence signal at step %u!\n", - nr_steps); - step.type = SW_FENCE_SIGNAL; - step.target = tmp; - goto add_step; - } + int_field(SW_FENCE_SIGNAL, target, + tmp >= 0, + "Invalid sw fence signal at step %u!\n"); } else if (!strcmp(field, "f")) { step.type = SW_FENCE; goto add_step; |