From patchwork Thu Apr 4 20:32:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Argenziano X-Patchwork-Id: 10886285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33DF4922 for ; Thu, 4 Apr 2019 20:33:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FC3328A84 for ; Thu, 4 Apr 2019 20:33:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1274E28AF1; Thu, 4 Apr 2019 20:33:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9F91928A84 for ; Thu, 4 Apr 2019 20:33:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7BC426E345; Thu, 4 Apr 2019 20:33:16 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 63FD56E345 for ; Thu, 4 Apr 2019 20:33:15 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Apr 2019 13:33:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,309,1549958400"; d="scan'208";a="146672513" Received: from relo-linux-2.fm.intel.com ([10.1.27.125]) by FMSMGA003.fm.intel.com with ESMTP; 04 Apr 2019 13:33:14 -0700 From: Antonio Argenziano To: intel-gfx@lists.freedesktop.org Date: Thu, 4 Apr 2019 13:32:49 -0700 Message-Id: <20190404203249.9937-1-antonio.argenziano@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] tests/i915/gem_madvise.c: Add more mappings X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Check madvise versus more memory mappings. Suggested-by: Chris Wilson Signed-off-by: Antonio Argenziano --- tests/i915/gem_madvise.c | 115 ++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 39 deletions(-) diff --git a/tests/i915/gem_madvise.c b/tests/i915/gem_madvise.c index 729a4d33..bcaaa22e 100644 --- a/tests/i915/gem_madvise.c +++ b/tests/i915/gem_madvise.c @@ -47,66 +47,103 @@ IGT_TEST_DESCRIPTION("Checks that the kernel reports EFAULT when trying to use" * */ -static jmp_buf jmp; +static sigjmp_buf jmp; static void __attribute__((noreturn)) sigtrap(int sig) { - longjmp(jmp, sig); + siglongjmp(jmp, sig); } +enum mode { CPU, WC, GTT }; +const char* modes[] = {[CPU] = "cpu", [WC] = "wc", [GTT] = "gtt"}; + static void dontneed_before_mmap(void) { - int fd = drm_open_driver(DRIVER_INTEL); + int fd; uint32_t handle; char *ptr; - handle = gem_create(fd, OBJECT_SIZE); - gem_madvise(fd, handle, I915_MADV_DONTNEED); - ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); - close(fd); - - signal(SIGSEGV, sigtrap); - signal(SIGBUS, sigtrap); - switch (setjmp(jmp)) { - case SIGBUS: - break; - case 0: - *ptr = 0; - default: - igt_assert(!"reached"); - break; + for (unsigned mode = CPU; mode <= GTT; mode++) { + igt_debug("Mapping mode: %s\n", modes[mode]); + + fd = drm_open_driver(DRIVER_INTEL); + handle = gem_create(fd, OBJECT_SIZE); + gem_madvise(fd, handle, I915_MADV_DONTNEED); + + switch (mode) { + case GTT: + ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); + break; + case CPU: + ptr = gem_mmap__cpu(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE); + break; + case WC: + ptr = gem_mmap__wc(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE); + break; + } + + close(fd); + + signal(SIGSEGV, sigtrap); + signal(SIGBUS, sigtrap); + switch (sigsetjmp(jmp, SIGBUS | SIGSEGV)) { + case SIGBUS: + break; + case 0: + *ptr = 0; + default: + igt_assert(!"reached"); + break; + } + munmap(ptr, OBJECT_SIZE); + signal(SIGBUS, SIG_DFL); + signal(SIGSEGV, SIG_DFL); } - munmap(ptr, OBJECT_SIZE); - signal(SIGBUS, SIG_DFL); - signal(SIGSEGV, SIG_DFL); } static void dontneed_after_mmap(void) { - int fd = drm_open_driver(DRIVER_INTEL); + int fd; uint32_t handle; char *ptr; - handle = gem_create(fd, OBJECT_SIZE); - ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); - igt_assert(ptr); - gem_madvise(fd, handle, I915_MADV_DONTNEED); - close(fd); - - signal(SIGBUS, sigtrap); - switch (setjmp(jmp)) { - case SIGBUS: - break; - case 0: - *ptr = 0; - default: - igt_assert(!"reached"); - break; + for (unsigned mode = CPU; mode <= GTT; mode++) { + igt_debug("Mapping mode: %s\n", modes[mode]); + + fd = drm_open_driver(DRIVER_INTEL); + handle = gem_create(fd, OBJECT_SIZE); + + switch (mode) { + case GTT: + ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); + break; + case CPU: + ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE); + break; + case WC: + ptr = gem_mmap__wc(fd, handle, 0, OBJECT_SIZE, PROT_READ | PROT_WRITE); + break; + } + + igt_assert(ptr); + gem_madvise(fd, handle, I915_MADV_DONTNEED); + close(fd); + + signal(SIGBUS, sigtrap); + switch (sigsetjmp(jmp, SIGBUS)) { + case SIGBUS: + break; + case 0: + *ptr = 0; + default: + igt_assert(!"reached"); + break; + } + munmap(ptr, OBJECT_SIZE); + signal(SIGBUS, SIG_DFL); } - munmap(ptr, OBJECT_SIZE); - signal(SIGBUS, SIG_DFL); } static void