1 /*
2  * Copyright (C) 2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  */
7 
8 #include "shared/source/utilities/software_tags.h"
9 
10 #include "shared/source/debug_settings/debug_settings_manager.h"
11 #include "shared/source/helpers/file_io.h"
12 
13 namespace NEO {
14 namespace SWTags {
15 
bxml(std::ostream & os)16 void BXMLHeapInfo::bxml(std::ostream &os) {
17     os << "<Structure Name=\"SWTAG_BXML_HEAP_INFO\" Source=\"Driver\" Project=\"All\">\n";
18     os << "  <Description>BXML heap info. This will always be at offset 0.</Description>\n";
19     os << "  <DWord Name=\"0\">\n";
20     os << "    <BitField HighBit=\"31\" LowBit=\"0\" Name=\"MagicNumber\" Format=\"U32\">\n";
21     os << "      <Description>This is the target of the MI_STORE_DATA_IMM that specifies where the heap exists. This value will always be 0xDEB06D0C.</Description>\n";
22     os << "      <ValidValue Value=\"DEB06D0Ch\" IsDefault=\"true\" Name=\"SWTAG_MAGIC_NUMBER\" />\n";
23     os << "    </BitField>\n";
24     os << "  </DWord>\n";
25     os << "  <DWord Name=\"1\">\n";
26     os << "    <BitField HighBit=\"31\" LowBit=\"0\" Name=\"HeapSize\" Format=\"U32\">\n";
27     os << "      <Description>Specifies the size in DWORDs of the BXML buffer allocated by the UMD driver.</Description>\n";
28     os << "    </BitField>\n";
29     os << "  </DWord>\n";
30     os << "  <DWord Name=\"2\">\n";
31     os << "    <BitField HighBit=\"31\" LowBit=\"0\" Name=\"Component\" Format=\"U32\">\n";
32     os << "      <Description>Specifies the component type.</Description>\n";
33     os << "    </BitField>\n";
34     os << "  </DWord>\n";
35     os << "</Structure>\n";
36 }
37 
bxml(std::ostream & os)38 void SWTagHeapInfo::bxml(std::ostream &os) {
39     os << "<Structure Name=\"SWTAG_HEAP_INFO\" Source=\"Driver\" Project=\"All\">\n";
40     os << "  <Description>Software tag heap info. This will always be at offset 0.</Description>\n";
41     os << "  <DWord Name=\"0\">\n";
42     os << "    <BitField HighBit=\"31\" LowBit=\"0\" Name=\"MagicNumber\" Format=\"U32\">\n";
43     os << "      <Description>This is the target of the MI_STORE_DATA_IMM that specifies where the heap exists. This value will always be 0xDEB06DD1.</Description>\n";
44     os << "      <ValidValue Value=\"DEB06DD1h\" IsDefault=\"true\" Name=\"SWTAG_MAGIC_NUMBER\"/>\n";
45     os << "    </BitField>\n";
46     os << "  </DWord>\n";
47     os << "  <DWord Name=\"1\">\n";
48     os << "    <BitField HighBit=\"31\" LowBit=\"0\" Name=\"HeapSize\" Format=\"U32\">\n";
49     os << "      <Description>Specifies the size in DWORDs of the tag heap allocated by the UMD driver. Maximum value is 1MB.</Description>\n";
50     os << "    </BitField>\n";
51     os << "  </DWord>\n";
52     os << "  <DWord Name=\"2\">\n";
53     os << "    <BitField HighBit=\"31\" LowBit=\"0\" Name=\"Component\" Format=\"U32\">\n";
54     os << "      <Description>Specifies the component type.</Description>\n";
55     os << "    </BitField>\n";
56     os << "  </DWord>\n";
57     os << "</Structure>\n";
58 }
59 
getMarkerNoopID(OpCode opcode)60 uint32_t BaseTag::getMarkerNoopID(OpCode opcode) {
61     MarkerNoopID id;
62     id.OpCode = static_cast<uint32_t>(opcode);
63     id.Reserved = 0;
64     return id.value;
65 }
66 
getOffsetNoopID(uint32_t offset)67 uint32_t BaseTag::getOffsetNoopID(uint32_t offset) {
68     OffsetNoopID id;
69     id.Offset = offset / sizeof(uint32_t);
70     id.SubTag = 0;
71     id.MagicBit = 1;
72     id.Reserved = 0;
73     return id.value;
74 }
75 
bxml(std::ostream & os,OpCode opcode,size_t size,const char * name)76 void BaseTag::bxml(std::ostream &os, OpCode opcode, size_t size, const char *name) {
77     os << "  <DWord Name=\"0\">\n";
78     os << "    <BitField Name=\"DriverDebug\" HighBit=\"31\" LowBit=\"31\" Format=\"OpCode\">\n";
79     os << "      <Description>Specifies this is a SW driver debug tag.</Description>\n";
80     os << "      <ValidValue Value=\"1\" IsDefault=\"true\" Name=\"DRIVER_DEBUG\" />\n";
81     os << "    </BitField>\n";
82     os << "    <BitField Name=\"Component\" HighBit=\"30\" LowBit=\"24\" Format=\"OpCode\">\n";
83     os << "      <Description>Specifies the component type.</Description>\n";
84     os << "      <ValidValue Value=\"1h\" IsDefault=\"true\" Name=\"COMMON\" />\n";
85     os << "    </BitField>\n";
86     os << "    <BitField Name=\"OpCode\" HighBit=\"23\" LowBit=\"0\" Format=\"OpCode\">\n";
87     os << "      <Description>Specifies the opcode.</Description>\n";
88     os << "      <ValidValue Value=\"" << static_cast<uint32_t>(opcode) << "\" IsDefault=\"true\" Name=\"" << name << "\" />\n";
89     os << "    </BitField>\n";
90     os << "  </DWord>\n";
91     os << "  <DWord Name=\"1\">\n";
92     os << "    <BitField Name=\"DWORDCount\" HighBit=\"31\" LowBit=\"0\" Format=\"=n\">\n";
93     os << "      <Description>Specifies the tag size in DWORDs (TotalSize - 2)</Description>\n";
94     os << "      <ValidValue Value=\"" << static_cast<uint32_t>(size / sizeof(uint32_t) - 2) << "\" IsDefault=\"true\" Name=\"DWORD_COUNT_n\" />\n";
95     os << "    </BitField>\n";
96     os << "  </DWord>\n";
97 }
98 
bxml(std::ostream & os)99 void KernelNameTag::bxml(std::ostream &os) {
100     os << "<Instruction Name=\"KernelName\" Source=\"Driver\" Project=\"All\" LengthBias=\"2\">\n";
101     os << "  <Description>Name of the kernel.</Description>\n";
102 
103     BaseTag::bxml(os, OpCode::KernelName, sizeof(KernelNameTag), "KERNEL_NAME");
104 
105     unsigned int stringDWORDSize = KENEL_NAME_STR_LENGTH / sizeof(uint32_t);
106     os << "  <Dword Name=\"2.." << 2 + stringDWORDSize - 1 << "\">\n";
107     os << "    <BitField Name=\"KernelName\" HighBit=\"" << 32 * stringDWORDSize - 1 << "\" LowBit=\"0\" Format=\"string\">\n";
108     os << "      <Description>Name of the kernel.</Description>\n";
109     os << "    </BitField>\n";
110     os << "  </Dword>\n";
111 
112     os << "</Instruction>\n";
113 }
114 
bxml(std::ostream & os)115 void PipeControlReasonTag::bxml(std::ostream &os) {
116     os << "<Instruction Name=\"PipeControlReason\" Source=\"Driver\" Project=\"All\" LengthBias=\"2\">\n";
117     os << "  <Description>Reason for why the PIPE_CONTROL was inserted.</Description>\n";
118 
119     BaseTag::bxml(os, OpCode::PipeControlReason, sizeof(PipeControlReasonTag), "PIPE_CONTROL_REASON");
120 
121     unsigned int stringDWORDSize = REASON_STR_LENGTH / sizeof(uint32_t);
122     os << "  <Dword Name=\"2.." << 2 + stringDWORDSize - 1 << "\">\n";
123     os << "    <BitField Name=\"PipeControlReason\" HighBit=\"" << 32 * stringDWORDSize - 1 << "\" LowBit=\"0\" Format=\"string\">\n";
124     os << "      <Description>Reason of the PIPE_CONTROL.</Description>\n";
125     os << "    </BitField>\n";
126     os << "  </Dword>\n";
127 
128     os << "</Instruction>\n";
129 }
130 
bxml(std::ostream & os)131 void CallNameBeginTag::bxml(std::ostream &os) {
132     os << "<Instruction Name=\"CallNameBegin\" Source=\"Driver\" Project=\"All\" LengthBias=\"2\">\n";
133     os << "  <Description>ZE Call where the GPU originated from.</Description>\n";
134 
135     BaseTag::bxml(os, OpCode::CallNameBegin, sizeof(CallNameBeginTag), "ZE_CALL_NAME_BEGIN");
136 
137     unsigned int stringDWORDSize = ZE_CALL_NAME_STR_LENGTH / sizeof(uint32_t);
138     os << "  <Dword Name=\"2.." << 2 + stringDWORDSize - 1 << "\">\n";
139     os << "    <BitField Name=\"CallNameBegin\" HighBit=\"" << 32 * stringDWORDSize - 1 << "\" LowBit=\"0\" Format=\"string\">\n";
140     os << "      <Description>Entry of ZE Call where the GPU originated from.</Description>\n";
141     os << "    </BitField>\n";
142     os << "  </Dword>\n";
143     os << "  <Dword Name=\"" << 2 + stringDWORDSize << ".." << 2 + 2 * stringDWORDSize - 1 << "\">\n";
144     os << "    <BitField Name=\"SWTagId\" HighBit=\"" << 32 * stringDWORDSize - 1 << "\" LowBit=\"0\" Format=\"string\">\n";
145     os << "      <Description>Exit of ZE Call where the GPU originated from.</Description>\n";
146     os << "    </BitField>\n";
147     os << "  </Dword>\n";
148 
149     os << "</Instruction>\n";
150 }
151 
bxml(std::ostream & os)152 void CallNameEndTag::bxml(std::ostream &os) {
153     os << "<Instruction Name=\"CallNameEnd\" Source=\"Driver\" Project=\"All\" LengthBias=\"2\">\n";
154     os << "  <Description>ZE Call where the GPU originated from.</Description>\n";
155 
156     BaseTag::bxml(os, OpCode::CallNameEnd, sizeof(CallNameEndTag), "ZE_CALL_NAME_END");
157 
158     unsigned int stringDWORDSize = ZE_CALL_NAME_STR_LENGTH / sizeof(uint32_t);
159     os << "  <Dword Name=\"2.." << 2 + stringDWORDSize - 1 << "\">\n";
160     os << "    <BitField Name=\"CallNameEnd\" HighBit=\"" << 32 * stringDWORDSize - 1 << "\" LowBit=\"0\" Format=\"string\">\n";
161     os << "      <Description>Exit of ZE Call where the GPU originated from.</Description>\n";
162     os << "    </BitField>\n";
163     os << "  </Dword>\n";
164     os << "  <Dword Name=\"" << 2 + stringDWORDSize << ".." << 2 + 2 * stringDWORDSize - 1 << "\">\n";
165     os << "    <BitField Name=\"SWTagId\" HighBit=\"" << 32 * stringDWORDSize - 1 << "\" LowBit=\"0\" Format=\"string\">\n";
166     os << "      <Description>Exit of ZE Call where the GPU originated from.</Description>\n";
167     os << "    </BitField>\n";
168     os << "  </Dword>\n";
169 
170     os << "</Instruction>\n";
171 }
172 
SWTagBXML()173 SWTagBXML::SWTagBXML() {
174     std::ostringstream ss;
175 
176     ss << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
177     ss << "<BSpec>\n";
178 
179     BXMLHeapInfo::bxml(ss);
180     SWTagHeapInfo::bxml(ss);
181 
182     KernelNameTag::bxml(ss);
183     PipeControlReasonTag::bxml(ss);
184     CallNameBeginTag::bxml(ss);
185     CallNameEndTag::bxml(ss);
186 
187     ss << "</BSpec>";
188 
189     str = ss.str();
190 
191     if (DebugManager.flags.DumpSWTagsBXML.get()) {
192         writeDataToFile("swtagsbxml_dump.xml", str.c_str(), str.size());
193     }
194 }
195 
196 } // namespace SWTags
197 } // namespace NEO
198