From patchwork Tue Apr 17 08:41:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10344565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2E26260548 for ; Tue, 17 Apr 2018 08:41:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DA3928A06 for ; Tue, 17 Apr 2018 08:41:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 125C728A08; Tue, 17 Apr 2018 08:41:48 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 7363228A06 for ; Tue, 17 Apr 2018 08:41:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AAAA86E08C; Tue, 17 Apr 2018 08:41:44 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B0666E060 for ; Tue, 17 Apr 2018 08:41:42 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id d1so33089936wrj.13 for ; Tue, 17 Apr 2018 01:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=ylpqiXOEL2qpBnlWagg8wlKPBZEFtx6aUWDXf1lhsnw=; b=RDwqlC/HnIJ+THyTNZVwDc7e1jEsvVDBrnhxHtC4i3tGh/MZfkyVuZatPHn9JQlAbZ FmWTLEZQTMk66+80nCp21ikf4CC7199w79N3OHCyobyCGnbCBfbYHi/DimrCuWWuS8Tl bBal3Uf+ipKPS9EsXrFluLy2q6Qyow6S4VS2YD6pfB6VuBmp0uQYeZ1re8xgK4/myliJ il5xcIzD76v+nciOESRM7vg9iOx4WTHBzYIDLgBmpCLP4CYgxOeiSZih2e3bsq1xkpH0 oQYf7X3XHVjJGu5H8b7XjxiM/khchAg+e4mqITctT/TsizX8VNCvAvfzmNUq4r+CFhs2 NSeA== 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; bh=ylpqiXOEL2qpBnlWagg8wlKPBZEFtx6aUWDXf1lhsnw=; b=Xns2zF9QbFYsHso9aMwCX6zZfKVtCmHQ/Ov+lTnF2NXDxtjreFCsJ1RtybOW8QF+vq wCy/UzkmlRxkPv7eWlTqDcE7nKhn4bTlEHyL4w/37gnyO/CfYs9ncUu/fm2IuxOm9Jv/ R9vQS/aJUnfIhy/O2JpaLXNCffBY/eqK134dyGG+MNmjnLQPvFVZHLUeHSSHVYhSmg8n rnxgCWzHZkm+r4HX3oia647Iqiny1BZjw9hEgvsdBh81PcXCixiySaKHxaeB7O2WvAdN FMrHTSrkSjoMXEFTEUEbP3qcF2SwFcmtTDqqge+GfQOQzX2z2wJeHv8VjN2/Nk3HysHZ Onzg== X-Gm-Message-State: ALQs6tBhgItggV//WEuZJkVqJcv02JLestWZmT15aQUPI4dSk2OZvl3g i4ihGZNneyM05W++lktq9JNStA== X-Google-Smtp-Source: AIpwx49UN2nAAx2T4OjWR/ux07TDlw3lvixOcGS6PT6utbikhD9+fUZDhwYLavvNLQhewUPJKlNLBg== X-Received: by 10.223.178.245 with SMTP id g108mr895840wrd.147.1523954500829; Tue, 17 Apr 2018 01:41:40 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id l1sm8245466wmh.25.2018.04.17.01.41.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 01:41:40 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Tue, 17 Apr 2018 09:41:11 +0100 Message-Id: <20180417084112.8352-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [CI i-g-t 1/2] tests/gem_exec_latency: New subtests for checking submission from RT tasks 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 MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin We want to make sure RT tasks which use a lot of CPU times can submit batch buffers with roughly the same latency (and certainly not worse) compared to normal tasks. Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson --- tests/gem_exec_latency.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/tests/gem_exec_latency.c b/tests/gem_exec_latency.c index 9498c0921e60..420ede0f83a0 100644 --- a/tests/gem_exec_latency.c +++ b/tests/gem_exec_latency.c @@ -36,11 +36,15 @@ #include #include #include +#include #include "drm.h" #include "igt_sysfs.h" #include "igt_vgem.h" +#include "igt_dummyload.h" +#include "igt_stats.h" + #include "i915/gem_ring.h" #define LOCAL_I915_EXEC_NO_RELOC (1<<11) @@ -351,6 +355,172 @@ static void latency_from_ring(int fd, } } +static void __rearm_spin_batch(igt_spin_t *spin) +{ + const uint32_t mi_arb_chk = 0x5 << 23; + + *spin->batch = mi_arb_chk; + *spin->running = 0; + __sync_synchronize(); +} + +static void +__submit_spin_batch(int fd, igt_spin_t *spin, unsigned int flags) +{ + struct drm_i915_gem_execbuffer2 eb = spin->execbuf; + + eb.flags &= ~(0x3f | I915_EXEC_BSD_MASK); + eb.flags |= flags | I915_EXEC_NO_RELOC; + + gem_execbuf(fd, &eb); +} + +struct rt_pkt +{ +#define RT_OK (0) +#define RT_FAIL (1) +#define RT_TIMEOUT (2) + int status; + struct igt_mean mean; + double max; +}; + +static void __spin_wait(struct rt_pkt *msg, igt_spin_t *spin, double *t_wait) +{ + struct timespec ts = { }; + uint64_t t_last = 0; + + igt_nsec_elapsed(&ts); + + while (!READ_ONCE(*spin->running)) { + uint64_t t = igt_nsec_elapsed(&ts); + + if ((t - t_last) > 5UL * NSEC_PER_SEC) { + /* Absolute timeout to save time. */ + msg->status = RT_TIMEOUT; + } else if ((t - t_last) > NSEC_PER_SEC / 10) { + /* Backoff every 100ms to give it chance to complete. */ + t_last = t; + usleep(1); + } + } + + *t_wait = igt_nsec_elapsed(&ts) / 1e9; + + msg->status = RT_OK; +} + +/* + * Test whether RT thread which hogs the CPU a lot can submit work with + * reasonable latency. + */ +static void +rthog_latency_on_ring(int fd, unsigned int ring, const char *name) +{ + const char *passname[] = { "warmup", "normal", "rt" }; + struct rt_pkt res[3]; + unsigned int i; + int link[2]; + int ret; + + igt_require(gem_can_store_dword(fd, ring)); + + igt_assert(pipe(link) == 0); + + memset(res, 0, sizeof(res)); + + igt_fork(child, 1) { + unsigned int pass = 0; /* Three passes: warmup, normal, rt. */ + + do { + struct rt_pkt msg = { }; + igt_spin_t *spin; + + igt_mean_init(&msg.mean); + + if (pass == 2) { + struct sched_param rt = + { .sched_priority = 99 }; + + ret = sched_setscheduler(0, + SCHED_FIFO | SCHED_RESET_ON_FORK, + &rt); + if (ret) { + igt_warn("Failed to set scheduling policy!\n"); + msg.status = RT_FAIL; + write(link[1], &msg, sizeof(msg)); + exit(1); + } + } + + spin = __igt_spin_batch_new_poll(fd, 0, ring); + if (!spin) { + igt_warn("Failed to create spinner! (%s)\n", + passname[pass]); + msg.status = RT_FAIL; + write(link[1], &msg, sizeof(msg)); + exit(1); + } + igt_spin_busywait_until_running(spin); + + igt_until_timeout(pass > 0 ? 5 : 2) { + double t; + + igt_spin_batch_end(spin); + gem_sync(fd, spin->handle); + + __rearm_spin_batch(spin); + __submit_spin_batch(fd, spin, ring); + + __spin_wait(&msg, spin, &t); + if (msg.status != RT_OK) { + igt_warn("Wait timeout! (%s)\n", + passname[pass]); + write(link[1], &msg, sizeof(msg)); + exit(1); + } + + if (t > msg.max) + msg.max = t; + + igt_mean_add(&msg.mean, t); + } + + igt_spin_batch_free(fd, spin); + + igt_info("%10s: mean=%.2fus variance=%.2fus max=%.2fus (n=%lu)\n", + passname[pass], + igt_mean_get(&msg.mean) * 1e6, + igt_mean_get_variance(&msg.mean) * 1e6, + msg.max * 1e6, + msg.mean.count); + + write(link[1], &msg, sizeof(msg)); + } while (++pass < 3); + + exit(0); + } + + for (i = 0; i < 3; i++) { + ret = read(link[0], &res[i], sizeof(res[0])); + igt_assert_eq(ret, sizeof(res[0])); + + igt_assert_eq(res[i].status, RT_OK); + } + + close(link[0]); + close(link[1]); + + igt_waitchildren(); + + /* + * Check that the submission latency variance for a task with RT + * priority is no larger than three times the same of a normal task. + */ + igt_assert(igt_mean_get_variance(&res[2].mean) < + igt_mean_get_variance(&res[1].mean) * 3); +} + igt_main { const struct intel_execution_engine *e; @@ -391,6 +561,12 @@ igt_main e->exec_id | e->flags, e->name, 0); + igt_subtest_f("%s-rthog-submit", e->name) + rthog_latency_on_ring(device, + e->exec_id | + e->flags, + e->name); + igt_subtest_f("%s-dispatch-queued", e->name) latency_on_ring(device, e->exec_id | e->flags,