From patchwork Tue Jun 23 15:01:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Morton X-Patchwork-Id: 6661981 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E39C99F380 for ; Tue, 23 Jun 2015 15:02:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 649C9205B7 for ; Tue, 23 Jun 2015 15:02:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6B51A205B5 for ; Tue, 23 Jun 2015 15:02:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B92006E10D; Tue, 23 Jun 2015 08:02:02 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C6BC6E10D for ; Tue, 23 Jun 2015 08:02:01 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 23 Jun 2015 08:02:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,666,1427785200"; d="scan'208";a="751773516" Received: from djmorton-linux.isw.intel.com ([10.102.226.153]) by orsmga002.jf.intel.com with ESMTP; 23 Jun 2015 08:01:59 -0700 From: Derek Morton To: intel-gfx@lists.freedesktop.org Date: Tue, 23 Jun 2015 16:01:53 +0100 Message-Id: <1435071713-14549-1-git-send-email-derek.j.morton@intel.com> X-Mailer: git-send-email 1.9.1 Cc: thomas.wood@intel.com Subject: [Intel-gfx] [PATCH i-g-t] tests/gem_fence_thrash.c: Reduce memory usage 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: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-5.6 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 On android platforms with 1Gb RAM gem_fence_thrash was failing with an out of memory error. This patch causes gem_close() to be called when a thread is finished with its handles rather than relying on the cleanup when the fd is closed. This greatly improves the memory footprint of the test allowing it to run on 1Mb systems. Also fixed a leak of the 'threads' variable. Signed-off-by: Derek Morton --- tests/gem_fence_thrash.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/gem_fence_thrash.c b/tests/gem_fence_thrash.c index 6447e13..bfb2e6d 100644 --- a/tests/gem_fence_thrash.c +++ b/tests/gem_fence_thrash.c @@ -60,26 +60,25 @@ struct test { }; static void * -bo_create (int fd, int tiling) +bo_create (int fd, int tiling, uint32_t *handle) { void *ptr; - int handle; - handle = gem_create(fd, OBJECT_SIZE); + *handle = gem_create(fd, OBJECT_SIZE); /* dirty cpu caches a bit ... */ - ptr = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE); + ptr = gem_mmap__cpu(fd, *handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE); igt_assert(ptr); memset(ptr, 0, OBJECT_SIZE); munmap(ptr, OBJECT_SIZE); - gem_set_tiling(fd, handle, tiling, 1024); + gem_set_tiling(fd, *handle, tiling, 1024); - ptr = gem_mmap(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); + ptr = gem_mmap(fd, *handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); igt_assert(ptr); /* XXX: mmap_gtt pulls the bo into the GTT read domain. */ - gem_sync(fd, handle); + gem_sync(fd, *handle); return ptr; } @@ -91,15 +90,19 @@ bo_copy (void *_arg) int fd = t->fd; int n; char *a, *b; + uint32_t ha, hb; - a = bo_create (fd, t->tiling); - b = bo_create (fd, t->tiling); + a = bo_create (fd, t->tiling, &ha); + b = bo_create (fd, t->tiling, &hb); for (n = 0; n < 1000; n++) { memcpy (a, b, OBJECT_SIZE); sched_yield (); } + gem_close(fd, ha); + gem_close(fd, hb); + return NULL; } @@ -112,15 +115,18 @@ _bo_write_verify(struct test *t) uint32_t v; unsigned int dwords = OBJECT_SIZE >> 2; const char *tile_str[] = { "none", "x", "y" }; + uint32_t *h; igt_assert(t->tiling >= 0 && t->tiling <= I915_TILING_Y); igt_assert_lt(0, t->num_surfaces); s = calloc(sizeof(*s), t->num_surfaces); igt_assert(s); + h = calloc(sizeof(*h), t->num_surfaces); + igt_assert(h); for (k = 0; k < t->num_surfaces; k++) - s[k] = bo_create(fd, t->tiling); + s[k] = bo_create(fd, t->tiling, &(h[k])); for (k = 0; k < t->num_surfaces; k++) { volatile uint32_t *a = s[k]; @@ -141,10 +147,13 @@ _bo_write_verify(struct test *t) } } - for (k = 0; k < t->num_surfaces; k++) + for (k = 0; k < t->num_surfaces; k++) { munmap(s[k], OBJECT_SIZE); + gem_close(fd, h[k]); + } free(s); + free(h); } static void * @@ -188,6 +197,8 @@ static int run_test(int threads_per_fence, void *f, int tiling, for (n = 0; n < num_threads; n++) pthread_join (threads[n], NULL); + + free(threads); } else { void *(*func)(void *) = f; igt_assert(func(&t) == (void *)0);