From patchwork Fri Sep 14 13:34:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10600789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B0366CB for ; Fri, 14 Sep 2018 13:35:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 306B32B6DC for ; Fri, 14 Sep 2018 13:35:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2402B2B6DD; Fri, 14 Sep 2018 13:35:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B436C2B6E0 for ; Fri, 14 Sep 2018 13:35:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C3C336E89C; Fri, 14 Sep 2018 13:35:00 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC52E6E89C for ; Fri, 14 Sep 2018 13:34:58 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id g33-v6so10658594wrd.1 for ; Fri, 14 Sep 2018 06:34:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cPsrNa27+i8cc38+B/9fij7ER+RyWouXkcgHgxU2u/0=; b=aNr+0BaPR/wAyWW5Bak1yopY0LgaBt47E6EgKKUJtCPtMIiLVC7Y3xiMcitBNeYJsw g/a1hajXq/Lcr+d/Ynf8fhXaru8+dO9+k64eAzQXzVdfdwOA7ERcjzWfgfrNgsOzA938 DyHOu5fe7ouHG7V8B3D7uzaZURtjaFd7aSvJZMKtFvLwSbKNqaONcnixM57ugclHDpud BJZj5fciBFuXh7iVoPTeO8woG06tC60sWZ1RztPKmXksADZJpaj178snL2ERDxzhoVuQ yi5HujpDNGTW809j308CyOJguP+Ez1zbIrso5K4N5bRHeVFnRoEuU+UFmCqYnbCJWF/G DK7A== X-Gm-Message-State: APzg51BecXBS8xQdcP6Ee88/mUyku1dYZmX+J+6LkDuGedDvGYjcP3pw kNrCFzruPxSyJNvf7ZcDX4z+mA== X-Google-Smtp-Source: ANB0VdbIIxeZ9FK5x0kwcAvNXOjAVTx72hJcC/FR6+enyk1uGua6TZASCj8NhqSGehKGEhPOGsFiLQ== X-Received: by 2002:adf:e2c5:: with SMTP id d5-v6mr10067756wrj.139.1536932097404; Fri, 14 Sep 2018 06:34:57 -0700 (PDT) Received: from localhost.localdomain ([95.144.165.37]) by smtp.gmail.com with ESMTPSA id 142-v6sm1361817wme.35.2018.09.14.06.34.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 06:34:56 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Fri, 14 Sep 2018 14:34:52 +0100 Message-Id: <20180914133452.19493-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] gem_wsim: Refactor how we sleep in period mode X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin 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 Suggested-by: Ville Syrjälä --- 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; }