blob: fc853f31f1bbf3d1458f762fac7d9a4b26c0127c [file] [log] [blame]
root553021d2012-01-11 14:37:42 +01001/*
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 Wood804e11f2015-08-17 17:57:43 +010027#include "igt.h"
root553021d2012-01-11 14:37:42 +010028#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
root553021d2012-01-11 14:37:42 +010031#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"
root553021d2012-01-11 14:37:42 +010037#include "intel_bufmgr.h"
root553021d2012-01-11 14:37:42 +010038
39static drm_intel_bufmgr *bufmgr;
40struct 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 Woodb2ac2642014-11-28 11:02:44 +000049IGT_TEST_DESCRIPTION("Check whether the libdrm vma limiter works.");
50
root553021d2012-01-11 14:37:42 +010051/* we do both cpu and gtt maps, so only need half of 64k to exhaust */
52#define BO_ARRAY_SIZE 35000
53drm_intel_bo *bos[BO_ARRAY_SIZE];
54
Daniel Vetterdda85fb2013-12-10 10:18:32 +010055igt_simple_main
root553021d2012-01-11 14:37:42 +010056{
57 int fd;
58 int i;
59 char *ptr;
60
Daniel Vetter1caaf0a2013-08-12 12:17:35 +020061 igt_skip_on_simulation();
Damien Lespiau5fa15f72013-04-29 18:40:39 +010062
Micah Fedkec81d2932015-07-22 21:54:02 +000063 fd = drm_open_driver(DRIVER_INTEL);
root553021d2012-01-11 14:37:42 +010064
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 Vetter83440952013-08-13 12:35:58 +020073 igt_assert(bos[i]);
root553021d2012-01-11 14:37:42 +010074
75 drm_intel_bo_map(bos[i], 1);
76 ptr = bos[i]->virtual;
Daniel Vetter83440952013-08-13 12:35:58 +020077 igt_assert(ptr);
root553021d2012-01-11 14:37:42 +010078 *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 Vetter83440952013-08-13 12:35:58 +020083 igt_assert(ptr);
root553021d2012-01-11 14:37:42 +010084 *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 Vetter83440952013-08-13 12:35:58 +020091 igt_assert(bos[i]);
root553021d2012-01-11 14:37:42 +010092
93 drm_intel_bo_map(bos[i], 1);
94 ptr = bos[i]->virtual;
Daniel Vetter83440952013-08-13 12:35:58 +020095 igt_assert(*ptr = 'c');
root553021d2012-01-11 14:37:42 +010096 drm_intel_bo_unmap(bos[i]);
97
98 drm_intel_gem_bo_map_gtt(bos[i]);
99 ptr = bos[i]->virtual;
Daniel Vetter83440952013-08-13 12:35:58 +0200100 igt_assert(*ptr = 'c');
root553021d2012-01-11 14:37:42 +0100101 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);
root553021d2012-01-11 14:37:42 +0100108}