From patchwork Mon Dec 8 17:22:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 5457791 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 06804BEEA8 for ; Mon, 8 Dec 2014 17:22:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2234A20160 for ; Mon, 8 Dec 2014 17:22:18 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C3ECC20125 for ; Mon, 8 Dec 2014 17:22:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 525936ECE2; Mon, 8 Dec 2014 09:22:16 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wg0-f54.google.com (mail-wg0-f54.google.com [74.125.82.54]) by gabe.freedesktop.org (Postfix) with ESMTP id DAC676ECE2 for ; Mon, 8 Dec 2014 09:22:14 -0800 (PST) Received: by mail-wg0-f54.google.com with SMTP id l2so6773003wgh.27 for ; Mon, 08 Dec 2014 09:22:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=T3EuyO3Iv5tOVrVdnWGFUJcRzbPHMAkJw2iLF03wk9o=; b=IM/ewIQoMHIzBSm+aTYhDEXWgzBV19RcwVemCSnPNfEsfp7t8feFENzf0G0ux+z89Z imTysZfAOuU8GvpDpYmmivhuOXMm9zUq4MKW3GfOaPfVi1je5x1qLbC/RLVLlE2/wPQj fkr+6S3Tns/+GlDf9+vYHFNS2WxMUkdJTRbzCcQ/YeBi17kFd714Z4X3NVK2Jl0tuX+P kHWfm4ITtjH9s8Fb+jbX55X2N2RcBcb6gjjrBwxsauprvK6oLUXXKmdCpSC3yiHYF4y5 K5PkmsqL10LoviIxEgSeZ+MGG/tIarOXBRVRWzgl3jwu58UGhNSv2qszpNIo0QmgNlRh mxlg== X-Gm-Message-State: ALoCoQnVqElO8/9M5gDq0jb22cj6M43gzNoksWb+FUF3xa4Csq77ssF7Yx9w87WxC00w+x2dr7Sj X-Received: by 10.180.96.227 with SMTP id dv3mr26174512wib.50.1418059333040; Mon, 08 Dec 2014 09:22:13 -0800 (PST) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id l10sm10534512wif.20.2014.12.08.09.22.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Dec 2014 09:22:12 -0800 (PST) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Mon, 8 Dec 2014 17:22:12 +0000 Message-Id: <1418059332-20071-1-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 2.1.0 Subject: [Intel-gfx] [PATCH i-g-t] lib: add a function to lock memory into RAM 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 Add a function to lock memory into RAM and use it in the gem_tiled_swapping test to reduce the amount of allocated memory required to force swapping. This also reduces the amount of time required for the test to complete, since the data set is smaller. Signed-off-by: Thomas Wood --- lib/igt_aux.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_aux.h | 3 +++ tests/gem_tiled_swapping.c | 7 ++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 3051d84..a98aa8f 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -601,3 +601,51 @@ struct type_name connector_type_names[] = { }; type_name_fn(connector_type) + + +/** + * igt_lock_mem: @size: the amount of memory to lock into RAM, in MB + * + * Allocate @size MB of memory and lock it into RAM. This releases any + * previously locked memory. + * + * Use #igt_unlock_mem to release the currently locked memory. + */ +static char *locked_mem; +static size_t locked_size; + +void igt_lock_mem(size_t size) +{ + long pagesize = sysconf(_SC_PAGESIZE); + size_t i; + + if (locked_mem) + igt_unlock_mem(); + + locked_size = size * 1024 * 1024; + + locked_mem = malloc(locked_size); + igt_assert(locked_mem); + + /* write into each page to ensure it is allocated */ + for (i = 0; i < locked_size; i += pagesize) + locked_mem[i] = i; + + mlock(locked_mem, locked_size); +} + +/** + * igt_unlock_mem: + * + * Release and free the RAM used by #igt_lock_mem. + */ +void igt_unlock_mem(void) +{ + if (!locked_mem) + return; + + munlock(locked_mem, locked_size); + + free(locked_mem); + locked_mem = NULL; +} diff --git a/lib/igt_aux.h b/lib/igt_aux.h index 6c83c53..b61555b 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -90,4 +90,7 @@ void intel_require_memory(uint32_t count, uint32_t size, unsigned mode); #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) +void igt_lock_mem(size_t size); +void igt_unlock_mem(void); + #endif /* IGT_AUX_H */ diff --git a/tests/gem_tiled_swapping.c b/tests/gem_tiled_swapping.c index 3fac52f..0684ab2 100644 --- a/tests/gem_tiled_swapping.c +++ b/tests/gem_tiled_swapping.c @@ -70,6 +70,7 @@ IGT_TEST_DESCRIPTION("Exercise swizzle code for swapping."); static uint32_t current_tiling_mode; #define PAGE_SIZE 4096 +#define AVAIL_RAM 512 static uint32_t create_bo_and_fill(int fd) @@ -156,8 +157,12 @@ igt_main intel_purge_vm_caches(); fd = drm_open_any(); + + /* lock RAM, leaving only 512MB available */ + igt_lock_mem(intel_get_total_ram_mb() - AVAIL_RAM); + /* need slightly more than available memory */ - count = intel_get_total_ram_mb() + intel_get_total_swap_mb() / 4; + count = AVAIL_RAM * 1.25; bo_handles = calloc(count, sizeof(uint32_t)); igt_assert(bo_handles);