From patchwork Fri Oct 13 11:00:20 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: 10004161 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 51FC5602B3 for ; Fri, 13 Oct 2017 11:00:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43B8229029 for ; Fri, 13 Oct 2017 11:00:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38ACD2902B; Fri, 13 Oct 2017 11:00:55 +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 74A1E29029 for ; Fri, 13 Oct 2017 11:00:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 109D96EAEC; Fri, 13 Oct 2017 11:00:54 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 561466EAEC for ; Fri, 13 Oct 2017 11:00:52 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP; 13 Oct 2017 04:00:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,370,1503385200"; d="scan'208";a="322850244" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by fmsmga004.fm.intel.com with ESMTP; 13 Oct 2017 04:00:50 -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; Fri, 13 Oct 2017 12:00:50 +0100 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Fri, 13 Oct 2017 13:00:20 +0200 Message-ID: <20171013110020.32078-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20171013110020.32078-1-michal.winiarski@intel.com> References: <20171013110020.32078-1-michal.winiarski@intel.com> MIME-Version: 1.0 X-Originating-IP: [172.28.171.152] Subject: [Intel-gfx] [PATCH i-g-t v2 4/4] lib/i915: 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. v2: Break the trend of expanding ioctl_wrappers Signed-off-by: MichaƂ Winiarski Cc: Arkadiusz Hiler Cc: Chris Wilson Cc: Katarzyna Dec Cc: Petri Latvala Reviewed-by: Katarzyna Dec Reviewed-by: Chris Wilson --- lib/i915/gem_context.c | 40 +++++++++++++++++++++++++++++++ lib/i915/gem_context.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/i915/gem_context.c b/lib/i915/gem_context.c index ba826ae3..6d9edf5e 100644 --- a/lib/i915/gem_context.c +++ b/lib/i915/gem_context.c @@ -197,3 +197,43 @@ 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); +} diff --git a/lib/i915/gem_context.h b/lib/i915/gem_context.h index 06b2ca99..a2339c4b 100644 --- a/lib/i915/gem_context.h +++ b/lib/i915/gem_context.h @@ -45,4 +45,10 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p); int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p); int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p); +#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); + #endif /* GEM_CONTEXT_H */ diff --git a/tests/gem_exec_nop.c b/tests/gem_exec_nop.c index 78f2b1bd..2356f3c4 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 d3df449a..6d3d725e 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 da5f26aa..18c7ea5b 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 fccc0c0e..e558682a 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) {