From patchwork Tue Oct 15 20:51:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Vivi X-Patchwork-Id: 3049191 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B749FBF924 for ; Tue, 15 Oct 2013 23:09:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A5CE6201B6 for ; Tue, 15 Oct 2013 23:09:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6CF57201BD for ; Tue, 15 Oct 2013 23:09:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E4BCE638E for ; Tue, 15 Oct 2013 16:09:50 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by gabe.freedesktop.org (Postfix) with ESMTP id C5003E6F14 for ; Tue, 15 Oct 2013 13:51:39 -0700 (PDT) Received: by mail-pa0-f42.google.com with SMTP id kx10so1495857pab.15 for ; Tue, 15 Oct 2013 13:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=x57HMLrdmGH3Y149/pIRNR6ua6jNJQpd7PUrqvW7cAY=; b=vxrt1r/uJPljUkR4gK9hNiQJM5ubTzN6EcPwlawRyn1g0Q5DkMYJ6ZWovo/Uqhf4tp BP5DUOdE93Kub1vRx6JLtrFFPUBKrD0g7EUYXQxJlyfrt11Q165XtnFkKVgBYYvP1sh8 CX8wQJcUb0pboLDz9KKWm9AHuCfovpJ46OAlPvbfhPGB5OIX4eYVXogMXoLgrX+eIW3t G/s/e3ajnQ7WRoJU8Hp9grC0ADt/SXrknrMIWKdY7+li6669SfGgdNi9CHFuJZRxymNZ SmFI9xcuq7+R7cLXIiJdit829fGFpVhjvxvPmmQOxDCQVGGNATb5NukfJbD41EgxT2aO gGHQ== X-Received: by 10.66.142.42 with SMTP id rt10mr44605220pab.1.1381870299616; Tue, 15 Oct 2013 13:51:39 -0700 (PDT) Received: from localhost (jfdmzpr06-ext.jf.intel.com. [134.134.137.75]) by mx.google.com with ESMTPSA id ok2sm18742449pbb.24.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 15 Oct 2013 13:51:39 -0700 (PDT) From: Rodrigo Vivi To: intel-gfx@lists.freedesktop.org Date: Tue, 15 Oct 2013 17:51:31 -0300 Message-Id: <1381870291-30674-1-git-send-email-rodrigo.vivi@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1381848067-5269-3-git-send-email-rodrigo.vivi@gmail.com> References: <1381848067-5269-3-git-send-email-rodrigo.vivi@gmail.com> MIME-Version: 1.0 Subject: [Intel-gfx] =?utf-8?q?=5BPATCH=5D_testcases=3A_Slice_Shutdown_tes?= =?utf-8?q?tscases=2E?= X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1. sysfs half/full switch. 2. on full execbuf without I915_EXEC_USE_PREDICATE 3. on full execbuf with I915_EXEC_USE_PREDICATE 4. on half execbuf without I915_EXEC_USE_PREDICATE 5. on half execbuf with I915_EXEC_USE_PREDICATE v2: include more tests and s/GT_FULL/USE_PREDICATE Signed-off-by: Rodrigo Vivi --- tests/Makefile.am | 1 + tests/gt_slice_config.c | 325 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 326 insertions(+) create mode 100644 tests/gt_slice_config.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 0290ae0..cf105e4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -50,6 +50,7 @@ TESTS_progs_M = \ gem_tiled_blits \ gem_tiled_partial_pwrite_pread \ gem_write_read_ring_switch \ + gt_slice_config \ kms_flip \ kms_render \ kms_setmode \ diff --git a/tests/gt_slice_config.c b/tests/gt_slice_config.c new file mode 100644 index 0000000..7b9f554 --- /dev/null +++ b/tests/gt_slice_config.c @@ -0,0 +1,325 @@ +/* + * Copyright © 2013 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. + * + * Authors: + * Rodrigo Vivi + * + */ + +/* + * Testcase: Test GT slice shutdown feature + * + * Sub tests: + * 1. sysfs half/full switch. + * 2. on full execbuf without I915_EXEC_USE_PREDICATE + * 3. on full execbuf with I915_EXEC_USE_PREDICATE + * 4. on half execbuf without I915_EXEC_USE_PREDICATE + * 5. on half execbuf with I915_EXEC_USE_PREDICATE + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include "drmtest.h" + +static void exec(int fd, uint32_t handle, bool use_predicate) +{ + struct drm_i915_gem_execbuffer2 execbuf; + struct drm_i915_gem_exec_object2 gem_exec[1]; + uint32_t b[2] = {MI_BATCH_BUFFER_END}; + int loops = 2000000; + int ret = 0; + + gem_write(fd, handle, 0, b, sizeof(b)); + + gem_exec[0].handle = handle; + gem_exec[0].relocation_count = 0; + gem_exec[0].relocs_ptr = 0; + gem_exec[0].alignment = 0; + gem_exec[0].offset = 0; + gem_exec[0].flags = 0; + gem_exec[0].rsvd1 = 0; + gem_exec[0].rsvd2 = 0; + + execbuf.buffers_ptr = (uintptr_t)gem_exec; + execbuf.buffer_count = 1; + execbuf.batch_start_offset = 0; + execbuf.batch_len = 8; + execbuf.cliprects_ptr = 0; + execbuf.num_cliprects = 0; + execbuf.DR1 = 0; + execbuf.DR4 = 0; + execbuf.flags = I915_EXEC_RENDER; + if (use_predicate) + execbuf.flags |= I915_EXEC_USE_PREDICATE; + i915_execbuffer2_set_context_id(execbuf, 0); + execbuf.rsvd2 = 0; + + while (loops-- && ret == 0) { + ret = drmIoctl(fd, + DRM_IOCTL_I915_GEM_EXECBUFFER2, + &execbuf); + } + gem_sync(fd, handle); +} + +static bool is_full(const int device) +{ + char *path; + FILE *file; + int ret; + char str[5]; + + ret = asprintf(&path, "/sys/class/drm/card%d/power/gt_slice_config", + device); + igt_assert(ret != -1); + + file = fopen(path, "r"); + igt_require(file); + + ret = fscanf(file, "%s", str); + igt_assert(ret != 0); + + fclose(file); + return strcmp(str, "half"); +} + +static int set_status(const int device, bool full) +{ + char *path; + FILE *file; + int ret; + char str[5]; + int attempts = 10; + + ret = asprintf(&path, "/sys/class/drm/card%d/power/gt_slice_config", + device); + igt_assert(ret != -1); + + file = fopen(path, "r"); + igt_require(file); + + ret = fscanf(file, "%s", str); + igt_assert(ret != 0); + + fclose(file); + + if (full == strcmp(str, "half")) + return 0; + + while (attempts-- && ret != 0) { + file = fopen(path, "w"); + igt_require(file); + ret = fprintf(file, "%s\n", full ? "full": "half"); + igt_assert(ret != -1); + ret = fclose(file); + sleep(1); + } + return ret; +} + +int main(int argc, char **argv) +{ + char *path; + FILE *file; + unsigned int rc6_enabled; + int ret; + uint32_t handle; + const int device = drm_get_card(); + const int fd = drm_open_any(); + const int devid = intel_get_drm_devid(fd); + bool initial = is_full(device); + + igt_skip_on_simulation(); + + igt_subtest_init(argc, argv); + + igt_fixture { + /* On Haswell Slices on/off switch depends on RC6 exit */ + ret = asprintf(&path, "/sys/class/drm/card%d/power/rc6_enable", + device); + igt_assert(ret != -1); + + file = fopen(path, "r"); + igt_require(file); + + fscanf(file, "%u", &rc6_enabled); + fclose(file); + + igt_require(IS_HASWELL(devid)); + igt_require(rc6_enabled); + } + + igt_subtest("sysfs") { + /* Switching states */ + ret = set_status(device, !initial); + if (ret < 0) + igt_fail(ret); + + /* Check if state has really changed */ + if (initial == is_full(device)) { + fprintf(stderr, + "gt_slice_config status hasn't changed\n"); + igt_fail(-1); + } + igt_success(); + } + + igt_subtest("execbuf-full") { + /* Enable all slices */ + ret = set_status(device, true); + if (ret < 0) + igt_fail(ret); + + igt_fork(child, 1) { + /* Start Render with I915_EXEC_USE_PREDICATE */ + handle = gem_create(fd, 4096); + exec(fd, handle, false); + gem_close(fd, handle); + } + + sleep(1); + if (!is_full(device)) { + fprintf(stderr, "All slices should be enabled\n"); + igt_fail(-1); + } + + /* Wait for idleness */ + igt_waitchildren(); + sleep(3); + + /* Check if it is back to half */ + if (!is_full(device)) { + fprintf(stderr, "All slices should be enabled\n"); + igt_fail(-1); + } + + igt_success(); + } + + igt_subtest("execbuf-full-predicate") { + /* Enable all slices */ + ret = set_status(device, true); + if (ret < 0) + igt_fail(ret); + + igt_fork(child, 1) { + /* Start Render with I915_EXEC_USE_PREDICATE */ + handle = gem_create(fd, 4096); + exec(fd, handle, true); + gem_close(fd, handle); + } + + sleep(1); + if (!is_full(device)) { + fprintf(stderr, "All slices should be enabled\n"); + igt_fail(-1); + } + + /* Wait for idleness */ + igt_waitchildren(); + sleep(3); + + /* Check if it is back to half */ + if (!is_full(device)) { + fprintf(stderr, "Only half slices should be enabled\n"); + igt_fail(-1); + } + + igt_success(); + } + + igt_subtest("execbuf-half") { + /* Disable half slices */ + ret = set_status(device, false); + if (ret < 0) + igt_fail(ret); + + igt_fork(child, 1) { + /* Start Render with I915_EXEC_USE_PREDICATE */ + handle = gem_create(fd, 4096); + exec(fd, handle, true); + gem_close(fd, handle); + } + + /* Check if it stays with only half slices enabled */ + sleep(1); + if (is_full(device)) { + fprintf(stderr, "Only half slices should be enabled during execution with predicate\n"); + igt_fail(-1); + } + + /* Wait for idleness */ + igt_waitchildren(); + sleep(3); + + /* Check if it is still half */ + if (is_full(device)) { + fprintf(stderr, "Only half slices should be enabled\n"); + igt_fail(-1); + } + igt_success(); + } + + igt_subtest("execbuf-half-predicate") { + /* Disable half slices */ + ret = set_status(device, false); + if (ret < 0) + igt_fail(ret); + + igt_fork(child, 1) { + /* Start Render with I915_EXEC_USE_PREDICATE*/ + handle = gem_create(fd, 4096); + exec(fd, handle, true); + gem_close(fd, handle); + } + + /* Check if it stays with only half slices enabled */ + sleep(1); + if (is_full(device)) { + fprintf(stderr, "Only half slices should be enabled during execution with predicate\n"); + set_status(device, initial); + igt_fail(-1); + } + + /* Wait for idleness */ + igt_waitchildren(); + sleep(3); + + /* Check if it is still half */ + if (is_full(device)) { + fprintf(stderr, "Only half slices should be enabled\n"); + set_status(device, initial); + igt_fail(-1); + } + set_status(device, initial); + igt_success(); + } + + igt_fixture { + close(fd); + } + + igt_exit(); +}