blob: f7dc4245b962a04fb7897d2e6592671592e3fd11 [file] [log] [blame]
Ben Widawsky62873792011-06-24 11:42:03 -07001/*
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 * Ben Widawsky <ben@bwidawsk.net>
25 *
26 */
27
28#include <stdint.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include "intel_gpu_tools.h"
32
33struct eu_rdata {
34 union {
35 struct {
36 uint8_t sendc_dep : 1;
37 uint8_t swh_dep : 1;
38 uint8_t pwc_dep : 1;
39 uint8_t n2_dep : 1;
40 uint8_t n1_dep : 1;
41 uint8_t n0_dep : 1;
42 uint8_t flag1_dep : 1;
43 uint8_t flag0_dep : 1;
44 uint8_t indx_dep : 1;
45 uint8_t mrf_dep : 1;
46 uint8_t dst_dep : 1;
47 uint8_t src2_dep : 1;
48 uint8_t src1_dep : 1;
49 uint8_t src0_dep : 1;
50 uint8_t mp_dep_pin : 1;
51 uint8_t sp_dep_pin : 1;
52 uint8_t fftid : 8;
53 uint8_t ffid : 4;
54 uint8_t instruction_valid : 1;
55 uint8_t thread_status : 3;
56 };
57 uint32_t dword;
58 } ud0;
59
60 union {
61 struct {
62 uint8_t mrf_addr : 4;
63 uint8_t dst_addr : 7;
64 uint8_t src2_addr : 7;
65 uint8_t src1_addr : 7;
66 uint8_t src0_addr : 7;
67 };
68 uint32_t dword;
69 } ud1;
70
71 union {
72 struct {
73 uint16_t exip : 12;
74 uint8_t opcode : 7;
75 uint8_t pwc : 8;
76 uint8_t instruction_valid : 1;
77 uint8_t mbz : 4;
78 };
79 uint32_t dword;
80 } ud2;
81};
82
83const char *thread_status[] =
84 {"INVALID", "invalid/no thread", "standby (dependency)", "INVALID", "Executing",
85 "INVALID" , "INVALID" , "INVALID"};
86
87static struct eu_rdata
88collect_rdata(int eu, int tid) {
89 struct eu_rdata rdata;
90
91 intel_register_write(0x7800, eu << 16 | (3 * tid) << 8);
92 rdata.ud0.dword = intel_register_read(0x7840);
93
94 intel_register_write(0x7800, eu << 16 | (3 * tid + 1) << 8);
95 rdata.ud1.dword = intel_register_read(0x7840);
96
97 intel_register_write(0x7800, eu << 16 | (3 * tid + 2) << 8);
98 rdata.ud2.dword = intel_register_read(0x7840);
99
100 return rdata;
101}
102static void
103print_rdata(struct eu_rdata rdata) {
104 printf("\t%s\n", thread_status[rdata.ud0.thread_status]);
105 printf("\tn1_dep: %d\n", rdata.ud0.n1_dep);
106 printf("\tpwc_dep: %d\n", rdata.ud0.pwc_dep);
107 printf("\tswh_dep: %d\n", rdata.ud0.swh_dep);
108 printf("\tsource 0 %x\n", rdata.ud1.src0_addr);
109 printf("\tsource 1 %x\n", rdata.ud1.src1_addr);
110 printf("\tsource 2 %x\n", rdata.ud1.src2_addr);
111 printf("\tdest %x\n", rdata.ud1.dst_addr);
112 printf("\tmrf %x\n", rdata.ud1.mrf_addr);
113 printf("\tIP: %x\n", rdata.ud2.exip);
114 printf("\topcode: %x\n", rdata.ud2.opcode);
115}
116
117static void
118find_stuck_threads(void)
119{
120 int i, j;
121 for (i = 0; i < 15; i++)
122 for (j = 0; j < 5; j++) {
123 struct eu_rdata rdata;
124 rdata = collect_rdata(i, j);
125 if (rdata.ud0.thread_status == 2 ||
126 rdata.ud0.thread_status == 4) {
127 printf("%d %d:\n", i, j);
128 print_rdata(rdata);
129 }
130 }
131}
132
133int main(int argc, char *argv[]) {
134 struct pci_device *pci_dev;
135 pci_dev = intel_get_pci_device();
136
137 intel_register_access_init(pci_dev, 1);
138 find_stuck_threads();
139// collect_rdata(atoi(argv[1]), atoi(argv[2]));
140 return 0;
141}