blob: 288324d4878a7a2491525bf8a9d7d7df3347323c [file] [log] [blame]
Daniel Vetter2d431fd2012-10-03 13:44:30 +02001/*
2 * Copyright (c) 2012 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 * Mika Kuoppala <mika.kuoppala@intel.com>
25 */
26
Thomas Wood804e11f2015-08-17 17:57:43 +010027#include "igt.h"
Daniel Vetter2d431fd2012-10-03 13:44:30 +020028#include <stdlib.h>
29#include <string.h>
Daniel Vetter2d431fd2012-10-03 13:44:30 +020030#include <fcntl.h>
31#include <unistd.h>
32#include <pthread.h>
33
Daniel Vetter2d431fd2012-10-03 13:44:30 +020034#include "intel_bufmgr.h"
35
Thomas Woodb2ac2642014-11-28 11:02:44 +000036IGT_TEST_DESCRIPTION("Check parallel access to tiled memory.");
37
Daniel Vetter2d431fd2012-10-03 13:44:30 +020038/* Testcase: check parallel access to tiled memory
39 *
40 * Parallel access to tiled memory caused sigbus
41 */
42
43#define NUM_THREADS 2
44#define WIDTH 4096
45#define HEIGHT 4096
46
47struct thread_ctx {
48 drm_intel_bo *bo;
49};
50
51static drm_intel_bufmgr *bufmgr;
52static struct thread_ctx tctx[NUM_THREADS];
53
54static void *copy_fn(void *p)
55{
56 unsigned char *buf;
57 struct thread_ctx *c = p;
58
59 buf = malloc(WIDTH * HEIGHT);
60 if (buf == NULL)
61 return (void *)1;
62
63 memcpy(buf, c->bo->virtual, WIDTH * HEIGHT);
64
65 free(buf);
66 return (void *)0;
67}
68
69static int copy_tile_threaded(drm_intel_bo *bo)
70{
71 int i;
72 int r;
73 pthread_t thr[NUM_THREADS];
74 void *status;
75
76 for (i = 0; i < NUM_THREADS; i++) {
77 tctx[i].bo = bo;
78 r = pthread_create(&thr[i], NULL, copy_fn, (void *)&tctx[i]);
Matt Roper07be8fe2015-03-05 15:01:00 -080079 igt_assert_eq(r, 0);
Daniel Vetter2d431fd2012-10-03 13:44:30 +020080 }
81
82 for (i = 0; i < NUM_THREADS; i++) {
83 pthread_join(thr[i], &status);
Daniel Vetter83440952013-08-13 12:35:58 +020084 igt_assert(status == 0);
Daniel Vetter2d431fd2012-10-03 13:44:30 +020085 }
86
87 return 0;
88}
89
Daniel Vetterdda85fb2013-12-10 10:18:32 +010090igt_simple_main
Daniel Vetter2d431fd2012-10-03 13:44:30 +020091{
92 int fd;
93 drm_intel_bo *bo;
94 uint32_t tiling_mode = I915_TILING_Y;
95 unsigned long pitch = 0;
96 int r;
97
Daniel Vetter1caaf0a2013-08-12 12:17:35 +020098 igt_skip_on_simulation();
Damien Lespiau5fa15f72013-04-29 18:40:39 +010099
Micah Fedkec81d2932015-07-22 21:54:02 +0000100 fd = drm_open_driver(DRIVER_INTEL);
Daniel Vetter83440952013-08-13 12:35:58 +0200101 igt_assert(fd >= 0);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200102
103 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
Daniel Vetter83440952013-08-13 12:35:58 +0200104 igt_assert(bufmgr);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200105
106 bo = drm_intel_bo_alloc_tiled(bufmgr, "mmap bo", WIDTH, HEIGHT, 1,
107 &tiling_mode, &pitch, 0);
Daniel Vetter83440952013-08-13 12:35:58 +0200108 igt_assert(bo);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200109
110 r = drm_intel_gem_bo_map_gtt(bo);
Daniel Vetter83440952013-08-13 12:35:58 +0200111 igt_assert(!r);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200112
113 r = copy_tile_threaded(bo);
Daniel Vetter83440952013-08-13 12:35:58 +0200114 igt_assert(!r);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200115
116 r = drm_intel_gem_bo_unmap_gtt(bo);
Daniel Vetter83440952013-08-13 12:35:58 +0200117 igt_assert(!r);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200118
119 drm_intel_bo_unreference(bo);
120 drm_intel_bufmgr_destroy(bufmgr);
121
122 close(fd);
Daniel Vetter2d431fd2012-10-03 13:44:30 +0200123}