root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 25 | */ |
| 26 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 27 | #include "igt.h" |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 28 | #include <stdlib.h> |
| 29 | #include <stdio.h> |
| 30 | #include <string.h> |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 31 | #include <fcntl.h> |
| 32 | #include <inttypes.h> |
| 33 | #include <errno.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <sys/time.h> |
| 36 | #include "drm.h" |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 37 | #include "intel_bufmgr.h" |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 38 | |
| 39 | static drm_intel_bufmgr *bufmgr; |
| 40 | struct intel_batchbuffer *batch; |
| 41 | |
| 42 | /* Testcase: check whether the libdrm vma limiter works |
| 43 | * |
| 44 | * We've had reports of the X server exhausting the default rlimit of 64k vma's |
| 45 | * in the kernel. libdrm has grown facilities to limit the vma caching since, |
| 46 | * this checks whether they actually work. |
| 47 | */ |
| 48 | |
Thomas Wood | b2ac264 | 2014-11-28 11:02:44 +0000 | [diff] [blame] | 49 | IGT_TEST_DESCRIPTION("Check whether the libdrm vma limiter works."); |
| 50 | |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 51 | /* we do both cpu and gtt maps, so only need half of 64k to exhaust */ |
| 52 | #define BO_ARRAY_SIZE 35000 |
| 53 | drm_intel_bo *bos[BO_ARRAY_SIZE]; |
| 54 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 55 | igt_simple_main |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 56 | { |
| 57 | int fd; |
| 58 | int i; |
| 59 | char *ptr; |
| 60 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 61 | igt_skip_on_simulation(); |
Damien Lespiau | 5fa15f7 | 2013-04-29 18:40:39 +0100 | [diff] [blame] | 62 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 63 | fd = drm_open_driver(DRIVER_INTEL); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 64 | |
| 65 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 66 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
| 67 | batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); |
| 68 | |
| 69 | drm_intel_bufmgr_gem_set_vma_cache_size(bufmgr, 500); |
| 70 | |
| 71 | for (i = 0; i < BO_ARRAY_SIZE; i++) { |
| 72 | bos[i] = drm_intel_bo_alloc(bufmgr, "mmap bo", 4096, 4096); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 73 | igt_assert(bos[i]); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 74 | |
| 75 | drm_intel_bo_map(bos[i], 1); |
| 76 | ptr = bos[i]->virtual; |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 77 | igt_assert(ptr); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 78 | *ptr = 'c'; |
| 79 | drm_intel_bo_unmap(bos[i]); |
| 80 | |
| 81 | drm_intel_gem_bo_map_gtt(bos[i]); |
| 82 | ptr = bos[i]->virtual; |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 83 | igt_assert(ptr); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 84 | *ptr = 'c'; |
| 85 | drm_intel_gem_bo_unmap_gtt(bos[i]); |
| 86 | } |
| 87 | |
| 88 | /* and recheck whether a second map of the same still works */ |
| 89 | for (i = 0; i < BO_ARRAY_SIZE; i++) { |
| 90 | bos[i] = drm_intel_bo_alloc(bufmgr, "mmap bo", 4096, 4096); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 91 | igt_assert(bos[i]); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 92 | |
| 93 | drm_intel_bo_map(bos[i], 1); |
| 94 | ptr = bos[i]->virtual; |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 95 | igt_assert(*ptr = 'c'); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 96 | drm_intel_bo_unmap(bos[i]); |
| 97 | |
| 98 | drm_intel_gem_bo_map_gtt(bos[i]); |
| 99 | ptr = bos[i]->virtual; |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 100 | igt_assert(*ptr = 'c'); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 101 | drm_intel_gem_bo_unmap_gtt(bos[i]); |
| 102 | } |
| 103 | |
| 104 | intel_batchbuffer_free(batch); |
| 105 | drm_intel_bufmgr_destroy(bufmgr); |
| 106 | |
| 107 | close(fd); |
root | 553021d | 2012-01-11 14:37:42 +0100 | [diff] [blame] | 108 | } |