1 /* 2 * Copyright (C) 2021 Intel Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 */ 7 8 #pragma once 9 #include "shared/source/helpers/string.h" 10 11 #include <sstream> 12 #include <string> 13 14 namespace NEO { 15 namespace SWTags { 16 17 enum class OpCode : uint32_t { 18 Unknown, 19 KernelName, 20 PipeControlReason, 21 CallNameBegin, 22 CallNameEnd 23 }; 24 25 enum class Component : uint32_t { 26 COMMON = 1 27 }; 28 29 struct BXMLHeapInfo { 30 const uint32_t magicNumber = 0xDEB06D0C; 31 const uint32_t heapSize; 32 const uint32_t component = static_cast<uint32_t>(Component::COMMON); 33 BXMLHeapInfoBXMLHeapInfo34 BXMLHeapInfo(size_t size) : heapSize(static_cast<uint32_t>(size)) {} 35 36 static void bxml(std::ostream &os); 37 }; 38 39 struct SWTagHeapInfo { 40 const uint32_t magicNumber = 0xDEB06DD1; 41 const uint32_t heapSize; 42 const uint32_t component = static_cast<uint32_t>(Component::COMMON); 43 SWTagHeapInfoSWTagHeapInfo44 SWTagHeapInfo(size_t size) : heapSize(static_cast<uint32_t>(size)) {} 45 46 static void bxml(std::ostream &os); 47 }; 48 49 struct BaseTag { 50 public: BaseTagBaseTag51 BaseTag(OpCode code, size_t size) : opcode(static_cast<uint32_t>(code)), 52 reserved(0), 53 component(static_cast<uint32_t>(Component::COMMON)), 54 driverDebug(1), 55 DWORDCount(static_cast<uint32_t>(size / sizeof(uint32_t) - 2)) {} 56 getOpCodeBaseTag57 OpCode getOpCode() const { return static_cast<OpCode>(opcode); } 58 static uint32_t getMarkerNoopID(OpCode opcode); 59 static uint32_t getOffsetNoopID(uint32_t offset); 60 static void bxml(std::ostream &os, OpCode opcode, size_t size, const char *name); 61 62 protected: 63 union MarkerNoopID { 64 struct { 65 uint32_t OpCode : 20; 66 uint32_t Reserved : 12; 67 }; 68 uint32_t value; 69 }; 70 union OffsetNoopID { 71 struct { 72 uint32_t Offset : 20; 73 uint32_t SubTag : 1; 74 uint32_t MagicBit : 1; 75 uint32_t Reserved : 10; 76 }; 77 uint32_t value; 78 }; 79 80 const uint32_t opcode : 20; 81 const uint32_t reserved : 4; 82 const uint32_t component : 7; 83 const uint32_t driverDebug : 1; // always 0x1 84 const uint32_t DWORDCount; 85 }; 86 87 struct KernelNameTag : public BaseTag { 88 public: KernelNameTagKernelNameTag89 KernelNameTag(const char *name, uint32_t callId) 90 : BaseTag(OpCode::KernelName, sizeof(KernelNameTag)) { 91 strcpy_s(kernelName, KENEL_NAME_STR_LENGTH, name); 92 } 93 94 static void bxml(std::ostream &os); 95 96 private: 97 static constexpr unsigned int KENEL_NAME_STR_LENGTH = sizeof(uint32_t) * 16; // Dword aligned 98 char kernelName[KENEL_NAME_STR_LENGTH] = {}; 99 }; 100 101 struct PipeControlReasonTag : public BaseTag { 102 public: PipeControlReasonTagPipeControlReasonTag103 PipeControlReasonTag(const char *reason, uint32_t callId) 104 : BaseTag(OpCode::PipeControlReason, sizeof(PipeControlReasonTag)) { 105 strcpy_s(reasonString, REASON_STR_LENGTH, reason); 106 } 107 108 static void bxml(std::ostream &os); 109 110 private: 111 static constexpr unsigned int REASON_STR_LENGTH = sizeof(uint32_t) * 32; // Dword aligned 112 char reasonString[REASON_STR_LENGTH] = {}; 113 }; 114 115 struct CallNameBeginTag : public BaseTag { 116 public: CallNameBeginTagCallNameBeginTag117 CallNameBeginTag(const char *name, uint32_t callId) 118 : BaseTag(OpCode::CallNameBegin, sizeof(CallNameBeginTag)) { 119 strcpy_s(zeCallName, ZE_CALL_NAME_STR_LENGTH, name); 120 snprintf(zeCallId, sizeof(uint32_t), "%x", callId); 121 } 122 123 static void bxml(std::ostream &os); 124 125 private: 126 static constexpr unsigned int ZE_CALL_NAME_STR_LENGTH = sizeof(uint32_t) * 32; // Dword aligned 127 char zeCallName[ZE_CALL_NAME_STR_LENGTH] = {}; 128 char zeCallId[ZE_CALL_NAME_STR_LENGTH] = {}; 129 }; 130 131 struct CallNameEndTag : public BaseTag { 132 public: CallNameEndTagCallNameEndTag133 CallNameEndTag(const char *name, uint32_t callId) 134 : BaseTag(OpCode::CallNameEnd, sizeof(CallNameEndTag)) { 135 strcpy_s(zeCallName, ZE_CALL_NAME_STR_LENGTH, name); 136 snprintf(zeCallId, sizeof(uint32_t), "%x", callId); 137 } 138 139 static void bxml(std::ostream &os); 140 141 private: 142 static constexpr unsigned int ZE_CALL_NAME_STR_LENGTH = sizeof(uint32_t) * 32; // Dword aligned 143 char zeCallName[ZE_CALL_NAME_STR_LENGTH] = {}; 144 char zeCallId[ZE_CALL_NAME_STR_LENGTH] = {}; 145 }; 146 147 struct SWTagBXML { 148 SWTagBXML(); 149 150 std::string str; 151 }; 152 153 } // namespace SWTags 154 } // namespace NEO 155