From patchwork Thu Aug 24 00:11:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Argenziano X-Patchwork-Id: 9918757 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 EFDE2602A0 for ; Thu, 24 Aug 2017 00:26:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E237728AB6 for ; Thu, 24 Aug 2017 00:26:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D596228AB8; Thu, 24 Aug 2017 00:26:51 +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.2 required=2.0 tests=BAYES_00, 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 50A1628AB6 for ; Thu, 24 Aug 2017 00:26:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1510E6E033; Thu, 24 Aug 2017 00:26:50 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id D97696E033 for ; Thu, 24 Aug 2017 00:26:48 +0000 (UTC) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Aug 2017 17:26:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,419,1498546800"; d="scan'208";a="141366094" Received: from relo-linux-2.fm.intel.com ([10.1.27.122]) by orsmga005.jf.intel.com with ESMTP; 23 Aug 2017 17:26:48 -0700 From: Antonio Argenziano To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Aug 2017 17:11:23 -0700 Message-Id: <20170824001123.13132-1-antonio.argenziano@intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [PATCH i-g-t] igt/gem_ringfill: Adds ringbuffer full preemption test X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP The testcase added here, stimulates this scenario where a high priority request is sent while another process keeps submitting requests and filling its ringbuffer. From RFC (Chris): - Use two FDs, one for each priority submission. - Move from gem_ringfill to gem_exec_schedule. - Bound processes to same cpu and wake with signals. Cc: Chris Wilson Signed-off-by: Antonio Argenziano --- tests/gem_exec_schedule.c | 113 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c index f2847863..476626e6 100644 --- a/tests/gem_exec_schedule.c +++ b/tests/gem_exec_schedule.c @@ -21,7 +21,12 @@ * IN THE SOFTWARE. */ +#define _GNU_SOURCE +#include +#include + #include +#include #include "igt.h" #include "igt_vgem.h" @@ -39,6 +44,15 @@ IGT_TEST_DESCRIPTION("Check that we can control the order of execution"); +static void alarm_handler(int sig) +{ +} + +static int __execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf) +{ + return ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf); +} + static int __ctx_set_priority(int fd, uint32_t ctx, int prio) { struct local_i915_gem_context_param param; @@ -659,6 +673,95 @@ static bool has_scheduler(int fd) return has > 0; } +static void bind_to_cpu(int cpu) +{ + const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); + cpu_set_t allowed; + + CPU_ZERO(&allowed); + CPU_SET(cpu % ncpus, &allowed); + igt_assert(sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed) == 0); +} + +static void setup_timer(int timeout) +{ + struct itimerval itv; + struct sigaction sa = { .sa_handler = alarm_handler }; + + sigaction(SIGALRM, &sa, NULL); + itv.it_interval.tv_sec = 0; + itv.it_interval.tv_usec = 100; + itv.it_value.tv_sec = 0; + itv.it_value.tv_usec = timeout * 1000; + setitimer(ITIMER_REAL, &itv, NULL); +} + +/* + * This test checks that is possible for a high priority request to trigger a + * preemption if another context has filled its ringbuffer. + * The aim of the test is to make sure that high priority requests cannot be + * stalled by low priority tasks. + * */ +static void preempt_while_ringbuffer_full(int fd, uint32_t engine) +{ + uint32_t hp_fd; + uint32_t hp_ctx, lp_ctx; + struct drm_i915_gem_exec_object2 obj, hp_obj; + struct drm_i915_gem_execbuffer2 execbuf; + + const unsigned timeout = 10; /*ms*/ + const uint32_t bbe = MI_BATCH_BUFFER_END; + + hp_fd = drm_open_driver(DRIVER_INTEL); + + memset(&execbuf, 0, sizeof(execbuf)); + memset(&obj, 0, sizeof(obj)); + memset(&hp_obj, 0, sizeof(hp_obj)); + + lp_ctx = gem_context_create(fd); + ctx_set_priority(fd, lp_ctx, -MAX_PRIO); + + hp_ctx = gem_context_create(hp_fd); + ctx_set_priority(hp_fd, hp_ctx, MAX_PRIO); + + hp_obj.handle = gem_create(fd, 4096); + gem_write(fd, hp_obj.handle, 0, &bbe, sizeof(bbe)); + + obj.handle = gem_create(fd, 4096); + gem_write(fd, obj.handle, 0, &bbe, sizeof(bbe)); + + execbuf.buffers_ptr = to_user_pointer(&obj); + execbuf.flags = engine; + execbuf.buffer_count = 1; + execbuf.rsvd1 = lp_ctx; + + /*Stall execution and fill ring*/ + igt_spin_batch_new(fd, lp_ctx, engine, 0); + + setup_timer(timeout); + while (__execbuf(fd, &execbuf) == 0) + ; + + /* steal cpu */ + bind_to_cpu(0); + igt_fork(child, 1) { + /* this child is forced to wait for parent to sleep */ + execbuf.buffers_ptr = to_user_pointer(&hp_obj); + execbuf.rsvd1 = hp_ctx; + setup_timer(timeout); + if (__execbuf(fd, &execbuf)) { + igt_assert_f(0, "Failed High priority submission.\n"); + igt_terminate_spin_batches(); + } + } + + /* process sleeps waiting for space to free, releasing child */ + setup_timer(2*timeout); + __execbuf(fd, &execbuf); + igt_terminate_spin_batches(); + igt_waitchildren(); +} + igt_main { const struct intel_execution_engine *e; @@ -669,7 +772,7 @@ igt_main igt_fixture { fd = drm_open_driver_master(DRIVER_INTEL); igt_require_gem(fd); - gem_require_mmap_wc(fd); + //gem_require_mmap_wc(fd); igt_fork_hang_detector(fd); } @@ -731,6 +834,14 @@ igt_main } } + igt_subtest_group { + for (e = intel_execution_engines; e->name; e++) { + igt_subtest_f("preempt-while-full-%s", e->name) { + preempt_while_ringbuffer_full(fd, e->exec_id | e->flags); + } + } + } + igt_fixture { igt_stop_hang_detector(); close(fd);