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 <[email protected]> 25 * 26 */ 27 28 /* 29 * Testcase: Unreferencing of active buffers 30 * 31 * Execs buffers and immediately unreferences them, hence the kernel active list 32 * will be the last one to hold a reference on them. Usually libdrm bo caching 33 * prevents that by keeping another reference. 34 */ 35 #include "igt.h" 36 #include <stdlib.h> 37 #include <stdio.h> 38 #include <string.h> 39 #include <fcntl.h> 40 #include <inttypes.h> 41 #include <errno.h> 42 #include <sys/stat.h> 43 #include <sys/time.h> 44 #include "drm.h" 45 #include "intel_bufmgr.h" 46 47 IGT_TEST_DESCRIPTION("Test unreferencing of active buffers."); 48 49 static drm_intel_bufmgr *bufmgr; 50 struct intel_batchbuffer *batch; 51 static drm_intel_bo *load_bo; 52 53 igt_simple_main 54 { 55 int fd, i; 56 57 igt_skip_on_simulation(); 58 59 fd = drm_open_driver(DRIVER_INTEL); 60 igt_require_gem(fd); 61 62 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); 63 igt_assert(bufmgr); 64 /* don't enable buffer reuse!! */ 65 //drm_intel_bufmgr_gem_enable_reuse(bufmgr); 66 67 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd)); 68 igt_assert(batch); 69 70 /* put some load onto the gpu to keep the light buffers active for long 71 * enough */ 72 for (i = 0; i < 1000; i++) { 73 load_bo = drm_intel_bo_alloc(bufmgr, "target bo", 1024*4096, 4096); 74 igt_assert(load_bo); 75 76 BLIT_COPY_BATCH_START(0); 77 OUT_BATCH((3 << 24) | /* 32 bits */ 78 (0xcc << 16) | /* copy ROP */ 79 4096); 80 OUT_BATCH(0); /* dst x1,y1 */ 81 OUT_BATCH((1024 << 16) | 512); 82 OUT_RELOC_FENCED(load_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); 83 OUT_BATCH((0 << 16) | 512); /* src x1, y1 */ 84 OUT_BATCH(4096); 85 OUT_RELOC_FENCED(load_bo, I915_GEM_DOMAIN_RENDER, 0, 0); 86 ADVANCE_BATCH(); 87 88 intel_batchbuffer_flush(batch); 89 90 drm_intel_bo_disable_reuse(load_bo); 91 drm_intel_bo_unreference(load_bo); 92 } 93 94 drm_intel_bufmgr_destroy(bufmgr); 95 96 close(fd); 97 } 98