From patchwork Wed Oct 11 09:15:25 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: 9999103 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 E5A4E60244 for ; Wed, 11 Oct 2017 09:16:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D903F28979 for ; Wed, 11 Oct 2017 09:16:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDAFA2897E; Wed, 11 Oct 2017 09:16:18 +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 C1F8928979 for ; Wed, 11 Oct 2017 09:16:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1439C6E5F9; Wed, 11 Oct 2017 09:16:16 +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 C9FB76E5E5 for ; Wed, 11 Oct 2017 09:16:14 +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:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.43,360,1503385200"; d="scan'208"; a="1180844005" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by orsmga001.jf.intel.com with ESMTP; 11 Oct 2017 02:16:14 -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:08 +0100 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: Date: Wed, 11 Oct 2017 11:15:25 +0200 Message-ID: <20171011091526.9342-2-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 2/3] lib: Extract helpers for determining scheduler capabilities 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 Couple of tests are using either determining scheduler capabilities or pretty printing. Let's move those to helpers in lib. We can also keep the value obtained from getparam static. Signed-off-by: MichaƂ Winiarski Cc: Arkadiusz Hiler Cc: Chris Wilson Cc: Katarzyna Dec Cc: Petri Latvala --- lib/igt_aux.c | 14 ++++++++++ lib/igt_aux.h | 1 + lib/ioctl_wrappers.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ lib/ioctl_wrappers.h | 8 ++++++ tests/gem_exec_nop.c | 34 +++---------------------- tests/gem_exec_schedule.c | 47 +++++----------------------------- tests/gem_exec_whisper.c | 22 ++-------------- tests/gem_sync.c | 34 +++---------------------- 8 files changed, 103 insertions(+), 122 deletions(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 0c77f85f..80ce9624 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -1473,6 +1473,20 @@ void igt_show_submission_method(int fd) flags & GEM_SUBMISSION_SEMAPHORES ? ", with semaphores" : ""); } +void igt_show_scheduler_capability(int fd) +{ + unsigned caps = gem_scheduler_capability(fd); + + if (!caps) + return; + + igt_info("Has kernel scheduler\n"); + if (caps & LOCAL_I915_SCHEDULER_CAP_PRIORITY) + igt_info(" - With priority sorting\n"); + if (caps & LOCAL_I915_SCHEDULER_CAP_PREEMPTION) + igt_info(" - With preemption enabled\n"); +} + static void __igt_lsof_fds(proc_t *proc_info, int *state, char *proc_path, const char *dir) { diff --git a/lib/igt_aux.h b/lib/igt_aux.h index b79c8e5c..36b435ba 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -279,6 +279,7 @@ void igt_unlock_mem(void); }) void igt_show_submission_method(int fd); +void igt_show_scheduler_capability(int fd); struct igt_mean; void igt_start_siglatency(int sig); /* 0 => SIGRTMIN (default) */ diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c index 87511fc6..b9f81d1b 100644 --- a/lib/ioctl_wrappers.c +++ b/lib/ioctl_wrappers.c @@ -1668,6 +1668,71 @@ void gem_require_mocs_registers(int fd) igt_require(gem_has_mocs_registers(fd)); } +#define LOCAL_I915_PARAM_HAS_SCHEDULER 41 + +/** + * gem_scheduler_capability: + * @fd: open i915 drm file descriptor + * + * Returns: Scheduler capability bitmap. + */ +unsigned gem_scheduler_capability(int fd) +{ + static int caps = -1; + + if (caps < 0) { + struct drm_i915_getparam gp; + + memset(&gp, 0, sizeof(gp)); + gp.param = LOCAL_I915_PARAM_HAS_SCHEDULER; + gp.value = ∩︀ + + caps = 0; + ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)); + errno = 0; + } + + return caps; +} + +/** + * gem_has_scheduler: + * @fd: open i915 drm file descriptor + * + * Feature test macro to query whether the driver has scheduling capability. + */ +bool gem_has_scheduler(int fd) +{ + return gem_scheduler_capability(fd) & + LOCAL_I915_SCHEDULER_CAP_ENABLED; +} + +/** + * gem_has_ctx_priority: + * @fd: open i915 drm file descriptor + * + * Feature test macro to query whether the driver supports assigning custom + * priorities to contexts from userspace. + */ +bool gem_has_ctx_priority(int fd) +{ + return gem_scheduler_capability(fd) & + LOCAL_I915_SCHEDULER_CAP_PRIORITY; +} + +/** + * gem_has_preemption: + * @fd: open i915 drm file descriptor + * + * Feature test macro to query whether the driver supports preempting active + * (currently executing on HW) workloads. + */ +bool gem_has_preemption(int fd) +{ + return gem_scheduler_capability(fd) & + LOCAL_I915_SCHEDULER_CAP_PREEMPTION; +} + /* prime */ /** diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index 1663b7f8..3531c478 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -187,6 +187,14 @@ void gem_require_ring(int fd, unsigned ring); bool gem_has_mocs_registers(int fd); void gem_require_mocs_registers(int fd); +#define LOCAL_I915_SCHEDULER_CAP_ENABLED (1 << 0) +#define LOCAL_I915_SCHEDULER_CAP_PRIORITY (1 << 1) +#define LOCAL_I915_SCHEDULER_CAP_PREEMPTION (1 << 2) +unsigned gem_scheduler_capability(int fd); +bool gem_has_scheduler(int fd); +bool gem_has_ctx_priority(int fd); +bool gem_has_preemption(int fd); + /* prime */ struct local_dma_buf_sync { uint64_t flags; diff --git a/tests/gem_exec_nop.c b/tests/gem_exec_nop.c index 6d62e94a..e7e9df2d 100644 --- a/tests/gem_exec_nop.c +++ b/tests/gem_exec_nop.c @@ -44,8 +44,6 @@ #include #include "drm.h" -#define BIT(x) (1ul << (x)) - #define LOCAL_I915_EXEC_NO_RELOC (1<<11) #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) @@ -54,10 +52,6 @@ #define ENGINE_FLAGS (I915_EXEC_RING_MASK | LOCAL_I915_EXEC_BSD_MASK) -#define LOCAL_PARAM_HAS_SCHEDULER 41 -#define HAS_SCHEDULER BIT(0) -#define HAS_PRIORITY BIT(1) -#define HAS_PREEMPTION BIT(2) #define LOCAL_CONTEXT_PARAM_PRIORITY 6 #define MAX_PRIO 1023 #define MIN_PRIO -1023 @@ -665,31 +659,9 @@ static void preempt(int fd, uint32_t handle, ring_name, count, elapsed(&start, &now)*1e6 / count); } -static unsigned int has_scheduler(int fd) -{ - drm_i915_getparam_t gp; - unsigned int caps = 0; - - gp.param = LOCAL_PARAM_HAS_SCHEDULER; - gp.value = (int *)∩︀ - drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp); - - if (!caps) - return 0; - - igt_info("Has kernel scheduler\n"); - if (caps & HAS_PRIORITY) - igt_info(" - With priority sorting\n"); - if (caps & HAS_PREEMPTION) - igt_info(" - With preemption enabled\n"); - - return caps; -} - igt_main { const struct intel_execution_engine *e; - unsigned int sched_caps = 0; uint32_t handle = 0; int device = -1; @@ -699,7 +671,7 @@ igt_main device = drm_open_driver(DRIVER_INTEL); igt_require_gem(device); igt_show_submission_method(device); - sched_caps = has_scheduler(device); + igt_show_scheduler_capability(device); handle = gem_create(device, 4096); gem_write(device, handle, 0, &bbe, sizeof(bbe)); @@ -746,8 +718,8 @@ igt_main igt_subtest_group { igt_fixture { - igt_require(sched_caps & HAS_PRIORITY); - igt_require(sched_caps & HAS_PREEMPTION); + igt_require(gem_has_ctx_priority(device)); + igt_require(gem_has_preemption(device)); } for (e = intel_execution_engines; e->name; e++) { diff --git a/tests/gem_exec_schedule.c b/tests/gem_exec_schedule.c index b65482ce..8dda7984 100644 --- a/tests/gem_exec_schedule.c +++ b/tests/gem_exec_schedule.c @@ -33,12 +33,6 @@ #include "igt_rand.h" #include "igt_sysfs.h" -#define BIT(x) (1ul << (x)) - -#define LOCAL_PARAM_HAS_SCHEDULER 41 -#define HAS_SCHEDULER BIT(0) -#define HAS_PRIORITY BIT(1) -#define HAS_PREEMPTION BIT(2) #define LOCAL_CONTEXT_PARAM_PRIORITY 6 #define LO 0 @@ -70,11 +64,6 @@ static void ctx_set_priority(int fd, uint32_t ctx, int prio) igt_assert_eq(__ctx_set_priority(fd, ctx, prio), 0); } -static void ctx_has_priority(int fd) -{ - igt_require(__ctx_set_priority(fd, 0, MAX_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) @@ -979,31 +968,9 @@ static void test_pi_ringfull(int fd, unsigned int engine) munmap(result, 4096); } -static unsigned int has_scheduler(int fd) -{ - drm_i915_getparam_t gp; - unsigned int caps = 0; - - gp.param = LOCAL_PARAM_HAS_SCHEDULER; - gp.value = (int *)∩︀ - drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp); - - if (!caps) - return 0; - - igt_info("Has kernel scheduler\n"); - if (caps & HAS_PRIORITY) - igt_info(" - With priority sorting\n"); - if (caps & HAS_PREEMPTION) - igt_info(" - With preemption enabled\n"); - - return caps; -} - igt_main { const struct intel_execution_engine *e; - unsigned int sched_caps = 0; int fd = -1; igt_skip_on_simulation(); @@ -1011,7 +978,7 @@ igt_main igt_fixture { fd = drm_open_driver_master(DRIVER_INTEL); igt_show_submission_method(fd); - sched_caps = has_scheduler(fd); + igt_show_scheduler_capability(fd); igt_require_gem(fd); gem_require_mmap_wc(fd); igt_fork_hang_detector(fd); @@ -1033,8 +1000,8 @@ igt_main igt_subtest_group { igt_fixture { - igt_require(sched_caps & HAS_SCHEDULER); - ctx_has_priority(fd); + igt_require(gem_has_scheduler(fd)); + igt_require(gem_has_ctx_priority(fd)); } igt_subtest("smoketest-all") @@ -1062,7 +1029,7 @@ igt_main igt_subtest_group { igt_fixture { - igt_require(sched_caps & HAS_PREEMPTION); + igt_require(gem_has_preemption(fd)); } igt_subtest_f("preempt-%s", e->name) @@ -1095,8 +1062,8 @@ igt_main igt_subtest_group { igt_fixture { - igt_require(sched_caps & HAS_SCHEDULER); - ctx_has_priority(fd); + igt_require(gem_has_scheduler(fd)); + igt_require(gem_has_ctx_priority(fd)); /* need separate rings */ igt_require(gem_has_execlists(fd)); @@ -1106,7 +1073,7 @@ igt_main igt_subtest_group { igt_fixture { gem_require_ring(fd, e->exec_id | e->flags); - igt_require(sched_caps & HAS_PREEMPTION); + igt_require(gem_has_preemption(fd)); } igt_subtest_f("pi-ringfull-%s", e->name) diff --git a/tests/gem_exec_whisper.c b/tests/gem_exec_whisper.c index 2707171a..80204cee 100644 --- a/tests/gem_exec_whisper.c +++ b/tests/gem_exec_whisper.c @@ -191,21 +191,8 @@ static void fini_hang(struct hang *h) close(h->fd); } -#define LOCAL_PARAM_HAS_SCHEDULER 41 #define LOCAL_CONTEXT_PARAM_PRIORITY 6 -static bool __has_scheduler(int fd) -{ - drm_i915_getparam_t gp; - int has = -1; - - gp.param = LOCAL_PARAM_HAS_SCHEDULER; - gp.value = &has; - drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp); - - return has > 0; -} - static int __ctx_set_priority(int fd, uint32_t ctx, int prio) { struct local_i915_gem_context_param param; @@ -250,13 +237,8 @@ static void whisper(int fd, unsigned engine, unsigned flags) int debugfs; if (flags & PRIORITY) { - int __fd = drm_open_driver(DRIVER_INTEL); - bool has_scheduler = __has_scheduler(__fd); - bool ctx_has_priority = - __ctx_set_priority(__fd, 0, 1) == 0; - close(__fd); - - igt_require(has_scheduler && ctx_has_priority); + igt_require(gem_has_scheduler(fd)); + igt_require(gem_has_ctx_priority(fd)); } debugfs = igt_debugfs_dir(fd); diff --git a/tests/gem_sync.c b/tests/gem_sync.c index 754c3202..e0b53905 100644 --- a/tests/gem_sync.c +++ b/tests/gem_sync.c @@ -27,18 +27,12 @@ #include "igt.h" #include "igt_sysfs.h" -#define BIT(x) (1ul << (x)) - #define LOCAL_I915_EXEC_NO_RELOC (1<<11) #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) #define LOCAL_I915_EXEC_BSD_SHIFT (13) #define LOCAL_I915_EXEC_BSD_MASK (3 << LOCAL_I915_EXEC_BSD_SHIFT) -#define LOCAL_PARAM_HAS_SCHEDULER 41 -#define HAS_SCHEDULER BIT(0) -#define HAS_PRIORITY BIT(1) -#define HAS_PREEMPTION BIT(2) #define LOCAL_CONTEXT_PARAM_PRIORITY 6 #define MAX_PRIO 1023 #define MIN_PRIO -1023 @@ -807,32 +801,10 @@ preempt(int fd, unsigned ring, int num_children, int timeout) gem_context_destroy(fd, ctx[0]); } -static unsigned int has_scheduler(int fd) -{ - drm_i915_getparam_t gp; - unsigned int caps = 0; - - gp.param = LOCAL_PARAM_HAS_SCHEDULER; - gp.value = (int *)∩︀ - drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp); - - if (!caps) - return 0; - - igt_info("Has kernel scheduler\n"); - if (caps & HAS_PRIORITY) - igt_info(" - With priority sorting\n"); - if (caps & HAS_PREEMPTION) - igt_info(" - With preemption enabled\n"); - - return caps; -} - igt_main { const struct intel_execution_engine *e; const int ncpus = sysconf(_SC_NPROCESSORS_ONLN); - unsigned int sched_caps = 0; int fd = -1; igt_skip_on_simulation(); @@ -841,7 +813,7 @@ igt_main fd = drm_open_driver(DRIVER_INTEL); igt_require_gem(fd); igt_show_submission_method(fd); - sched_caps = has_scheduler(fd); + igt_show_scheduler_capability(fd); igt_fork_hang_detector(fd); } @@ -886,8 +858,8 @@ igt_main igt_subtest_group { igt_fixture { - igt_require(sched_caps & HAS_PRIORITY); - igt_require(sched_caps & HAS_PREEMPTION); + igt_require(gem_has_ctx_priority(fd)); + igt_require(gem_has_preemption(fd)); } igt_subtest("preempt-all")