Back to index

libdrm  2.4.37
radeon_ttm.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2011 Red Hat
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice (including the next
00012  * paragraph) shall be included in all copies or substantial portions of the
00013  * Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00018  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00021  * IN THE SOFTWARE.
00022  *
00023  * Authors:
00024  *    Jerome Glisse <j.glisse@gmail.com>
00025  */
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include "rbo.h"
00029 
00030 /* allocate as many single page bo to try to starve the kernel
00031  * memory zone (below highmem)
00032  */
00033 void ttm_starve_kernel_private_memory(int fd)
00034 {
00035     struct list_head list;
00036     struct rbo *bo, *tmp;
00037     unsigned nbo = 0;
00038 
00039     printf("\n[%s]\n", __func__);
00040     list_inithead(&list);
00041     while (1) {
00042         bo = rbo(fd, 0, 4096, 0, NULL);
00043         if (bo == NULL) {
00044             printf("failing after %d bo\n", nbo);
00045             break;
00046         }
00047         nbo++;
00048         list_add(&bo->list, &list);
00049     }
00050     LIST_FOR_EACH_ENTRY_SAFE(bo, tmp, &list, list) {
00051         list_del(&bo->list);
00052         rbo_decref(bo);
00053     }
00054 }
00055 
00056 int radeon_open_fd(void)
00057 {
00058     return drmOpen("radeon", NULL);
00059 }
00060 
00061 int main(void)
00062 {
00063     int radeonfd;
00064 
00065     radeonfd = radeon_open_fd();
00066     if (radeonfd < 0) {
00067         fprintf(stderr, "failed to open radeon fd\n");
00068         return -1;
00069     }
00070 
00071     ttm_starve_kernel_private_memory(radeonfd);
00072 
00073     close(radeonfd);
00074     return 0;
00075 }