From patchwork Wed Mar 5 11:32:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sourab.gupta@intel.com X-Patchwork-Id: 3773331 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 A95759F1EE for ; Wed, 5 Mar 2014 11:31:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 82F5720251 for ; Wed, 5 Mar 2014 11:31:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3AAEE20222 for ; Wed, 5 Mar 2014 11:31:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 139AFFA52C; Wed, 5 Mar 2014 03:31:42 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 2004CFA52C for ; Wed, 5 Mar 2014 03:31:40 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 05 Mar 2014 03:31:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,592,1389772800"; d="scan'208";a="486402289" Received: from sourabgu-desktop.iind.intel.com ([10.223.82.69]) by fmsmga001.fm.intel.com with ESMTP; 05 Mar 2014 03:31:37 -0800 From: sourab.gupta@intel.com To: intel-gfx@lists.freedesktop.org Date: Wed, 5 Mar 2014 17:02:11 +0530 Message-Id: <1394019131-8659-1-git-send-email-sourab.gupta@intel.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Cc: "Cc: Daniel Vetter" , Sourab Gupta , "Cc: Jesse Barnes" , "Cc: Chris Wilson" Subject: [Intel-gfx] =?utf-8?q?=5BRFC=5D_tests/gem=5Fstolen=5Fmem=3A_New_t?= =?utf-8?q?estcases_for_testing_the_non_cpu_mappable_buffer_objects?= =?utf-8?q?=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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 From: Sourab Gupta The testcases test the buffer objects created with the cpu_map_not_needed flag. These are used to test the allocation, copy, truncation and non-cpu mappable nature of the buffer objects created with this flag. Signed-off-by: Sourab Gupta --- tests/Makefile.sources | 1 + tests/gem_stolen_mem.c | 277 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 tests/gem_stolen_mem.c diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 88866ac..74961ba 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -51,6 +51,7 @@ TESTS_progs_M = \ gem_ringfill \ gem_set_tiling_vs_blt \ gem_storedw_batches_loop \ + gem_stolen_mem \ gem_tiled_blits \ gem_tiled_partial_pwrite_pread \ gem_write_read_ring_switch \ diff --git a/tests/gem_stolen_mem.c b/tests/gem_stolen_mem.c new file mode 100644 index 0000000..805b26f --- /dev/null +++ b/tests/gem_stolen_mem.c @@ -0,0 +1,277 @@ +/* + * 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: + * Sourab Gupta + */ + +#include +#include +#include +#include +#include +#include + +#include "drm.h" +#include "i915_drm.h" +#include "drmtest.h" +#include "rendercopy.h" +#include "intel_bufmgr.h" +#include "intel_batchbuffer.h" +#include "intel_gpu_tools.h" + +#define MAX_STOLEN_BO_OBJS 12 +#define GEM_WAIT_DUR 1000000000 /* units: ns */ + +/*define below to halt the testcase for check mem stats */ +//#define CHECK_MEM_STATS + +static drm_intel_bufmgr *bufmgr; +struct intel_batchbuffer *batch; +static const int width = 1920, height = 1080; +static const int size = 4*1920*1080; /* size of 1 object */ + +static int fd; +static drm_intel_bo **src_bo, **dest_bo, **src_bo_new, **dest_bo_new; + +static jmp_buf jmp; + +static void sigtrap(int sig) +{ + longjmp(jmp, sig); +} + +/* + * Testcase to check that the stolen bo is not cpu mappable + * + */ +static void +stolen_mmap_check(void) +{ + unsigned long pitch = 0; + uint32_t *virt, i, ret, tiling_mode = I915_TILING_NONE; + drm_intel_bo *src, *dest; + + src= drm_intel_bo_alloc(bufmgr, "src bo", size, 4096); + dest = drm_intel_bo_alloc_tiled(bufmgr, "dest bo", width, height, 4, + &tiling_mode, &pitch, BO_ALLOC_CPU_MAP_NOT_NEEDED ); + + /* Fill the src BO with dwords */ + do_or_die(drm_intel_bo_map(src, 1)); + virt = src->virtual; + for (i = 0; i < width*height; i++) + virt[i] = i; + + intel_copy_bo(batch, dest, src, width, height); + + //Try to mmap the (already processed) stolen bo + ret = drm_intel_bo_map(dest, 1); + igt_assert(ret != 0); + + drm_intel_bo_unreference(src); + drm_intel_bo_unreference(dest); +} + +/* + * Testcase to check the copy operation on stolen bo. + * First fully exhaust the stolen memory. In the end make space for one stolen mem bo. + */ +static void stolen_bo_copy(int num_bo) +{ + unsigned long pitch = 0; + uint32_t tiling_mode = I915_TILING_NONE; + uint32_t *virt, ret, i, count; + + for(count=0; countvirtual; + for (i = 0; i < width*height; i++) + virt[i] = i; + + + intel_copy_bo(batch, dest_bo[count], src_bo[count], width, height); + + ret = drm_intel_gem_bo_map_gtt(dest_bo[count]); + igt_assert(!ret); + + virt = dest_bo[count]->virtual; + drm_intel_gem_bo_wait(dest_bo[count],GEM_WAIT_DUR); + /* verify */ + for (i = 0; i < width*height; i++) { + if (virt[i] != i) { + fprintf(stderr, "Expected 0x%08x, found 0x%08x " + "at offset 0x%08x\n", + i, virt[i], i * 4); + abort(); + } + } + + drm_intel_bo_unmap(src_bo[count]); + } + +#if defined CHECK_MEM_STATS + printf("Halt to check mem statistics (through debugfs). Expected the stolen mem area to be full.\ + Press any key to continue\n"); + getchar(); +#endif + /* + * Mark one bo as purgeable, so that the backing storage is truncated + * and space for atleast one obj is there in stolen mem + */ + drm_intel_bo_madvise(dest_bo[0], I915_MADV_DONTNEED); + +} + +/* + * This testcase will test the truncation logic of the stolen objects. + * At the end of every iteration of first loop, the objects will be marked as purgeable. + * In the second loop, the objects are checked to verify that they are not usable/accessible + */ +static void stolen_bo_copy_purge(int num_bo) +{ + unsigned long pitch = 0; + uint32_t tiling_mode = I915_TILING_NONE; + uint32_t *virt, ret, i, count; + + + for(count=0; countvirtual; + for (i = 0; i < width*height; i++) + virt[i] = i; + + intel_copy_bo(batch, dest_bo_new[count], src_bo_new[count], width, height); + + ret = drm_intel_gem_bo_map_gtt(dest_bo_new[count]); + igt_assert(!ret); + + virt = dest_bo_new[count]->virtual; + drm_intel_gem_bo_wait(dest_bo_new[count],1000000000); + /* verify */ + for (i = 0; i < width*height; i++) { + if (virt[i] != i) { + fprintf(stderr, "Expected 0x%08x, found 0x%08x " + "at offset 0x%08x\n", + i, virt[i], i * 4); + abort(); + } + } + + drm_intel_bo_unmap(src_bo_new[count]); + + drm_intel_bo_madvise(dest_bo_new[count], I915_MADV_DONTNEED); + } + + signal(SIGBUS, sigtrap); + for(i=0;ivirtual; + switch (setjmp(jmp)) { + case SIGBUS: + break; + case 0: + *virt = 0; + default: + printf("Test fail for bo:%d\n", i); + igt_assert(!"reached"); + break; + } + munmap(virt, size); + } + signal(SIGBUS, SIG_DFL); +} + +int main(int argc, char **argv) +{ + int i, bo_count=0; + + igt_subtest_init(argc, argv); + igt_skip_on_simulation(); + + igt_fixture { + fd = drm_open_any(); + + if (argc > 1) + bo_count = atoi(argv[1]); + + igt_assert(bo_count != 0); + + bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); + + batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); + + src_bo = malloc(MAX_STOLEN_BO_OBJS*sizeof(drm_intel_bo*)); + dest_bo = malloc(MAX_STOLEN_BO_OBJS*sizeof(drm_intel_bo*)); + src_bo_new = malloc(bo_count*sizeof(drm_intel_bo*)); + dest_bo_new = malloc(bo_count*sizeof(drm_intel_bo*)); + } + + /* check the non cpu mappable nature */ + igt_subtest("stolen-bo-mmap") + stolen_mmap_check(); + + /* check the copy operation and exhaust space for all but one obj from stolen mem */ + igt_subtest("stolen-bo-copy") + stolen_bo_copy(MAX_STOLEN_BO_OBJS); + + /*checking the purging logic for objs working on driver */ + igt_subtest("stolen-bo-copy-purge") + stolen_bo_copy_purge(bo_count); + + + igt_fixture { + for(i=0;i