From patchwork Fri Oct 13 11:00:19 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: 10004159 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 1A521602B3 for ; Fri, 13 Oct 2017 11:00:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C44829029 for ; Fri, 13 Oct 2017 11:00:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0137F2902B; Fri, 13 Oct 2017 11:00:47 +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 1434529029 for ; Fri, 13 Oct 2017 11:00:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A08E76EAE7; Fri, 13 Oct 2017 11:00:46 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9EE656EAE7 for ; Fri, 13 Oct 2017 11:00:45 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Oct 2017 04:00:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,370,1503385200"; d="scan'208";a="322850124" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by fmsmga004.fm.intel.com with ESMTP; 13 Oct 2017 04:00:44 -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:43 +0100 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Fri, 13 Oct 2017 13:00:19 +0200 Message-ID: <20171013110020.32078-3-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 3/4] lib/i915: Move context related helpers to lib/i915/gem_context 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 We'd like to make ioctl_wrappers a bit thinner, and we plan to add new helpers in the following patch. Let's move context related helpers before adding more content. 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 --- .../intel-gpu-tools/intel-gpu-tools-docs.xml | 1 + lib/Makefile.sources | 2 + lib/i915/gem_context.c | 199 +++++++++++++++++++++ lib/i915/gem_context.h | 48 +++++ lib/ioctl_wrappers.c | 157 +--------------- lib/ioctl_wrappers.h | 22 +-- lib/meson.build | 2 + 7 files changed, 254 insertions(+), 177 deletions(-) create mode 100644 lib/i915/gem_context.c create mode 100644 lib/i915/gem_context.h diff --git a/docs/reference/intel-gpu-tools/intel-gpu-tools-docs.xml b/docs/reference/intel-gpu-tools/intel-gpu-tools-docs.xml index 8c14bd07..c5be60d0 100644 --- a/docs/reference/intel-gpu-tools/intel-gpu-tools-docs.xml +++ b/docs/reference/intel-gpu-tools/intel-gpu-tools-docs.xml @@ -48,6 +48,7 @@ igt/i915 API Reference + diff --git a/lib/Makefile.sources b/lib/Makefile.sources index c33723f9..09c9ef9f 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -3,6 +3,8 @@ lib_source_list = \ drmtest.c \ drmtest.h \ i830_reg.h \ + i915/gem_context.c \ + i915/gem_context.h \ i915/gem_scheduler.c \ i915/gem_scheduler.h \ i915_3d.h \ diff --git a/lib/i915/gem_context.c b/lib/i915/gem_context.c new file mode 100644 index 00000000..ba826ae3 --- /dev/null +++ b/lib/i915/gem_context.c @@ -0,0 +1,199 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + +#include "ioctl_wrappers.h" +#include "drmtest.h" + +#include "i915/gem_context.h" + +/** + * SECTION:gem_context + * @short_description: Helpers for dealing with contexts + * @title: GEM Context + * + * This helper library contains functions used for handling gem contexts. + * Conceptually, gem contexts are similar to their CPU counterparts, in that + * they are a mix of software and hardware features allowing to isolate some + * aspects of task execution. Initially it was just a matter of maintaining + * separate state for each context, but more features were added, some + * improving contexts isolation (per-context address space), some are just + * software features improving submission model (context priority). + */ + +/** + * gem_context_create: + * @fd: open i915 drm file descriptor + * + * This wraps the CONTEXT_CREATE ioctl, which is used to allocate a new + * context. Note that similarly to gem_set_caching() this wrapper skips on + * kernels and platforms where context support is not available. + * + * Returns: The id of the allocated context. + */ +uint32_t gem_context_create(int fd) +{ + struct drm_i915_gem_context_create create; + + memset(&create, 0, sizeof(create)); + if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create)) { + int err = -errno; + igt_skip_on(err == -ENODEV || errno == -EINVAL); + igt_assert_eq(err, 0); + } + igt_assert(create.ctx_id != 0); + errno = 0; + + return create.ctx_id; +} + +int __gem_context_destroy(int fd, uint32_t ctx_id) +{ + struct drm_i915_gem_context_destroy destroy; + int ret; + + memset(&destroy, 0, sizeof(destroy)); + destroy.ctx_id = ctx_id; + + ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); + if (ret) + return -errno; + return 0; +} + +/** + * gem_context_destroy: + * @fd: open i915 drm file descriptor + * @ctx_id: i915 context id + * + * This wraps the CONTEXT_DESTROY ioctl, which is used to free a context. + */ +void gem_context_destroy(int fd, uint32_t ctx_id) +{ + struct drm_i915_gem_context_destroy destroy; + + memset(&destroy, 0, sizeof(destroy)); + destroy.ctx_id = ctx_id; + + do_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); +} + +int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p) +{ +#define LOCAL_I915_GEM_CONTEXT_GETPARAM 0x34 +#define LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_GETPARAM, struct local_i915_gem_context_param) + if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, p)) + return -errno; + + errno = 0; + return 0; +} + +/** + * gem_context_get_param: + * @fd: open i915 drm file descriptor + * @p: i915 context parameter + * + * This wraps the CONTEXT_GET_PARAM ioctl, which is used to get a context + * parameter. + */ +void gem_context_get_param(int fd, struct local_i915_gem_context_param *p) +{ + igt_assert(__gem_context_get_param(fd, p) == 0); +} + + +int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p) +{ +#define LOCAL_I915_GEM_CONTEXT_SETPARAM 0x35 +#define LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_SETPARAM, struct local_i915_gem_context_param) + if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, p)) + return -errno; + + errno = 0; + return 0; +} +/** + * gem_context_set_param: + * @fd: open i915 drm file descriptor + * @p: i915 context parameter + * + * This wraps the CONTEXT_SET_PARAM ioctl, which is used to set a context + * parameter. + */ +void gem_context_set_param(int fd, struct local_i915_gem_context_param *p) +{ + igt_assert(__gem_context_set_param(fd, p) == 0); +} + +/** + * gem_context_require_param: + * @fd: open i915 drm file descriptor + * @param: i915 context parameter + * + * Feature test macro to query whether context parameter support for @param + * is available. Automatically skips through igt_require() if not. + */ +void gem_context_require_param(int fd, uint64_t param) +{ + struct local_i915_gem_context_param p; + + p.context = 0; + p.param = param; + p.value = 0; + p.size = 0; + + igt_require(igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0); +} + +void gem_context_require_bannable(int fd) +{ + static int has_ban_period = -1; + static int has_bannable = -1; + + if (has_bannable < 0) { + struct local_i915_gem_context_param p; + + p.context = 0; + p.param = LOCAL_CONTEXT_PARAM_BANNABLE; + p.value = 0; + p.size = 0; + + has_bannable = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0; + } + + if (has_ban_period < 0) { + struct local_i915_gem_context_param p; + + p.context = 0; + p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; + p.value = 0; + p.size = 0; + + has_ban_period = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0; + } + + igt_require(has_ban_period || has_bannable); +} diff --git a/lib/i915/gem_context.h b/lib/i915/gem_context.h new file mode 100644 index 00000000..06b2ca99 --- /dev/null +++ b/lib/i915/gem_context.h @@ -0,0 +1,48 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef GEM_CONTEXT_H +#define GEM_CONTEXT_H + +uint32_t gem_context_create(int fd); +void gem_context_destroy(int fd, uint32_t ctx_id); +int __gem_context_destroy(int fd, uint32_t ctx_id); +struct local_i915_gem_context_param { + uint32_t context; + uint32_t size; + uint64_t param; +#define LOCAL_CONTEXT_PARAM_BAN_PERIOD 0x1 +#define LOCAL_CONTEXT_PARAM_NO_ZEROMAP 0x2 +#define LOCAL_CONTEXT_PARAM_GTT_SIZE 0x3 +#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4 +#define LOCAL_CONTEXT_PARAM_BANNABLE 0x5 + uint64_t value; +}; +void gem_context_require_bannable(int fd); +void gem_context_require_param(int fd, uint64_t param); +void gem_context_get_param(int fd, struct local_i915_gem_context_param *p); +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); + +#endif /* GEM_CONTEXT_H */ diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index 87511fc6..7ad2b7b0 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -894,161 +894,6 @@ int gem_madvise(int fd, uint32_t handle, int state) return madv.retained; } -/** - * gem_context_create: - * @fd: open i915 drm file descriptor - * - * This wraps the CONTEXT_CREATE ioctl, which is used to allocate a new - * context. Note that similarly to gem_set_caching() this wrapper skips on - * kernels and platforms where context support is not available. - * - * Returns: The id of the allocated context. - */ -uint32_t gem_context_create(int fd) -{ - struct drm_i915_gem_context_create create; - - memset(&create, 0, sizeof(create)); - if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create)) { - int err = -errno; - igt_skip_on(err == -ENODEV || errno == -EINVAL); - igt_assert_eq(err, 0); - } - igt_assert(create.ctx_id != 0); - errno = 0; - - return create.ctx_id; -} - -int __gem_context_destroy(int fd, uint32_t ctx_id) -{ - struct drm_i915_gem_context_destroy destroy; - int ret; - - memset(&destroy, 0, sizeof(destroy)); - destroy.ctx_id = ctx_id; - - ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); - if (ret) - return -errno; - return 0; -} - -/** - * gem_context_destroy: - * @fd: open i915 drm file descriptor - * @ctx_id: i915 context id - * - * This wraps the CONTEXT_DESTROY ioctl, which is used to free a context. - */ -void gem_context_destroy(int fd, uint32_t ctx_id) -{ - struct drm_i915_gem_context_destroy destroy; - - memset(&destroy, 0, sizeof(destroy)); - destroy.ctx_id = ctx_id; - - do_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy); -} - -int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p) -{ -#define LOCAL_I915_GEM_CONTEXT_GETPARAM 0x34 -#define LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_GETPARAM, struct local_i915_gem_context_param) - if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, p)) - return -errno; - - errno = 0; - return 0; -} - -/** - * gem_context_get_param: - * @fd: open i915 drm file descriptor - * @p: i915 context parameter - * - * This wraps the CONTEXT_GET_PARAM ioctl, which is used to get a context - * parameter. - */ -void gem_context_get_param(int fd, struct local_i915_gem_context_param *p) -{ - igt_assert(__gem_context_get_param(fd, p) == 0); -} - - -int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p) -{ -#define LOCAL_I915_GEM_CONTEXT_SETPARAM 0x35 -#define LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_SETPARAM, struct local_i915_gem_context_param) - if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, p)) - return -errno; - - errno = 0; - return 0; -} -/** - * gem_context_set_param: - * @fd: open i915 drm file descriptor - * @p: i915 context parameter - * - * This wraps the CONTEXT_SET_PARAM ioctl, which is used to set a context - * parameter. - */ -void gem_context_set_param(int fd, struct local_i915_gem_context_param *p) -{ - igt_assert(__gem_context_set_param(fd, p) == 0); -} - -/** - * gem_context_require_param: - * @fd: open i915 drm file descriptor - * @param: i915 context parameter - * - * Feature test macro to query whether context parameter support for @param - * is available. Automatically skips through igt_require() if not. - */ -void gem_context_require_param(int fd, uint64_t param) -{ - struct local_i915_gem_context_param p; - - p.context = 0; - p.param = param; - p.value = 0; - p.size = 0; - - igt_require(igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0); -} - -void gem_context_require_bannable(int fd) -{ - static int has_ban_period = -1; - static int has_bannable = -1; - - if (has_bannable < 0) { - struct local_i915_gem_context_param p; - - p.context = 0; - p.param = LOCAL_CONTEXT_PARAM_BANNABLE; - p.value = 0; - p.size = 0; - - has_bannable = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0; - } - - if (has_ban_period < 0) { - struct local_i915_gem_context_param p; - - p.context = 0; - p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD; - p.value = 0; - p.size = 0; - - has_ban_period = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0; - } - - igt_require(has_ban_period || has_bannable); -} - int __gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle) { struct local_i915_gem_userptr userptr; @@ -1455,7 +1300,7 @@ uint64_t gem_aperture_size(int fd) memset(&p, 0, sizeof(p)); p.param = 0x3; - if (ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0) { + if (__gem_context_get_param(fd, &p) == 0) { aperture_size = p.value; } else { struct drm_i915_gem_get_aperture aperture; diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index 76a4e80d..f7752aea 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -36,6 +36,7 @@ #include #include +#include "i915/gem_context.h" #include "i915/gem_scheduler.h" /** @@ -121,27 +122,6 @@ int gem_munmap(void *ptr, uint64_t size); int gem_madvise(int fd, uint32_t handle, int state); -uint32_t gem_context_create(int fd); -void gem_context_destroy(int fd, uint32_t ctx_id); -int __gem_context_destroy(int fd, uint32_t ctx_id); -struct local_i915_gem_context_param { - uint32_t context; - uint32_t size; - uint64_t param; -#define LOCAL_CONTEXT_PARAM_BAN_PERIOD 0x1 -#define LOCAL_CONTEXT_PARAM_NO_ZEROMAP 0x2 -#define LOCAL_CONTEXT_PARAM_GTT_SIZE 0x3 -#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4 -#define LOCAL_CONTEXT_PARAM_BANNABLE 0x5 - uint64_t value; -}; -void gem_context_require_bannable(int fd); -void gem_context_require_param(int fd, uint64_t param); -void gem_context_get_param(int fd, struct local_i915_gem_context_param *p); -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_GEM_USERPTR 0x33 #define LOCAL_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_USERPTR, struct local_i915_gem_userptr) struct local_i915_gem_userptr { diff --git a/lib/meson.build b/lib/meson.build index 22811743..f0125a6d 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -2,6 +2,7 @@ lib_headers = [ 'debug.h', 'drmtest.h', 'i830_reg.h', + 'i915/gem_context.h', 'i915/gem_scheduler.h', 'i915_3d.h', 'i915_reg.h', @@ -49,6 +50,7 @@ lib_headers = [ lib_sources = [ 'drmtest.c', + 'i915/gem_context.c', 'i915/gem_scheduler.c', 'igt_debugfs.c', 'igt_aux.c',