lib/drmtest: extract mappable aperture trasher infrastructure
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Sun, 15 Jan 2012 17:32:11 +0000 (18:32 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Sun, 15 Jan 2012 17:32:11 +0000 (18:32 +0100)
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
lib/drmtest.c
lib/drmtest.h
tests/gem_partial_pwrite_pread.c

index 40f3ac5..521a38a 100644 (file)
@@ -289,6 +289,7 @@ uint64_t gem_mappable_aperture_size(void)
        return pci_dev->regions[bar].size;
 }
 
+/* signal interrupt helpers */
 static pid_t signal_helper = -1;
 long long int sig_stat;
 static void signal_helper_process(pid_t pid)
@@ -330,3 +331,43 @@ void drmtest_stop_signal_helper(void)
 
        signal_helper = -1;
 }
+
+/* mappable aperture trasher helper */
+drm_intel_bo **trash_bos;
+int num_trash_bos;
+
+void drmtest_init_aperture_trashers(drm_intel_bufmgr *bufmgr)
+{
+       int i;
+
+       num_trash_bos = gem_mappable_aperture_size() / (1024*1024);
+
+       trash_bos = malloc(num_trash_bos * sizeof(drm_intel_bo *));
+       assert(trash_bos);
+
+       for (i = 0; i < num_trash_bos; i++)
+               trash_bos[i] = drm_intel_bo_alloc(bufmgr, "trash bo", 1024*1024, 4096);
+}
+
+void drmtest_trash_aperture(void)
+{
+       int i;
+       uint8_t *gtt_ptr;
+
+       for (i = 0; i < num_trash_bos; i++) {
+               drm_intel_gem_bo_map_gtt(trash_bos[i]);
+               gtt_ptr = trash_bos[i]->virtual;
+               *gtt_ptr = 0;
+               drm_intel_gem_bo_unmap_gtt(trash_bos[i]);
+       }
+}
+
+void drmtest_cleanup_aperture_trashers(void)
+{
+       int i;
+
+       for (i = 0; i < num_trash_bos; i++)
+               drm_intel_bo_unreference(trash_bos[i]);
+
+       free(trash_bos);
+}
index dc69b43..3a3bc9a 100644 (file)
 #include <errno.h>
 
 #include "xf86drm.h"
+#include "intel_batchbuffer.h"
 
 int drm_open_any(void);
 int drm_open_any_master(void);
 
 void gem_quiescent_gpu(int fd);
 
+/* ioctl wrappers and similar stuff for bare metal testing */
 void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride);
 void gem_close(int fd, uint32_t handle);
 void gem_write(int fd, uint32_t handle, uint32_t offset,  const void *buf, uint32_t size);
@@ -50,5 +52,11 @@ void *gem_mmap(int fd, uint32_t handle, int size, int prot);
 uint64_t gem_aperture_size(int fd);
 uint64_t gem_mappable_aperture_size(void);
 
+/* generally useful helpers */
 void drmtest_fork_signal_helper(void);
 void drmtest_stop_signal_helper(void);
+
+/* helpers based upon the libdrm buffer manager */
+void drmtest_init_aperture_trashers(drm_intel_bufmgr *bufmgr);
+void drmtest_trash_aperture(void);
+void drmtest_cleanup_aperture_trashers(void);
index e00167f..6280e98 100644 (file)
@@ -56,39 +56,9 @@ drm_intel_bo *scratch_bo;
 drm_intel_bo *staging_bo;
 #define BO_SIZE (4*4096)
 uint32_t devid;
+uint64_t mappable_gtt_limit;
 int fd;
 
-drm_intel_bo *trash_bos[10000];
-int num_trash_bos;
-
-static void
-init_aperture_trashers(void)
-{
-       int i;
-
-       if (intel_gen(devid) >= 6)
-               num_trash_bos = 512;
-       else
-               num_trash_bos = 256;
-
-       for (i = 0; i < num_trash_bos; i++)
-               trash_bos[i] = drm_intel_bo_alloc(bufmgr, "trash bo", 1024*1024, 4096);
-}
-
-static void
-trash_aperture(void)
-{
-       int i;
-       uint8_t *gtt_ptr;
-
-       for (i = 0; i < num_trash_bos; i++) {
-               drm_intel_gem_bo_map_gtt(trash_bos[i]);
-               gtt_ptr = trash_bos[i]->virtual;
-               *gtt_ptr = 0;
-               drm_intel_gem_bo_unmap_gtt(trash_bos[i]);
-       }
-}
-
 static void
 copy_bo(drm_intel_bo *src, drm_intel_bo *dst)
 {
@@ -124,9 +94,9 @@ blt_bo_fill(drm_intel_bo *tmp_bo, drm_intel_bo *bo, int val)
 
        drm_intel_gem_bo_unmap_gtt(tmp_bo);
 
-       if (bo->offset < num_trash_bos*1024*1024 &&
+       if (bo->offset < mappable_gtt_limit &&
            (IS_G33(devid) || intel_gen(devid) >= 4))
-               trash_aperture();
+               drmtest_trash_aperture();
 
        copy_bo(tmp_bo, bo);
 }
@@ -151,7 +121,8 @@ int main(int argc, char **argv)
        scratch_bo = drm_intel_bo_alloc(bufmgr, "scratch bo", BO_SIZE, 4096);
        staging_bo = drm_intel_bo_alloc(bufmgr, "staging bo", BO_SIZE, 4096);
 
-       init_aperture_trashers();
+       drmtest_init_aperture_trashers(bufmgr);
+       mappable_gtt_limit = gem_mappable_aperture_size();
 
        printf("checking partial reads\n");
        for (i = 0; i < 1000; i++) {
@@ -276,6 +247,7 @@ int main(int argc, char **argv)
                drm_intel_gem_bo_unmap_gtt(staging_bo);
        }
 
+       drmtest_cleanup_aperture_trashers();
        drm_intel_bufmgr_destroy(bufmgr);
 
        close(fd);