From patchwork Wed Oct 11 09:15:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 9999107 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 9249160244 for ; Wed, 11 Oct 2017 09:16:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85BD02897A for ; Wed, 11 Oct 2017 09:16:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A4A62897D; Wed, 11 Oct 2017 09:16:21 +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 A46B02897A for ; Wed, 11 Oct 2017 09:16:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 524646E5FA; Wed, 11 Oct 2017 09:16:20 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id C0E286E5FA for ; Wed, 11 Oct 2017 09:16:19 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2017 02:16:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.43,360,1503385200"; d="scan'208"; a="1180844025" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by orsmga001.jf.intel.com with ESMTP; 11 Oct 2017 02:16:18 -0700 Received: from localhost (172.28.171.152) by IRSMSX102.ger.corp.intel.com (163.33.3.155) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 11 Oct 2017 10:16:18 +0100 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Wed, 11 Oct 2017 11:15:26 +0200 Message-ID: <20171011091526.9342-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20171011091526.9342-1-michal.winiarski@intel.com> References: <20171011091526.9342-1-michal.winiarski@intel.com> MIME-Version: 1.0 X-Originating-IP: [172.28.171.152] Subject: [Intel-gfx] [PATCH i-g-t 3/3] lib: Extract context priority setparam to a helper 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: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Another example of something that is used across different tests, and should be moved to lib. Signed-off-by: MichaƂ Winiarski Cc: Arkadiusz Hiler Cc: Chris Wilson Cc: Katarzyna Dec Cc: Petri Latvala --- lib/ioctl_wrappers.c | 40 +++++++++++++++++++++++++++++++ lib/ioctl_wrappers.h | 6 +++++ tests/gem_exec_nop.c | 26 ++++---------------- tests/gem_exec_schedule.c | 60 ++++++++++++++++------------------------------- tests/gem_exec_whisper.c | 23 ++++-------------- tests/gem_sync.c | 27 ++++----------------- 6 files changed, 78 insertions(+), 104 deletions(-) diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index b9f81d1b..0ba36151 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -1049,6 +1049,46 @@ void gem_context_require_bannable(int fd) igt_require(has_ban_period || has_bannable); } +#define LOCAL_I915_CONTEXT_PARAM_PRIORITY 0x6 + +/** + * __gem_context_set_priority: + * @fd: open i915 drm file descriptor + * @ctx_id: i915 context id + * @prio: desired context priority + * + * This function modifies priority property of the context. + * It is used by the scheduler to decide on the ordering of requests submitted + * to the hardware. + * + * Returns: An integer equal to zero for success and negative for failure + */ +int __gem_context_set_priority(int fd, uint32_t ctx_id, int prio) +{ + struct local_i915_gem_context_param p; + + memset(&p, 0, sizeof(p)); + p.context = ctx_id; + p.size = 0; + p.param = LOCAL_I915_CONTEXT_PARAM_PRIORITY; + p.value = prio; + + return __gem_context_set_param(fd, &p); +} + +/** + * gem_context_set_priority: + * @fd: open i915 drm file descriptor + * @ctx_id: i915 context id + * @prio: desired context priority + * + * Like __gem_context_set_priority(), except we assert on failure. + */ +void gem_context_set_priority(int fd, uint32_t ctx_id, int prio) +{ + igt_assert(__gem_context_set_priority(fd, ctx_id, prio) == 0); +} + int __gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle) { struct local_i915_gem_userptr userptr; diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index 3531c478..d72c8f5c 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -195,6 +195,12 @@ bool gem_has_scheduler(int fd); bool gem_has_ctx_priority(int fd); bool gem_has_preemption(int fd); +#define LOCAL_I915_CONTEXT_MAX_USER_PRIORITY 1023 +#define LOCAL_I915_CONTEXT_DEFAULT_PRIORITY 0 +#define LOCAL_I915_CONTEXT_MIN_USER_PRIORITY -1023 +int __gem_context_set_priority(int fd, uint32_t ctx, int prio); +void gem_context_set_priority(int fd, uint32_t ctx, int prio); + /* prime */ struct local_dma_buf_sync { uint64_t flags; diff --git a/tests/gem_exec_nop.c b/tests/gem_exec_nop.c index e7e9df2d..368f0e05 100644 --- a/tests/gem_exec_nop.c +++ b/tests/gem_exec_nop.c @@ -52,9 +52,8 @@ #define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) -#define LOCAL_CONTEXT_PARAM_PRIORITY 6 -#define MAX_PRIO 1023 -#define MIN_PRIO -1023 +#define MAX_PRIO LOCAL_I915_CONTEXT_MAX_USER_PRIORITY +#define MIN_PRIO LOCAL_I915_CONTEXT_MIN_USER_PRIORITY #define FORKED 1 #define CHAINED 2 @@ -585,23 +584,6 @@ static void fence_signal(int fd, uint32_t handle, igt_info("Signal %s: %'lu cycles (%'lu signals): %.3fus\n", ring_name, count, signal, elapsed(&start, &now) * 1e6 / count); } -static int __ctx_set_priority(int fd, uint32_t ctx, int prio) -{ - struct local_i915_gem_context_param param; - - memset(¶m, 0, sizeof(param)); - param.context = ctx; - param.size = 0; - param.param = LOCAL_CONTEXT_PARAM_PRIORITY; - param.value = prio; - - return __gem_context_set_param(fd, ¶m); -} - -static void ctx_set_priority(int fd, uint32_t ctx, int prio) -{ - igt_assert_eq(__ctx_set_priority(fd, ctx, prio), 0); -} static void preempt(int fd, uint32_t handle, unsigned ring_id, const char *ring_name) @@ -615,10 +597,10 @@ static void preempt(int fd, uint32_t handle, gem_require_ring(fd, ring_id); ctx[0] = gem_context_create(fd); - ctx_set_priority(fd, ctx[0], MIN_PRIO); + gem_context_set_priority(fd, ctx[0], MIN_PRIO); ctx[1] = gem_context_create(fd); - ctx_set_priority(fd, ctx[1], MAX_PRIO); + gem_context_set_priority(fd, ctx[1], MAX_PRIO); memset(&obj, 0, sizeof(obj)); obj.handle = handle; diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c index 8dda7984..521807b4 100644 --- a/tests/gem_exec_schedule.c +++ b/tests/gem_exec_schedule.c @@ -33,37 +33,17 @@ #include "igt_rand.h" #include "igt_sysfs.h" -#define LOCAL_CONTEXT_PARAM_PRIORITY 6 - #define LO 0 #define HI 1 #define NOISE 2 -#define MAX_PRIO 1023 -#define MIN_PRIO -1023 +#define MAX_PRIO LOCAL_I915_CONTEXT_MAX_USER_PRIORITY +#define MIN_PRIO LOCAL_I915_CONTEXT_MIN_USER_PRIORITY #define BUSY_QLEN 8 IGT_TEST_DESCRIPTION("Check that we can control the order of execution"); -static int __ctx_set_priority(int fd, uint32_t ctx, int prio) -{ - struct local_i915_gem_context_param param; - - memset(¶m, 0, sizeof(param)); - param.context = ctx; - param.size = 0; - param.param = LOCAL_CONTEXT_PARAM_PRIORITY; - param.value = prio; - - return __gem_context_set_param(fd, ¶m); -} - -static void ctx_set_priority(int fd, uint32_t ctx, int prio) -{ - igt_assert_eq(__ctx_set_priority(fd, ctx, prio), 0); -} - static void store_dword(int fd, uint32_t ctx, unsigned ring, uint32_t target, uint32_t offset, uint32_t value, uint32_t cork, unsigned write_domain) @@ -156,7 +136,7 @@ static uint32_t create_highest_priority(int fd) * priority (and therefore the max user priority), so no context * can overtake us, and we effectively can form a plug. */ - __ctx_set_priority(fd, ctx, MAX_PRIO); + __gem_context_set_priority(fd, ctx, MAX_PRIO); return ctx; } @@ -245,7 +225,7 @@ static void smoketest(int fd, unsigned ring, unsigned timeout) int prio; prio = hars_petruska_f54_1_random_unsafe_max(MAX_PRIO - MIN_PRIO) + MIN_PRIO; - ctx_set_priority(fd, ctx, prio); + gem_context_set_priority(fd, ctx, prio); engine = engines[hars_petruska_f54_1_random_unsafe_max(nengine)]; store_dword(fd, ctx, engine, scratch, @@ -287,10 +267,10 @@ static void reorder(int fd, unsigned ring, unsigned flags) uint32_t ctx[2]; ctx[LO] = gem_context_create(fd); - ctx_set_priority(fd, ctx[LO], MIN_PRIO); + gem_context_set_priority(fd, ctx[LO], MIN_PRIO); ctx[HI] = gem_context_create(fd); - ctx_set_priority(fd, ctx[HI], flags & EQUAL ? MIN_PRIO : 0); + gem_context_set_priority(fd, ctx[HI], flags & EQUAL ? MIN_PRIO : 0); scratch = gem_create(fd, 4096); plug(fd, &cork); @@ -326,13 +306,13 @@ static void promotion(int fd, unsigned ring) uint32_t ctx[3]; ctx[LO] = gem_context_create(fd); - ctx_set_priority(fd, ctx[LO], MIN_PRIO); + gem_context_set_priority(fd, ctx[LO], MIN_PRIO); ctx[HI] = gem_context_create(fd); - ctx_set_priority(fd, ctx[HI], 0); + gem_context_set_priority(fd, ctx[HI], 0); ctx[NOISE] = gem_context_create(fd); - ctx_set_priority(fd, ctx[NOISE], MIN_PRIO/2); + gem_context_set_priority(fd, ctx[NOISE], MIN_PRIO/2); result = gem_create(fd, 4096); dep = gem_create(fd, 4096); @@ -385,16 +365,16 @@ static void preempt(int fd, unsigned ring, unsigned flags) uint32_t ctx[2]; ctx[LO] = gem_context_create(fd); - ctx_set_priority(fd, ctx[LO], MIN_PRIO); + gem_context_set_priority(fd, ctx[LO], MIN_PRIO); ctx[HI] = gem_context_create(fd); - ctx_set_priority(fd, ctx[HI], MAX_PRIO); + gem_context_set_priority(fd, ctx[HI], MAX_PRIO); for (int n = 0; n < 16; n++) { if (flags & NEW_CTX) { gem_context_destroy(fd, ctx[LO]); ctx[LO] = gem_context_create(fd); - ctx_set_priority(fd, ctx[LO], MIN_PRIO); + gem_context_set_priority(fd, ctx[LO], MIN_PRIO); } spin[n] = __igt_spin_batch_new(fd, ctx[LO], ring, 0); igt_debug("spin[%d].handle=%d\n", n, spin[n]->handle); @@ -436,12 +416,12 @@ static void preempt_other(int fd, unsigned ring) */ ctx[LO] = gem_context_create(fd); - ctx_set_priority(fd, ctx[LO], MIN_PRIO); + gem_context_set_priority(fd, ctx[LO], MIN_PRIO); ctx[NOISE] = gem_context_create(fd); ctx[HI] = gem_context_create(fd); - ctx_set_priority(fd, ctx[HI], MAX_PRIO); + gem_context_set_priority(fd, ctx[HI], MAX_PRIO); n = 0; for_each_engine(fd, other) { @@ -496,7 +476,7 @@ static void preempt_self(int fd, unsigned ring) ctx[HI] = gem_context_create(fd); n = 0; - ctx_set_priority(fd, ctx[HI], MIN_PRIO); + gem_context_set_priority(fd, ctx[HI], MIN_PRIO); for_each_engine(fd, other) { spin[n] = __igt_spin_batch_new(fd, ctx[NOISE], other, 0); store_dword(fd, ctx[HI], other, @@ -504,7 +484,7 @@ static void preempt_self(int fd, unsigned ring) 0, I915_GEM_DOMAIN_RENDER); n++; } - ctx_set_priority(fd, ctx[HI], MAX_PRIO); + gem_context_set_priority(fd, ctx[HI], MAX_PRIO); store_dword(fd, ctx[HI], ring, result, (n + 1)*sizeof(uint32_t), n + 1, 0, I915_GEM_DOMAIN_RENDER); @@ -542,7 +522,7 @@ static void deep(int fd, unsigned ring) ctx = malloc(sizeof(*ctx) * nctx); for (int n = 0; n < nctx; n++) { ctx[n] = gem_context_create(fd); - ctx_set_priority(fd, ctx[n], MAX_PRIO - nctx + n); + gem_context_set_priority(fd, ctx[n], MAX_PRIO - nctx + n); } result = gem_create(fd, size); @@ -784,7 +764,7 @@ static void reorder_wide(int fd, unsigned ring) uint32_t *batch; execbuf.rsvd1 = gem_context_create(fd); - ctx_set_priority(fd, execbuf.rsvd1, n); + gem_context_set_priority(fd, execbuf.rsvd1, n); obj[2].handle = gem_create(fd, sz); batch = gem_mmap__gtt(fd, obj[2].handle, sz, PROT_WRITE); @@ -878,7 +858,7 @@ static void test_pi_ringfull(int fd, unsigned int engine) execbuf.buffer_count = 1; execbuf.flags = engine; execbuf.rsvd1 = gem_context_create(fd); - ctx_set_priority(fd, execbuf.rsvd1, MIN_PRIO); + gem_context_set_priority(fd, execbuf.rsvd1, MIN_PRIO); gem_execbuf(fd, &execbuf); gem_sync(fd, obj[1].handle); @@ -926,7 +906,7 @@ static void test_pi_ringfull(int fd, unsigned int engine) igt_debug("Creating HP context\n"); execbuf.rsvd1 = gem_context_create(fd); - ctx_set_priority(fd, execbuf.rsvd1, MAX_PRIO); + gem_context_set_priority(fd, execbuf.rsvd1, MAX_PRIO); kill(getppid(), SIGALRM); sched_yield(); diff --git a/tests/gem_exec_whisper.c b/tests/gem_exec_whisper.c index 80204cee..2df2d584 100644 --- a/tests/gem_exec_whisper.c +++ b/tests/gem_exec_whisper.c @@ -191,25 +191,10 @@ static void fini_hang(struct hang *h) close(h->fd); } -#define LOCAL_CONTEXT_PARAM_PRIORITY 6 - -static int __ctx_set_priority(int fd, uint32_t ctx, int prio) -{ - struct local_i915_gem_context_param param; - - memset(¶m, 0, sizeof(param)); - param.context = ctx; - param.size = 0; - param.param = LOCAL_CONTEXT_PARAM_PRIORITY; - param.value = prio; - - return __gem_context_set_param(fd, ¶m); -} - -static void ctx_set_priority(int fd, uint32_t ctx) +static void ctx_set_random_priority(int fd, uint32_t ctx) { int prio = hars_petruska_f54_1_random_unsafe_max(1024) - 512; - igt_assert_eq(__ctx_set_priority(fd, ctx, prio), 0); + gem_context_set_priority(fd, ctx, prio); }; static void whisper(int fd, unsigned engine, unsigned flags) @@ -430,7 +415,7 @@ static void whisper(int fd, unsigned engine, unsigned flags) gem_open(this_fd, gem_flink(fd, handle[1])); if (flags & PRIORITY) - ctx_set_priority(this_fd, 0); + ctx_set_random_priority(this_fd, 0); } if (!(flags & CHAIN)) { @@ -440,7 +425,7 @@ static void whisper(int fd, unsigned engine, unsigned flags) if (flags & CONTEXTS) { execbuf.rsvd1 = contexts[rand() % 64]; if (flags & PRIORITY) - ctx_set_priority(this_fd, execbuf.rsvd1); + ctx_set_random_priority(this_fd, execbuf.rsvd1); } gem_execbuf(this_fd, &execbuf); diff --git a/tests/gem_sync.c b/tests/gem_sync.c index e0b53905..9c21ee54 100644 --- a/tests/gem_sync.c +++ b/tests/gem_sync.c @@ -33,9 +33,8 @@ #define LOCAL_I915_EXEC_BSD_SHIFT (13) #define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT) -#define LOCAL_CONTEXT_PARAM_PRIORITY 6 -#define MAX_PRIO 1023 -#define MIN_PRIO -1023 +#define MAX_PRIO LOCAL_I915_CONTEXT_MAX_USER_PRIORITY +#define MIN_PRIO LOCAL_I915_CONTEXT_MIN_USER_PRIORITY #define ENGINE_MASK (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) @@ -690,24 +689,6 @@ store_all(int fd, int num_children, int timeout) igt_assert_eq(intel_detect_and_clear_missed_interrupts(fd), 0); } -static int __ctx_set_priority(int fd, uint32_t ctx, int prio) -{ - struct local_i915_gem_context_param param; - - memset(¶m, 0, sizeof(param)); - param.context = ctx; - param.size = 0; - param.param = LOCAL_CONTEXT_PARAM_PRIORITY; - param.value = prio; - - return __gem_context_set_param(fd, ¶m); -} - -static void ctx_set_priority(int fd, uint32_t ctx, int prio) -{ - igt_assert_eq(__ctx_set_priority(fd, ctx, prio), 0); -} - static void preempt(int fd, unsigned ring, int num_children, int timeout) { @@ -746,10 +727,10 @@ preempt(int fd, unsigned ring, int num_children, int timeout) } ctx[0] = gem_context_create(fd); - ctx_set_priority(fd, ctx[0], MIN_PRIO); + gem_context_set_priority(fd, ctx[0], MIN_PRIO); ctx[1] = gem_context_create(fd); - ctx_set_priority(fd, ctx[1], MAX_PRIO); + gem_context_set_priority(fd, ctx[1], MAX_PRIO); intel_detect_and_clear_missed_interrupts(fd); igt_fork(child, num_children) {