From patchwork Wed Nov 6 15:29:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rodrigo Vivi X-Patchwork-Id: 3147981 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 267229F3C4 for ; Wed, 6 Nov 2013 15:30:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85BF320588 for ; Wed, 6 Nov 2013 15:30:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id BB6D820586 for ; Wed, 6 Nov 2013 15:30:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3562BF049B; Wed, 6 Nov 2013 07:30:20 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com [209.85.216.181]) by gabe.freedesktop.org (Postfix) with ESMTP id 834B2F0492 for ; Wed, 6 Nov 2013 07:30:05 -0800 (PST) Received: by mail-qc0-f181.google.com with SMTP id w4so5924591qcr.40 for ; Wed, 06 Nov 2013 07:30:04 -0800 (PST) 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=2xMYxj9lOGMhK3o0XbIeQRw67SfFfsJ7zx5YVDQAYDE=; b=Gf887J31gk0gK5kjHCz2b7Tgr9UgjG9qksYUA1ChUD0bnKbf0T5iYZs57UYmStuHNz 85a/D7cMsOFUuHm3JOlzDLweRXkJIDXAEAbG2rzQVBf9EaZBSIql+WsMghcCDyAb1Nq1 Mdql8X2uorYQIuokpuiZZciSTuW9eJs7kBRO+EUwX6qOtjEzNnpqhfhaomXDZxIqqFIK m887frj4kgsI3T/yFJrEmAgjgAGhSVj+4BYXuIOYrhRL5YPozDi+He2LAs1EuqiYWsOs IasZzT3jagChajPGVQSJySt6N3UVRie3F1/rM0fqk0XTN5O3fWafrUAsBwhzO9bcRJzG Jp9g== X-Received: by 10.236.83.69 with SMTP id p45mr2510873yhe.40.1383751803953; Wed, 06 Nov 2013 07:30:03 -0800 (PST) Received: from localhost.localdomain ([177.140.135.10]) by mx.google.com with ESMTPSA id s4sm45479464yhs.14.2013.11.06.07.30.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 06 Nov 2013 07:30:03 -0800 (PST) From: Rodrigo Vivi To: intel-gfx@lists.freedesktop.org Date: Wed, 6 Nov 2013 13:29:43 -0200 Message-Id: <1383751783-3961-1-git-send-email-rodrigo.vivi@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <20131106072239.GF1775@phenom.ffwll.local> References: <20131106072239.GF1775@phenom.ffwll.local> 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@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.1 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. 4. execbuf without I915_EXEC_USE_PREDICATE 5. execbuf with I915_EXEC_USE_PREDICATE v2: include more tests and s/GT_FULL/USE_PREDICATE v3: make it more reliable and fix few comments v4: use number of slices on (1,2) instead of half and full strings. v5: respect new naming convention Signed-off-by: Rodrigo Vivi --- tests/Makefile.am | 1 + tests/pm_gt_slices.c | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 tests/pm_gt_slices.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 0426ec0..e114bdf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -57,6 +57,7 @@ TESTS_progs_M = \ kms_render \ kms_setmode \ $(NOUVEAU_TESTS_M) \ + pm_gt_slices \ pm_pc8 \ prime_self_import \ template \ diff --git a/tests/pm_gt_slices.c b/tests/pm_gt_slices.c new file mode 100644 index 0000000..8388aca --- /dev/null +++ b/tests/pm_gt_slices.c @@ -0,0 +1,268 @@ +/* + * 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. + * 4. on execbuf without I915_EXEC_USE_PREDICATE + * 5. on 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 = 1000000; + 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 int slices_on(const int device) +{ + char *path; + FILE *file; + int ret; + int slices; + + ret = asprintf(&path, "/sys/class/drm/card%d/power/gt_slices", + device); + igt_assert(ret != -1); + + file = fopen(path, "r"); + igt_require(file); + + ret = fscanf(file, "%d", &slices); + igt_assert(ret != 0); + + fclose(file); + return slices; +} + +static int set_status(const int device, int slices) +{ + char *path; + FILE *file; + int ret; + int attempts = 10; + + ret = asprintf(&path, "/sys/class/drm/card%d/power/gt_slices", + device); + igt_assert(ret != -1); + + while (attempts-- && ret != 0) { + file = fopen(path, "w"); + igt_require(file); + ret = fprintf(file, "%d\n", slices); + 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 i, ret; + uint32_t handle; + const int device = drm_get_card(); + const int fd = drm_open_any(); + const int devid = intel_get_drm_devid(fd); + int initial = slices_on(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 */ + if (initial == 1) + ret = set_status(device, 2); + else + ret = set_status(device, 1); + if (ret < 0) { + fprintf(stderr, "Switch states via sysfs failed\n"); + igt_fail(ret); + } + + igt_success(); + } + + igt_subtest("execbuf-legacy") { + /* Disable half slices */ + ret = set_status(device, 1); + if (ret < 0) + igt_fail(ret); + + /* Wait until it is back to half */ + for (i = 30; i >= 0 && slices_on(device) == 2; i--) { + if (i == 0) + igt_skip("Took so long to go to half. Probably a legacy support is in use at GPU simutaneously\n"); + sleep(1); + } + + igt_fork(child, 1) { + /* Start Render without I915_EXEC_USE_PREDICATE */ + handle = gem_create(fd, 4096); + exec(fd, handle, false); + gem_close(fd, handle); + } + + /* Check if it forces full slices enable for legacy support */ + for (i = 10; i >= 0 && slices_on(device) == 1; i--) { + if (i == 0) { + fprintf(stderr, "2 slices should be enabled\n"); + igt_fail(-1); + } + sleep(1); + } + + /* Wait for idleness */ + igt_waitchildren(); + + /* Check if it is back to half */ + for (i = 20; i >= 0 && slices_on(device) == 2; i--) { + if (i == 0) { + fprintf(stderr, "Only 1 slice should be enabled\n"); + igt_fail(-1); + } + sleep(1); + } + + igt_success(); + } + + igt_subtest("execbuf-predicate") { + /* Disable half slices */ + ret = set_status(device, 1); + if (ret < 0) + igt_fail(ret); + + /* Wait until it is back to half */ + for (i = 30; i >= 0 && slices_on(device) == 2; i--) { + if (i == 0) + igt_skip("Took so long to go to half. Probably a legacy support is in use at GPU simutaneously\n"); + sleep(1); + } + + 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 (slices_on(device) == 2) { + fprintf(stderr, "Only 1 slice should be enabled during execution with predicate\n"); + set_status(device, initial); + igt_fail(-1); + } + + /* Wait for idleness */ + igt_waitchildren(); + + /* Check if it is back to half */ + for (i = 20; i >= 0 && slices_on(device) == 2; i--) { + if (i == 0) { + fprintf(stderr, "Only 1 slice should be enabled\n"); + set_status(device, initial); + igt_fail(-1); + } + sleep(1); + } + + set_status(device, initial); + igt_success(); + } + + igt_fixture { + close(fd); + } + + igt_exit(); +}