[Intel-gfx] [PATCH i-g-t] gem_wsim: Refactor how we sleep in period mode
Tvrtko Ursulin
tursulin at ursulin.net
Fri Sep 14 13:34:52 UTC 2018
From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Period mode tries to execute every workload iteration with a given
frequency.
Up to now code used to calculate the relative sleep needed to hit the
required start of the next iteration, but we can do conceptually better
if we use clock_nanosleep in absolute mode and tell it to simply wake us
up at the exact time the next iteration should start.
This shouldn't have a huge effect on accuracy today (we do nothing to
account for any drift across iterations), but is conceptually cleaner and,
if we start dealing with signals in the future, will be much better.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Suggested-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
Just churn at this point?
---
benchmarks/gem_wsim.c | 43 +++++++++++++++++++++++++++++++++----------
1 file changed, 33 insertions(+), 10 deletions(-)
diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index e0709487897b..4ce1e80d0241 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -1847,6 +1847,15 @@ static bool sync_deps(struct workload *wrk, struct w_step *w)
return synced;
}
+static void
+timespec_add_us(struct timespec *ts, unsigned int us)
+{
+ uint64_t ns = ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec + us * 1000;
+
+ ts->tv_sec = ns / NSEC_PER_SEC;
+ ts->tv_nsec = ns % NSEC_PER_SEC;
+}
+
static void *run_workload(void *data)
{
struct workload *wrk = (struct workload *)data;
@@ -1873,20 +1882,21 @@ static void *run_workload(void *data)
for (i = 0, w = wrk->steps; wrk->run && (i < wrk->nr_steps);
i++, w++) {
enum intel_engine_id engine = w->engine;
- int do_sleep = 0;
+ struct timespec now;
if (w->type == DELAY) {
- do_sleep = w->delay;
+ clock_gettime(CLOCK_MONOTONIC, &now);
} else if (w->type == PERIOD) {
- struct timespec now;
+ int remain_us;
clock_gettime(CLOCK_MONOTONIC, &now);
- do_sleep = w->period -
- elapsed_us(&wrk->repeat_start, &now);
- if (do_sleep < 0) {
+ remain_us = w->period -
+ elapsed_us(&wrk->repeat_start,
+ &now);
+ if (remain_us < 0) {
if (verbose > 1)
- printf("%u: Dropped period @ %u/%u (%dus late)!\n",
- wrk->id, count, i, do_sleep);
+ printf("%u: Missed period @ %u/%u (%dus late)!\n",
+ wrk->id, count, i, -remain_us);
continue;
}
} else if (w->type == SYNC) {
@@ -1936,8 +1946,21 @@ static void *run_workload(void *data)
continue;
}
- if (do_sleep || w->type == PERIOD) {
- usleep(do_sleep);
+ if (w->type == DELAY || w->type == PERIOD) {
+ struct timespec end;
+ unsigned int us;
+
+ if (w->type == PERIOD) {
+ end = wrk->repeat_start;
+ us = w->period;
+ } else {
+ end = now;
+ us = w->delay;
+ }
+
+ timespec_add_us(&end, us);
+ clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
+ &end, NULL);
continue;
}
--
2.17.1
More information about the Intel-gfx
mailing list