From: Tvrtko Ursulin <tursulin@ursulin.net>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org,
Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Subject: [igt-dev] [PATCH i-g-t] gem_wsim: Refactor how we sleep in period mode
Date: Fri, 14 Sep 2018 14:34:52 +0100 [thread overview]
Message-ID: <20180914133452.19493-1-tvrtko.ursulin@linux.intel.com> (raw)
From: Tvrtko Ursulin <tvrtko.ursulin@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@intel.com>
Suggested-by: Ville Syrjälä <ville.syrjala@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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2018-09-14 13:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-14 13:34 Tvrtko Ursulin [this message]
2018-09-14 15:29 ` [igt-dev] ✗ Fi.CI.BAT: failure for gem_wsim: Refactor how we sleep in period mode Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180914133452.19493-1-tvrtko.ursulin@linux.intel.com \
--to=tursulin@ursulin.net \
--cc=Intel-gfx@lists.freedesktop.org \
--cc=igt-dev@lists.freedesktop.org \
--cc=tvrtko.ursulin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).