From patchwork Thu Apr 5 12:40:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10324529 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 54931600CB for ; Thu, 5 Apr 2018 12:40:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45E9D29171 for ; Thu, 5 Apr 2018 12:40:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AF8A29186; Thu, 5 Apr 2018 12:40:46 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 87D9329189 for ; Thu, 5 Apr 2018 12:40:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 847636E767; Thu, 5 Apr 2018 12:40:44 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 60D8A6E71D for ; Thu, 5 Apr 2018 12:40:42 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id y55so28156327wry.3 for ; Thu, 05 Apr 2018 05:40: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:in-reply-to:references; bh=30y/HnuTIWkWdu7NX0WeHB6Cb2MsjyWbeLfltnJ5Rz8=; b=jFoN4pQT2D7YLsSKVMT8G7OE/8fGNl5ZCqU6pbdBUDR9yKiNkbCdZuSPq2xs127jRJ gATzzeZACo3GSTptv7L3oanN7yTwpOsW3vISxLSXWpjrJhK1sYVx8GwE9PGsc3umm71B 3TF9JiVE+3Lm6CKv/+tHtRWWuiutTzQNJgJjtzH1c0XU83mfEtEtSLWywPTOL3yF44AK /FKFTz4VYGj+POOrSIKWonYct1c/NK6aalhavNyPxJULn7ohux8zFAao0NpO86lmHTYH NrRLjqFxJQo+sILLu0Ni/7H+bkUFWzqAZ5vZjDID69r5FvAFxaI3mQP0Cti68Byd7MAS pNTA== 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:in-reply-to :references; bh=30y/HnuTIWkWdu7NX0WeHB6Cb2MsjyWbeLfltnJ5Rz8=; b=sqJAf+J0dCIAR0DHoBOVQ3NWpVDjHAqNHfrGnMOiuDuvtq1eXwsG6sbQDjuHId0n/v 9d8yVuEJosVsjMfjpVIGi5Bo9MXFOkyrRJraAvV9f/454YiRabWJPwajgw08E30fPev0 1v9ZQaoIP4uMdb+6oc/w+i36Ocz6By+RYyhwWxLaqvl+c/eq65Evb5MmkEbBTOlAG9hN hQa2Q0sGaIPhvYjrTAAiBW4gcSQuTcDcSKtCcr6+t0uAi3C4pYzAJyh9Y6U0DelBDL5z TWErG1zLv6zdhHzmkj9U71lamJQzAkNVKg1bNxKqrN4x82/IGjrcBClkE1Crltqbs06S GaeA== X-Gm-Message-State: AElRT7E9KBYdWxQ+YLUDQyEIOcM4s1w1Opqf/Tu0LVvIQyQUv/GKX2m6 vgaIUFvCW1qS7hg7GnWq3g+UE5Hj X-Google-Smtp-Source: AIpwx48LKqzBumJwefbMKe/hMVm5SNAMzXgAZ2aYlWFOkwMftviZSv3LzYtE8YCut2I0KnXxEc/EEw== X-Received: by 10.223.195.132 with SMTP id p4mr15523545wrf.279.1522932040542; Thu, 05 Apr 2018 05:40:40 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id i44sm4796068wri.23.2018.04.05.05.40.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 05:40:40 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Thu, 5 Apr 2018 13:40:27 +0100 Message-Id: <20180405124028.22766-5-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180405124028.22766-1-tvrtko.ursulin@linux.intel.com> References: <20180405124028.22766-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 4/5] tests/perf_pmu: Add tests for engine queued/runnable/running stats 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 Simple tests to check reported queue depths are correct. v2: * Improvements similar to ones from i915_query.c. Signed-off-by: Tvrtko Ursulin --- tests/perf_pmu.c | 258 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c index 590e6526b069..7fccb437d048 100644 --- a/tests/perf_pmu.c +++ b/tests/perf_pmu.c @@ -169,6 +169,7 @@ static unsigned int e2ring(int gem_fd, const struct intel_execution_engine2 *e) #define TEST_RUNTIME_PM (8) #define FLAG_LONG (16) #define FLAG_HANG (32) +#define TEST_CONTEXTS (64) static igt_spin_t * __spin_poll(int fd, uint32_t ctx, unsigned long flags) { @@ -959,6 +960,223 @@ multi_client(int gem_fd, const struct intel_execution_engine2 *e) assert_within_epsilon(val[1], perf_slept[1], tolerance); } +static double calc_queued(uint64_t d_val, uint64_t d_ns) +{ + return (double)d_val * 1e9 / I915_SAMPLE_QUEUED_DIVISOR / d_ns; +} + +static void +queued(int gem_fd, const struct intel_execution_engine2 *e, unsigned int flags) +{ + const unsigned long engine = e2ring(gem_fd, e); + const uint32_t bbe = MI_BATCH_BUFFER_END; + const unsigned int max_rq = 10; + double queued[max_rq + 1]; + unsigned int n, i; + uint64_t val[2]; + uint64_t ts[2]; + uint32_t bo; + int fd; + + igt_require_sw_sync(); + if (flags & TEST_CONTEXTS) + gem_require_contexts(gem_fd); + + memset(queued, 0, sizeof(queued)); + + bo = gem_create(gem_fd, 4096); + gem_write(gem_fd, bo, 4092, &bbe, sizeof(bbe)); + + fd = open_pmu(I915_PMU_ENGINE_QUEUED(e->class, e->instance)); + + for (n = 0; n <= max_rq; n++) { + IGT_CORK_FENCE(cork); + int fence = -1; + + gem_quiescent_gpu(gem_fd); + + if (n) + fence = igt_cork_plug(&cork, -1); + + for (i = 0; i < n; i++) { + struct drm_i915_gem_exec_object2 obj = { }; + struct drm_i915_gem_execbuffer2 eb = { }; + + obj.handle = bo; + + eb.buffer_count = 1; + eb.buffers_ptr = to_user_pointer(&obj); + + eb.flags = engine | I915_EXEC_FENCE_IN; + if (flags & TEST_CONTEXTS) + eb.rsvd1 = gem_context_create(gem_fd); + eb.rsvd2 = fence; + + gem_execbuf(gem_fd, &eb); + + if (flags & TEST_CONTEXTS) + gem_context_destroy(gem_fd, eb.rsvd1); + } + + val[0] = __pmu_read_single(fd, &ts[0]); + usleep(batch_duration_ns / 1000); + val[1] = __pmu_read_single(fd, &ts[1]); + + queued[n] = calc_queued(val[1] - val[0], ts[1] - ts[0]); + igt_info("n=%u queued=%.2f\n", n, queued[n]); + + if (fence >= 0) + igt_cork_unplug(&cork); + + for (i = 0; i < n; i++) + gem_sync(gem_fd, bo); + } + + close(fd); + + gem_close(gem_fd, bo); + + for (i = 0; i <= max_rq; i++) + assert_within_epsilon(queued[i], i, tolerance); +} + +static unsigned long __query_wait(igt_spin_t *spin, unsigned int n) +{ + struct timespec ts = { }; + unsigned long t; + + igt_nsec_elapsed(&ts); + + if (spin->running) { + igt_spin_busywait_until_running(spin); + } else { + igt_debug("__spin_wait - usleep mode\n"); + usleep(500e3); /* Better than nothing! */ + } + + t = igt_nsec_elapsed(&ts); + + return spin->running ? t : 500e6 / n; +} + +static void +runnable(int gem_fd, const struct intel_execution_engine2 *e) +{ + const unsigned long engine = e2ring(gem_fd, e); + bool contexts = gem_has_contexts(gem_fd); + const unsigned int max_rq = 10; + igt_spin_t *spin[max_rq + 1]; + double runnable[max_rq + 1]; + uint32_t ctx[max_rq]; + unsigned int n, i; + uint64_t val[2]; + uint64_t ts[2]; + int fd; + + memset(runnable, 0, sizeof(runnable)); + + if (contexts) { + for (i = 0; i < max_rq; i++) + ctx[i] = gem_context_create(gem_fd); + } + + fd = open_pmu(I915_PMU_ENGINE_RUNNABLE(e->class, e->instance)); + + for (n = 0; n <= max_rq; n++) { + gem_quiescent_gpu(gem_fd); + + for (i = 0; i < n; i++) { + uint32_t ctx_ = contexts ? ctx[i] : 0; + + if (i == 0) + spin[i] = __spin_poll(gem_fd, ctx_, engine); + else + spin[i] = __igt_spin_batch_new(gem_fd, ctx_, + engine, 0); + } + + if (n) + usleep(__query_wait(spin[0], n) * n); + + val[0] = __pmu_read_single(fd, &ts[0]); + usleep(batch_duration_ns / 1000); + val[1] = __pmu_read_single(fd, &ts[1]); + + runnable[n] = calc_queued(val[1] - val[0], ts[1] - ts[0]); + igt_info("n=%u runnable=%.2f\n", n, runnable[n]); + + for (i = 0; i < n; i++) { + end_spin(gem_fd, spin[i], FLAG_SYNC); + igt_spin_batch_free(gem_fd, spin[i]); + } + } + + if (contexts) { + for (i = 0; i < max_rq; i++) + gem_context_destroy(gem_fd, ctx[i]); + } + + close(fd); + + assert_within_epsilon(runnable[0], 0, tolerance); + igt_assert(runnable[max_rq] > 0.0); + + if (contexts) + assert_within_epsilon(runnable[max_rq] - runnable[max_rq - 1], + 1, tolerance); +} + +static void +running(int gem_fd, const struct intel_execution_engine2 *e) +{ + const unsigned long engine = e2ring(gem_fd, e); + const unsigned int max_rq = 10; + igt_spin_t *spin[max_rq + 1]; + double running[max_rq + 1]; + unsigned int n, i; + uint64_t val[2]; + uint64_t ts[2]; + int fd; + + memset(running, 0, sizeof(running)); + memset(spin, 0, sizeof(spin)); + + fd = open_pmu(I915_PMU_ENGINE_RUNNING(e->class, e->instance)); + + for (n = 0; n <= max_rq; n++) { + gem_quiescent_gpu(gem_fd); + + for (i = 0; i < n; i++) { + if (i == 0) + spin[i] = __spin_poll(gem_fd, 0, engine); + else + spin[i] = __igt_spin_batch_new(gem_fd, 0, + engine, 0); + } + + if (n) + usleep(__query_wait(spin[0], n) * n); + + val[0] = __pmu_read_single(fd, &ts[0]); + usleep(batch_duration_ns / 1000); + val[1] = __pmu_read_single(fd, &ts[1]); + + running[n] = calc_queued(val[1] - val[0], ts[1] - ts[0]); + igt_info("n=%u running=%.2f\n", n, running[n]); + + for (i = 0; i < n; i++) { + end_spin(gem_fd, spin[i], FLAG_SYNC); + igt_spin_batch_free(gem_fd, spin[i]); + } + } + + close(fd); + + assert_within_epsilon(running[0], 0, tolerance); + for (i = 1; i <= max_rq; i++) + igt_assert(running[i] > 0); +} + /** * Tests that i915 PMU corectly errors out in invalid initialization. * i915 PMU is uncore PMU, thus: @@ -1692,6 +1910,15 @@ igt_main igt_subtest_f("init-sema-%s", e->name) init(fd, e, I915_SAMPLE_SEMA); + igt_subtest_f("init-queued-%s", e->name) + init(fd, e, I915_SAMPLE_QUEUED); + + igt_subtest_f("init-runnable-%s", e->name) + init(fd, e, I915_SAMPLE_RUNNABLE); + + igt_subtest_f("init-running-%s", e->name) + init(fd, e, I915_SAMPLE_RUNNING); + igt_subtest_group { igt_fixture { gem_require_engine(fd, e->class, e->instance); @@ -1797,6 +2024,27 @@ igt_main igt_subtest_f("busy-hang-%s", e->name) single(fd, e, TEST_BUSY | FLAG_HANG); + + /** + * Test that queued metric works. + */ + igt_subtest_f("queued-%s", e->name) + queued(fd, e, 0); + + igt_subtest_f("queued-contexts-%s", e->name) + queued(fd, e, TEST_CONTEXTS); + + /** + * Test that runnable metric works. + */ + igt_subtest_f("runnable-%s", e->name) + runnable(fd, e); + + /** + * Test that running metric works. + */ + igt_subtest_f("running-%s", e->name) + running(fd, e); } /** @@ -1889,6 +2137,16 @@ igt_main e->name) single(render_fd, e, TEST_BUSY | TEST_TRAILING_IDLE); + igt_subtest_f("render-node-queued-%s", e->name) + queued(render_fd, e, 0); + igt_subtest_f("render-node-queued-contexts-%s", + e->name) + queued(render_fd, e, TEST_CONTEXTS); + igt_subtest_f("render-node-runnable-%s", + e->name) + runnable(render_fd, e); + igt_subtest_f("render-node-running-%s", e->name) + running(render_fd, e); } }