blob: 75827908203f67cc3afc9b5188acc792b70751a3 [file] [log] [blame]
Chris Wilson9579e542016-05-23 21:56:01 +01001/*
2 * Copyright © 2013 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 */
24
25#define _GNU_SOURCE
26#include <sched.h>
27
28#include "igt.h"
29
30IGT_TEST_DESCRIPTION("Stress legacy cursor ioctl");
31
32struct data {
33 int fd;
34};
35
36static uint32_t state = 0x12345678;
37
38static uint32_t
39hars_petruska_f54_1_random (void)
40{
41#define rol(x,k) ((x << k) | (x >> (32-k)))
42 return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
43#undef rol
44}
45
46static void stress(struct data *data, unsigned mode, int timeout)
47{
48 drmModeRes *r;
49 struct drm_mode_cursor arg;
50 int n;
51
52 r = drmModeGetResources(data->fd);
53 igt_assert(r);
54
55 memset(&arg, 0, sizeof(arg));
56 arg.flags = DRM_MODE_CURSOR_BO;
57 arg.crtc_id = 0;
58 arg.width = 64;
59 arg.height = 64;
60 arg.handle = gem_create(data->fd, 4*64*64);
61
62 for (n = 0; n < r->count_crtcs; n++)
63 drmIoctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg);
64
65 arg.flags = mode;
66 igt_fork(child, sysconf(_SC_NPROCESSORS_ONLN)) {
67 struct sched_param rt = {.sched_priority = 99 };
68 cpu_set_t allowed;
69 unsigned long count = 0;
70
71 sched_setscheduler(getpid(), SCHED_RR, &rt);
72
73 CPU_ZERO(&allowed);
74 CPU_SET(child, &allowed);
75 sched_setaffinity(getpid(), sizeof(cpu_set_t), &allowed);
76
77 igt_until_timeout(timeout) {
78 arg.crtc_id = r->crtcs[hars_petruska_f54_1_random() % r->count_crtcs];
79 do_ioctl(data->fd, DRM_IOCTL_MODE_CURSOR, &arg);
80 count++;
81 }
82
83 igt_info("[%d] count=%lu\n", child, count);
84 }
85 igt_waitchildren();
86
87 gem_close(data->fd, arg.handle);
88 drmModeFreeResources(r);
89}
90
91igt_main
92{
93 struct data data = { .fd = -1 };
94
95 igt_skip_on_simulation();
96
97 igt_fixture {
98 data.fd = drm_open_driver_master(DRIVER_INTEL);
99 kmstest_set_vt_graphics_mode();
100 }
101
102 igt_subtest("stress-bo")
103 stress(&data, DRM_MODE_CURSOR_BO, 20);
104 igt_subtest("stress-move")
105 stress(&data, DRM_MODE_CURSOR_MOVE, 20);
106
107 igt_fixture {
108 }
109}