├── .clang-format ├── main ├── Base │ ├── TLGlobal.cpp │ ├── CMakeLists.txt │ ├── TLGlobal.hpp │ ├── TLLocal.hpp │ └── TLEnum.hpp ├── V3 │ ├── CMakeLists.txt │ └── v3_memaxi.hpp ├── DPI │ ├── CMakeLists.txt │ ├── tilelink_dpi_configs.hpp │ ├── tilelink_enum.svh │ ├── memory_dpi.hpp │ ├── tilelink_dpi.hpp │ └── memory_dpi.svh ├── CHIron │ ├── CMakeLists.txt │ ├── clogdpi_b.hpp │ ├── clogdpi_b.svh │ ├── clog_b.hpp │ ├── clog.hpp │ └── clogdpi_b.cpp ├── Events │ ├── CMakeLists.txt │ ├── TLSystemEvent.cpp │ └── TLSystemEvent.hpp ├── Fuzzer │ ├── CMakeLists.txt │ ├── MMIOFuzzer.cpp │ ├── Fuzzer.h │ └── ULFuzzer.cpp ├── Memory │ ├── CMakeLists.txt │ ├── Bundle.hpp │ └── MemoryAgent.hpp ├── Plugins │ ├── CMakeLists.txt │ ├── ChiselDB.hpp │ ├── CHIronCLogB.hpp │ ├── ChiselDB.cpp │ ├── CHIronCLogB.cpp │ ├── PluginManager.hpp │ └── PluginManager.cpp ├── System │ ├── CMakeLists.txt │ └── TLSystem.hpp ├── TLAgent │ ├── CMakeLists.txt │ ├── ULAgent.h │ ├── Bundle.h │ ├── MMIOAgent.h │ └── BaseAgent.h ├── Sequencer │ ├── CMakeLists.txt │ └── TLSequencer.hpp ├── PortGen │ ├── CMakeLists.txt │ ├── portgen_static.hpp │ ├── portgen_dynamic.hpp │ ├── portgen_main.cpp │ └── portgen_dynamic.cpp ├── Utils │ ├── autoinclude.h │ ├── assert.hpp │ ├── TLDefault.h │ ├── gravity_utility.hpp │ └── Common.h └── CMakeLists.txt ├── .gitignore ├── assets ├── README.overall.png ├── README.portgen.dynamic.png └── README.portgen.static.png ├── configs ├── coupledL2-test-l2l3.tltest.ini ├── coupledL2-test-l2l3l2.tltest.ini ├── openLLC-test-l2l3.tltest.ini ├── openLLC-test-l2l3l2.tltest.ini └── user.tltest.ini ├── .gitmodules ├── scripts └── run_v3lt.sh ├── LICENSE └── Makefile /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM -------------------------------------------------------------------------------- /main/Base/TLGlobal.cpp: -------------------------------------------------------------------------------- 1 | #include "TLGlobal.hpp" 2 | 3 | TLGlobal glbl; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | cmake-build-debug 3 | verilated 4 | run 5 | .idea 6 | .vscode 7 | .metals 8 | .scala-build -------------------------------------------------------------------------------- /assets/README.overall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenXiangShan/tl-test-new/HEAD/assets/README.overall.png -------------------------------------------------------------------------------- /main/V3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(V3 OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/Base/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(Base OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/DPI/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(DPI OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/CHIron/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(CHIron OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/Events/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(Events OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/Fuzzer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(Fuzzer OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/Memory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(Memory OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/Plugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(Plugins OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/System/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(System OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/TLAgent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(TLAgent OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /assets/README.portgen.dynamic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenXiangShan/tl-test-new/HEAD/assets/README.portgen.dynamic.png -------------------------------------------------------------------------------- /assets/README.portgen.static.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenXiangShan/tl-test-new/HEAD/assets/README.portgen.static.png -------------------------------------------------------------------------------- /main/Sequencer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources *.cpp *h *.hpp) 2 | 3 | ADD_LIBRARY(Sequencer OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /main/PortGen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE sources portgen_static.cpp portgen_dynamic.cpp) 2 | 3 | ADD_LIBRARY(PortGen OBJECT ${sources}) 4 | -------------------------------------------------------------------------------- /configs/coupledL2-test-l2l3.tltest.ini: -------------------------------------------------------------------------------- 1 | # coupledL2-test-l2l3 2 | [tltest.config] 3 | core = 1 4 | core.tl_c = 1 5 | core.tl_ul = 0 -------------------------------------------------------------------------------- /configs/coupledL2-test-l2l3l2.tltest.ini: -------------------------------------------------------------------------------- 1 | # coupledL2-test-l2l3l2 2 | [tltest.config] 3 | core = 2 4 | core.tl_c = 1 5 | core.tl_ul = 0 -------------------------------------------------------------------------------- /configs/openLLC-test-l2l3.tltest.ini: -------------------------------------------------------------------------------- 1 | # coupledL2-test-l2l3 2 | [tltest.config] 3 | core = 1 4 | core.tl_c = 1 5 | core.tl_ul = 2 6 | -------------------------------------------------------------------------------- /configs/openLLC-test-l2l3l2.tltest.ini: -------------------------------------------------------------------------------- 1 | # coupledL2-test-l2l3l2 2 | [tltest.config] 3 | core = 2 4 | core.tl_c = 1 5 | core.tl_ul = 2 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dut/CoupledL2"] 2 | path = dut/CoupledL2 3 | url = https://github.com/OpenXiangShan/CoupledL2.git 4 | [submodule "dut/OpenLLC"] 5 | path = dut/OpenLLC 6 | url = https://github.com/OpenXiangShan/OpenLLC.git 7 | -------------------------------------------------------------------------------- /scripts/run_v3lt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd ./run && ./tltest_v3lt 2>&1 | tee tltest_v3lt.log 3 | exit ${PIPESTATUS[0]} 4 | 5 | # NOTICE: 6 | # * Wrap executable with piped tee to save log. 7 | # * Keep the logging procedure simple for now, sophisticated implementation 8 | # might be available in future. 9 | # 10 | -------------------------------------------------------------------------------- /main/PortGen/portgen_static.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TLC_TEST_V3_PORTGEN_STATIC_H 4 | #define TLC_TEST_V3_PORTGEN_STATIC_H 5 | 6 | #include 7 | 8 | 9 | namespace V3::PortGen { 10 | 11 | std::string Generate(int coreCount, int tlULPerCore); 12 | } 13 | 14 | 15 | #endif // TLC_TEST_V3_PORTGEN_DYNAMIC_H 16 | -------------------------------------------------------------------------------- /main/System/TLSystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TLC_TEST_STARTUP_H 4 | #define TLC_TEST_STARTUP_H 5 | 6 | #include "../Sequencer/TLSequencer.hpp" 7 | #include "../Plugins/PluginManager.hpp" 8 | 9 | #include 10 | 11 | 12 | void TLInitialize(TLSequencer** tltest, PluginManager** plugins, std::function tlcfgInit); 13 | void TLFinalize(TLSequencer** tltest, PluginManager** plugins); 14 | 15 | 16 | #endif // TLC_TEST_STARTUP_H 17 | 18 | -------------------------------------------------------------------------------- /main/DPI/tilelink_dpi_configs.hpp: -------------------------------------------------------------------------------- 1 | // ================================================ 2 | // ## BOSC XiangShan Kunminghu Internal ## 3 | // TL-Test-Passive Infrastructure 4 | // - author : Kumonda 221 (Ding Haonan) 5 | // - email : 6 | // Built on: May 13 2024 - 16:00:25 7 | // ------------------------------------------------ 8 | // Build target: tltest_dpi_configs_gen.cpp 9 | // ================================================ 10 | // 11 | #ifndef GUARD_TLTEST_DPI_CONFIGS 12 | #define GUARD_TLTEST_DPI_CONFIGS 13 | 14 | #define TLTEST_LOCAL_CORE_COUNT 4 15 | 16 | #define TLTEST_LOCAL_MASTER_COUNT_PER_CORE_TLC 1 17 | #define TLTEST_LOCAL_MASTER_COUNT_PER_CORE_TLUL 2 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /main/Events/TLSystemEvent.cpp: -------------------------------------------------------------------------------- 1 | #include "TLSystemEvent.hpp" 2 | // 3 | // Created by Kumonda221 on 2024-05-06 4 | // 5 | 6 | 7 | // Implementation of: class TLSystemInitializationPreEvent 8 | TLSystemInitializationPreEvent::TLSystemInitializationPreEvent(TLLocalConfig* config) noexcept 9 | : config (config) 10 | { } 11 | 12 | // Implementation of: class TLSystemInitializationPostEvent 13 | TLSystemInitializationPostEvent::TLSystemInitializationPostEvent(TLSequencer* system) noexcept 14 | : system (system) 15 | { } 16 | 17 | 18 | 19 | // Implementation of: class TLSystemFinalizationPreEvent 20 | TLSystemFinalizationPreEvent::TLSystemFinalizationPreEvent(TLSequencer* system) noexcept 21 | : system (system) 22 | { } 23 | 24 | // Implementation of: class TLSystemFinalizationPostEvent 25 | 26 | -------------------------------------------------------------------------------- /main/Plugins/ChiselDB.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // 4 | // 5 | 6 | #ifndef TLC_TEST_PLUGINS_CHISEL_DB 7 | #define TLC_TEST_PLUGINS_CHISEL_DB 8 | 9 | #include "PluginManager.hpp" 10 | 11 | 12 | namespace ChiselDB { 13 | 14 | // 15 | void InitDB(); 16 | void SaveDB(const char* file); 17 | 18 | // 19 | class PluginInstance : public Plugin { 20 | public: 21 | PluginInstance() noexcept; 22 | 23 | public: 24 | std::string GetDisplayName() const noexcept override; 25 | std::string GetDescription() const noexcept override; 26 | std::string GetVersion() const noexcept override; 27 | 28 | void OnEnable() override; 29 | void OnDisable() override; 30 | }; 31 | 32 | } 33 | 34 | 35 | #endif // TLC_TEST_PLUGINS_CHISEL_DB 36 | -------------------------------------------------------------------------------- /main/Plugins/CHIronCLogB.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // 4 | // 5 | 6 | #ifndef TLC_TEST_PLUGINS_CHIRON_CLOG_B 7 | #define TLC_TEST_PLUGINS_CHIRON_CLOG_B 8 | 9 | #include "PluginManager.hpp" 10 | 11 | 12 | namespace CHIron::CLogB { 13 | 14 | // 15 | bool Init(const char* file); 16 | void Close(); 17 | 18 | // 19 | class PluginInstance : public Plugin { 20 | public: 21 | PluginInstance() noexcept; 22 | 23 | public: 24 | std::string GetDisplayName() const noexcept override; 25 | std::string GetDescription() const noexcept override; 26 | std::string GetVersion() const noexcept override; 27 | 28 | void OnEnable() override; 29 | void OnDisable() override; 30 | }; 31 | } 32 | 33 | 34 | 35 | #endif // TLC_TEST_PLUGINS_CHIRON_CLOG_B 36 | -------------------------------------------------------------------------------- /main/DPI/tilelink_enum.svh: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Kumonda221 (Ding Haonan) on 2024/03/20 3 | // 4 | 5 | `define PutFullData 0 6 | `define PutPartialData 1 7 | `define ArithmeticData 2 8 | `define LogicalData 3 9 | `define Get 4 10 | `define Intent 5 11 | `define AcquireBlock 6 12 | `define AcquirePerm 7 13 | 14 | `define ProbeBlock 6 15 | `define ProbePerm 7 16 | 17 | `define AccessAck 0 18 | `define AccessAckData 1 19 | `define HintAck 2 20 | `define ProbeAck 4 21 | `define ProbeAckData 5 22 | `define Release 6 23 | `define ReleaseData 7 24 | 25 | `define Grant 4 26 | `define GrantData 5 27 | `define ReleaseAck 6 28 | 29 | `define GrantAck 0 30 | -------------------------------------------------------------------------------- /main/Base/TLGlobal.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TLC_TEST_TLCONFIG_H 4 | #define TLC_TEST_TLCONFIG_H 5 | 6 | 7 | #define TLTP_LOG_GLOBAL(str_proc) \ 8 | { std::cout << Gravity::StringAppender().Append("[tl-test-new] ", __FILE__, ": ").str_proc.ToString(); } 9 | 10 | 11 | struct TLGlobalConfiguration { 12 | 13 | bool errorHintInaccurate; 14 | 15 | bool verbose; 16 | bool verbose_xact_fired; 17 | bool verbose_xact_sequenced; 18 | bool verbose_xact_data_complete; 19 | bool verbose_l2tol1hint_accuracy; 20 | bool verbose_memory_axi_write; 21 | bool verbose_memory_axi_read; 22 | bool verbose_memory_data_full; 23 | bool verbose_data_full; 24 | bool verbose_agent_debug; 25 | }; 26 | 27 | struct TLGlobalContext { 28 | }; 29 | 30 | struct TLGlobal { 31 | 32 | TLGlobalConfiguration cfg; 33 | TLGlobalContext ctx; 34 | }; 35 | 36 | 37 | extern TLGlobal glbl; 38 | 39 | 40 | #endif //TLC_TEST_TLCONFIG_H 41 | -------------------------------------------------------------------------------- /main/PortGen/portgen_dynamic.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TLC_TEST_V3_PORTGEN_DYNAMIC_H 4 | #define TLC_TEST_V3_PORTGEN_DYNAMIC_H 5 | 6 | #include "../Utils/autoinclude.h" 7 | 8 | #include AUTOINCLUDE_VERILATED(VTestTop.h) 9 | 10 | #include "../Sequencer/TLSequencer.hpp" 11 | 12 | #include 13 | #include 14 | 15 | 16 | namespace V3::PortGen { 17 | 18 | void LoadDynamic(std::vector includePaths, int coreCount, int tlULPerCore); 19 | 20 | void LoadStatic(); 21 | 22 | uint64_t GetCoreCount(); 23 | uint64_t GetULPortCountPerCore(); 24 | 25 | void PushChannelA(VTestTop* verilated, TLSequencer* tltest); 26 | void PullChannelA(VTestTop* verilated, TLSequencer* tltest); 27 | 28 | void PushChannelB(VTestTop* verilated, TLSequencer* tltest); 29 | void PullChannelB(VTestTop* verilated, TLSequencer* tltest); 30 | 31 | void PushChannelC(VTestTop* verilated, TLSequencer* tltest); 32 | void PullChannelC(VTestTop* verilated, TLSequencer* tltest); 33 | 34 | void PushChannelD(VTestTop* verilated, TLSequencer* tltest); 35 | void PullChannelD(VTestTop* verilated, TLSequencer* tltest); 36 | 37 | void PushChannelE(VTestTop* verilated, TLSequencer* tltest); 38 | void PullChannelE(VTestTop* verilated, TLSequencer* tltest); 39 | } 40 | 41 | 42 | #endif // TLC_TEST_V3_PORTGEN_DYNAMIC_H 43 | -------------------------------------------------------------------------------- /main/Plugins/ChiselDB.cpp: -------------------------------------------------------------------------------- 1 | #include "ChiselDB.hpp" 2 | 3 | #include "../Utils/autoinclude.h" 4 | #include "../Utils/Common.h" 5 | 6 | #include AUTOINCLUDE_CHISELDB(chisel_db.cpp) 7 | #include AUTOINCLUDE_CHISELDB(perfCCT.cpp) 8 | 9 | 10 | // 11 | void ChiselDB::InitDB() 12 | { 13 | init_db(true, false, ""); 14 | } 15 | 16 | // 17 | void ChiselDB::SaveDB(const char* file) 18 | { 19 | save_db(file); 20 | } 21 | 22 | 23 | // Implementation of: class PluginInstance 24 | namespace ChiselDB { 25 | 26 | PluginInstance::PluginInstance() noexcept 27 | : Plugin ("chiseldb") 28 | { } 29 | 30 | std::string PluginInstance::GetDisplayName() const noexcept 31 | { 32 | return "ChiselDB"; 33 | } 34 | 35 | std::string PluginInstance::GetDescription() const noexcept 36 | { 37 | return "ChiselDB Compatibility Plugin for TL-Test New"; 38 | } 39 | 40 | std::string PluginInstance::GetVersion() const noexcept 41 | { 42 | return "Kunming Lake"; 43 | } 44 | 45 | void PluginInstance::OnEnable() 46 | { 47 | LogInfo("ChiselDB", Append("Enabled").EndLine()); 48 | 49 | InitDB(); 50 | 51 | LogInfo("ChiselDB", Append("DB Initialized").EndLine()); 52 | } 53 | 54 | void PluginInstance::OnDisable() 55 | { 56 | const char* file = "chiseldb.db"; 57 | 58 | LogInfo("ChiselDB", Append("Saving DB to: ", file).EndLine()); 59 | 60 | SaveDB(file); 61 | 62 | LogInfo("ChiselDB", Append("Saved DB").EndLine()); 63 | LogInfo("ChiselDB", Append("Disabled").EndLine()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /main/Memory/Bundle.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TLC_TEST_AXI_BUNDLE_H 2 | #define TLC_TEST_AXI_BUNDLE_H 3 | 4 | #include "../Utils/Common.h" 5 | 6 | 7 | namespace axi_agent { 8 | 9 | // 10 | class DecoupledBundle { 11 | public: 12 | uint8_t valid; 13 | uint8_t ready; 14 | 15 | bool fire() const { 16 | return valid && ready; 17 | } 18 | }; 19 | 20 | // 21 | class BundleChannelAW : public DecoupledBundle { 22 | public: 23 | uint32_t id; 24 | uint64_t addr; 25 | uint8_t len; 26 | uint8_t size; 27 | uint8_t burst; 28 | }; 29 | 30 | template 31 | class BundleChannelW : public DecoupledBundle { 32 | public: 33 | shared_tldata_t data; 34 | uint64_t strb; 35 | uint8_t last; 36 | }; 37 | 38 | class BundleChannelB : public DecoupledBundle { 39 | public: 40 | uint32_t id; 41 | uint8_t resp; 42 | }; 43 | 44 | // 45 | class BundleChannelAR : public DecoupledBundle { 46 | public: 47 | uint32_t id; 48 | uint64_t addr; 49 | uint8_t len; 50 | uint8_t size; 51 | uint8_t burst; 52 | }; 53 | 54 | template 55 | class BundleChannelR : public DecoupledBundle { 56 | public: 57 | uint32_t id; 58 | shared_tldata_t data; 59 | uint8_t resp; 60 | uint8_t last; 61 | }; 62 | 63 | // 64 | template 65 | class Bundle { 66 | public: 67 | BundleChannelAW aw; 68 | BundleChannelW w; 69 | BundleChannelB b; 70 | BundleChannelAR ar; 71 | BundleChannelR r; 72 | }; 73 | } 74 | 75 | #endif // TLC_TEST_AXI_BUNDLE_H 76 | -------------------------------------------------------------------------------- /configs/user.tltest.ini: -------------------------------------------------------------------------------- 1 | [tltest.config] 2 | # core 3 | # core.tl_c 4 | # core.tl_ul 5 | maximum_cycle = 0 6 | memory.enable = 1 7 | memory.start = 0x00000000 8 | memory.end = 0x00080000 # ~0x0007FFFF 9 | memory.backend.ooor = 0 10 | memory.backend.rd.depth = 0 11 | memory.backend.rd.latency = 0 12 | memory.backend.wr.depth = 0 13 | memory.backend.wr.latency = 0 14 | memory.backend.cycle_unit = 2 15 | memory.backend.port.count = 1 16 | memory.sync.strict = 0 17 | mmio.enable = 0 18 | mmio.start = 0 19 | mmio.end = 0 20 | cmo.enable = 0 21 | cmo.enable.cbo.clean = 1 22 | cmo.enable.cbo.flush = 1 23 | cmo.enable.cbo.inval = 1 24 | cmo.start = 0x00000000 25 | cmo.end = 0x00080000 26 | cmo.parallel.depth = 0 27 | 28 | error.hintInaccurate = 0 29 | 30 | [tltest.sequence] 31 | mode.0 = FUZZ_ARI 32 | mode.1 = FUZZ_ARI 33 | mode.2 = FUZZ_ARI 34 | mode.3 = FUZZ_ARI 35 | mode.4 = FUZZ_ARI 36 | mode.5 = FUZZ_ARI 37 | 38 | [tltest.profile] 39 | cycle_unit = 2 40 | 41 | [tltest.fuzzer] 42 | seed = 1000 43 | ari.interval = 10000 44 | ari.target = 18 45 | stream.interval = 100 46 | stream.step = 0x40 47 | stream.start = 0x00000000 48 | stream.end = 0x00080000 # ~0x0007FFFF 49 | 50 | unified.enable = 0 51 | unified.mode = ANVIL 52 | 53 | unified.anvil.size = 256 54 | unified.anvil.epoch = 64 55 | unified.anvil.width.b = 1 56 | 57 | [tltest.logger] 58 | verbose = 0 59 | verbose.xact_fired = 1 60 | verbose.xact_sequenced = 0 61 | verbose.xact_data_complete = 1 62 | verbose.memory.axi_write = 1 63 | verbose.memory.axi_read = 1 64 | verbose.data_full = 0 65 | verbose.agent_debug = 0 66 | -------------------------------------------------------------------------------- /main/Fuzzer/MMIOFuzzer.cpp: -------------------------------------------------------------------------------- 1 | #include "Fuzzer.h" 2 | 3 | 4 | MMIOFuzzer::MMIOFuzzer(tl_agent::MMIOAgent* mmioAgent) noexcept 5 | { 6 | this->mmioAgent = mmioAgent; 7 | 8 | this->mmioStart = mmioAgent->config().mmioStart; 9 | this->mmioEnd = mmioAgent->config().mmioEnd; 10 | } 11 | 12 | void MMIOFuzzer::randomTest(bool put) 13 | { 14 | if (!mmioAgent->config().mmioEnable) 15 | return; 16 | 17 | paddr_t addr = (CAGENT_RAND64(mmioAgent, "MMIOFuzzer")); 18 | 19 | addr = remap_mmio_address(addr); 20 | 21 | if (!put || CAGENT_RAND64(mmioAgent, "MMIOFuzzer") % 2) // Get 22 | mmioAgent->do_get(addr &= ~paddr_t(0x07), 3, 0xff); 23 | else 24 | { 25 | // Put 26 | auto data = make_shared_tldata(); 27 | for (int i = 0; i < DATASIZE_MMIO; i++) 28 | data->data[i] = (uint8_t)CAGENT_RAND64(mmioAgent, "MMIOFuzzer"); 29 | 30 | if (CAGENT_RAND64(mmioAgent, "MMIOFuzzer") % 2) // PutPartialData 31 | { 32 | uint8_t size = (uint8_t)(CAGENT_RAND64(mmioAgent, "MMIOFuzzer") % 4); 33 | uint8_t mask; 34 | 35 | if (size == 3) 36 | { 37 | mask = 0xff; 38 | addr &= ~paddr_t(0x07); 39 | } 40 | else if (size == 2) 41 | { 42 | mask = 0xf << (addr & 0x04); 43 | addr &= ~paddr_t(0x03); 44 | } 45 | else if (size == 1) 46 | { 47 | mask = 0x3 << (addr & 0x06); 48 | addr &= ~paddr_t(0x01); 49 | } 50 | else if (size == 0) 51 | { 52 | mask = 0x1 << (addr & 0x07); 53 | } 54 | 55 | mmioAgent->do_putpartialdata(addr, size, mask, data); 56 | 57 | } 58 | else // PutFullData 59 | mmioAgent->do_putfulldata(addr &= ~paddr_t(0x07), data); 60 | } 61 | } 62 | 63 | void MMIOFuzzer::tick() 64 | { 65 | if (this->startupInterval < mmioAgent->config().startupCycle) 66 | { 67 | this->startupInterval++; 68 | return; 69 | } 70 | 71 | this->randomTest(true); 72 | } 73 | -------------------------------------------------------------------------------- /main/Plugins/CHIronCLogB.cpp: -------------------------------------------------------------------------------- 1 | #include "CHIronCLogB.hpp" 2 | 3 | #include "../CHIron/clogdpi_b.hpp" 4 | #include "../Utils/gravity_utility.hpp" 5 | #include "../Utils/Common.h" 6 | 7 | // 8 | static constexpr const char* SHARED_NAME[] = { 9 | "l3top" 10 | }; 11 | 12 | // 13 | bool CHIron::CLogB::Init(const char *file) 14 | { 15 | for (int i = 0; i < (sizeof(SHARED_NAME) / sizeof(SHARED_NAME[0])); i++) 16 | { 17 | uint32_t status; 18 | void* handle = CLogB_OpenFile(Gravity::StringAppender() 19 | .Append(file, ".", SHARED_NAME[i] , ".b").ToString().c_str(), &status); 20 | 21 | if (status) 22 | return false; 23 | 24 | CLogB_ShareHandle(SHARED_NAME[i], handle); 25 | } 26 | 27 | return true; 28 | } 29 | 30 | void CHIron::CLogB::Close() 31 | { 32 | for (int i = 0; i < (sizeof(SHARED_NAME) / sizeof(SHARED_NAME[0])); i++) 33 | { 34 | void* handle = CLogB_GetSharedHandle(SHARED_NAME[i]); 35 | 36 | if (handle) 37 | { 38 | CLogB_CloseFile(handle); 39 | CLogB_UnshareHandle(SHARED_NAME[i]); 40 | } 41 | } 42 | } 43 | 44 | 45 | // Implementation of: class PluginInstance 46 | namespace CHIron::CLogB { 47 | 48 | PluginInstance::PluginInstance() noexcept 49 | : Plugin ("chiron.clog.b") 50 | { } 51 | 52 | std::string PluginInstance::GetDisplayName() const noexcept 53 | { 54 | return "CHIron::CLogB"; 55 | } 56 | 57 | std::string PluginInstance::GetDescription() const noexcept 58 | { 59 | return "CHIron CLog.B Compatibility Plugin for TL-Test New"; 60 | } 61 | 62 | std::string PluginInstance::GetVersion() const noexcept 63 | { 64 | return "Kunming Lake"; 65 | } 66 | 67 | void PluginInstance::OnEnable() 68 | { 69 | LogInfo("CHIron::CLogB", Append("Enabled").EndLine()); 70 | 71 | Init("clog"); 72 | 73 | LogInfo("CHIron::CLogB", Append("Initialized").EndLine()); 74 | } 75 | 76 | void PluginInstance::OnDisable() 77 | { 78 | LogInfo("CHIron::CLogB", Append("Saving CLog.B to: clog.*.b").EndLine()); 79 | 80 | Close(); 81 | 82 | LogInfo("CHIron::CLogB", Append("Disabled").EndLine()); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /main/DPI/memory_dpi.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | /* 7 | * DPI functions to connect AXI Channel AW 8 | */ 9 | extern "C" void MemoryAXIPullChannelAW( 10 | const int portId, 11 | uint8_t* ready); 12 | 13 | extern "C" void MemoryAXIPushChannelAW( 14 | const int portId, 15 | const uint8_t valid, 16 | const uint32_t id, 17 | const uint64_t addr, 18 | const uint8_t burst, 19 | const uint8_t size, 20 | const uint8_t len); 21 | 22 | /* 23 | * DPI functions to connect AXI Channel W 24 | */ 25 | extern "C" void MemoryAXIPullChannelW( 26 | const int portId, 27 | uint8_t* ready); 28 | 29 | extern "C" void MemoryAXIPushChannelW( 30 | const int portId, 31 | const uint8_t valid, 32 | const uint64_t strb, 33 | const uint8_t last, 34 | const uint64_t data0, 35 | const uint64_t data1, 36 | const uint64_t data2, 37 | const uint64_t data3); 38 | 39 | /* 40 | * DPI functions to connect AXI Channel B 41 | */ 42 | extern "C" void MemoryAXIPullChannelB( 43 | const int portId, 44 | uint8_t* valid, 45 | uint32_t* id, 46 | uint8_t* resp); 47 | 48 | extern "C" void MemoryAXIPushChannelB( 49 | const int portId, 50 | const uint8_t ready); 51 | 52 | /* 53 | * DPI functions to connect AXI Channel AR 54 | */ 55 | extern "C" void MemoryAXIPullChannelAR( 56 | const int portId, 57 | uint8_t* ready); 58 | 59 | extern "C" void MemoryAXIPushChannelAR( 60 | const int portId, 61 | const uint8_t valid, 62 | const uint32_t id, 63 | const uint64_t addr, 64 | const uint8_t burst, 65 | const uint8_t size, 66 | const uint8_t len); 67 | 68 | /* 69 | * DPI functions to connect AXI Channel R 70 | */ 71 | extern "C" void MemoryAXIPullChannelR( 72 | const int portId, 73 | uint8_t* valid, 74 | uint32_t* id, 75 | uint8_t* resp, 76 | uint8_t* last, 77 | uint64_t* data0, 78 | uint64_t* data1, 79 | uint64_t* data2, 80 | uint64_t* data3); 81 | 82 | extern "C" void MemoryAXIPushChannelR( 83 | const int portId, 84 | const uint8_t ready); 85 | -------------------------------------------------------------------------------- /main/Events/TLSystemEvent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // Created by Kumonda221 on 2024-05-06 4 | // 5 | 6 | #ifndef TLC_TEST_EVENTS_SYSTEM_EVENT_H 7 | #define TLC_TEST_EVENTS_SYSTEM_EVENT_H 8 | 9 | #include "../Utils/gravity_eventbus.hpp" 10 | #include "../Sequencer/TLSequencer.hpp" 11 | 12 | 13 | /* 14 | * TL-Test TileLink subsystem initialization events 15 | */ 16 | class TLSystemInitializationPreEvent : public Gravity::Event 17 | { 18 | public: 19 | TLLocalConfig* const config; 20 | 21 | public: 22 | TLSystemInitializationPreEvent(TLLocalConfig* config) noexcept; 23 | }; 24 | 25 | class TLSystemInitializationPostEvent : public Gravity::Event 26 | { 27 | public: 28 | TLSequencer* const system; 29 | 30 | public: 31 | TLSystemInitializationPostEvent(TLSequencer* system) noexcept; 32 | }; 33 | // 34 | 35 | 36 | /* 37 | * TL-Test TileLink subsystem finalization events 38 | * ----------------------------------------------------------------------- 39 | * IMPORTANT: 40 | * 1. Finalization events are required to be handled silently 41 | * (no throw, no termination, no assertion failure, ...). 42 | */ 43 | class TLSystemFinalizationPreEvent : public Gravity::Event 44 | { 45 | public: 46 | TLSequencer* const system; 47 | 48 | public: 49 | TLSystemFinalizationPreEvent(TLSequencer* system) noexcept; 50 | }; 51 | 52 | class TLSystemFinalizationPostEvent : public Gravity::Event 53 | { }; 54 | // 55 | 56 | 57 | 58 | /* 59 | * TL-Test TileLink subsystem finish events 60 | * ----------------------------------------------------------------------- 61 | * This event is called by TL-Test components to finish the main routine 62 | * and never called by master routine (e.g. TLSequencer). 63 | */ 64 | class TLSystemFinishEvent : public Gravity::Event 65 | { }; 66 | // 67 | 68 | 69 | /* 70 | * TL-Test TileLink subsystem finished events 71 | * ----------------------------------------------------------------------- 72 | * This event is called by main routine to broadcast the finished state of 73 | * main routine and never called by TL-Test components. 74 | * It is guaranteed that all circuit activity was ended after this event. 75 | */ 76 | class TLSystemFinishedEvent : public Gravity::Event 77 | { }; 78 | 79 | class TLSystemFailedEvent : public Gravity::Event 80 | { }; 81 | // 82 | 83 | 84 | #endif // TLC_TEST_EVENTS_SYSTEM_EVENT_H 85 | 86 | -------------------------------------------------------------------------------- /main/Utils/autoinclude.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TLTEST_AUTOINCLUDE_H 4 | #define TLTEST_AUTOINCLUDE_H 5 | 6 | 7 | #define __STR0(x) #x 8 | #define __STR1(x) __STR0(x) 9 | 10 | 11 | #ifndef DUT_PATH 12 | // This default path could be changed for IDE language server, normally not used in compilation 13 | # define DUT_PATH "../../dut/CoupledL2" 14 | #endif 15 | 16 | #ifndef DUT_PATH_TOKEN 17 | // This default path could be changed for IDE language server, normally not used in compilation 18 | # define DUT_PATH_TOKEN ../../dut/CoupledL2 19 | #endif 20 | 21 | 22 | #ifndef DUT_BUILD_PATH 23 | // This default path could be changed for IDE language server, normally not used in compilation 24 | # define DUT_BUILD_PATH "../../dut/CoupledL2/build" 25 | #endif 26 | 27 | #ifndef DUT_BUILD_PATH_TOKEN 28 | // This default path could be changed for IDE language server, normally not used in compilation 29 | # define DUT_BUILD_PATH_TOKEN ../../dut/CoupledL2/build 30 | #endif 31 | 32 | 33 | #ifndef CHISELDB_PATH 34 | // This default path could be changed for IDE language server, normally not used in compilation 35 | # define CHISELDB_PATH DUT_BUILD_PATH 36 | #endif 37 | 38 | #ifndef CHISELDB_PATH_TOKEN 39 | // This default path could be changed for IDE language server, normally not used in compilation 40 | # define CHISELDB_PATH_TOKEN DUT_BUILD_PATH_TOKEN 41 | #endif 42 | 43 | 44 | #ifndef VERILATED_PATH_TOKEN 45 | // This default path could be changed for IDE language server, normally not used in compilation 46 | # define VERILATED_PATH_TOKEN ../../verilated 47 | #endif 48 | 49 | #ifndef VERILATED_PATH 50 | // This default path could be changed for IDE language server, normally not used in compilation 51 | # define VERILATED_PATH "../../verilated" 52 | #endif 53 | 54 | 55 | #ifndef CURRENT_PATH 56 | # define CURRENT_PATH "." 57 | #endif 58 | 59 | 60 | #ifndef VERILATOR_INCLUDE 61 | # define VERILATOR_INCLUDE "." 62 | #endif 63 | 64 | 65 | /* 66 | * *NOTICE: For using macros in #include lines. 67 | * :) This is my magic, you don't need to read these. Relax and just use it. 68 | */ 69 | #define __AUTOINCLUDE_DUT_BUILT(file) DUT_BUILD_PATH_TOKEN/file 70 | #define AUTOINCLUDE_DUT_BUILT(file) __STR1(__AUTOINCLUDE_DUT_BUILT(file)) 71 | 72 | #define __AUTOINCLUDE_CHISELDB(file) CHISELDB_PATH_TOKEN/file 73 | #define AUTOINCLUDE_CHISELDB(file) __STR1(__AUTOINCLUDE_CHISELDB(file)) 74 | 75 | #define __AUTOINCLUDE_VERILATED(file) VERILATED_PATH_TOKEN/file 76 | #define AUTOINCLUDE_VERILATED(file) __STR1(__AUTOINCLUDE_VERILATED(file)) 77 | 78 | 79 | #endif // TLTEST_AUTOINCLUDE_H 80 | -------------------------------------------------------------------------------- /main/Utils/assert.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #ifndef TLCTEST_EVENTS_ASSERT_HEADER 5 | #define TLCTEST_EVENTS_ASSERT_HEADER 6 | 7 | #include 8 | 9 | #include "../Utils/gravity_eventbus.hpp" 10 | 11 | 12 | class TLAssertFailureEvent : public Gravity::Event { 13 | private: 14 | std::string sourceLocation; 15 | std::string info; 16 | 17 | public: 18 | TLAssertFailureEvent() noexcept; 19 | TLAssertFailureEvent(const std::string& sourceLocation, const std::string& info) noexcept; 20 | 21 | const std::string& GetSourceLocation() const noexcept; 22 | void SetSourceLocation(const std::string& info) noexcept; 23 | 24 | const std::string& GetInfo() const noexcept; 25 | void SetInfo(const std::string& info) noexcept; 26 | }; 27 | 28 | 29 | class TLAssertFailureException : public std::exception { 30 | private: 31 | TLAssertFailureEvent copiedEvent; 32 | 33 | public: 34 | TLAssertFailureException(const TLAssertFailureEvent& event) noexcept; 35 | 36 | const TLAssertFailureEvent& GetCopiedEvent() const noexcept; 37 | }; 38 | 39 | 40 | 41 | // Implementation of: class TLAssertFailureEvent 42 | /* 43 | std::string sourceLocation; 44 | std::string info; 45 | */ 46 | 47 | inline TLAssertFailureEvent::TLAssertFailureEvent() noexcept 48 | : sourceLocation () 49 | , info () 50 | { } 51 | 52 | inline TLAssertFailureEvent::TLAssertFailureEvent( 53 | const std::string& sourceLocation, 54 | const std::string& info) noexcept 55 | : sourceLocation (sourceLocation) 56 | , info (info) 57 | { } 58 | 59 | inline const std::string& TLAssertFailureEvent::GetSourceLocation() const noexcept 60 | { 61 | return sourceLocation; 62 | } 63 | 64 | inline void TLAssertFailureEvent::SetSourceLocation(const std::string& sourceLocation) noexcept 65 | { 66 | this->sourceLocation = sourceLocation; 67 | } 68 | 69 | inline const std::string& TLAssertFailureEvent::GetInfo() const noexcept 70 | { 71 | return info; 72 | } 73 | 74 | inline void TLAssertFailureEvent::SetInfo(const std::string& info) noexcept 75 | { 76 | this->info = info; 77 | } 78 | 79 | 80 | // Implementation of: class TLAssertFailureException 81 | /* 82 | TLAssertFailureEvent copiedEvent; 83 | */ 84 | 85 | inline TLAssertFailureException::TLAssertFailureException(const TLAssertFailureEvent& event) noexcept 86 | : copiedEvent (event) 87 | { } 88 | 89 | inline const TLAssertFailureEvent& TLAssertFailureException::GetCopiedEvent() const noexcept 90 | { 91 | return copiedEvent; 92 | } 93 | 94 | 95 | #endif // TLCTEST_EVENTS_ASSERT_HEADER 96 | -------------------------------------------------------------------------------- /main/CHIron/clogdpi_b.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* 6 | * CLog.B file handle operations. 7 | */ 8 | extern "C" void* CLogB_OpenFile( 9 | const char* path, 10 | uint32_t* status); 11 | 12 | extern "C" void CLogB_CloseFile( 13 | void* handle); 14 | 15 | extern "C" void CLogB_ShareHandle( 16 | const char* id, 17 | void* handle); 18 | 19 | extern "C" int CLogB_UnshareHandle( 20 | const char* id); 21 | 22 | extern "C" void* CLogB_GetSharedHandle( 23 | const char* id 24 | ); 25 | 26 | 27 | /* 28 | * CLog.B parameters write operations. 29 | */ 30 | extern "C" void CLogB_WriteParameters( 31 | void* handle, 32 | uint32_t issue, 33 | uint32_t nodeidWidth, 34 | uint32_t addrWidth, 35 | uint32_t reqRsvdcWidth, 36 | uint32_t datRsvdcWidth, 37 | uint32_t dataWidth, 38 | uint32_t dataCheckPresent, 39 | uint32_t poisonPresent, 40 | uint32_t mpamPresent); 41 | 42 | extern "C" void CLogB_SharedWriteParameters( 43 | const char* id, 44 | uint32_t issue, 45 | uint32_t nodeidWidth, 46 | uint32_t addrWidth, 47 | uint32_t reqRsvdcWidth, 48 | uint32_t datRsvdcWidth, 49 | uint32_t dataWidth, 50 | uint32_t dataCheckPresent, 51 | uint32_t poisonPresent, 52 | uint32_t mpamPresent); 53 | 54 | 55 | /* 56 | * CLog.B topologies write operations. 57 | */ 58 | extern "C" void CLogB_WriteTopo( 59 | void* handle, 60 | uint32_t nodeId, 61 | uint32_t nodeType 62 | ); 63 | 64 | extern "C" void CLogB_WriteTopoEnd( 65 | void* handle); 66 | 67 | extern "C" void CLogB_SharedWriteTopo( 68 | const char* id, 69 | uint32_t nodeId, 70 | uint32_t nodeType 71 | ); 72 | 73 | extern "C" void CLogB_SharedWriteTopoEnd( 74 | const char* id); 75 | 76 | 77 | /* 78 | * CLog.B log record write operations. 79 | */ 80 | extern "C" void CLogB_WriteRecord( 81 | void* handle, 82 | uint64_t time, 83 | uint32_t nodeId, 84 | uint32_t channel, 85 | const uint32_t* flit, 86 | uint32_t flitLength 87 | ); 88 | 89 | extern "C" void CLogB_SharedWriteRecord( 90 | const char* id, 91 | uint64_t time, 92 | uint32_t nodeId, 93 | uint32_t channel, 94 | const uint32_t* flit, 95 | uint32_t flitLength 96 | ); 97 | -------------------------------------------------------------------------------- /main/PortGen/portgen_main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include "portgen_static.hpp" 7 | 8 | #include "../Utils/TLDefault.h" 9 | #include "../Utils/inicpp.hpp" 10 | 11 | 12 | void usage() 13 | { 14 | std::cout << "Usage: [-c ] [-U ] [-L ]" << std::endl; 15 | std::cout << " -c - Specify default core count" << std::endl; 16 | std::cout << " -C - Specify default TL-C port count per-core" << std::endl; 17 | std::cout << " -L - Specify default TL-UL port count per-core" << std::endl; 18 | } 19 | 20 | int main(int argc, char** argv) 21 | { 22 | // 23 | uint64_t coreCount = TLTEST_DEFAULT_CORE_COUNT; 24 | uint64_t masterCountPerCoreTLC = TLTEST_DEFAULT_MASTER_COUNT_PER_CORE_TLC; 25 | uint64_t masterCountPerCoreTLUL = TLTEST_DEFAULT_MASTER_COUNT_PER_CORE_TLUL; 26 | 27 | // 28 | char* endptr = NULL; 29 | 30 | int o; 31 | while ((o = getopt(argc, argv, "c:C:L:h")) != -1) 32 | { 33 | switch (o) 34 | { 35 | case 'c': 36 | coreCount = strtoul(optarg, &endptr, 0); 37 | break; 38 | 39 | case 'C': 40 | masterCountPerCoreTLC = strtoul(optarg, &endptr, 0); 41 | break; 42 | 43 | case 'L': 44 | masterCountPerCoreTLUL = strtoul(optarg, &endptr, 0); 45 | break; 46 | 47 | case 'h': 48 | usage(); 49 | return 0; 50 | 51 | case '?': 52 | std::cout << "error: unknown option: " << char(optopt) << std::endl; 53 | usage(); 54 | return 1; 55 | } 56 | } 57 | 58 | // read configuration override 59 | inicpp::IniManager ini("tltest.ini"); 60 | 61 | # define INI_OVERRIDE_INT(section_name, key, target) \ 62 | { \ 63 | auto section = ini[section_name]; \ 64 | if (section.isKeyExist(key)) \ 65 | { \ 66 | target = section.toInt(key); \ 67 | std::cout << "[PortGen] Configuration override: " << key << " -> " << #target << " = " << target << std::endl; \ 68 | } \ 69 | } \ 70 | 71 | 72 | INI_OVERRIDE_INT("tltest.config", "core", coreCount); 73 | INI_OVERRIDE_INT("tltest.config", "core.tl_c", masterCountPerCoreTLC); 74 | INI_OVERRIDE_INT("tltest.config", "core.tl_ul", masterCountPerCoreTLUL) 75 | 76 | # undef INI_OVERRIDE_INT 77 | 78 | // 79 | std::ofstream fout("portgen.cpp"); 80 | 81 | if (!fout.is_open()) 82 | { 83 | std::cout << "Failed to open file: portgen.cpp" << std::endl; 84 | return 1; 85 | } 86 | 87 | fout << V3::PortGen::Generate(coreCount, masterCountPerCoreTLUL); 88 | 89 | fout.flush(); 90 | fout.close(); 91 | } -------------------------------------------------------------------------------- /main/Plugins/PluginManager.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // 4 | // 5 | 6 | #ifndef TLC_TEST_PLUGIN_MANAGER 7 | #define TLC_TEST_PLUGIN_MANAGER 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "../Utils/gravity_eventbus.hpp" 14 | 15 | 16 | class Plugin { 17 | private: 18 | const std::string name; 19 | 20 | public: 21 | Plugin(const char* name) noexcept; 22 | Plugin(const std::string& name) noexcept; 23 | virtual ~Plugin(); 24 | 25 | public: 26 | virtual std::string GetName() const noexcept final; 27 | virtual std::string GetDisplayName() const noexcept = 0; 28 | virtual std::string GetVersion() const noexcept = 0; 29 | virtual std::string GetDescription() const noexcept = 0; 30 | 31 | public: 32 | virtual void OnEnable() = 0; 33 | virtual void OnDisable() = 0; 34 | }; 35 | 36 | 37 | class PluginManager { 38 | private: 39 | std::map plugins; 40 | 41 | public: 42 | using iterator = std::map::iterator; 43 | using const_iterator = std::map::const_iterator; 44 | 45 | public: 46 | void EnablePlugin(Plugin* plugin); 47 | Plugin* DisablePlugin(const std::string& name); 48 | 49 | void DisableAll(std::function callback); 50 | 51 | Plugin* GetPlugin(const std::string& name) noexcept; 52 | const Plugin* GetPlugin(const std::string& name) const noexcept; 53 | bool HasPlugin(const std::string& name) const noexcept; 54 | 55 | iterator begin() noexcept; 56 | const_iterator begin() const noexcept; 57 | 58 | iterator end() noexcept; 59 | const_iterator end() const noexcept; 60 | }; 61 | 62 | 63 | namespace PluginEvent { 64 | 65 | // 66 | class Base { 67 | private: 68 | PluginManager* const manager; 69 | Plugin* const plugin; 70 | 71 | public: 72 | Base(PluginManager* manager, Plugin* plugin) noexcept; 73 | 74 | public: 75 | PluginManager* GetManager() const noexcept; 76 | Plugin* GetPlugin() const noexcept; 77 | }; 78 | 79 | // 80 | class PreEnable : public Base, public Gravity::Event 81 | { 82 | public: 83 | PreEnable(PluginManager* manager, Plugin* plugin) noexcept; 84 | }; 85 | 86 | class PostEnable : public Base, public Gravity::Event 87 | { 88 | public: 89 | PostEnable(PluginManager* manager, Plugin* plugin) noexcept; 90 | }; 91 | 92 | // 93 | class PreDisable : public Base, public Gravity::Event 94 | { 95 | public: 96 | PreDisable(PluginManager* manager, Plugin* plugin) noexcept; 97 | }; 98 | 99 | class PostDisable : public Base, public Gravity::Event 100 | { 101 | public: 102 | PostDisable(PluginManager* manager, Plugin* plugin) noexcept; 103 | }; 104 | } 105 | 106 | 107 | #endif // TLC_TEST_PLUGIN_MANAGER 108 | -------------------------------------------------------------------------------- /main/TLAgent/ULAgent.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by ljw on 10/21/21. 3 | // 4 | 5 | #ifndef TLC_TEST_ULAGENT_H 6 | #define TLC_TEST_ULAGENT_H 7 | 8 | #include "BaseAgent.h" 9 | #include "../Utils/Common.h" 10 | #include "../Utils/ScoreBoard.h" 11 | #include "Bundle.h" 12 | #include "CAgent.h" 13 | 14 | namespace tl_agent { 15 | 16 | class UL_SBEntry { 17 | public: 18 | paddr_t address; 19 | TLOpcodeA req_type; 20 | int status; 21 | uint64_t time_stamp; 22 | std::array data; 23 | UL_SBEntry(const TLLocalContext* ctx, TLOpcodeA req_type, int status, paddr_t address) { 24 | this->req_type = req_type; 25 | this->status = status; 26 | this->address = address; 27 | this->time_stamp = ctx->cycle(); 28 | } 29 | UL_SBEntry(const TLLocalContext* ctx, TLOpcodeA req_type, int status, paddr_t address, std::array data) { 30 | this->req_type = req_type; 31 | this->status = status; 32 | this->address = address; 33 | this->time_stamp = ctx->cycle(); 34 | this->data = data; 35 | } 36 | void update_status(const TLLocalContext* ctx, int status) { 37 | this->status = status; 38 | this->time_stamp = ctx->cycle(); 39 | } 40 | }; 41 | 42 | template 43 | struct ScoreBoardUpdateCallbackULSBEntry : public ScoreBoardUpdateCallback 44 | { 45 | void update(const TLLocalContext* ctx, const Tk& key, std::shared_ptr& data) 46 | { 47 | # if SB_DEBUG == 1 48 | 49 | # endif 50 | } 51 | }; 52 | 53 | 54 | class ULAgent : public BaseAgent<> { 55 | public: 56 | using LocalScoreBoard = ScoreBoard>; 57 | 58 | private: 59 | uint64_t* cycles; 60 | PendingTrans> pendingA; 61 | PendingTrans> pendingD; 62 | /* We only need a localBoard recording SourceID -> UL_SBEntry 63 | * because UL agent needn't store data. 64 | */ 65 | LocalScoreBoard* localBoard; // SourceID -> UL_SBEntry 66 | void timeout_check() override; 67 | 68 | public: 69 | ULAgent(TLLocalConfig* cfg, MemoryBackend* mem, GlobalBoard* gb, UncachedBoard* ub, int sys, int id, unsigned int seed, uint64_t* cycles) noexcept; 70 | virtual ~ULAgent() noexcept; 71 | 72 | uint64_t cycle() const noexcept override; 73 | 74 | Resp send_a (std::shared_ptr>& a) override; 75 | void handle_b (std::shared_ptr& b) override; 76 | Resp send_c (std::shared_ptr>& c) override; 77 | void fire_a() override; 78 | void fire_b() override; 79 | void fire_c() override; 80 | void fire_d() override; 81 | void fire_e() override; 82 | void handle_channel() override; 83 | void update_signal() override; 84 | ActionDenialEnum do_getAuto (paddr_t address); 85 | ActionDenialEnum do_get (paddr_t address, uint8_t size, uint32_t mask); 86 | ActionDenialEnum do_putfulldata (paddr_t address, shared_tldata_t data); 87 | ActionDenialEnum do_putpartialdata (paddr_t address, uint8_t size, uint32_t mask, shared_tldata_t data); 88 | }; 89 | 90 | } 91 | 92 | #endif //TLC_TEST_ULAGENT_H 93 | -------------------------------------------------------------------------------- /main/Utils/TLDefault.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #ifndef TLTEST_DEFAULT_H 5 | #define TLTEST_DEFAULT_H 6 | 7 | 8 | #ifndef TLTEST_DEFAULT_SEED 9 | # define TLTEST_DEFAULT_SEED 0 10 | #endif 11 | 12 | 13 | #ifndef TLTEST_DEFAULT_CORE_COUNT 14 | # define TLTEST_DEFAULT_CORE_COUNT 1 15 | #endif 16 | 17 | #ifndef TLTEST_DEFAULT_MASTER_COUNT_PER_CORE_TLC 18 | # define TLTEST_DEFAULT_MASTER_COUNT_PER_CORE_TLC 1 19 | #endif 20 | 21 | #ifndef TLTEST_DEFAULT_MASTER_COUNT_PER_CORE_TLUL 22 | # define TLTEST_DEFAULT_MASTER_COUNT_PER_CORE_TLUL 0 23 | #endif 24 | 25 | 26 | #ifndef TLTEST_DEFAULT_STARTUP_CYCLE 27 | # define TLTEST_DEFAULT_STARTUP_CYCLE 100 28 | #endif 29 | 30 | #ifndef TLTEST_DEFAULT_MAXIMUM_CYCLE 31 | # define TLTEST_DEFAULT_MAXIMUM_CYCLE 0 32 | #endif 33 | 34 | 35 | #ifndef TLTEST_DEFAULT_MEMORY_ENABLE 36 | # define TLTEST_DEFAULT_MEMORY_ENABLE 1 37 | #endif 38 | 39 | #ifndef TLTEST_DEFAULT_MEMORY_START 40 | # define TLTEST_DEFAULT_MEMORY_START 0x00000000 41 | #endif 42 | 43 | #ifndef TLTEST_DEFAULT_MEMORY_END 44 | # define TLTEST_DEFAULT_MEMORY_END 0x80000000 45 | #endif 46 | 47 | #ifndef TLTEST_DEFAULT_MEMORY_OOOR 48 | # define TLTEST_DEFAULT_MEMORY_OOOR 1 49 | #endif 50 | 51 | #ifndef TLTEST_DEFAULT_MEMORY_READ_DEPTH 52 | # define TLTEST_DEFAULT_MEMORY_READ_DEPTH 0 53 | #endif 54 | 55 | #ifndef TLTEST_DEFAULT_MEMORY_READ_LATENCY 56 | # define TLTEST_DEFAULT_MEMORY_READ_LATENCY 0 57 | #endif 58 | 59 | #ifndef TLTEST_DEFAULT_MEMORY_WRITE_DEPTH 60 | # define TLTEST_DEFAULT_MEMORY_WRITE_DEPTH 0 61 | #endif 62 | 63 | #ifndef TLTEST_DEFAULT_MEMORY_WRITE_LATENCY 64 | # define TLTEST_DEFAULT_MEMORY_WRITE_LATENCY 0 65 | #endif 66 | 67 | #ifndef TLTEST_DEFAULT_MEMORY_CYCLE_UNIT 68 | # define TLTEST_DEFAULT_MEMORY_CYCLE_UNIT 2 69 | #endif 70 | 71 | #ifndef TLTEST_DEFAULT_MEMORY_PORT_COUNT 72 | # define TLTEST_DEFAULT_MEMORY_PORT_COUNT 1 73 | #endif 74 | 75 | #ifndef TLTEST_DEFAULT_MEMORY_SYNC_STRICT 76 | # define TLTEST_DEFAULT_MEMORY_SYNC_STRICT 0 77 | #endif 78 | 79 | 80 | #ifndef TLTEST_DEFAULT_MMIO_ENABLE 81 | # define TLTEST_DEFAULT_MMIO_ENABLE 0 82 | #endif 83 | 84 | #ifndef TLTEST_DEFAULT_MMIO_START 85 | # define TLTEST_DEFAULT_MMIO_START 0x80000000 86 | #endif 87 | 88 | #ifndef TLTEST_DEFAULT_MMIO_END 89 | # define TLTEST_DEFAULT_MMIO_END 0x90000000 90 | #endif 91 | 92 | 93 | #ifndef TLTEST_DEFAULT_CMO_ENABLE 94 | # define TLTEST_DEFAULT_CMO_ENABLE 0 95 | #endif 96 | 97 | #ifndef TLTEST_DEFAULT_CMO_ENABLE_CBO_CLEAN 98 | # define TLTEST_DEFAULT_CMO_ENABLE_CBO_CLEAN 1 99 | #endif 100 | 101 | #ifndef TLTEST_DEFAULT_CMO_ENABLE_CBO_FLUSH 102 | # define TLTEST_DEFAULT_CMO_ENABLE_CBO_FLUSH 1 103 | #endif 104 | 105 | #ifndef TLTEST_DEFAULT_CMO_ENABLE_CBO_INVAL 106 | # define TLTEST_DEFAULT_CMO_ENABLE_CBO_INVAL 1 107 | #endif 108 | 109 | #ifndef TLTEST_DEFAULT_CMO_START 110 | # define TLTEST_DEFAULT_CMO_START 0x00000000 111 | #endif 112 | 113 | #ifndef TLTEST_DEFAULT_CMO_END 114 | # define TLTEST_DEFAULT_CMO_END 0x80000000 115 | #endif 116 | 117 | #ifndef TLTEST_DEFAULT_CMO_PARALLEL_DEPTH 118 | # define TLTEST_DEFAULT_CMO_PARALLEL_DEPTH 0 119 | #endif 120 | 121 | 122 | #ifndef TLTEST_DEFAULT_PROFILE_CYCLE_UNIT 123 | # define TLTEST_DEFAULT_PROFILE_CYCLE_UNIT 2 124 | #endif 125 | 126 | 127 | #endif // TLTEST_DEFAULT_H -------------------------------------------------------------------------------- /main/Plugins/PluginManager.cpp: -------------------------------------------------------------------------------- 1 | #include "PluginManager.hpp" 2 | // 3 | // 4 | // 5 | 6 | #include "../Utils/Common.h" 7 | 8 | 9 | // Implementation of: class Plugin 10 | Plugin::Plugin(const char* name) noexcept 11 | : name (name) 12 | { } 13 | 14 | Plugin::Plugin(const std::string& name) noexcept 15 | : name (name) 16 | { } 17 | 18 | Plugin::~Plugin() 19 | { } 20 | 21 | std::string Plugin::GetName() const noexcept 22 | { 23 | return name; 24 | } 25 | 26 | 27 | // Implementation of: class PluginManager 28 | void PluginManager::EnablePlugin(Plugin* plugin) 29 | { 30 | tlsys_assert(plugin, "PluginManager attempted to enable a NULL plugin instance."); 31 | 32 | PluginEvent::PreEnable(this, plugin).Fire(); 33 | plugin->OnEnable(); 34 | PluginEvent::PostEnable(this, plugin).Fire(); 35 | 36 | plugins[plugin->GetName()] = plugin; 37 | } 38 | 39 | Plugin* PluginManager::DisablePlugin(const std::string& name) 40 | { 41 | auto iter = plugins.find(name); 42 | 43 | if (iter == end()) 44 | return nullptr; 45 | 46 | Plugin* plugin = iter->second; 47 | 48 | PluginEvent::PreDisable(this, plugin).Fire(); 49 | plugin->OnDisable(); 50 | PluginEvent::PostDisable(this, plugin).Fire(); 51 | 52 | plugins.erase(iter); 53 | 54 | return plugin; 55 | } 56 | 57 | void PluginManager::DisableAll(std::function callback) 58 | { 59 | while (!plugins.empty()) 60 | DisablePlugin(plugins.begin()->first); 61 | } 62 | 63 | Plugin* PluginManager::GetPlugin(const std::string& name) noexcept 64 | { 65 | auto iter = plugins.find(name); 66 | 67 | if (iter == end()) 68 | return nullptr; 69 | 70 | return iter->second; 71 | } 72 | 73 | const Plugin* PluginManager::GetPlugin(const std::string& name) const noexcept 74 | { 75 | auto iter = plugins.find(name); 76 | 77 | if (iter == end()) 78 | return nullptr; 79 | 80 | return iter->second; 81 | } 82 | 83 | bool PluginManager::HasPlugin(const std::string& name) const noexcept 84 | { 85 | return plugins.find(name) != end(); 86 | } 87 | 88 | PluginManager::iterator PluginManager::begin() noexcept 89 | { 90 | return plugins.begin(); 91 | } 92 | 93 | PluginManager::const_iterator PluginManager::begin() const noexcept 94 | { 95 | return plugins.begin(); 96 | } 97 | 98 | PluginManager::iterator PluginManager::end() noexcept 99 | { 100 | return plugins.end(); 101 | } 102 | 103 | PluginManager::const_iterator PluginManager::end() const noexcept 104 | { 105 | return plugins.end(); 106 | } 107 | 108 | 109 | // Implementation of: class PluginEvent::Base 110 | PluginEvent::Base::Base(PluginManager* manager, Plugin* plugin) noexcept 111 | : manager (manager) 112 | , plugin (plugin) 113 | { } 114 | 115 | PluginManager* PluginEvent::Base::GetManager() const noexcept 116 | { 117 | return manager; 118 | } 119 | 120 | Plugin* PluginEvent::Base::GetPlugin() const noexcept 121 | { 122 | return plugin; 123 | } 124 | 125 | // Implementation of: class PluginEvent::PreEnable 126 | PluginEvent::PreEnable::PreEnable(PluginManager* manager, Plugin* plugin) noexcept 127 | : Base (manager, plugin) 128 | { } 129 | 130 | // Implementation of: class PluginEvent::PostEnable 131 | PluginEvent::PostEnable::PostEnable(PluginManager* manager, Plugin* plugin) noexcept 132 | : Base (manager, plugin) 133 | { } 134 | 135 | // Implementation of: class PluginEvent::PreDisable 136 | PluginEvent::PreDisable::PreDisable(PluginManager* manager, Plugin* plugin) noexcept 137 | : Base (manager, plugin) 138 | { } 139 | 140 | // Implementation of: class PluginEvent::PostDisable 141 | PluginEvent::PostDisable::PostDisable(PluginManager* manager, Plugin* plugin) noexcept 142 | : Base (manager, plugin) 143 | { } 144 | -------------------------------------------------------------------------------- /main/CHIron/clogdpi_b.svh: -------------------------------------------------------------------------------- 1 | /* 2 | * Value Definitions. 3 | */ 4 | `define CLOG_ISSUE_B 0 5 | `define CLOG_ISSUE_E 3 6 | 7 | `define CLOG_NODE_TYPE_RN_F 1 8 | `define CLOG_NODE_TYPE_RN_D 2 9 | `define CLOG_NODE_TYPE_RN_I 3 10 | `define CLOG_NODE_TYPE_HN_F 5 11 | `define CLOG_NODE_TYPE_HN_I 7 12 | `define CLOG_NODE_TYPE_SN_F 9 13 | `define CLOG_NODE_TYPE_SN_I 11 14 | `define CLOG_NODE_TYPE_MN 12 15 | 16 | `define CLOG_CHANNEL_TXREQ 0 17 | `define CLOG_CHANNEL_TXRSP 1 18 | `define CLOG_CHANNEL_TXDAT 2 19 | `define CLOG_CHANNEL_TXSNP 3 20 | `define CLOG_CHANNEL_RXREQ 4 21 | `define CLOG_CHANNEL_RXRSP 5 22 | `define CLOG_CHANNEL_RXDAT 6 23 | `define CLOG_CHANNEL_RXSNP 7 24 | 25 | 26 | /* 27 | * CLog.B file handle operations. 28 | */ 29 | import "DPI-C" function chandle CLogB_OpenFile ( 30 | input string path, 31 | output int status 32 | ); 33 | 34 | import "DPI-C" function void CLogB_CloseFile ( 35 | input chandle handle 36 | ); 37 | 38 | import "DPI-C" function void CLogB_ShareHandle ( 39 | input string id, 40 | input chandle handle 41 | ); 42 | 43 | import "DPI-C" function int CLogB_UnshareHandle ( 44 | input string id 45 | ); 46 | 47 | import "DPI-C" function chandle CLogB_GetSharedHandle ( 48 | input string id 49 | ); 50 | 51 | 52 | /* 53 | * CLog.B parameters write operations. 54 | */ 55 | import "DPI-C" function void CLogB_WriteParameters ( 56 | input chandle handle, 57 | input int issue, 58 | input int nodeIdWidth, 59 | input int addrWidth, 60 | input int reqRsvdcWidth, 61 | input int datRsvdcWidth, 62 | input int dataWidth, 63 | input int dataCheckPresent, 64 | input int poisonPresent, 65 | input int mpamPresent 66 | ); 67 | 68 | import "DPI-C" function void CLogB_SharedWriteParameters ( 69 | input string id, 70 | input int issue, 71 | input int nodeIdWidth, 72 | input int addrWidth, 73 | input int reqRsvdcWidth, 74 | input int datRsvdcWidth, 75 | input int dataWidth, 76 | input int dataCheckPresent, 77 | input int poisonPresent, 78 | input int mpamPresent 79 | ); 80 | 81 | 82 | /* 83 | * CLog.B topologies write operations. 84 | */ 85 | import "DPI-C" function void CLogB_WriteTopo ( 86 | input chandle handle, 87 | input int nodeId, 88 | input int nodeType 89 | ); 90 | 91 | import "DPI-C" function void CLogB_WriteTopoEnd ( 92 | input chandle handle 93 | ); 94 | 95 | import "DPI-C" function void CLogB_SharedWriteTopo ( 96 | input string id, 97 | input int nodeId, 98 | input int nodeType 99 | ); 100 | 101 | import "DPI-C" function void CLogB_SharedWriteTopoEnd ( 102 | input string id 103 | ); 104 | 105 | 106 | /* 107 | * CLog.B log record write operations. 108 | */ 109 | import "DPI-C" function void CLogB_WriteRecord ( 110 | input chandle handle, 111 | input longint cycletime, 112 | input int nodeId, 113 | input int channel, 114 | input bit [511:0] flit, 115 | input int flitLength 116 | ); 117 | 118 | import "DPI-C" function void CLogB_SharedWriteRecord ( 119 | input string id, 120 | input longint cycleTime, 121 | input int nodeId, 122 | input int channel, 123 | input bit [511:0] flit, 124 | input int flitLength 125 | ); 126 | -------------------------------------------------------------------------------- /main/TLAgent/Bundle.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by ljw on 10/21/21. 3 | // 4 | 5 | #ifndef TLC_TEST_BUNDLE_H 6 | #define TLC_TEST_BUNDLE_H 7 | 8 | #include "../Utils/Common.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace tl_agent { 15 | 16 | // 17 | class DecoupledBundle { 18 | public: 19 | uint8_t valid; 20 | uint8_t ready; 21 | 22 | bool fire() const { 23 | return valid && ready; 24 | } 25 | }; 26 | 27 | class ValidBundle { 28 | public: 29 | uint8_t valid; 30 | 31 | bool fire() const { 32 | return valid; 33 | } 34 | }; 35 | 36 | // 37 | template 38 | class BundleChannelA : public DecoupledBundle { 39 | public: 40 | uint8_t opcode; 41 | uint8_t param; 42 | uint8_t size; 43 | uint64_t source; 44 | uint32_t mask; 45 | paddr_t address; 46 | shared_tldata_t data; 47 | Usr usr; 48 | Echo echo; 49 | uint8_t corrupt; 50 | uint8_t needHint; 51 | paddr_t vaddr; 52 | uint8_t alias; 53 | }; 54 | 55 | class BundleChannelB : public DecoupledBundle { 56 | public: 57 | uint8_t opcode; 58 | uint8_t param; 59 | uint8_t size; 60 | uint64_t source; 61 | paddr_t address; 62 | uint8_t corrupt; 63 | uint8_t alias; 64 | uint8_t needdata; 65 | }; 66 | 67 | template 68 | class BundleChannelC : public DecoupledBundle { 69 | public: 70 | uint8_t opcode; 71 | uint8_t param; 72 | uint8_t size; 73 | uint64_t source; 74 | paddr_t address; 75 | Usr usr; 76 | Echo echo; 77 | uint8_t dirty; 78 | shared_tldata_t data; 79 | uint8_t corrupt; 80 | uint8_t needHint; 81 | paddr_t vaddr; 82 | uint8_t alias; 83 | }; 84 | 85 | template 86 | class BundleChannelD : public DecoupledBundle { 87 | public: 88 | uint8_t opcode; 89 | uint8_t param; 90 | uint8_t size; 91 | uint64_t source; 92 | uint64_t sink; 93 | uint8_t denied; 94 | Usr usr; 95 | Echo echo; 96 | uint8_t dirty; 97 | shared_tldata_t data; 98 | uint8_t corrupt; 99 | }; 100 | 101 | class BundleChannelE : public DecoupledBundle { 102 | public: 103 | uint64_t sink; 104 | paddr_t addr; // used for index scoreboard 105 | uint8_t alias; 106 | }; 107 | 108 | template 109 | class Bundle { 110 | public: 111 | BundleChannelA a; 112 | BundleChannelB b; 113 | BundleChannelC c; 114 | BundleChannelD d; 115 | BundleChannelE e; 116 | }; 117 | 118 | // 119 | class BundleCMOReq : public DecoupledBundle { 120 | public: 121 | uint8_t opcode; 122 | paddr_t address; 123 | }; 124 | 125 | class BundleCMOResp : public DecoupledBundle { 126 | public: 127 | paddr_t address; 128 | }; 129 | 130 | class BundleCMO { 131 | public: 132 | BundleCMOReq req; 133 | BundleCMOResp resp; 134 | }; 135 | 136 | // 137 | class BundleL2ToL1Hint : public ValidBundle { 138 | public: 139 | uint32_t sourceId; 140 | uint8_t isKeyword; 141 | }; 142 | } 143 | 144 | #endif //TLC_TEST_BUNDLE_H 145 | -------------------------------------------------------------------------------- /main/Sequencer/TLSequencer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // Created by Kumonda221 on 04/04/24 4 | // 5 | 6 | #ifndef TLC_TEST_SEQUENCER_H 7 | #define TLC_TEST_SEQUENCER_H 8 | 9 | #include 10 | 11 | #include "../Utils/ScoreBoard.h" 12 | #include "../Utils/ULScoreBoard.h" 13 | #include "../Utils/Common.h" 14 | #include "../TLAgent/ULAgent.h" 15 | #include "../TLAgent/CAgent.h" 16 | #include "../TLAgent/MMIOAgent.h" 17 | #include "../Memory/MemoryAgent.hpp" 18 | #include "../Fuzzer/Fuzzer.h" 19 | 20 | /* 21 | * Procedure sequence of a TileLink cycle: 22 | * Tick() -> FireChannel*() -> Tock() -> UpdateChannel*() 23 | */ 24 | class TLSequencer { 25 | public: 26 | enum class State { 27 | NOT_INITIALIZED = 0, 28 | ALIVE, 29 | FAILED, 30 | FINISHED 31 | }; 32 | 33 | public: 34 | using BaseAgent = tl_agent::BaseAgent<>; 35 | using ULAgent = tl_agent::ULAgent; 36 | using CAgent = tl_agent::CAgent; 37 | 38 | using ReqField = tl_agent::ReqField; 39 | using RespField = tl_agent::RespField; 40 | using EchoField = tl_agent::EchoField; 41 | 42 | using BundleChannelA = tl_agent::BundleChannelA; 43 | using BundleChannelB = tl_agent::BundleChannelB; 44 | using BundleChannelC = tl_agent::BundleChannelC; 45 | using BundleChannelD = tl_agent::BundleChannelD; 46 | using BundleChannelE = tl_agent::BundleChannelE; 47 | using Bundle = tl_agent::Bundle; 48 | 49 | using IOChannelA = tl_agent::BundleChannelA; 50 | using IOChannelB = tl_agent::BundleChannelB; 51 | using IOChannelC = tl_agent::BundleChannelC; 52 | using IOChannelD = tl_agent::BundleChannelD; 53 | using IOChannelE = tl_agent::BundleChannelE; 54 | using IOPort = tl_agent::Bundle; 55 | 56 | using MMIOAgent = tl_agent::MMIOAgent; 57 | using MMIOPort = tl_agent::Bundle; 58 | using MMIOGlobalStatus = tl_agent::MMIOGlobalStatus; 59 | 60 | using L2ToL1HintPort = tl_agent::BundleL2ToL1Hint; 61 | 62 | using MemoryAgent = axi_agent::MemoryAgent; 63 | using MemoryAXIPort = axi_agent::Bundle; 64 | 65 | private: 66 | State state; 67 | 68 | uint8_t* pmem; 69 | 70 | GlobalBoard* globalBoard; 71 | UncachedBoard* uncachedBoard; 72 | 73 | BaseAgent** agents; 74 | CAgent** cAgents; 75 | ULAgent** ulAgents; 76 | 77 | Fuzzer** fuzzers; 78 | UnifiedFuzzer* unifiedFuzzer; 79 | 80 | MMIOGlobalStatus* mmioGlobalStatus; 81 | 82 | MMIOAgent** mmioAgents; 83 | MMIOFuzzer** mmioFuzzers; 84 | 85 | MemoryAgent** memories; 86 | 87 | TLLocalConfig config; 88 | 89 | IOPort** io; 90 | MMIOPort** mmio; 91 | L2ToL1HintPort** l2ToL1Hint; 92 | MemoryAXIPort** memoryAXI; 93 | 94 | uint64_t cycles; 95 | 96 | public: 97 | TLSequencer() noexcept; 98 | ~TLSequencer() noexcept; 99 | 100 | const TLLocalConfig& GetLocalConfig() const noexcept; 101 | 102 | State GetState() const noexcept; 103 | bool IsAlive() const noexcept; 104 | bool IsFailed() const noexcept; 105 | bool IsFinished() const noexcept; 106 | 107 | size_t GetAgentCount() const noexcept; 108 | size_t GetCAgentCount() const noexcept; 109 | size_t GetULAgentCount() const noexcept; 110 | 111 | void Initialize(const TLLocalConfig& cfg) noexcept; 112 | void Finalize() noexcept; 113 | void Tick(uint64_t cycles) noexcept; 114 | void Tock() noexcept; 115 | 116 | IOPort* IO() noexcept; 117 | IOPort& IO(int deviceId) noexcept; 118 | 119 | MMIOPort* MMIO() noexcept; 120 | MMIOPort& MMIO(int deviceId) noexcept; 121 | 122 | L2ToL1HintPort* L2ToL1Hint() noexcept; 123 | L2ToL1HintPort& L2ToL1Hint(int deviceId) noexcept; 124 | 125 | MemoryAXIPort* MemoryAXI() noexcept; 126 | MemoryAXIPort& MemoryAXI(int deviceId) noexcept; 127 | }; 128 | 129 | 130 | #endif //TLC_TEST_SEQUENCER_H 131 | -------------------------------------------------------------------------------- /main/TLAgent/MMIOAgent.h: -------------------------------------------------------------------------------- 1 | #ifndef TLC_TEST_MMIOAGENT_H 2 | #define TLC_TEST_MMIOAGENT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "BaseAgent.h" 9 | #include "ULAgent.h" 10 | #include "Bundle.h" 11 | #include "../Utils/Common.h" 12 | 13 | 14 | namespace tl_agent { 15 | 16 | class InflightMMIO { 17 | public: 18 | bool dataCheck; // timely first in-flight 19 | paddr_t address; 20 | TLOpcodeA opcode; 21 | uint8_t size; 22 | uint8_t mask; 23 | uint64_t timeStamp; 24 | int status; 25 | shared_tldata_t data; 26 | 27 | public: 28 | InflightMMIO(const TLLocalContext* ctx, 29 | bool dataCheck, 30 | TLOpcodeA opcode, 31 | int status, 32 | paddr_t address, 33 | uint8_t size, 34 | uint8_t mask) noexcept; 35 | 36 | void updateStatus(const TLLocalContext* ctx, int status) noexcept; 37 | }; 38 | 39 | class MMIOGlobalStatus { 40 | private: 41 | std::unordered_set inflightAddress; 42 | uint8_t* data; 43 | size_t dataSize; 44 | const TLLocalConfig* tlcfg; 45 | 46 | public: 47 | MMIOGlobalStatus(const TLLocalConfig* tlcfg) noexcept; 48 | ~MMIOGlobalStatus() noexcept; 49 | 50 | public: 51 | void setInflight(const TLLocalContext* ctx, paddr_t address); 52 | void freeInflight(const TLLocalContext* ctx, paddr_t address); 53 | bool isInflight(const TLLocalContext* ctx, paddr_t address) const noexcept; 54 | bool isInflightGet(const TLLocalContext* ctx, paddr_t address) const noexcept; 55 | bool isInflightPut(const TLLocalContext* ctx, paddr_t address) const noexcept; 56 | 57 | void updateData(const TLLocalContext* ctx, paddr_t address, uint8_t size, uint8_t mask, uint8_t* data); 58 | void verifyData(const TLLocalContext* ctx, paddr_t address, uint8_t size, uint8_t mask, uint8_t* data) const; 59 | }; 60 | 61 | class MMIOLocalStatus { 62 | private: 63 | std::unordered_map> inflight; 64 | 65 | public: 66 | void update(const TLLocalContext* ctx, uint64_t source, std::shared_ptr mmio) noexcept; 67 | std::shared_ptr query(const TLLocalContext* ctx, uint64_t source) const; 68 | bool contains(const TLLocalContext* ctx, uint64_t source) const noexcept; 69 | void erase(const TLLocalContext* ctx, uint64_t source); 70 | void clear() noexcept; 71 | }; 72 | 73 | class MMIOAgent : public BaseAgent { 74 | private: 75 | uint64_t* cycles; 76 | PendingTrans> pendingA; 77 | PendingTrans> pendingD; 78 | MMIOGlobalStatus* globalStatus; 79 | MMIOLocalStatus* localStatus; 80 | 81 | public: 82 | MMIOAgent(TLLocalConfig* cfg, MMIOGlobalStatus* globalStatus, int id, unsigned int seed, uint64_t* cycles) noexcept; 83 | virtual ~MMIOAgent() noexcept; 84 | 85 | uint64_t cycle() const noexcept override; 86 | 87 | Resp send_a (std::shared_ptr>& a) override; 88 | void handle_b (std::shared_ptr& b) override; 89 | Resp send_c (std::shared_ptr>& c) override; 90 | void fire_a() override; 91 | void fire_b() override; 92 | void fire_c() override; 93 | void fire_d() override; 94 | void fire_e() override; 95 | void handle_channel() override; 96 | void update_signal() override; 97 | bool do_get (paddr_t address, uint8_t size, uint8_t mask); 98 | bool do_putfulldata (paddr_t address, shared_tldata_t data); 99 | bool do_putpartialdata (paddr_t address, uint8_t size, uint8_t mask, shared_tldata_t data); 100 | 101 | void timeout_check() override; 102 | bool mainSys() const noexcept override; 103 | }; 104 | } 105 | 106 | #endif // TLC_TEST_MMIOAGENT_H 107 | -------------------------------------------------------------------------------- /main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | CMAKE_MINIMUM_REQUIRED(VERSION 3.16) 3 | PROJECT(tltest_new) 4 | 5 | # 6 | if (NOT DEFINED CMAKE_BUILD_TYPE) 7 | SET(CMAKE_BUILD_TYPE Debug) 8 | endif () 9 | 10 | if(NOT DEFINED BUILD_DPI) 11 | SET(BUILD_DPI ON) 12 | endif () 13 | 14 | if (NOT DEFINED BUILD_V3) 15 | SET(BUILD_V3 ON) 16 | endif () 17 | 18 | if (NOT DEFINED BUILD_PORTGEN) 19 | SET(BUILD_PORTGEN ON) 20 | endif () 21 | 22 | 23 | # 24 | if (NOT DEFINED DUT_PATH) 25 | SET(DUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../dut/CoupledL2") 26 | endif () 27 | 28 | if (NOT DEFINED DUT_BUILD_PATH) 29 | SET(DUT_BUILD_PATH "${DUT_PATH}/build") 30 | endif () 31 | 32 | if (NOT DEFINED CHISELDB_PATH) 33 | SET(CHISELDB_PATH "${DUT_PATH}/build") 34 | endif () 35 | 36 | if (NOT DEFINED VERILATOR_INCLUDE) 37 | SET(VERILATOR_INCLUDE "/usr/local/share/verilator/include") 38 | endif () 39 | 40 | if (NOT DEFINED VERIALTED_PATH) 41 | SET(VERILATED_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../verilated") 42 | endif () 43 | 44 | if (NOT DEFINED TLTEST_PORTGEN_DYNAMIC) 45 | SET(TLTEST_PORTGEN_DYNAMIC, OFF) 46 | endif () 47 | 48 | if (NOT DEFINED TLTEST_MEMORY) 49 | SET(TLTEST_MEMORY 1) 50 | endif () 51 | 52 | 53 | # 54 | ADD_DEFINITIONS(-DCXX_COMPILER="${CMAKE_CXX_COMPILER}") 55 | ADD_DEFINITIONS(-DCURRENT_PATH="${CMAKE_CURRENT_SOURCE_DIR}") 56 | ADD_DEFINITIONS(-DDUT_PATH="${DUT_PATH}") 57 | ADD_DEFINITIONS(-DDUT_PATH_TOKEN=${DUT_PATH}) 58 | ADD_DEFINITIONS(-DDUT_BUILD_PATH="${DUT_BUILD_PATH}") 59 | ADD_DEFINITIONS(-DDUT_BUILD_PATH_TOKEN=${DUT_BUILD_PATH}) 60 | ADD_DEFINITIONS(-DCHISELDB_PATH="${CHISELDB_PATH}") 61 | ADD_DEFINITIONS(-DCHISELDB_PATH_TOKEN=${CHISELDB_PATH}) 62 | ADD_DEFINITIONS(-DVERILATED_PATH="${VERILATED_PATH}") 63 | ADD_DEFINITIONS(-DVERILATED_PATH_TOKEN=${VERILATED_PATH}) 64 | ADD_DEFINITIONS(-DVERILATOR_INCLUDE="${VERILATOR_INCLUDE}") 65 | ADD_DEFINITIONS(-DTLTEST_MEMORY=${TLTEST_MEMORY}) 66 | 67 | if (TLTEST_PORTGEN_DYNAMIC) 68 | ADD_DEFINITIONS(-DTLTEST_PORTGEN_DYNAMIC) 69 | endif () 70 | 71 | 72 | # 73 | SET(CMAKE_CXX_STANDARD 20) 74 | SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -std=c++20 -O0 -Wall -g2 -ggdb") 75 | SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -std=c++20 -O3 -Wall") 76 | 77 | ADD_COMPILE_OPTIONS(-fPIC) 78 | 79 | # 80 | ADD_SUBDIRECTORY(Base) 81 | ADD_SUBDIRECTORY(Sequencer) 82 | ADD_SUBDIRECTORY(Memory) 83 | ADD_SUBDIRECTORY(TLAgent) 84 | ADD_SUBDIRECTORY(Fuzzer) 85 | ADD_SUBDIRECTORY(Events) 86 | ADD_SUBDIRECTORY(System) 87 | ADD_SUBDIRECTORY(CHIron) 88 | ADD_SUBDIRECTORY(Plugins) 89 | 90 | FIND_PACKAGE(SQLite3 REQUIRED) 91 | FIND_PACKAGE(ZLIB REQUIRED) 92 | FIND_PACKAGE(Threads REQUIRED) 93 | INCLUDE_DIRECTORIES(${SQLite3_INCLUDE_DIRS}) 94 | 95 | # 96 | if (BUILD_DPI) 97 | 98 | ADD_SUBDIRECTORY(DPI) 99 | 100 | ADD_LIBRARY(tltest_dpi SHARED Base Sequencer Memory TLAgent Fuzzer Events System CHIron Plugins DPI) 101 | TARGET_LINK_LIBRARIES(tltest_dpi PUBLIC 102 | Base DPI Sequencer Memory TLAgent Fuzzer Events System Plugins sqlite3) 103 | endif () 104 | 105 | # 106 | if (BUILD_V3) 107 | 108 | INCLUDE_DIRECTORIES(${VERILATOR_INCLUDE}) # change to your verilator root include on error 109 | INCLUDE_DIRECTORIES(${VERILATOR_INCLUDE}/vltstd) 110 | 111 | ADD_SUBDIRECTORY(V3) 112 | ADD_SUBDIRECTORY(PortGen) 113 | 114 | ADD_EXECUTABLE(tltest_v3lt Base Sequencer Memory TLAgent Fuzzer Events System CHIron Plugins PortGen V3) 115 | 116 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 117 | TARGET_LINK_LIBRARIES(tltest_v3lt 118 | Base Sequencer Memory TLAgent Fuzzer Events System CHIron Plugins PortGen V3 sqlite3 119 | "-lz" 120 | "-Wl,--whole-archive" 121 | ${VERILATED_PATH}/libvltdut.a 122 | "-Wl,--no-whole-archive" 123 | Threads::Threads ZLIB::ZLIB atomic 124 | "-rdynamic" 125 | ${CMAKE_DL_LIBS}) 126 | else () 127 | TARGET_LINK_LIBRARIES(tltest_v3lt 128 | Base Sequencer Memory TLAgent Fuzzer Events System CHIron Plugins PortGen V3 sqlite3 129 | "-Wl,--whole-archive" 130 | ${VERILATED_PATH}/libvltdut.a 131 | "-Wl,--no-whole-archive" 132 | Threads::Threads ZLIB::ZLIB atomic 133 | "-rdynamic" 134 | ${CMAKE_DL_LIBS}) 135 | endif () 136 | 137 | 138 | if (NOT TLTEST_PORTGEN_DYNAMIC) 139 | 140 | ADD_EXECUTABLE(portgen PortGen/portgen_static.cpp PortGen/portgen_main.cpp) 141 | TARGET_LINK_LIBRARIES(portgen) 142 | 143 | ADD_CUSTOM_COMMAND( 144 | TARGET portgen 145 | POST_BUILD 146 | COMMAND portgen 147 | COMMAND ${CMAKE_CXX_COMPILER} portgen.cpp -fPIC -shared -o tltest_portgen.so -I${CMAKE_CURRENT_SOURCE_DIR} -I${VERILATED_PATH} -I${VERILATOR_INCLUDE} -I${VERILATOR_INCLUDE}/vltstd 148 | VERBATIM) 149 | 150 | SET_PROPERTY( 151 | TARGET portgen 152 | APPEND 153 | PROPERTY ADDITIONAL_CLEAN_FILES portgen.cpp tltest_portgen.so) 154 | endif() 155 | endif () 156 | 157 | -------------------------------------------------------------------------------- /main/Utils/gravity_utility.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __BULLSEYE_SIMS_GRAVITY__UTILITY 4 | #define __BULLSEYE_SIMS_GRAVITY__UTILITY 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace Gravity { 11 | 12 | /* 13 | * String Appender (builder pattern helper for std::ostringstream) 14 | * ---------------------------------------------------------------- 15 | * Usage: 16 | * StringAppender appender("Hello"); 17 | * appender.Append(", ").Append("World!").Append(123).ToString(); 18 | * or 19 | * StringAppender().Append("Hello, ").Append("World!").Append(123).ToString(); 20 | * StringAppender("Hello, ").Append("World!").Append(123).ToString(); 21 | */ 22 | class StringAppender { 23 | private: 24 | std::ostringstream oss; 25 | 26 | public: 27 | inline StringAppender() noexcept {}; 28 | inline ~StringAppender() noexcept {}; 29 | 30 | template 31 | inline StringAppender(const T& value) noexcept 32 | { oss << value; } 33 | 34 | template 35 | inline StringAppender(const T& value, const U&... args) noexcept 36 | { oss << value; Append(args...); } 37 | 38 | inline StringAppender& Hex() noexcept 39 | { oss << std::hex; return *this; } 40 | 41 | inline StringAppender& Dec() noexcept 42 | { oss << std::dec; return *this; } 43 | 44 | inline StringAppender& Oct() noexcept 45 | { oss << std::oct; return *this; } 46 | 47 | inline StringAppender& Fixed() noexcept 48 | { oss << std::fixed; return *this; } 49 | 50 | inline StringAppender& Scientific() noexcept 51 | { oss << std::scientific; return *this; } 52 | 53 | inline StringAppender& HexFloat() noexcept 54 | { oss << std::hexfloat; return *this; } 55 | 56 | inline StringAppender& DefaultFloat() noexcept 57 | { oss << std::defaultfloat; return *this; } 58 | 59 | inline StringAppender& Base(int n) noexcept 60 | { oss << std::setbase(n); return *this; } 61 | 62 | template 63 | inline StringAppender& Fill(CharT c) noexcept 64 | { oss << std::setfill(c); return *this; } 65 | 66 | inline StringAppender& Precision(int n) noexcept 67 | { oss << std::setprecision(n); return *this; } 68 | 69 | inline StringAppender& NextWidth(int n) noexcept 70 | { oss << std::setw(n); return *this; } 71 | 72 | inline StringAppender& BoolAlpha() noexcept 73 | { oss << std::boolalpha; return *this; } 74 | 75 | inline StringAppender& NoBoolAlpha() noexcept 76 | { oss << std::noboolalpha; return *this; } 77 | 78 | inline StringAppender& ShowBase() noexcept 79 | { oss << std::showbase; return *this; } 80 | 81 | inline StringAppender& NoShowBase() noexcept 82 | { oss << std::noshowbase; return *this; } 83 | 84 | inline StringAppender& ShowPoint() noexcept 85 | { oss << std::showpoint; return *this; } 86 | 87 | inline StringAppender& NoShowPoint() noexcept 88 | { oss << std::noshowpoint; return *this; } 89 | 90 | inline StringAppender& ShowPos() noexcept 91 | { oss << std::showpos; return *this; } 92 | 93 | inline StringAppender& NoShowPos() noexcept 94 | { oss << std::noshowpos; return *this; } 95 | 96 | inline StringAppender& SkipWs() noexcept 97 | { oss << std::skipws; return *this; } 98 | 99 | inline StringAppender& NoSkipWs() noexcept 100 | { oss << std::noskipws; return *this; } 101 | 102 | inline StringAppender& Left() noexcept 103 | { oss << std::left; return *this; } 104 | 105 | inline StringAppender& Right() noexcept 106 | { oss << std::right; return *this; } 107 | 108 | inline StringAppender& Internal() noexcept 109 | { oss << std::internal; return *this; } 110 | 111 | inline StringAppender& NewLine() noexcept 112 | { oss << std::endl; return *this; } 113 | 114 | inline StringAppender& EndLine() noexcept 115 | { oss << std::endl; return *this; } 116 | 117 | inline StringAppender& Append() noexcept 118 | { return *this; } 119 | 120 | template 121 | inline StringAppender& Append(const T& value) noexcept 122 | { oss << value; return *this; } 123 | 124 | template 125 | inline StringAppender& Append(const T& value, const U&... args) noexcept 126 | { oss << value; return Append(args...); } 127 | 128 | template 129 | inline StringAppender& operator<<(const T& value) noexcept 130 | { oss << value; return *this; } 131 | 132 | inline std::string ToString() const noexcept 133 | { return oss.str(); } 134 | }; 135 | } 136 | 137 | 138 | #endif // __BULLSEYE_SIMS_GRAVITY__UTILITY 139 | -------------------------------------------------------------------------------- /main/Memory/MemoryAgent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TLC_TEST_MEMORY_AGENT_H 4 | #define TLC_TEST_MEMORY_AGENT_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "../Base/TLLocal.hpp" 12 | 13 | #include "Bundle.hpp" 14 | 15 | 16 | namespace axi_agent { 17 | 18 | // 19 | inline constexpr uint8_t BURST_FIXED = 0b00; 20 | inline constexpr uint8_t BURST_INCR = 0b01; 21 | inline constexpr uint8_t BURST_WRAP = 0b10; 22 | 23 | // 24 | template 25 | class FiredBundle { 26 | public: 27 | uint64_t time; 28 | TBundle bundle; 29 | }; 30 | 31 | using FiredBundleAW = FiredBundle; 32 | using FiredBundleAR = FiredBundle; 33 | using FiredBundleB = FiredBundle; 34 | 35 | template 36 | using FiredBundleW = FiredBundle>; 37 | 38 | template 39 | using FiredBundleR = FiredBundle>; 40 | 41 | // 42 | template 43 | class AXIWriteTransaction { 44 | public: 45 | FiredBundleAW request; 46 | std::vector> data; 47 | FiredBundleB response; 48 | 49 | public: 50 | bool dataDone; 51 | 52 | public: 53 | AXIWriteTransaction() noexcept; 54 | AXIWriteTransaction(const FiredBundleAW& request) noexcept; 55 | }; 56 | 57 | template 58 | class AXIReadTransaction { 59 | public: 60 | FiredBundleAR request; 61 | std::vector> data; 62 | 63 | public: 64 | size_t dataPending; 65 | size_t dataSending; 66 | 67 | public: 68 | AXIReadTransaction() noexcept; 69 | AXIReadTransaction(const FiredBundleAR& request) noexcept; 70 | }; 71 | 72 | // 73 | class MemoryAgent : public TLLocalContext, public MemoryBackend { 74 | public: 75 | using axi_port = Bundle; 76 | using axiport_t = axi_port; 77 | 78 | protected: 79 | TLLocalConfig* cfg; 80 | 81 | uint8_t* pmem; 82 | bool pmemExternal; 83 | 84 | uint64_t* cycles; 85 | axi_port* port; 86 | 87 | const unsigned int seed; 88 | const int id; 89 | 90 | private: 91 | std::mt19937_64 rand; 92 | 93 | protected: 94 | // *NOTICE: There is no pendingWrites mechanism because all AXI writes 95 | // were handled in-order regardless of ID match. 96 | std::list pendingReadRequests; 97 | std::list>> pendingReadResponses; 98 | 99 | std::list>> activeWrites; 100 | std::vector>> activeReads; 101 | 102 | std::list>> finishedWrites; 103 | 104 | public: 105 | MemoryAgent(TLLocalConfig* cfg, unsigned int seed, uint64_t* cycles, int id) noexcept; 106 | MemoryAgent(TLLocalConfig* cfg, unsigned int seed, uint64_t* cycles, int id, uint8_t* pmem) noexcept; 107 | virtual ~MemoryAgent() noexcept; 108 | 109 | public: 110 | virtual uint64_t cycle() const noexcept override; 111 | virtual int sys() const noexcept override; 112 | virtual int sysId() const noexcept override; 113 | virtual unsigned int sysSeed() const noexcept override; 114 | 115 | virtual const TLLocalConfig& config() const noexcept override; 116 | virtual TLLocalConfig& config() noexcept override; 117 | 118 | virtual bool mainSys() const noexcept override; 119 | 120 | public: 121 | uint8_t* memory() noexcept; 122 | const uint8_t* memory() const noexcept; 123 | 124 | virtual uint8_t& access(paddr_t addr) noexcept override; 125 | virtual uint8_t access(paddr_t addr) const noexcept override; 126 | 127 | virtual bool accessible(paddr_t addr) const noexcept override; 128 | 129 | size_t size() const noexcept; 130 | 131 | bool is_w_active(uint32_t wid) const noexcept; 132 | bool is_r_active(uint32_t rid) const noexcept; 133 | 134 | void handle_aw(); 135 | void handle_w(); 136 | void send_b(); 137 | void handle_ar(); 138 | void send_r(); 139 | 140 | void fire_aw(); 141 | void fire_w(); 142 | void fire_b(); 143 | void fire_ar(); 144 | void fire_r(); 145 | 146 | void handle_channel(); 147 | void update_signal(); 148 | 149 | public: 150 | inline void connect(axiport_t* p) { this->port = p; } 151 | inline uint64_t rand64() noexcept { return rand(); } 152 | }; 153 | } 154 | 155 | #endif // TLC_TEST_MEMORY_AGENT_H 156 | -------------------------------------------------------------------------------- /main/DPI/tilelink_dpi.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __TILELINK_DPI_HPP 4 | #define __TILELINK_DPI_HPP 5 | 6 | #include 7 | 8 | 9 | /* 10 | * DPI system interactions : IsAlive 11 | */ 12 | extern "C" int TileLinkSystemIsAlive(); 13 | 14 | /* 15 | * DPI system interactions : IsFailed 16 | */ 17 | extern "C" int TileLinkSystemIsFailed(); 18 | 19 | /* 20 | * DPI system interactions : IsFinished 21 | */ 22 | extern "C" int TileLinkSystemIsFinished(); 23 | 24 | 25 | /* 26 | * DPI system interactions : Initialize 27 | */ 28 | extern "C" void TileLinkSystemInitialize(); 29 | 30 | /* 31 | * DPI system interactions : Finalize 32 | */ 33 | extern "C" void TileLinkSystemFinalize(); 34 | 35 | /* 36 | * DPI system interactions : Tick 37 | */ 38 | extern "C" void TileLinkSystemTick( 39 | const uint64_t cycles); 40 | 41 | /* 42 | * DPI system interactions : Tock 43 | */ 44 | extern "C" void TileLinkSystemTock(); 45 | 46 | 47 | /* 48 | * DPI function to connect TileLink Channel A 49 | */ 50 | extern "C" void TileLinkPushChannelA( 51 | const int deviceId, 52 | const uint8_t ready); 53 | 54 | extern "C" void TileLinkPullChannelA( 55 | const int deviceId, 56 | uint8_t* valid, 57 | uint8_t* opcode, 58 | uint8_t* param, 59 | uint8_t* size, 60 | uint64_t* source, 61 | uint64_t* address, 62 | uint8_t* user_needHint, 63 | uint64_t* user_vaddr, 64 | uint8_t* user_alias, 65 | uint32_t* mask, 66 | uint64_t* data0, 67 | uint64_t* data1, 68 | uint64_t* data2, 69 | uint64_t* data3, 70 | uint8_t* corrupt); 71 | // 72 | 73 | 74 | /* 75 | * DPI function to connect TileLink Channel B 76 | */ 77 | extern "C" void TileLinkPushChannelB( 78 | const int deviceId, 79 | const uint8_t valid, 80 | const uint8_t opcode, 81 | const uint8_t param, 82 | const uint8_t size, 83 | const uint64_t source, 84 | const uint64_t address, 85 | const uint32_t mask, 86 | const uint64_t data0, 87 | const uint64_t data1, 88 | const uint64_t data2, 89 | const uint64_t data3, 90 | const uint8_t corrupt); 91 | 92 | extern "C" void TileLinkPullChannelB( 93 | const int deviceId, 94 | uint8_t* ready); 95 | // 96 | 97 | 98 | /* 99 | * DPI function to connect TileLink Channel C 100 | */ 101 | extern "C" void TileLinkPushChannelC( 102 | const int deviceId, 103 | const uint8_t ready); 104 | 105 | extern "C" void TileLinkPullChannelC( 106 | const int deviceId, 107 | uint8_t* valid, 108 | uint8_t* opcode, 109 | uint8_t* param, 110 | uint8_t* size, 111 | uint64_t* source, 112 | uint64_t* address, 113 | uint8_t* user_needHint, 114 | uint64_t* user_vaddr, 115 | uint8_t* user_alias, 116 | uint64_t* data0, 117 | uint64_t* data1, 118 | uint64_t* data2, 119 | uint64_t* data3, 120 | uint8_t* corrupt); 121 | // 122 | 123 | 124 | /* 125 | * DPI function to connect TileLink Channel D 126 | */ 127 | extern "C" void TileLinkPushChannelD( 128 | const int deviceId, 129 | const uint8_t valid, 130 | const uint8_t opcode, 131 | const uint8_t param, 132 | const uint8_t size, 133 | const uint64_t source, 134 | const uint64_t sink, 135 | const uint8_t denied, 136 | const uint64_t data0, 137 | const uint64_t data1, 138 | const uint64_t data2, 139 | const uint64_t data3, 140 | const uint8_t corrupt); 141 | 142 | extern "C" void TileLinkPullChannelD( 143 | const int deviceId, 144 | uint8_t* ready); 145 | // 146 | 147 | 148 | /* 149 | * DPI function to connect TileLink Channel E 150 | */ 151 | extern "C" void TileLinkPushChannelE( 152 | const int deviceId, 153 | const uint8_t ready); 154 | 155 | extern "C" void TileLinkPullChannelE( 156 | const int deviceId, 157 | uint8_t* valid, 158 | uint64_t* sink); 159 | // 160 | 161 | 162 | /* 163 | * DPI function to connect TileLink MMIO Channel A 164 | */ 165 | extern "C" void TileLinkMMIOPushChannelA ( 166 | const int deviceId, 167 | const uint8_t ready 168 | ); 169 | 170 | extern "C" void TileLinkMMIOPullChannelA ( 171 | const int deviceId, 172 | uint8_t* valid, 173 | uint8_t* opcode, 174 | uint8_t* param, 175 | uint8_t* size, 176 | uint64_t* source, 177 | uint64_t* address, 178 | uint8_t* mask, 179 | uint64_t* data, 180 | uint8_t* corrupt 181 | ); 182 | // 183 | 184 | 185 | /* 186 | * DPI function to connect TileLink MMIO Channel D 187 | */ 188 | extern "C" void TileLinkMMIOPushChannelD ( 189 | const int deviceId, 190 | const uint8_t valid, 191 | const uint8_t opcode, 192 | const uint8_t param, 193 | const uint8_t size, 194 | const uint64_t source, 195 | const uint64_t sink, 196 | const uint8_t denied, 197 | const uint64_t data, 198 | const uint8_t corrupt 199 | ); 200 | 201 | extern "C" void TileLinkMMIOPullChannelD ( 202 | const int deviceId, 203 | uint8_t* ready 204 | ); 205 | // 206 | 207 | 208 | #endif // __TILELINK_DPI_HPP 209 | -------------------------------------------------------------------------------- /main/Fuzzer/Fuzzer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by wkf on 2021/10/29. 3 | // 4 | 5 | #ifndef TLC_TEST_FUZZER_H 6 | #define TLC_TEST_FUZZER_H 7 | 8 | #include "../Base/TLLocal.hpp" 9 | #include "../TLAgent/ULAgent.h" 10 | #include "../TLAgent/CAgent.h" 11 | #include "../TLAgent/MMIOAgent.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | #ifndef CFUZZER_RAND_RANGE_TAG 20 | # define CFUZZER_RAND_RANGE_TAG 0x80 21 | #endif 22 | 23 | #ifndef CFUZZER_RAND_RANGE_SET 24 | # define CFUZZER_RAND_RANGE_SET 0x80 25 | #endif 26 | 27 | #ifndef CFUZZER_RAND_RANGE_ALIAS 28 | # define CFUZZER_RAND_RANGE_ALIAS 0x4 29 | #endif 30 | 31 | 32 | #ifndef CFUZZER_RANGE_ITERATE_INTERVAL 33 | # define CFUZZER_RANGE_ITERATE_INTERVAL (5 * 1000 * 1000) 34 | #endif 35 | 36 | #ifndef CFUZZER_RANGE_ITERATE_TARGET 37 | # define CFUZZER_RANGE_ITERATE_TARGET 24 38 | #endif 39 | 40 | 41 | #ifndef CFUZZER_FUZZ_STREAM_INTERVAL 42 | # define CFUZZER_FUZZ_STREAM_INTERVAL 2000 43 | #endif 44 | 45 | #ifndef CFUZZER_FUZZ_STREAM_STEP 46 | # define CFUZZER_FUZZ_STREAM_STEP 0x40 47 | #endif 48 | 49 | #ifndef CFUZZER_FUZZ_STREAM_START 50 | # define CFUZZER_FUZZ_STREAM_START 0x80000000 51 | #endif 52 | 53 | #ifndef CFUZZER_FUZZ_STREAM_END 54 | # define CFUZZER_FUZZ_STREAM_END 0xA0000000 55 | #endif 56 | 57 | 58 | class Fuzzer { 59 | protected: 60 | uint64_t *cycles; 61 | public: 62 | size_t startupInterval; 63 | 64 | TLSequenceMode mode; 65 | 66 | size_t memoryStart; 67 | size_t memoryEnd; 68 | size_t mmioStart; 69 | size_t mmioEnd; 70 | size_t cmoStart; 71 | size_t cmoEnd; 72 | 73 | size_t fuzzARIRangeIndex; 74 | size_t fuzzARIRangeIterationTime; 75 | size_t fuzzARIRangeIterationInterval; 76 | size_t fuzzARIRangeIterationCount; 77 | size_t fuzzARIRangeIterationTarget; 78 | std::vector fuzzARIRangeOrdinal; 79 | 80 | size_t fuzzStreamOffset; 81 | size_t fuzzStreamInterval; 82 | size_t fuzzStreamStepTime; 83 | bool fuzzStreamEnded; 84 | size_t fuzzStreamStep; 85 | size_t fuzzStreamStart; 86 | size_t fuzzStreamEnd; 87 | public: 88 | Fuzzer() noexcept = default; 89 | virtual ~Fuzzer() noexcept = default; 90 | virtual void tick() = 0; 91 | inline void set_cycles(uint64_t *cycles) { 92 | this->cycles = cycles; 93 | } 94 | inline paddr_t remap_memory_address(paddr_t addr) { 95 | return ((addr % (memoryEnd - memoryStart)) + memoryStart); 96 | } 97 | inline paddr_t remap_mmio_address(paddr_t addr) { 98 | return ((addr % (mmioEnd - mmioStart)) + mmioStart); 99 | } 100 | inline paddr_t remap_cmo_address(paddr_t addr) { 101 | return ((addr % (cmoEnd - cmoStart)) + cmoStart); 102 | } 103 | }; 104 | 105 | class ULFuzzer: public Fuzzer { 106 | private: 107 | tl_agent::ULAgent *ulAgent; 108 | public: 109 | ULFuzzer(tl_agent::ULAgent *ulAgent) noexcept; 110 | virtual ~ULFuzzer() noexcept = default; 111 | void randomTest(bool put); 112 | void caseTest(); 113 | void caseTest2(); 114 | void tick(); 115 | }; 116 | 117 | class MMIOFuzzer : public Fuzzer { 118 | private: 119 | tl_agent::MMIOAgent* mmioAgent; 120 | public: 121 | MMIOFuzzer(tl_agent::MMIOAgent* ulAgent) noexcept; 122 | virtual ~MMIOFuzzer() noexcept = default; 123 | void randomTest(bool put); 124 | void tick(); 125 | }; 126 | 127 | 128 | struct CFuzzRange { 129 | size_t ordinal; 130 | uint64_t maxTag; 131 | uint64_t maxSet; 132 | uint64_t maxAlias; 133 | 134 | inline bool operator<(const CFuzzRange& obj) const noexcept 135 | { 136 | return ordinal < obj.ordinal; 137 | } 138 | 139 | inline void swap(CFuzzRange& obj) const noexcept 140 | { 141 | 142 | } 143 | }; 144 | 145 | class CFuzzer: public Fuzzer { 146 | private: 147 | class BandwidthProfilerStatus { 148 | public: 149 | uint64_t step; 150 | 151 | uint64_t addr; 152 | uint64_t cycle; 153 | uint64_t count; 154 | 155 | uint64_t distributionSplit; 156 | uint64_t distributionCycle; 157 | uint64_t distributionCount; 158 | 159 | public: 160 | class Distributed { 161 | public: 162 | uint64_t cycle; 163 | uint64_t count; 164 | }; 165 | 166 | std::vector distributions; 167 | }; 168 | 169 | private: 170 | tl_agent::CAgent* cAgent; 171 | bool flagDone; 172 | 173 | BandwidthProfilerStatus bwprof; 174 | 175 | public: 176 | CFuzzer(tl_agent::CAgent *cAgent) noexcept; 177 | virtual ~CFuzzer() noexcept = default; 178 | void randomTest(bool do_alias); 179 | void caseTest(); 180 | void tick(); 181 | bool done() const noexcept; 182 | }; 183 | 184 | 185 | class UnifiedFuzzer : public Fuzzer { 186 | private: 187 | TLLocalConfig* cfg; 188 | 189 | tl_agent::CAgent** cAgents; 190 | tl_agent::ULAgent** ulAgents; 191 | tl_agent::MMIOAgent** mmioAgents; 192 | 193 | size_t cAgentCount; 194 | size_t ulAgentCountPerC; 195 | size_t mmioAgentCount; 196 | 197 | protected: 198 | struct FuzzedAddress { 199 | paddr_t base; 200 | size_t size; 201 | 202 | bool IsInRange(paddr_t addr) noexcept; 203 | bool IsOverlappedRange(paddr_t base, size_t size) noexcept; 204 | }; 205 | 206 | struct ExclusiveFuzzedAddress : public FuzzedAddress { 207 | size_t agentIndex; 208 | }; 209 | 210 | std::vector* fuzzedLocally; 211 | std::vector fuzzedExclusively; 212 | 213 | std::unordered_set* monitoredGrant; 214 | 215 | struct { 216 | size_t counterU; 217 | size_t counterR; 218 | size_t counterB; 219 | size_t epoch; 220 | std::vector ordinal; 221 | } contextAnvil; 222 | 223 | public: 224 | UnifiedFuzzer(TLLocalConfig* cfg, 225 | tl_agent::CAgent** cAgents, 226 | size_t cAgentCount, 227 | tl_agent::ULAgent** ulAgents, 228 | size_t ulAgentCountPerC, 229 | tl_agent::MMIOAgent** mmioAgents, 230 | size_t mmioAgentCount); 231 | 232 | virtual ~UnifiedFuzzer() noexcept; 233 | 234 | public: 235 | void OnGrant(tl_agent::GrantEvent& event) noexcept; 236 | 237 | public: 238 | bool IsMode(TLUnifiedSequenceMode mode) const noexcept; 239 | 240 | void InitAnvil(); 241 | void TickAnvil(); 242 | 243 | void RandomC(tl_agent::CAgent* cAgent, paddr_t begin, paddr_t end, bool cmoEnabled = true); 244 | 245 | public: 246 | void tick(); 247 | }; 248 | 249 | 250 | #endif //TLC_TEST_FUZZER_H 251 | -------------------------------------------------------------------------------- /main/Base/TLLocal.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TLC_TEST_TLLOCAL_H 4 | #define TLC_TEST_TLLOCAL_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | enum class TLSequenceMode { 12 | PASSIVE = 0, 13 | FUZZ_ARI, 14 | FUZZ_STREAM, 15 | FUZZ_COUNTER, 16 | FUZZ_COUNTER_SYNC, 17 | STREAM_COPY2, 18 | STREAM_MULTI, 19 | BWPROF_STREAM_STRIDE_READ 20 | }; 21 | 22 | enum class TLUnifiedSequenceMode { 23 | PASSIVE = 0, 24 | /* 25 | Pattern Anvil: 26 | | S p a t i a l 27 | --+------------------> 28 | T | U U = C0 AcquirePerm toT (MakeUnique) 29 | e | U R = C0 ReleaseData toN 30 | m | U B = C1 Get / AcquireBlock toB (ReadNotSharedDirty) 31 | p | U C = C2 Get / AcquireBlock toB (ReadNotSharedDirty) 32 | o | R U 33 | r | R U 34 | a | R U 35 | l | R U 36 | | R 37 | | R 38 | | B C R 39 | | B C R 40 | | B C 41 | | B C 42 | v 43 | */ ANVIL, 44 | }; 45 | 46 | struct TLLocalConfig { 47 | public: 48 | uint64_t seed; 49 | 50 | unsigned int coreCount; // L1-L2 system count 51 | unsigned int masterCountPerCoreTLC; // TL-C master count per core 52 | unsigned int masterCountPerCoreTLUL; // TL-UL master count per core 53 | 54 | std::unordered_map sequenceModes; // Agent sequence modes 55 | 56 | uint64_t startupCycle; // Start-up interval cycle count 57 | uint64_t maximumCycle; // Maximum cycle count 58 | 59 | uint64_t memoryEnable; // Memory (cacheable) region enable 60 | uint64_t memoryStart; // Memory (cacheable) region start address 61 | uint64_t memoryEnd; // Memory (cacheable) region end address 62 | 63 | uint64_t memoryOOOR; // Memory (cacheable) backend out-of-order read 64 | uint64_t memoryReadDepth; // Memory (cacheable) backend read tracker depth 65 | uint64_t memoryReadLatency; // Memory (cacheable) backend read latency 66 | uint64_t memoryWriteDepth; // Memory (cacheable) backend write tracker depth 67 | uint64_t memoryWriteLatency; // Memory (cacheable) backend write latency 68 | uint64_t memoryCycleUnit; // Memory (cacheable) backend cycle unit 69 | 70 | uint64_t memoryPortCount; // Memory (cacheable) backend port count 71 | 72 | uint64_t memorySyncStrict; // Memory (cacheable) strict sync mode (must be disabled on multi-core for cbo.inval) 73 | 74 | uint64_t mmioEnable; // MMIO region enable 75 | uint64_t mmioStart; // MMIO region start address 76 | uint64_t mmioEnd; // MMIO region end address 77 | 78 | uint64_t cmoEnable; // CMO region enable 79 | uint64_t cmoEnableCBOClean; // CMO enable 'cbo.clean' 80 | uint64_t cmoEnableCBOFlush; // CMO enable 'cbo.flush' 81 | uint64_t cmoEnableCBOInval; // CMO enable 'cbo.inval' 82 | uint64_t cmoStart; // CMO region start address 83 | uint64_t cmoEnd; // CMO region end address 84 | uint64_t cmoParallelDepth; // CMO parallel depth 85 | 86 | uint64_t fuzzARIInterval; // Fuzz Auto Range Iteration interval 87 | uint64_t fuzzARITarget; // Fuzz Auto Range Iteration target 88 | 89 | uint64_t fuzzStreamInterval; // Fuzz Stream interval 90 | uint64_t fuzzStreamStep; // Fuzz Stream step 91 | uint64_t fuzzStreamStart; // Fuzz Stream start address 92 | uint64_t fuzzStreamEnd; // Fuzz Stream end address 93 | 94 | uint64_t profileCycleUnit; // Profiler cycle unit 95 | 96 | bool unifiedSequenceEnable; 97 | TLUnifiedSequenceMode unifiedSequenceMode; 98 | struct { 99 | uint64_t size; 100 | uint64_t epoch; 101 | uint64_t widthB; 102 | uint64_t thresholdR; 103 | uint64_t thresholdB; 104 | uint64_t noise; 105 | } unifiedSequenceModeAnvil; 106 | 107 | public: 108 | size_t GetAgentCount() const noexcept; 109 | size_t GetCAgentCount() const noexcept; 110 | size_t GetULAgentCount() const noexcept; 111 | }; 112 | 113 | 114 | class TLLocalContext { 115 | public: 116 | virtual uint64_t cycle() const noexcept = 0; 117 | virtual int sys() const noexcept = 0; 118 | virtual int sysId() const noexcept = 0; 119 | virtual unsigned int sysSeed() const noexcept = 0; 120 | 121 | virtual const TLLocalConfig& config() const noexcept = 0; 122 | virtual TLLocalConfig& config() noexcept = 0; 123 | 124 | virtual bool mainSys() const noexcept; 125 | 126 | size_t GetAgentCount() const noexcept; 127 | size_t GetCAgentCount() const noexcept; 128 | size_t GetULAgentCount() const noexcept; 129 | }; 130 | 131 | inline size_t TLLocalConfig::GetCAgentCount() const noexcept 132 | { 133 | return coreCount * masterCountPerCoreTLC; 134 | } 135 | 136 | inline size_t TLLocalConfig::GetULAgentCount() const noexcept 137 | { 138 | return coreCount * masterCountPerCoreTLUL; 139 | } 140 | 141 | inline size_t TLLocalConfig::GetAgentCount() const noexcept 142 | { 143 | return GetCAgentCount() + GetULAgentCount(); 144 | } 145 | 146 | inline bool TLLocalContext::mainSys() const noexcept 147 | { 148 | return true; 149 | } 150 | 151 | inline size_t TLLocalContext::GetCAgentCount() const noexcept 152 | { 153 | return config().GetCAgentCount(); 154 | } 155 | 156 | inline size_t TLLocalContext::GetULAgentCount() const noexcept 157 | { 158 | return config().GetULAgentCount(); 159 | } 160 | 161 | inline size_t TLLocalContext::GetAgentCount() const noexcept 162 | { 163 | return config().GetAgentCount(); 164 | } 165 | 166 | #endif // TLC_TEST_TLLOCAL_H 167 | -------------------------------------------------------------------------------- /main/CHIron/clog_b.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CHI__CLOG_B 4 | #define __CHI__CLOG_B 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "clog_b_tag.hpp" 14 | 15 | namespace CLog::CLogB { 16 | 17 | /* CLog.B Tag Reader */ 18 | class Reader { 19 | public: 20 | virtual ~Reader() noexcept; 21 | 22 | public: 23 | std::shared_ptr Next(std::istream& is, std::string& errorMessage) noexcept; 24 | 25 | public: 26 | virtual bool OnTagCHIParameters(std::shared_ptr tag, std::string& errorMessage) noexcept; 27 | virtual bool OnTagCHITopologies(std::shared_ptr tag, std::string& errorMessage) noexcept; 28 | virtual bool OnTagCHIRecords(std::shared_ptr tag, std::string& errorMessage) noexcept; 29 | }; 30 | 31 | /* CLog.B Tag Reader with Callbacks */ 32 | class ReaderWithCallback : public Reader { 33 | public: 34 | ReaderWithCallback() noexcept; 35 | virtual ~ReaderWithCallback() noexcept; 36 | 37 | public: 38 | using CallbackOnTagCHIParameters = 39 | std::function, std::string&)>; 40 | 41 | using CallbackOnTagCHITopologies = 42 | std::function, std::string&)>; 43 | 44 | using CallbackOnTagCHIRecords = 45 | std::function, std::string&)>; 46 | 47 | public: 48 | CallbackOnTagCHIParameters callbackOnTagCHIParameters; 49 | CallbackOnTagCHITopologies callbackOnTagCHITopologies; 50 | CallbackOnTagCHIRecords callbackOnTagCHIRecords; 51 | 52 | public: 53 | virtual bool OnTagCHIParameters(std::shared_ptr tag, std::string& errorMessage) noexcept override; 54 | virtual bool OnTagCHITopologies(std::shared_ptr tag, std::string& errorMessage) noexcept override; 55 | virtual bool OnTagCHIRecords(std::shared_ptr tag, std::string& errorMessage) noexcept override; 56 | }; 57 | 58 | /* CLog.B Tag Writer */ 59 | class Writer { 60 | public: 61 | void Next(std::ostream& os, const Tag* tag) const noexcept; 62 | }; 63 | } 64 | 65 | 66 | // Implementation of: class Reader 67 | namespace CLog::CLogB { 68 | /* 69 | */ 70 | 71 | inline Reader::~Reader() noexcept 72 | { } 73 | 74 | inline bool Reader::OnTagCHIParameters(std::shared_ptr tag, std::string& errorMessage) noexcept 75 | { 76 | return true; 77 | } 78 | 79 | inline bool Reader::OnTagCHITopologies(std::shared_ptr tag, std::string& errorMessage) noexcept 80 | { 81 | return true; 82 | } 83 | 84 | inline bool Reader::OnTagCHIRecords(std::shared_ptr tag, std::string& errorMessage) noexcept 85 | { 86 | return true; 87 | } 88 | 89 | inline std::shared_ptr Reader::Next(std::istream& is, std::string& errorMessage) noexcept 90 | { 91 | // read tag type 92 | tagtype_t type; 93 | 94 | if (!is.read(reinterpret_cast(&type), 1)) 95 | return std::shared_ptr(new TagEOF); 96 | 97 | // read length 98 | size_t length; 99 | 100 | if (!is.read(reinterpret_cast(&length), 8)) 101 | { 102 | errorMessage = "Reader: length: unexpected EOF"; 103 | return nullptr; 104 | } 105 | 106 | length = details::__bswap64_to_little(length); 107 | 108 | // 109 | if (type == Encodings::CHI_PARAMETERS) 110 | { 111 | std::shared_ptr tag(new TagCHIParameters); 112 | 113 | if (!tag->Deserialize(is, errorMessage)) 114 | return nullptr; 115 | 116 | if (!OnTagCHIParameters(tag, errorMessage)) 117 | return nullptr; 118 | 119 | return tag; 120 | } 121 | else if (type == Encodings::CHI_TOPOS) 122 | { 123 | std::shared_ptr tag(new TagCHITopologies); 124 | 125 | if (!tag->Deserialize(is, errorMessage)) 126 | return nullptr; 127 | 128 | if (!OnTagCHITopologies(tag, errorMessage)) 129 | return nullptr; 130 | 131 | return tag; 132 | } 133 | else if (type == Encodings::CHI_RECORDS) 134 | { 135 | std::shared_ptr tag(new TagCHIRecords); 136 | 137 | if (!tag->Deserialize(is, errorMessage)) 138 | return nullptr; 139 | 140 | if (!OnTagCHIRecords(tag, errorMessage)) 141 | return nullptr; 142 | 143 | return tag; 144 | } 145 | else 146 | { 147 | errorMessage = Gravity::StringAppender("Reader: ") 148 | .Append("unrecognized tag type: ", uint64_t(type)) 149 | .ToString(); 150 | return nullptr; 151 | } 152 | } 153 | } 154 | 155 | 156 | // Implementation of: class ReaderWithCallback 157 | namespace CLog::CLogB { 158 | /* 159 | CallbackOnTagCHIParameters callbackOnTagCHIParameters; 160 | CallbackOnTagCHITopologies callbackOnTagCHITopologies; 161 | CallbackOnTagCHIRecords callbackOnTagCHIRecords; 162 | */ 163 | 164 | inline ReaderWithCallback::ReaderWithCallback() noexcept 165 | : callbackOnTagCHIParameters ([](auto, auto) { return true; }) 166 | , callbackOnTagCHITopologies ([](auto, auto) { return true; }) 167 | , callbackOnTagCHIRecords ([](auto, auto) { return true; }) 168 | { } 169 | 170 | inline ReaderWithCallback::~ReaderWithCallback() noexcept 171 | { } 172 | 173 | inline bool ReaderWithCallback::OnTagCHIParameters(std::shared_ptr tag, std::string& errorMessage) noexcept 174 | { 175 | return callbackOnTagCHIParameters(tag, errorMessage); 176 | } 177 | 178 | inline bool ReaderWithCallback::OnTagCHITopologies(std::shared_ptr tag, std::string& errorMessage) noexcept 179 | { 180 | return callbackOnTagCHITopologies(tag, errorMessage); 181 | } 182 | 183 | inline bool ReaderWithCallback::OnTagCHIRecords(std::shared_ptr tag, std::string& errorMessage) noexcept 184 | { 185 | return callbackOnTagCHIRecords(tag, errorMessage); 186 | } 187 | } 188 | 189 | 190 | // Implementation of: class Writer 191 | namespace CLog::CLogB { 192 | /* 193 | */ 194 | 195 | inline void Writer::Next(std::ostream& os, const Tag* tag) const noexcept 196 | { 197 | std::ostringstream oss(std::ios_base::out | std::ios_base::binary); 198 | 199 | // write tag type 200 | os.write(reinterpret_cast(&(tag->type)), 1); 201 | 202 | // serialize tag 203 | tag->Serialize(oss); 204 | 205 | // write tag length 206 | size_t length = details::__bswap64_to_little(oss.tellp()); 207 | os.write(reinterpret_cast(&length), 8); 208 | 209 | // write tag 210 | os.write(reinterpret_cast(oss.str().c_str()), length); 211 | } 212 | } 213 | 214 | 215 | #endif // __CHI__CLOG_B 216 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 木兰宽松许可证, 第2版 2 | 3 | 木兰宽松许可证, 第2版 4 | 2020年1月 http://license.coscl.org.cn/MulanPSL2 5 | 6 | 7 | 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: 8 | 9 | 0. 定义 10 | 11 | “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 12 | 13 | “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 14 | 15 | “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 16 | 17 | “法人实体”是指提交贡献的机构及其“关联实体”。 18 | 19 | “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 20 | 21 | 1. 授予版权许可 22 | 23 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 24 | 25 | 2. 授予专利许可 26 | 27 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 28 | 29 | 3. 无商标许可 30 | 31 | “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 32 | 33 | 4. 分发限制 34 | 35 | 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 36 | 37 | 5. 免责声明与责任限制 38 | 39 | “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 40 | 41 | 6. 语言 42 | “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 43 | 44 | 条款结束 45 | 46 | 如何将木兰宽松许可证,第2版,应用到您的软件 47 | 48 | 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: 49 | 50 | 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; 51 | 52 | 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; 53 | 54 | 3, 请将如下声明文本放入每个源文件的头部注释中。 55 | 56 | Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 57 | XiangShan is licensed under Mulan PSL v2. 58 | You can use this software according to the terms and conditions of the Mulan PSL v2. 59 | You may obtain a copy of Mulan PSL v2 at: 60 | http://license.coscl.org.cn/MulanPSL2 61 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 62 | See the Mulan PSL v2 for more details. 63 | 64 | 65 | Mulan Permissive Software License,Version 2 66 | 67 | Mulan Permissive Software License,Version 2 (Mulan PSL v2) 68 | January 2020 http://license.coscl.org.cn/MulanPSL2 69 | 70 | Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: 71 | 72 | 0. Definition 73 | 74 | Software means the program and related documents which are licensed under this License and comprise all Contribution(s). 75 | 76 | Contribution means the copyrightable work licensed by a particular Contributor under this License. 77 | 78 | Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. 79 | 80 | Legal Entity means the entity making a Contribution and all its Affiliates. 81 | 82 | Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. 83 | 84 | 1. Grant of Copyright License 85 | 86 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. 87 | 88 | 2. Grant of Patent License 89 | 90 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. 91 | 92 | 3. No Trademark License 93 | 94 | No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. 95 | 96 | 4. Distribution Restriction 97 | 98 | You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. 99 | 100 | 5. Disclaimer of Warranty and Limitation of Liability 101 | 102 | THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 103 | 104 | 6. Language 105 | 106 | THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. 107 | 108 | END OF THE TERMS AND CONDITIONS 109 | 110 | How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software 111 | 112 | To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: 113 | 114 | i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; 115 | 116 | ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; 117 | 118 | iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. 119 | 120 | 121 | Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 122 | XiangShan is licensed under Mulan PSL v2. 123 | You can use this software according to the terms and conditions of the Mulan PSL v2. 124 | You may obtain a copy of Mulan PSL v2 at: 125 | http://license.coscl.org.cn/MulanPSL2 126 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 127 | See the Mulan PSL v2 for more details. 128 | -------------------------------------------------------------------------------- /main/CHIron/clog.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __CHI__CLOG 4 | #define __CHI__CLOG 5 | 6 | #include // IWYU pragma: keep 7 | #include 8 | 9 | #define CLOG_STANDALONE 10 | 11 | #ifndef CLOG_STANDALONE 12 | # include "../chi/basic/chi_parameters.hpp" 13 | #endif 14 | 15 | 16 | namespace CLog { 17 | 18 | /* 19 | * Enumeration of CHI Issue versions 20 | */ 21 | enum class Issue { 22 | B = 0, 23 | Eb = 3 24 | }; 25 | 26 | /* 27 | * Enumeration of CHI standard node types 28 | */ 29 | enum class NodeType { 30 | RN_F = 1, 31 | RN_D = 2, 32 | RN_I = 3, 33 | HN_F = 5, 34 | HN_I = 7, 35 | SN_F = 9, 36 | SN_I = 11, 37 | MN = 12 38 | }; 39 | 40 | std::string NodeTypeToString(NodeType type) noexcept; 41 | 42 | /* 43 | * Enumeration of CHI channels 44 | */ 45 | enum class Channel { 46 | TXREQ = 0, 47 | TXRSP = 1, 48 | TXDAT = 2, 49 | TXSNP = 3, 50 | 51 | RXREQ = 4, 52 | RXRSP = 5, 53 | RXDAT = 6, 54 | RXSNP = 7, 55 | }; 56 | 57 | /* 58 | * CHI parameter container 59 | */ 60 | class Parameters { 61 | protected: 62 | Issue issue; 63 | size_t nodeIdWidth; 64 | size_t reqAddrWidth; 65 | size_t reqRsvdcWidth; 66 | size_t datRsvdcWidth; 67 | size_t dataWidth; 68 | bool dataCheckPresent; 69 | bool poisonPresent; 70 | bool mpamPresent; 71 | 72 | public: 73 | Parameters() noexcept; 74 | 75 | public: 76 | void SetIssue(Issue issue) noexcept; 77 | bool SetNodeIdWidth(size_t nodeIdWidth) noexcept; 78 | bool SetReqAddrWidth(size_t reqAddrWidth) noexcept; 79 | bool SetReqRSVDCWidth(size_t reqRsvdcWidth) noexcept; 80 | bool SetDatRSVDCWidth(size_t datRsvdcWidth) noexcept; 81 | bool SetDataWidth(size_t dataWidth) noexcept; 82 | void SetDataCheckPresent(bool dataCheckPresent) noexcept; 83 | void SetPoisonPresent(bool poisonPresent) noexcept; 84 | void SetMPAMPresent(bool mpamPresent) noexcept; 85 | 86 | public: 87 | Issue GetIssue() const noexcept; 88 | size_t GetNodeIdWidth() const noexcept; 89 | size_t GetReqAddrWidth() const noexcept; 90 | size_t GetReqRSVDCWidth() const noexcept; 91 | size_t GetDatRSVDCWidth() const noexcept; 92 | size_t GetDataWidth() const noexcept; 93 | bool IsDataCheckPresent() const noexcept; 94 | bool IsPoisonPresent() const noexcept; 95 | bool IsMPAMPresent() const noexcept; 96 | }; 97 | } 98 | 99 | 100 | // Implementation of: class Parameters 101 | namespace CLog { 102 | /* 103 | Issue issue; 104 | size_t nodeIdWidth; 105 | size_t reqAddrWidth; 106 | size_t reqRsvdcWidth; 107 | size_t datRsvdcWidth; 108 | size_t dataWidth; 109 | bool dataCheckPresent; 110 | bool poisonPresent; 111 | bool mpamPresent; 112 | */ 113 | 114 | inline Parameters::Parameters() noexcept 115 | : issue (Issue::B) 116 | , nodeIdWidth (7) 117 | , reqAddrWidth (44) 118 | , reqRsvdcWidth (0) 119 | , datRsvdcWidth (0) 120 | , dataWidth (128) 121 | , dataCheckPresent (false) 122 | , poisonPresent (false) 123 | , mpamPresent (false) 124 | { } 125 | 126 | inline void Parameters::SetIssue(Issue issue) noexcept 127 | { 128 | this->issue = issue; 129 | } 130 | 131 | inline bool Parameters::SetNodeIdWidth(size_t nodeIdWidth) noexcept 132 | { 133 | #ifndef CLOG_STANDALONE 134 | if (!CHI::CheckNodeIdWidth(nodeIdWidth)) 135 | return false; 136 | #endif 137 | 138 | this->nodeIdWidth = nodeIdWidth; 139 | 140 | return true; 141 | } 142 | 143 | inline bool Parameters::SetReqAddrWidth(size_t reqAddrWidth) noexcept 144 | { 145 | #ifndef CLOG_STANDALONE 146 | if (!CHI::CheckReqAddrWidth(reqAddrWidth)) 147 | return false; 148 | #endif 149 | 150 | this->reqAddrWidth = reqAddrWidth; 151 | 152 | return true; 153 | } 154 | 155 | inline bool Parameters::SetReqRSVDCWidth(size_t reqRsvdcWidth) noexcept 156 | { 157 | #ifndef CLOG_STANDALONE 158 | if (!CHI::CheckRSVDCWidth(reqRsvdcWidth)) 159 | return false; 160 | #endif 161 | 162 | this->reqRsvdcWidth = reqRsvdcWidth; 163 | 164 | return true; 165 | } 166 | 167 | inline bool Parameters::SetDatRSVDCWidth(size_t datRsvdcWidth) noexcept 168 | { 169 | #ifndef CLOG_STANDALONE 170 | if (!CHI::CheckRSVDCWidth(datRsvdcWidth)) 171 | return false; 172 | #endif 173 | 174 | this->datRsvdcWidth = datRsvdcWidth; 175 | 176 | return true; 177 | } 178 | 179 | inline bool Parameters::SetDataWidth(size_t dataWidth) noexcept 180 | { 181 | #ifndef CLOG_STANDALONE 182 | if (!CHI::CheckDataWidth(dataWidth)) 183 | return false; 184 | #endif 185 | 186 | this->dataWidth = dataWidth; 187 | 188 | return true; 189 | } 190 | 191 | inline void Parameters::SetDataCheckPresent(bool dataCheckPresent) noexcept 192 | { 193 | this->dataCheckPresent = dataCheckPresent; 194 | } 195 | 196 | inline void Parameters::SetPoisonPresent(bool poisonPresent) noexcept 197 | { 198 | this->poisonPresent = poisonPresent; 199 | } 200 | 201 | inline void Parameters::SetMPAMPresent(bool mpamPresent) noexcept 202 | { 203 | this->mpamPresent = mpamPresent; 204 | } 205 | 206 | inline Issue Parameters::GetIssue() const noexcept 207 | { 208 | return issue; 209 | } 210 | 211 | inline size_t Parameters::GetNodeIdWidth() const noexcept 212 | { 213 | return nodeIdWidth; 214 | } 215 | 216 | inline size_t Parameters::GetReqAddrWidth() const noexcept 217 | { 218 | return reqAddrWidth; 219 | } 220 | 221 | inline size_t Parameters::GetReqRSVDCWidth() const noexcept 222 | { 223 | return reqRsvdcWidth; 224 | } 225 | 226 | inline size_t Parameters::GetDatRSVDCWidth() const noexcept 227 | { 228 | return datRsvdcWidth; 229 | } 230 | 231 | inline size_t Parameters::GetDataWidth() const noexcept 232 | { 233 | return dataWidth; 234 | } 235 | 236 | inline bool Parameters::IsDataCheckPresent() const noexcept 237 | { 238 | return dataCheckPresent; 239 | } 240 | 241 | inline bool Parameters::IsPoisonPresent() const noexcept 242 | { 243 | return poisonPresent; 244 | } 245 | 246 | inline bool Parameters::IsMPAMPresent() const noexcept 247 | { 248 | return mpamPresent; 249 | } 250 | } 251 | 252 | 253 | // Implementation of: NodeTypeToString 254 | namespace CLog { 255 | inline std::string NodeTypeToString(NodeType type) noexcept 256 | { 257 | switch (type) 258 | { 259 | case NodeType::RN_F: return "RN-F"; 260 | case NodeType::RN_D: return "RN-D"; 261 | case NodeType::RN_I: return "RN-I"; 262 | case NodeType::HN_F: return "HN-F"; 263 | case NodeType::HN_I: return "HN-I"; 264 | case NodeType::SN_F: return "SN-F"; 265 | case NodeType::SN_I: return "SN-I"; 266 | case NodeType::MN: return "MN"; 267 | default: return ""; 268 | } 269 | } 270 | } 271 | 272 | 273 | #endif // __CHI__CLOG 274 | -------------------------------------------------------------------------------- /main/Fuzzer/ULFuzzer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by wkf on 2021/10/29. 3 | // 4 | 5 | #include "Fuzzer.h" 6 | 7 | 8 | static std::vector FUZZ_ARI_RANGES = { 9 | { .ordinal = 0, .maxTag = CFUZZER_RAND_RANGE_TAG, .maxSet = CFUZZER_RAND_RANGE_SET, .maxAlias = CFUZZER_RAND_RANGE_ALIAS }, 10 | { .ordinal = 1, .maxTag = 0x1, .maxSet = 0x10, .maxAlias = 0x4 }, 11 | { .ordinal = 2, .maxTag = 0x10, .maxSet = 0x1, .maxAlias = 0x4 } 12 | }; 13 | 14 | static CFuzzRange FUZZ_STREAM_RANGE = { 15 | .ordinal = 0, .maxTag = 0x10, .maxSet = 0x10, .maxAlias = CFUZZER_RAND_RANGE_ALIAS 16 | }; 17 | 18 | static inline size_t fact(size_t n) noexcept 19 | { 20 | size_t r = 1; 21 | for (size_t i = 1; i <= n; i++) 22 | r *= i; 23 | return r; 24 | } 25 | 26 | 27 | ULFuzzer::ULFuzzer(tl_agent::ULAgent *ulAgent) noexcept { 28 | this->ulAgent = ulAgent; 29 | 30 | this->memoryStart = ulAgent->config().memoryStart; 31 | this->memoryEnd = ulAgent->config().memoryEnd; 32 | 33 | this->fuzzARIRangeIndex = 0; 34 | this->fuzzARIRangeIterationInterval = ulAgent->config().fuzzARIInterval; 35 | this->fuzzARIRangeIterationTarget = ulAgent->config().fuzzARITarget; 36 | 37 | this->fuzzARIRangeIterationCount = 0; 38 | this->fuzzARIRangeIterationTime = ulAgent->config().fuzzARIInterval; 39 | 40 | this->fuzzStreamOffset = 0; 41 | this->fuzzStreamStepTime = ulAgent->config().fuzzStreamStep; 42 | this->fuzzStreamEnded = false; 43 | this->fuzzStreamStep = ulAgent->config().fuzzStreamStep; 44 | this->fuzzStreamInterval = ulAgent->config().fuzzStreamInterval; 45 | this->fuzzStreamStart = ulAgent->config().fuzzStreamStart; 46 | this->fuzzStreamEnd = ulAgent->config().fuzzStreamEnd; 47 | 48 | decltype(ulAgent->config().sequenceModes.end()) modeInMap; 49 | if ((modeInMap = ulAgent->config().sequenceModes.find(ulAgent->sysId())) 50 | != ulAgent->config().sequenceModes.end()) 51 | this->mode = modeInMap->second; 52 | else 53 | this->mode = TLSequenceMode::FUZZ_ARI; 54 | 55 | if (this->mode == TLSequenceMode::FUZZ_ARI) 56 | { 57 | LogInfo(this->ulAgent->cycle(), Append("ULFuzzer [", ulAgent->sysId(), "] in FUZZ_ARI mode").EndLine()); 58 | 59 | for (size_t i = 0; i < FUZZ_ARI_RANGES.size(); i++) 60 | this->fuzzARIRangeOrdinal.push_back(i); 61 | 62 | size_t loop = ulAgent->sysSeed() % fact(fuzzARIRangeOrdinal.size()); 63 | for (size_t i = 0; i < loop; i++) 64 | std::next_permutation(fuzzARIRangeOrdinal.begin(), fuzzARIRangeOrdinal.end()); 65 | 66 | LogInfo(this->ulAgent->cycle(), Append("Initial Fuzz Set: index = ", this->fuzzARIRangeIndex, ", permutation: ")); 67 | LogEx( 68 | std::cout << "[ "; 69 | for (size_t i = 0; i < fuzzARIRangeOrdinal.size(); i++) 70 | std::cout << fuzzARIRangeOrdinal[i] << " "; 71 | std::cout << "]"; 72 | ); 73 | LogEx(std::cout << std::endl); 74 | } 75 | else if (this->mode == TLSequenceMode::FUZZ_STREAM) 76 | { 77 | LogInfo(this->ulAgent->cycle(), Append("ULFuzzer [", ulAgent->sysId(), "] in FUZZ_STREAM mode").EndLine()); 78 | LogInfo(this->ulAgent->cycle(), Append("ULFuzzer [", ulAgent->sysId(), "] stream steps ") 79 | .Hex().ShowBase().Append(this->fuzzStreamStep).EndLine()); 80 | LogInfo(this->ulAgent->cycle(), Append("ULFuzzer [", ulAgent->sysId(), "] stream starts at ") 81 | .Hex().ShowBase().Append(this->fuzzStreamStart).EndLine()); 82 | LogInfo(this->ulAgent->cycle(), Append("ULFuzzer [", ulAgent->sysId(), "] stream ends at ") 83 | .Hex().ShowBase().Append(this->fuzzStreamEnd).EndLine()); 84 | } 85 | } 86 | 87 | void ULFuzzer::randomTest(bool put) { 88 | if (this->mode == TLSequenceMode::PASSIVE) 89 | { 90 | return; 91 | } 92 | else if (this->mode == TLSequenceMode::FUZZ_ARI || this->mode == TLSequenceMode::FUZZ_STREAM) 93 | { 94 | paddr_t addr = (CAGENT_RAND64(ulAgent, "ULFuzzer") % 0x400) << 6; 95 | 96 | if (this->mode == TLSequenceMode::FUZZ_ARI) 97 | { 98 | // Tag + Set + Offset 99 | addr = ((CAGENT_RAND64(ulAgent, "ULFuzzer") % FUZZ_ARI_RANGES[fuzzARIRangeOrdinal[fuzzARIRangeIndex]].maxTag) << 13) 100 | + ((CAGENT_RAND64(ulAgent, "ULFuzzer") % FUZZ_ARI_RANGES[fuzzARIRangeOrdinal[fuzzARIRangeIndex]].maxSet) << 6); 101 | 102 | addr = remap_memory_address(addr); 103 | } 104 | else // FUZZ_STREAM 105 | { 106 | addr = ((CAGENT_RAND64(ulAgent, "ULFuzzer") % FUZZ_STREAM_RANGE.maxTag) << 13) 107 | + ((CAGENT_RAND64(ulAgent, "ULFuzzer") % FUZZ_STREAM_RANGE.maxSet) << 6) 108 | + this->fuzzStreamOffset 109 | + this->fuzzStreamStart; 110 | } 111 | 112 | if (!put || CAGENT_RAND64(ulAgent, "ULFuzzer") % 2) { // Get 113 | ulAgent->do_getAuto(addr); 114 | } else { // Put 115 | auto putdata = make_shared_tldata(); 116 | for (int i = 0; i < DATASIZE; i++) { 117 | putdata->data[i] = (uint8_t)CAGENT_RAND64(ulAgent, "ULFuzzer"); 118 | } 119 | ulAgent->do_putfulldata(addr, putdata); 120 | } 121 | } 122 | } 123 | 124 | void ULFuzzer::caseTest() { 125 | if (*cycles == 500) { 126 | auto putdata = make_shared_tldata(); 127 | for (int i = 0; i < DATASIZE/2; i++) { 128 | putdata->data[i] = (uint8_t)CAGENT_RAND64(ulAgent, "ULFuzzer"); 129 | } 130 | for (int i = DATASIZE/2; i < DATASIZE; i++) { 131 | putdata->data[i] = putdata->data[i-DATASIZE/2]; 132 | } 133 | ulAgent->do_putpartialdata(0x1070, 2, 0xf0000, putdata); 134 | } 135 | if (*cycles == 600) { 136 | ulAgent->do_getAuto(0x1040); 137 | } 138 | } 139 | 140 | void ULFuzzer::caseTest2() { 141 | if (*cycles == 100) { 142 | auto putdata = make_shared_tldata(); 143 | for (int i = 0; i < DATASIZE/2; i++) { 144 | putdata->data[i] = (uint8_t)CAGENT_RAND64(ulAgent, "ULFuzzer"); 145 | } 146 | for (int i = DATASIZE/2; i < DATASIZE; i++) { 147 | putdata->data[i] = putdata->data[i-DATASIZE/2]; 148 | } 149 | ulAgent->do_putpartialdata(0x1000, 2, 0xf, putdata); 150 | } 151 | if (*cycles == 500) { 152 | ulAgent->do_get(0x1000, 2, 0xf); 153 | } 154 | } 155 | 156 | void ULFuzzer::tick() { 157 | 158 | if (this->startupInterval < ulAgent->config().startupCycle) 159 | { 160 | this->startupInterval++; 161 | return; 162 | } 163 | 164 | if (this->mode == TLSequenceMode::FUZZ_ARI) 165 | { 166 | this->randomTest(false); 167 | 168 | if (this->ulAgent->cycle() >= this->fuzzARIRangeIterationTime) 169 | { 170 | this->fuzzARIRangeIterationTime += this->fuzzARIRangeIterationInterval; 171 | this->fuzzARIRangeIndex++; 172 | 173 | if (this->fuzzARIRangeIndex == fuzzARIRangeOrdinal.size()) 174 | { 175 | this->fuzzARIRangeIndex = 0; 176 | this->fuzzARIRangeIterationCount++; 177 | 178 | std::next_permutation(fuzzARIRangeOrdinal.begin(), fuzzARIRangeOrdinal.end()); 179 | } 180 | 181 | LogInfo(this->ulAgent->cycle(), Append("Fuzz Set switched: index = ", this->fuzzARIRangeIndex, ", permutation: ")); 182 | LogEx( 183 | std::cout << "[ "; 184 | for (size_t i = 0; i < fuzzARIRangeOrdinal.size(); i++) 185 | std::cout << fuzzARIRangeOrdinal[i] << " "; 186 | std::cout << "]"; 187 | ); 188 | LogEx(std::cout << std::endl); 189 | } 190 | 191 | if (this->fuzzARIRangeIterationCount == this->fuzzARIRangeIterationTarget) 192 | { 193 | // TLSystemFinishEvent().Fire(); 194 | } 195 | } 196 | else if (this->mode == TLSequenceMode::FUZZ_STREAM) 197 | { 198 | this->randomTest(false); 199 | 200 | if (this->ulAgent->cycle() >= this->fuzzStreamStepTime) 201 | { 202 | this->fuzzStreamStepTime += this->fuzzStreamInterval; 203 | this->fuzzStreamOffset += this->fuzzStreamStep; 204 | } 205 | 206 | if (this->fuzzStreamEnded) 207 | { 208 | // TLSystemFinishEvent().Fire(); 209 | } 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /main/V3/v3_memaxi.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Utils/autoinclude.h" 4 | #include AUTOINCLUDE_VERILATED(VTestTop.h) 5 | 6 | #include "../Sequencer/TLSequencer.hpp" 7 | 8 | namespace V3::Memory { 9 | 10 | inline void PullChannelAW(VTestTop* verilated, TLSequencer* tltest) 11 | { 12 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 13 | verilated->mem_axi_0_aw_ready = port.aw.ready; 14 | } 15 | 16 | inline void PushChannelAW(VTestTop* verilated, TLSequencer* tltest) 17 | { 18 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 19 | port.aw.valid = verilated->mem_axi_0_aw_valid; 20 | port.aw.id = verilated->mem_axi_0_aw_bits_id; 21 | port.aw.addr = verilated->mem_axi_0_aw_bits_addr; 22 | port.aw.burst = verilated->mem_axi_0_aw_bits_burst; 23 | port.aw.size = verilated->mem_axi_0_aw_bits_size; 24 | port.aw.len = verilated->mem_axi_0_aw_bits_len; 25 | } 26 | 27 | inline void PullChannelW(VTestTop* verilated, TLSequencer* tltest) 28 | { 29 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 30 | verilated->mem_axi_0_w_ready = port.w.ready; 31 | } 32 | 33 | inline void PushChannelW(VTestTop* verilated, TLSequencer* tltest) 34 | { 35 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 36 | port.w.valid = verilated->mem_axi_0_w_valid; 37 | port.w.strb = verilated->mem_axi_0_w_bits_strb; 38 | port.w.last = verilated->mem_axi_0_w_bits_last; 39 | port.w.data->data[0] = verilated->mem_axi_0_w_bits_data[0] & 0xFF; 40 | port.w.data->data[1] = (verilated->mem_axi_0_w_bits_data[0] >> 8) & 0xFF; 41 | port.w.data->data[2] = (verilated->mem_axi_0_w_bits_data[0] >> 16) & 0xFF; 42 | port.w.data->data[3] = (verilated->mem_axi_0_w_bits_data[0] >> 24) & 0xFF; 43 | port.w.data->data[4] = verilated->mem_axi_0_w_bits_data[1] & 0xFF; 44 | port.w.data->data[5] = (verilated->mem_axi_0_w_bits_data[1] >> 8) & 0xFF; 45 | port.w.data->data[6] = (verilated->mem_axi_0_w_bits_data[1] >> 16) & 0xFF; 46 | port.w.data->data[7] = (verilated->mem_axi_0_w_bits_data[1] >> 24) & 0xFF; 47 | port.w.data->data[8] = verilated->mem_axi_0_w_bits_data[2] & 0xFF; 48 | port.w.data->data[9] = (verilated->mem_axi_0_w_bits_data[2] >> 8) & 0xFF; 49 | port.w.data->data[10] = (verilated->mem_axi_0_w_bits_data[2] >> 16) & 0xFF; 50 | port.w.data->data[11] = (verilated->mem_axi_0_w_bits_data[2] >> 24) & 0xFF; 51 | port.w.data->data[12] = verilated->mem_axi_0_w_bits_data[3] & 0xFF; 52 | port.w.data->data[13] = (verilated->mem_axi_0_w_bits_data[3] >> 8) & 0xFF; 53 | port.w.data->data[14] = (verilated->mem_axi_0_w_bits_data[3] >> 16) & 0xFF; 54 | port.w.data->data[15] = (verilated->mem_axi_0_w_bits_data[3] >> 24) & 0xFF; 55 | port.w.data->data[16] = verilated->mem_axi_0_w_bits_data[4] & 0xFF; 56 | port.w.data->data[17] = (verilated->mem_axi_0_w_bits_data[4] >> 8) & 0xFF; 57 | port.w.data->data[18] = (verilated->mem_axi_0_w_bits_data[4] >> 16) & 0xFF; 58 | port.w.data->data[19] = (verilated->mem_axi_0_w_bits_data[4] >> 24) & 0xFF; 59 | port.w.data->data[20] = verilated->mem_axi_0_w_bits_data[5] & 0xFF; 60 | port.w.data->data[21] = (verilated->mem_axi_0_w_bits_data[5] >> 8) & 0xFF; 61 | port.w.data->data[22] = (verilated->mem_axi_0_w_bits_data[5] >> 16) & 0xFF; 62 | port.w.data->data[23] = (verilated->mem_axi_0_w_bits_data[5] >> 24) & 0xFF; 63 | port.w.data->data[24] = verilated->mem_axi_0_w_bits_data[6] & 0xFF; 64 | port.w.data->data[25] = (verilated->mem_axi_0_w_bits_data[6] >> 8) & 0xFF; 65 | port.w.data->data[26] = (verilated->mem_axi_0_w_bits_data[6] >> 16) & 0xFF; 66 | port.w.data->data[27] = (verilated->mem_axi_0_w_bits_data[6] >> 24) & 0xFF; 67 | port.w.data->data[28] = verilated->mem_axi_0_w_bits_data[7] & 0xFF; 68 | port.w.data->data[29] = (verilated->mem_axi_0_w_bits_data[7] >> 8) & 0xFF; 69 | port.w.data->data[30] = (verilated->mem_axi_0_w_bits_data[7] >> 16) & 0xFF; 70 | port.w.data->data[31] = (verilated->mem_axi_0_w_bits_data[7] >> 24) & 0xFF; 71 | } 72 | 73 | inline void PullChannelB(VTestTop* verilated, TLSequencer* tltest) 74 | { 75 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 76 | verilated->mem_axi_0_b_valid = port.b.valid; 77 | verilated->mem_axi_0_b_bits_id = port.b.id; 78 | verilated->mem_axi_0_b_bits_resp = port.b.resp; 79 | } 80 | 81 | inline void PushChannelB(VTestTop* verilated, TLSequencer* tltest) 82 | { 83 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 84 | port.b.ready = verilated->mem_axi_0_b_ready; 85 | } 86 | 87 | inline void PullChannelAR(VTestTop* verilated, TLSequencer* tltest) 88 | { 89 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 90 | verilated->mem_axi_0_ar_ready = port.ar.ready; 91 | } 92 | 93 | inline void PushChannelAR(VTestTop* verilated, TLSequencer* tltest) 94 | { 95 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 96 | port.ar.valid = verilated->mem_axi_0_ar_valid; 97 | port.ar.id = verilated->mem_axi_0_ar_bits_id; 98 | port.ar.addr = verilated->mem_axi_0_ar_bits_addr; 99 | port.ar.burst = verilated->mem_axi_0_ar_bits_burst; 100 | port.ar.size = verilated->mem_axi_0_ar_bits_size; 101 | port.ar.len = verilated->mem_axi_0_ar_bits_len; 102 | } 103 | 104 | inline void PullChannelR(VTestTop* verilated, TLSequencer* tltest) 105 | { 106 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 107 | verilated->mem_axi_0_r_valid = port.r.valid; 108 | verilated->mem_axi_0_r_bits_id = port.r.id; 109 | verilated->mem_axi_0_r_bits_resp = port.r.resp; 110 | verilated->mem_axi_0_r_bits_last = port.r.last; 111 | verilated->mem_axi_0_r_bits_data[0] = (uint32_t(port.r.data->data[0])) 112 | | (uint32_t(port.r.data->data[1]) << 8) 113 | | (uint32_t(port.r.data->data[2]) << 16) 114 | | (uint32_t(port.r.data->data[3]) << 24); 115 | verilated->mem_axi_0_r_bits_data[1] = (uint32_t(port.r.data->data[4])) 116 | | (uint32_t(port.r.data->data[5]) << 8) 117 | | (uint32_t(port.r.data->data[6]) << 16) 118 | | (uint32_t(port.r.data->data[7]) << 24); 119 | verilated->mem_axi_0_r_bits_data[2] = (uint32_t(port.r.data->data[8])) 120 | | (uint32_t(port.r.data->data[9]) << 8) 121 | | (uint32_t(port.r.data->data[10]) << 16) 122 | | (uint32_t(port.r.data->data[11]) << 24); 123 | verilated->mem_axi_0_r_bits_data[3] = (uint32_t(port.r.data->data[12])) 124 | | (uint32_t(port.r.data->data[13]) << 8) 125 | | (uint32_t(port.r.data->data[14]) << 16) 126 | | (uint32_t(port.r.data->data[15]) << 24); 127 | verilated->mem_axi_0_r_bits_data[4] = (uint32_t(port.r.data->data[16])) 128 | | (uint32_t(port.r.data->data[17]) << 8) 129 | | (uint32_t(port.r.data->data[18]) << 16) 130 | | (uint32_t(port.r.data->data[19]) << 24); 131 | verilated->mem_axi_0_r_bits_data[5] = (uint32_t(port.r.data->data[20])) 132 | | (uint32_t(port.r.data->data[21]) << 8) 133 | | (uint32_t(port.r.data->data[22]) << 16) 134 | | (uint32_t(port.r.data->data[23]) << 24); 135 | verilated->mem_axi_0_r_bits_data[6] = (uint32_t(port.r.data->data[24])) 136 | | (uint32_t(port.r.data->data[25]) << 8) 137 | | (uint32_t(port.r.data->data[26]) << 16) 138 | | (uint32_t(port.r.data->data[27]) << 24); 139 | verilated->mem_axi_0_r_bits_data[7] = (uint32_t(port.r.data->data[28])) 140 | | (uint32_t(port.r.data->data[29]) << 8) 141 | | (uint32_t(port.r.data->data[30]) << 16) 142 | | (uint32_t(port.r.data->data[31]) << 24); 143 | } 144 | 145 | inline void PushChannelR(VTestTop* verilated, TLSequencer* tltest) 146 | { 147 | TLSequencer::MemoryAXIPort& port = tltest->MemoryAXI(0); 148 | port.r.ready = verilated->mem_axi_0_r_ready; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /main/Base/TLEnum.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // Created by Kumonda221 (Ding Haonan) on 2024/03/20 4 | // 5 | 6 | #ifndef TLC_TEST_TLENUM_H 7 | #define TLC_TEST_TLENUM_H 8 | 9 | #include 10 | 11 | #include "../Utils/gravity_utility.hpp" 12 | 13 | 14 | enum class TLOpcodeA { 15 | PutFullData = 0, 16 | PutPartialData = 1, 17 | ArithmeticData = 2, 18 | LogicalData = 3, 19 | Get = 4, 20 | Intent = 5, 21 | AcquireBlock = 6, 22 | AcquirePerm = 7, 23 | // = 8, 24 | // = 9, 25 | // = 10, 26 | // = 11, 27 | CBOClean = 12, 28 | CBOFlush = 13, 29 | CBOInval = 14 30 | }; 31 | 32 | enum class TLOpcodeB { 33 | PutFullData = 0, 34 | PutPartialData = 1, 35 | ArithmeticData = 2, 36 | LogicalData = 3, 37 | Get = 4, 38 | Intent = 5, 39 | ProbeBlock = 6, 40 | ProbePerm = 7 41 | }; 42 | 43 | enum class TLOpcodeC { 44 | AccessAck = 0, 45 | AccessAckData = 1, 46 | HintAck = 2, 47 | // = 3, 48 | ProbeAck = 4, 49 | ProbeAckData = 5, 50 | Release = 6, 51 | ReleaseData = 7 52 | }; 53 | 54 | enum class TLOpcodeD { 55 | AccessAck = 0, 56 | AccessAckData = 1, 57 | HintAck = 2, 58 | // = 3, 59 | Grant = 4, 60 | GrantData = 5, 61 | ReleaseAck = 6, 62 | // = 7, 63 | CBOAck = 8 64 | }; 65 | 66 | enum class TLOpcodeE { 67 | 68 | }; 69 | 70 | 71 | enum class TLPermDirection { 72 | toT = 0, 73 | toB, 74 | toN 75 | }; 76 | using TLParamProbe = TLPermDirection; 77 | using TLParamGrant = TLPermDirection; 78 | using TLParamGrantData = TLPermDirection; 79 | 80 | 81 | enum class TLPermPromotion { 82 | NtoB = 0, 83 | NtoT, 84 | BtoT 85 | }; 86 | using TLParamAcquire = TLPermPromotion; 87 | 88 | 89 | enum class TLPermDemotion { 90 | TtoB = 0, 91 | TtoN, 92 | BtoN, 93 | TtoT, 94 | BtoB, 95 | NtoN 96 | }; 97 | using TLParamRelease = TLPermDemotion; 98 | using TLParamProbeAck = TLPermDemotion; 99 | 100 | enum class TLPermission { 101 | // 102 | NIL = -1, 103 | // 104 | INVALID = 0, 105 | BRANCH, 106 | TRUNK, 107 | TIP 108 | }; 109 | 110 | 111 | // 112 | template 113 | inline constexpr bool TLEnumEquals(Ta a, Tb b) noexcept 114 | { 115 | return static_cast(a) == static_cast(b); 116 | } 117 | 118 | template 119 | inline constexpr bool TLEnumEquals(Ta a, Tb b, Tbs... bs) noexcept 120 | { 121 | return TLEnumEquals(a, b) || TLEnumEquals(a, bs...); 122 | } 123 | 124 | 125 | // 126 | inline std::string TLOpcodeAToString(TLOpcodeA opcode) noexcept 127 | { 128 | switch (opcode) 129 | { 130 | case TLOpcodeA::PutFullData: return "PutFullData"; 131 | case TLOpcodeA::PutPartialData: return "PutPartialData"; 132 | case TLOpcodeA::ArithmeticData: return "ArithmeticData"; 133 | case TLOpcodeA::LogicalData: return "LogicalData"; 134 | case TLOpcodeA::Get: return "Get"; 135 | case TLOpcodeA::Intent: return "Intent"; 136 | case TLOpcodeA::AcquireBlock: return "AcquireBlock"; 137 | case TLOpcodeA::AcquirePerm: return "AcquirePerm"; 138 | case TLOpcodeA::CBOClean: return "CBOClean"; 139 | case TLOpcodeA::CBOFlush: return "CBOFlush"; 140 | case TLOpcodeA::CBOInval: return "CBOInval"; 141 | default: 142 | return Gravity::StringAppender("").ToString(); 143 | } 144 | } 145 | 146 | inline std::string TLOpcodeBToString(TLOpcodeB opcode) noexcept 147 | { 148 | switch (opcode) 149 | { 150 | case TLOpcodeB::PutFullData: return "PutFullData"; 151 | case TLOpcodeB::PutPartialData: return "PutPartialData"; 152 | case TLOpcodeB::ArithmeticData: return "ArithmeticData"; 153 | case TLOpcodeB::LogicalData: return "LogicalData"; 154 | case TLOpcodeB::Get: return "Get"; 155 | case TLOpcodeB::Intent: return "Intent"; 156 | case TLOpcodeB::ProbeBlock: return "ProbeBlock"; 157 | case TLOpcodeB::ProbePerm: return "ProbePerm"; 158 | default: 159 | return Gravity::StringAppender("").ToString(); 160 | } 161 | } 162 | 163 | inline std::string TLOpcodeCToString(TLOpcodeC opcode) noexcept 164 | { 165 | switch (opcode) 166 | { 167 | case TLOpcodeC::AccessAck: return "AccessAck"; 168 | case TLOpcodeC::AccessAckData: return "AccessAckData"; 169 | case TLOpcodeC::HintAck: return "HintAck"; 170 | case TLOpcodeC::ProbeAck: return "ProbeAck"; 171 | case TLOpcodeC::ProbeAckData: return "ProbeAckData"; 172 | case TLOpcodeC::Release: return "Release"; 173 | case TLOpcodeC::ReleaseData: return "ReleaseData"; 174 | default: 175 | return Gravity::StringAppender("").ToString(); 176 | } 177 | } 178 | 179 | inline std::string TLOpcodeDToString(TLOpcodeD opcode) noexcept 180 | { 181 | switch (opcode) 182 | { 183 | case TLOpcodeD::AccessAck: return "AccessAck"; 184 | case TLOpcodeD::AccessAckData: return "AccessAckData"; 185 | case TLOpcodeD::HintAck: return "HintAck"; 186 | case TLOpcodeD::Grant: return "Grant"; 187 | case TLOpcodeD::GrantData: return "GrantData"; 188 | case TLOpcodeD::ReleaseAck: return "ReleaseAck"; 189 | case TLOpcodeD::CBOAck: return "CBOAck"; 190 | default: 191 | return Gravity::StringAppender("").ToString(); 192 | } 193 | } 194 | 195 | inline std::string ProbeParamToString(TLParamProbe param) noexcept 196 | { 197 | switch (param) 198 | { 199 | case TLParamProbe::toT: return "toT"; 200 | case TLParamProbe::toB: return "toB"; 201 | case TLParamProbe::toN: return "toN"; 202 | default: 203 | return Gravity::StringAppender("").ToString(); 204 | } 205 | } 206 | 207 | inline std::string GrantParamToString(TLParamGrant param) noexcept 208 | { 209 | switch (param) 210 | { 211 | case TLParamGrant::toT: return "toT"; 212 | case TLParamGrant::toB: return "toB"; 213 | case TLParamGrant::toN: return "toN"; 214 | default: 215 | return Gravity::StringAppender("").ToString(); 216 | } 217 | } 218 | 219 | inline std::string GrantDataParamToString(TLParamGrantData param) noexcept 220 | { 221 | switch (param) 222 | { 223 | case TLParamGrantData::toT: return "toT"; 224 | case TLParamGrantData::toB: return "toB"; 225 | case TLParamGrantData::toN: return "toN"; 226 | default: 227 | return Gravity::StringAppender("").ToString(); 228 | } 229 | } 230 | 231 | inline std::string AcquireParamToString(TLParamAcquire param) noexcept 232 | { 233 | switch (param) 234 | { 235 | case TLParamAcquire::NtoB: return "NtoB"; 236 | case TLParamAcquire::NtoT: return "NtoT"; 237 | case TLParamAcquire::BtoT: return "BtoT"; 238 | default: 239 | return Gravity::StringAppender("").ToString(); 240 | } 241 | } 242 | 243 | inline std::string ProbeAckParamToString(TLParamProbeAck param) noexcept 244 | { 245 | switch (param) 246 | { 247 | case TLParamProbeAck::TtoB: return "TtoB"; 248 | case TLParamProbeAck::TtoN: return "TtoN"; 249 | case TLParamProbeAck::BtoN: return "BtoN"; 250 | case TLParamProbeAck::TtoT: return "TtoT"; 251 | case TLParamProbeAck::BtoB: return "BtoB"; 252 | case TLParamProbeAck::NtoN: return "NtoN"; 253 | default: 254 | return Gravity::StringAppender("").ToString(); 255 | } 256 | } 257 | 258 | inline std::string ReleaseParamToString(TLParamRelease param) noexcept 259 | { 260 | switch (param) 261 | { 262 | case TLParamRelease::TtoB: return "TtoB"; 263 | case TLParamRelease::TtoN: return "TtoN"; 264 | case TLParamRelease::BtoN: return "BtoN"; 265 | case TLParamRelease::TtoT: return "TtoT"; 266 | case TLParamRelease::BtoB: return "BtoB"; 267 | case TLParamRelease::NtoN: return "NtoN"; 268 | default: 269 | return Gravity::StringAppender("").ToString(); 270 | } 271 | } 272 | 273 | inline std::string PrivilegeToString(TLPermission privilege) noexcept 274 | { 275 | switch (privilege) 276 | { 277 | case TLPermission::INVALID: return "INVALID"; 278 | case TLPermission::BRANCH: return "BRANCH"; 279 | case TLPermission::TRUNK: return "TRUNK"; 280 | case TLPermission::TIP: return "TIP"; 281 | default: 282 | return Gravity::StringAppender("").ToString(); 283 | } 284 | } 285 | 286 | #endif // TLC_TEST_TLENUM_H 287 | -------------------------------------------------------------------------------- /main/DPI/memory_dpi.svh: -------------------------------------------------------------------------------- 1 | /* 2 | * AXI Channel AW 3 | */ 4 | import "DPI-C" function void MemoryAXIPullChannelAW ( 5 | input int portId, 6 | output byte ready 7 | ); 8 | 9 | function void SvMemoryAXIPullChannelAW ( 10 | input int portId, 11 | output logic ready 12 | ); 13 | 14 | if (1) begin 15 | 16 | MemoryAXIPullChannelAW( 17 | portId, 18 | ready 19 | ); 20 | end 21 | 22 | endfunction 23 | 24 | import "DPI-C" function void MemoryAXIPushChannelAW ( 25 | input int portId, 26 | input byte valid, 27 | input int id, 28 | input longint addr, 29 | input byte burst, 30 | input byte size, 31 | input byte len 32 | ); 33 | 34 | function void SvMemoryAXIPushChannelAW ( 35 | input int portId, 36 | input logic resetn, 37 | input logic valid, 38 | input logic [10:0] id, 39 | input logic [47:0] addr, 40 | input logic [1:0] burst, 41 | input logic [2:0] size, 42 | input logic [7:0] len 43 | ); 44 | 45 | guard_valid: assert (!resetn || !$isunknown(valid)) else $fatal("MemoryAXIPushChannelAW: 'valid' is unknown"); 46 | 47 | guard_id: assert (!resetn || !valid || !$isunknown(id )) else $fatal("MemoryAXIPushChannelAW: 'id' is unknown"); 48 | guard_addr: assert (!resetn || !valid || !$isunknown(addr )) else $fatal("MemoryAXIPushChannelAW: 'addr' is unknown"); 49 | guard_burst: assert (!resetn || !valid || !$isunknown(burst )) else $fatal("MemoryAXIPushChannelAW: 'burst' is unknown"); 50 | guard_size: assert (!resetn || !valid || !$isunknown(size )) else $fatal("MemoryAXIPushChannelAW: 'size' is unknown"); 51 | guard_len: assert (!resetn || !valid || !$isunknown(len )) else $fatal("MemoryAXIPushChannelAW: 'len' is unknown"); 52 | 53 | if (resetn) begin 54 | 55 | MemoryAXIPushChannelAW ( 56 | portId, 57 | valid, 58 | id, 59 | addr, 60 | burst, 61 | size, 62 | len 63 | ); 64 | end 65 | 66 | endfunction 67 | 68 | 69 | /* 70 | * AXI Channel W 71 | */ 72 | import "DPI-C" function void MemoryAXIPullChannelW ( 73 | input int portId, 74 | output byte ready 75 | ); 76 | 77 | function void SvMemoryAXIPullChannelW ( 78 | input int portId, 79 | output logic ready 80 | ); 81 | 82 | if (1) begin 83 | 84 | MemoryAXIPullChannelW ( 85 | portId, 86 | ready 87 | ); 88 | end 89 | 90 | endfunction 91 | 92 | import "DPI-C" function void MemoryAXIPushChannelW ( 93 | input int portId, 94 | input byte valid, 95 | input longint strb, 96 | input byte last, 97 | input longint data0, 98 | input longint data1, 99 | input longint data2, 100 | input longint data3 101 | ); 102 | 103 | function void SvMemoryAXIPushChannelW ( 104 | input int portId, 105 | input logic resetn, 106 | input logic valid, 107 | input logic [31:0] strb, 108 | input logic last, 109 | input logic [255:0] data 110 | ); 111 | 112 | guard_valid: assert (!resetn || !$isunknown(valid)) else $fatal("MemoryAXIPushChannelW: 'valid' is unknown"); 113 | 114 | guard_strb: assert (!resetn || !valid || !$isunknown(strb )) else $fatal("MemoryAXIPushChannelW: 'strb' is unknown"); 115 | guard_last: assert (!resetn || !valid || !$isunknown(last )) else $fatal("MemoryAXIPushChannelW: 'last' is unknown"); 116 | 117 | if (resetn) begin 118 | 119 | MemoryAXIPushChannelW ( 120 | portId, 121 | valid, 122 | strb, 123 | last, 124 | data[63:0], 125 | data[127:64], 126 | data[191:128], 127 | data[255:192] 128 | ); 129 | end 130 | 131 | endfunction 132 | 133 | 134 | /* 135 | * AXI Channel B 136 | */ 137 | import "DPI-C" function void MemoryAXIPullChannelB ( 138 | input int portId, 139 | output byte valid, 140 | output int id, 141 | output byte resp 142 | ); 143 | 144 | function void SvMemoryAXIPullChannelB ( 145 | input int portId, 146 | output logic valid, 147 | output logic [10:0] id, 148 | output logic [1:0] resp 149 | ); 150 | 151 | if (1) begin 152 | 153 | MemoryAXIPullChannelB ( 154 | portId, 155 | valid, 156 | id, 157 | resp 158 | ); 159 | end 160 | 161 | endfunction 162 | 163 | import "DPI-C" function void MemoryAXIPushChannelB ( 164 | input int portId, 165 | input byte ready 166 | ); 167 | 168 | function void SvMemoryAXIPushChannelB ( 169 | input int portId, 170 | input logic resetn, 171 | input logic ready 172 | ); 173 | 174 | guard_ready: assert (!resetn || !$isunknown(ready)) else $fatal("MemoryAXIPushChannelB: 'ready' is unknown"); 175 | 176 | if (resetn) begin 177 | 178 | MemoryAXIPushChannelB ( 179 | portId, 180 | ready 181 | ); 182 | end 183 | 184 | endfunction 185 | 186 | 187 | /* 188 | * AXI Channel AR 189 | */ 190 | import "DPI-C" function void MemoryAXIPullChannelAR ( 191 | input int portId, 192 | output byte ready 193 | ); 194 | 195 | function void SvMemoryAXIPullChannelAR ( 196 | input int portId, 197 | output logic ready 198 | ); 199 | 200 | if (1) begin 201 | 202 | MemoryAXIPullChannelAR ( 203 | portId, 204 | ready 205 | ); 206 | end 207 | 208 | endfunction 209 | 210 | import "DPI-C" function void MemoryAXIPushChannelAR ( 211 | input int portId, 212 | input byte valid, 213 | input int id, 214 | input longint addr, 215 | input byte burst, 216 | input byte size, 217 | input byte len 218 | ); 219 | 220 | function void SvMemoryAXIPushChannelAR ( 221 | input int portId, 222 | input logic resetn, 223 | input logic valid, 224 | input logic [10:0] id, 225 | input logic [47:0] addr, 226 | input logic [1:0] burst, 227 | input logic [2:0] size, 228 | input logic [7:0] len 229 | ); 230 | 231 | guard_valid: assert (!resetn || !$isunknown(valid)) else $fatal("MemoryAXIPushChannelAR: 'valid' is unknown"); 232 | 233 | guard_id: assert (!resetn || !valid || !$isunknown(id )) else $fatal("MemoryAXIPushChannelAR: 'id' is unknown"); 234 | guard_addr: assert (!resetn || !valid || !$isunknown(addr )) else $fatal("MemoryAXIPushChannelAR: 'addr' is unknown"); 235 | guard_burst: assert (!resetn || !valid || !$isunknown(burst )) else $fatal("MemoryAXIPushChannelAR: 'burst' is unknown"); 236 | guard_size: assert (!resetn || !valid || !$isunknown(size )) else $fatal("MemoryAXIPushChannelAR: 'size' is unknown"); 237 | guard_len: assert (!resetn || !valid || !$isunknown(len )) else $fatal("MemoryAXIPushChannelAR: 'len' is unknown"); 238 | 239 | if (resetn) begin 240 | 241 | MemoryAXIPushChannelAR ( 242 | portId, 243 | valid, 244 | id, 245 | addr, 246 | burst, 247 | size, 248 | len 249 | ); 250 | end 251 | 252 | endfunction 253 | 254 | 255 | /* 256 | * AXI Channel R 257 | */ 258 | import "DPI-C" function void MemoryAXIPullChannelR ( 259 | input int portId, 260 | output byte valid, 261 | output int id, 262 | output byte resp, 263 | output byte last, 264 | output longint data0, 265 | output longint data1, 266 | output longint data2, 267 | output longint data3 268 | ); 269 | 270 | function void SvMemoryAXIPullChannelR ( 271 | input int portId, 272 | output logic valid, 273 | output logic [10:0] id, 274 | output logic [1:0] resp, 275 | output logic last, 276 | output logic [255:0] data 277 | ); 278 | 279 | if (1) begin 280 | 281 | MemoryAXIPullChannelR ( 282 | portId, 283 | valid, 284 | id, 285 | resp, 286 | last, 287 | data[63:0], 288 | data[127:64], 289 | data[191:128], 290 | data[255:192] 291 | ); 292 | end 293 | 294 | endfunction 295 | 296 | import "DPI-C" function void MemoryAXIPushChannelR ( 297 | input int portId, 298 | input byte ready 299 | ); 300 | 301 | function void SvMemoryAXIPushChannelR ( 302 | input int portId, 303 | input logic resetn, 304 | input logic ready 305 | ); 306 | 307 | guard_ready: assert (!resetn || !$isunknown(ready)) else $fatal("MemoryAXIPushChannelR: 'ready' is unknown"); 308 | 309 | if (resetn) begin 310 | 311 | MemoryAXIPushChannelR ( 312 | portId, 313 | ready 314 | ); 315 | end 316 | 317 | endfunction 318 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | THREADS_BUILD ?= 1 2 | 3 | CMAKE_CXX_COMPILER := 4 | ifneq ($(origin CXX_COMPILER), undefined) 5 | CMAKE_CXX_COMPILER := -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) 6 | endif 7 | 8 | 9 | init: 10 | git submodule update --init --recursive 11 | $(MAKE) -C ./dut/CoupledL2 init 12 | $(MAKE) -C ./dut/OpenLLC init 13 | 14 | FORCE: 15 | 16 | 17 | tltest-prepare-all: 18 | cmake ./main -B ./main/build -DBUILD_DPI=ON -DBUILD_V3=ON $(CMAKE_CXX_COMPILER) 19 | 20 | tltest-prepare-dpi: 21 | cmake ./main -B ./main/build -DBUILD_DPI=ON -DBUILD_V3=OFF $(CMAKE_CXX_COMPILER) 22 | 23 | tltest-prepare-v3: 24 | cmake ./main -B ./main/build -DBUILD_V3=ON -DBUILD_DPI=OFF $(CMAKE_CXX_COMPILER) 25 | 26 | 27 | tltest-prepare-all-coupledL2: 28 | cmake ./main -B ./main/build -DBUILD_DPI=ON -DBUILD_V3=ON $(CMAKE_CXX_COMPILER) \ 29 | -DDUT_PATH="${PWD}/dut/CoupledL2" -DTLTEST_MEMORY=0 30 | 31 | tltest-prepare-dpi-coupledL2: 32 | cmake ./main -B ./main/build -DBUILD_DPI=ON -DBUILD_V3=OFF $(CMAKE_CXX_COMPILER) \ 33 | -DDUT_PATH="${PWD}/dut/CoupledL2" -DTLTEST_MEMORY=0 34 | 35 | tltest-prepare-v3-coupledL2: 36 | cmake ./main -B ./main/build -DBUILD_V3=ON -DBUILD_DPI=OFF $(CMAKE_CXX_COMPILER) \ 37 | -DDUT_PATH="${PWD}/dut/CoupledL2" -DTLTEST_MEMORY=0 38 | 39 | 40 | tltest-prepare-all-openLLC: 41 | cmake ./main -B ./main/build -DBUILD_DPI=ON -DBUILD_V3=ON $(CMAKE_CXX_COMPILER) \ 42 | -DDUT_PATH="${PWD}/dut/OpenLLC" 43 | 44 | tltest-prepare-dpi-openLLC: 45 | cmake ./main -B ./main/build -DBUILD_DPI=ON -DBUILD_V3=OFF $(CMAKE_CXX_COMPILER) \ 46 | -DDUT_PATH="${PWD}/dut/OpenLLC" 47 | 48 | tltest-prepare-v3-openLLC: 49 | cmake ./main -B ./main/build -DBUILD_V3=ON -DBUILD_DPI=OFF $(CMAKE_CXX_COMPILER) \ 50 | -DDUT_PATH="${PWD}/dut/OpenLLC" 51 | 52 | 53 | tltest-portgen: 54 | $(MAKE) -C ./main/build portgen -j$(THREADS_BUILD) -s --always-make 55 | 56 | tltest-clean: 57 | $(MAKE) -C ./main/build clean -s 58 | 59 | tltest-config-user: 60 | @test -d ./main/build || mkdir -p ./main/build 61 | @cat ./configs/user.tltest.ini 62 | @echo "" 63 | @cat ./configs/user.tltest.ini > ./main/build/tltest.ini 64 | @echo "" >> ./main/build/tltest.ini 65 | 66 | tltest-config-coupledL2-test-l2l3: tltest-config-user 67 | @cat ./configs/coupledL2-test-l2l3.tltest.ini 68 | @echo "" 69 | @cat ./configs/coupledL2-test-l2l3.tltest.ini >> ./main/build/tltest.ini 70 | @echo "tltest-config-postbuild: tltest-config-coupledL2-test-l2l3" > ./main/build/Makefile.config 71 | 72 | tltest-config-coupledL2-test-l2l3l2: tltest-config-user 73 | @cat ./configs/coupledL2-test-l2l3l2.tltest.ini 74 | @echo "" 75 | @cat ./configs/coupledL2-test-l2l3l2.tltest.ini >> ./main/build/tltest.ini 76 | @echo "tltest-config-postbuild: tltest-config-coupledL2-test-l2l3l2" > ./main/build/Makefile.config 77 | 78 | tltest-config-openLLC-test-l2l3: tltest-config-user 79 | @cat ./configs/openLLC-test-l2l3.tltest.ini 80 | @echo "" 81 | @cat ./configs/openLLC-test-l2l3.tltest.ini >> ./main/build/tltest.ini 82 | @echo "tltest-config-postbuild: tltest-config-openLLC-test-l2l3" > ./main/build/Makefile.config 83 | 84 | tltest-config-openLLC-test-l2l3l2: tltest-config-user 85 | @cat ./configs/openLLC-test-l2l3l2.tltest.ini 86 | @echo "" 87 | @cat ./configs/openLLC-test-l2l3l2.tltest.ini >> ./main/build/tltest.ini 88 | @echo "tltest-config-postbuild: tltest-config-openLLC-test-l2l3l2" > ./main/build/Makefile.config 89 | 90 | tltest-config-postbuild: 91 | 92 | tltest-build: 93 | $(MAKE) -C ./main/build -j$(THREADS_BUILD) -s 94 | $(MAKE) -C ./main/build portgen -j$(THREADS_BUILD) -s --always-make 95 | 96 | tltest-build-all-coupledL2: tltest-prepare-all-coupledL2 tltest-build 97 | 98 | tltest-build-dpi-coupledL2: tltest-prepare-dpi-coupledL2 tltest-build 99 | 100 | tltest-build-v3-coupledL2: tltest-prepare-v3-coupledL2 tltest-build 101 | 102 | tltest-build-all-openLLC: tltest-prepare-all-openLLC tltest-build 103 | 104 | tltest-build-dpi-openLLC: tltest-prepare-dpi-openLLC tltest-build 105 | 106 | tltest-build-v3-openLLC: tltest-prepare-v3-openLLC tltest-build 107 | 108 | 109 | coupledL2-compile: 110 | $(MAKE) -C ./dut/CoupledL2 compile 111 | 112 | coupledL2-verilog-test-top-l2l3: 113 | $(MAKE) -C ./dut/CoupledL2 test-top-l2l3 114 | 115 | coupledL2-verilog-test-top-l2l3l2: 116 | $(MAKE) -C ./dut/CoupledL2 test-top-l2l3l2 117 | 118 | coupledL2-verilog-clean: 119 | $(MAKE) -C ./dut/CoupledL2 clean 120 | 121 | openLLC-compile: 122 | $(MAKE) -C ./dut/OpenLLC compile 123 | 124 | openLLC-verilog-test-top-l2l3: 125 | $(MAKE) -C ./dut/OpenLLC test-top-l2l3 126 | 127 | openLLC-verilog-test-top-l2l3l2: 128 | $(MAKE) -C ./dut/OpenLLC test-top-l2l3l2 129 | 130 | openLLC-verilog-clean: 131 | $(MAKE) -C ./dut/OpenLLC clean 132 | 133 | 134 | VERILATOR := verilator 135 | VERILATOR_COMMON_ARGS_COUPLEDL2 := ./dut/CoupledL2/build/*.*v \ 136 | --Mdir ./verilated \ 137 | -O3 \ 138 | --trace-fst \ 139 | --top TestTop \ 140 | --build-jobs $(THREADS_BUILD) --verilate-jobs $(THREADS_BUILD) \ 141 | -DSIM_TOP_MODULE_NAME=TestTop \ 142 | -Wno-fatal 143 | VERILATOR_COMMON_ARGS_OPENLLC := ./dut/OpenLLC/build/*.*v \ 144 | --Mdir ./verilated \ 145 | -O3 \ 146 | --trace-fst \ 147 | --top TestTop \ 148 | --build-jobs $(THREADS_BUILD) --verilate-jobs $(THREADS_BUILD) \ 149 | -DSIM_TOP_MODULE_NAME=TestTop \ 150 | -Wno-fatal 151 | 152 | coupledL2-verilate-cc: 153 | rm -rf verilated 154 | mkdir verilated 155 | $(VERILATOR) $(VERILATOR_COMMON_ARGS_COUPLEDL2) --cc 156 | 157 | coupledL2-verilate-build: 158 | $(VERILATOR) $(VERILATOR_COMMON_ARGS_COUPLEDL2) --cc --exe --build -o tltest_v3lt \ 159 | libtltest_v3lt.a \ 160 | -LDFLAGS "-lsqlite3 -ldl" -CFLAGS "-rdynamic" 161 | 162 | coupledL2-verilate: 163 | rm -rf verilated 164 | mkdir verilated 165 | verilator --trace-fst --cc --build --lib-create vltdut --Mdir ./verilated ./dut/CoupledL2/build/*.*v -Wno-fatal \ 166 | --top TestTop --build-jobs $(THREADS_BUILD) --verilate-jobs $(THREADS_BUILD) -DSIM_TOP_MODULE_NAME=TestTop 167 | 168 | coupledL2-verilate-clean: 169 | rm -rf verilated 170 | 171 | openLLC-verilate-cc: 172 | rm -rf verilated 173 | mkdir verilated 174 | $(VERILATOR) $(VERILATOR_COMMON_ARGS_OPENLLC) --cc 175 | 176 | openLLC-verilate-build: 177 | $(VERILATOR) $(VERILATOR_COMMON_ARGS_OPENLLC) --cc --exe --build -o tltest_v3lt \ 178 | lbtltest_v3lt.a \ 179 | -LDFLAGS "-lsqlite3 -ldl" -CFLAGS "-rdynamic" 180 | 181 | openLLC-verilate: 182 | rm -rf verilated 183 | mkdir verilated 184 | verilator --trace-fst --cc --build --lib-create vltdut --Mdir ./verilated ./dut/OpenLLC/build/*.*v -Wno-fatal \ 185 | --top TestTop --build-jobs $(THREADS_BUILD) --verilate-jobs $(THREADS_BUILD) -DSIM_TOP_MODULE_NAME=TestTop 186 | 187 | openLLC-verilate-clean: 188 | rm -rf verilated 189 | 190 | 191 | coupledL2-test-l2l3: coupledL2-compile coupledL2-verilog-test-top-l2l3 coupledL2-verilate \ 192 | tltest-config-coupledL2-test-l2l3 tltest-build-all-coupledL2 193 | 194 | coupledL2-test-l2l3-v3: coupledL2-compile coupledL2-verilog-test-top-l2l3 coupledL2-verilate \ 195 | tltest-config-coupledL2-test-l2l3 tltest-build-v3-coupledL2 196 | 197 | coupledL2-test-l2l3-dpi: coupledL2-compile coupledL2-verilog-test-top-l2l3 coupledL2-verilate \ 198 | tltest-config-coupledL2-test-l2l3 tltest-build-dpi-coupledL2 199 | 200 | 201 | coupledL2-test-l2l3l2: coupledL2-compile coupledL2-verilog-test-top-l2l3l2 coupledL2-verilate \ 202 | tltest-config-coupledL2-test-l2l3l2 tltest-build-all-coupledL2 203 | 204 | coupledL2-test-l2l3l2-v3: coupledL2-compile coupledL2-verilog-test-top-l2l3l2 coupledL2-verilate \ 205 | tltest-config-coupledL2-test-l2l3l2 tltest-build-v3-coupledL2 206 | 207 | coupledL2-test-l2l3l2-dpi: coupledL2-compile coupledL2-verilog-test-top-l2l3l2 coupledL2-verilate \ 208 | tltest-config-coupledL2-test-l2l3l2 tltest-build-dpi-coupledL2 209 | 210 | 211 | openLLC-test-l2l3: openLLC-compile openLLC-verilog-test-top-l2l3 openLLC-verilate \ 212 | tltest-config-openLLC-test-l2l3 tltest-build-all-openLLC 213 | 214 | openLLC-test-l2l3-v3: openLLC-compile openLLC-verilog-test-top-l2l3 openLLC-verilate \ 215 | tltest-config-openLLC-test-l2l3 tltest-build-v3-openLLC 216 | 217 | openLLC-test-l2l3-dpi: openLLC-compile openLLC-verilog-test-top-l2l3 openLLC-verilate \ 218 | tltest-config-openLLC-test-l2l3 tltest-build-dpi-openLLC 219 | 220 | 221 | openLLC-test-l2l3l2: openLLC-compile openLLC-verilog-test-top-l2l3l2 openLLC-verilate \ 222 | tltest-config-openLLC-test-l2l3l2 tltest-build-all-openLLC 223 | 224 | openLLC-test-l2l3l2-v3: openLLC-compile openLLC-verilog-test-top-l2l3l2 openLLC-verilate \ 225 | tltest-config-openLLC-test-l2l3l2 tltest-build-v3-openLLC 226 | 227 | openLLC-test-l2l3l2-dpi: openLLC-compile openLLC-verilog-test-top-l2l3l2 openLLC-verilate \ 228 | tltest-config-openLLC-test-l2l3l2 tltest-build-dpi-openLLC 229 | 230 | 231 | -include ./main/build/Makefile.config 232 | 233 | run: FORCE tltest-config-postbuild 234 | @rm -rf ./run 235 | @mkdir ./run 236 | @cp ./main/build/tltest_v3lt ./run/ 237 | @cp ./main/build/tltest_portgen.so ./run/ 238 | @cp ./main/build/tltest.ini ./run/ 239 | @bash ./scripts/run_v3lt.sh 240 | 241 | run_coupledL2-test-l2l3: FORCE tltest-config-coupledL2-test-l2l3 242 | @rm -rf ./run 243 | @mkdir ./run 244 | @cp ./main/build/tltest_v3lt ./run/ 245 | @cp ./main/build/tltest_portgen.so ./run/ 246 | @cp ./main/build/tltest.ini ./run/ 247 | @bash ./scripts/run_v3lt.sh 248 | 249 | run_coupledL2-test-l2l3l2: FORCE tltest-config-coupledL2-test-l2l3l2 250 | @rm -rf ./run 251 | @mkdir ./run 252 | @cp ./main/build/tltest_v3lt ./run/ 253 | @cp ./main/build/tltest_portgen.so ./run/ 254 | @cp ./main/build/tltest.ini ./run/ 255 | @bash ./scripts/run_v3lt.sh 256 | 257 | run_openLLC-test-l2l3: FORCE tltest-config-openLLC-test-l2l3 258 | @rm -rf ./run 259 | @mkdir ./run 260 | @cp ./main/build/tltest_v3lt ./run/ 261 | @cp ./main/build/tltest_portgen.so ./run/ 262 | @cp ./main/build/tltest.ini ./run/ 263 | @bash ./scripts/run_v3lt.sh 264 | 265 | run_openLLC-test-l2l3l2: FORCE tltest-config-openLLC-test-l2l3l2 266 | @rm -rf ./run 267 | @mkdir ./run 268 | @cp ./main/build/tltest_v3lt ./run/ 269 | @cp ./main/build/tltest_portgen.so ./run/ 270 | @cp ./main/build/tltest.ini ./run/ 271 | @bash ./scripts/run_v3lt.sh 272 | 273 | 274 | run-with-portgen: FORCE tltest-config-postbuild tltest-portgen 275 | @rm -rf ./run 276 | @mkdir ./run 277 | @cp ./main/build/tltest_v3lt ./run/ 278 | @cp ./main/build/tltest_portgen.so ./run/ 279 | @cp ./main/build/tltest.ini ./run/ 280 | @bash ./scripts/run_v3lt.sh 281 | 282 | 283 | clean: coupledL2-verilate-clean coupledL2-verilog-clean openLLC-verilate-clean openLLC-verilog-clean 284 | rm -rf ./main/build 285 | mkdir ./main/build 286 | -------------------------------------------------------------------------------- /main/CHIron/clogdpi_b.cpp: -------------------------------------------------------------------------------- 1 | #include "clogdpi_b.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "../Utils/concurrentqueue.hpp" 13 | 14 | #include "clog_b.hpp" 15 | 16 | 17 | #define CLOG_B_RECORD_BLOCK_LIMIT 1048576 18 | #define CLOG_B_RECORD_BLOCK_COMPRESSION 1 19 | 20 | 21 | /* 22 | * CLog.B operation handle and structures. 23 | */ 24 | struct CLogBHandle { 25 | std::ofstream* ofs; 26 | std::string ofpath; 27 | moodycamel::ConcurrentQueue* 28 | queue; 29 | std::atomic_bool stop; 30 | std::thread worker; 31 | 32 | std::vector 33 | topos; 34 | 35 | CLog::CLogB::TagCHIRecords* records; 36 | uint64_t lastRecordTime; 37 | }; 38 | 39 | std::unordered_map SHARED_HANDLES; 40 | 41 | 42 | /* 43 | * CLog.B file handle operations implementations. 44 | */ 45 | 46 | extern "C" void* CLogB_OpenFile( 47 | const char* path, 48 | uint32_t* status) 49 | { 50 | CLogBHandle* handle = new CLogBHandle; 51 | 52 | std::ofstream* ofs = 53 | new std::ofstream(path, std::ios_base::out | std::ios_base::trunc); 54 | 55 | if (!*ofs) 56 | { 57 | *status = 1; 58 | std::cout << "[CLog.B] unable to open file: " << path << std::endl; 59 | return NULL; 60 | } 61 | else 62 | { 63 | std::cout << "[CLog.B] opened file: " << path << std::endl; 64 | } 65 | 66 | *status = 0; 67 | 68 | handle->ofs = ofs; 69 | handle->ofpath = path; 70 | handle->queue = new moodycamel::ConcurrentQueue; 71 | handle->stop = false; 72 | 73 | std::atomic_thread_fence(std::memory_order_seq_cst); 74 | 75 | handle->worker = std::thread([=]() -> void { 76 | CLog::CLogB::TagCHIRecords* records; 77 | while (1) 78 | { 79 | if (handle->queue->try_dequeue(records)) 80 | { 81 | CLog::CLogB::Writer().Next(*handle->ofs, records); 82 | delete records; 83 | } 84 | else if (handle->stop) 85 | return; 86 | } 87 | }); 88 | 89 | handle->records = nullptr; 90 | 91 | return handle; 92 | } 93 | 94 | extern "C" void CLogB_CloseFile( 95 | void* handle) 96 | { 97 | CLogBHandle* chandle = (CLogBHandle*) handle; 98 | 99 | if (chandle->records) 100 | { 101 | while (!chandle->queue->try_enqueue(chandle->records)); 102 | chandle->records = nullptr; 103 | } 104 | 105 | while (chandle->queue->size_approx()); 106 | 107 | chandle->stop = true; 108 | 109 | chandle->worker.join(); 110 | 111 | chandle->ofs->close(); 112 | 113 | std::cout << "[CLog.B] closed file: " << chandle->ofpath << std::endl; 114 | 115 | delete chandle->ofs; 116 | delete chandle->queue; 117 | if (chandle->records) 118 | delete chandle->records; 119 | delete chandle; 120 | } 121 | 122 | extern "C" void CLogB_ShareHandle( 123 | const char* id, 124 | void* handle) 125 | { 126 | SHARED_HANDLES[std::string(id)] = (CLogBHandle*) handle; 127 | } 128 | 129 | extern "C" int CLogB_UnshareHandle( 130 | const char* id) 131 | { 132 | return SHARED_HANDLES.erase(std::string(id)); 133 | } 134 | 135 | extern "C" void* CLogB_GetSharedHandle( 136 | const char* id) 137 | { 138 | auto iter = SHARED_HANDLES.find(std::string(id)); 139 | 140 | if (iter == SHARED_HANDLES.end()) 141 | return nullptr; 142 | 143 | return iter->second; 144 | } 145 | 146 | 147 | /* 148 | * CLog.B parameters write operations implementations. 149 | */ 150 | extern "C" void CLogB_WriteParameters( 151 | void* handle, 152 | uint32_t issue, 153 | uint32_t nodeidWidth, 154 | uint32_t addrWidth, 155 | uint32_t reqRsvdcWidth, 156 | uint32_t datRsvdcWidth, 157 | uint32_t dataWidth, 158 | uint32_t dataCheckPresent, 159 | uint32_t poisonPresent, 160 | uint32_t mpamPresent) 161 | { 162 | // 163 | CLog::Parameters params; 164 | params.SetIssue(CLog::Issue(issue)); 165 | params.SetNodeIdWidth(nodeidWidth); 166 | params.SetReqAddrWidth(addrWidth); 167 | params.SetReqRSVDCWidth(reqRsvdcWidth); 168 | params.SetDatRSVDCWidth(datRsvdcWidth); 169 | params.SetDataWidth(dataWidth); 170 | params.SetDataCheckPresent(dataCheckPresent); 171 | params.SetPoisonPresent(poisonPresent); 172 | params.SetMPAMPresent(mpamPresent); 173 | 174 | // 175 | CLogBHandle* chandle = (CLogBHandle*) handle; 176 | 177 | CLog::CLogB::TagCHIParameters tag; 178 | tag.parameters = params; 179 | 180 | CLog::CLogB::Writer().Next(*chandle->ofs, &tag); 181 | } 182 | 183 | extern "C" void CLogB_SharedWriteParameters( 184 | const char* id, 185 | uint32_t issue, 186 | uint32_t nodeIdWidth, 187 | uint32_t addrWidth, 188 | uint32_t reqRsvdcWidth, 189 | uint32_t datRsvdcWidth, 190 | uint32_t dataWidth, 191 | uint32_t dataCheckPresent, 192 | uint32_t poisonPresent, 193 | uint32_t mpamPresent) 194 | { 195 | auto iter = SHARED_HANDLES.find(std::string(id)); 196 | 197 | if (iter == SHARED_HANDLES.end()) 198 | return; 199 | 200 | CLogB_WriteParameters( 201 | iter->second, 202 | issue, 203 | nodeIdWidth, 204 | addrWidth, 205 | reqRsvdcWidth, 206 | datRsvdcWidth, 207 | dataWidth, 208 | dataCheckPresent, 209 | poisonPresent, 210 | mpamPresent 211 | ); 212 | } 213 | 214 | 215 | /* 216 | * CLog.B topologies write operations implementations. 217 | */ 218 | extern "C" void CLogB_WriteTopo( 219 | void* handle, 220 | uint32_t nodeId, 221 | uint32_t nodeType) 222 | { 223 | CLogBHandle* chandle = (CLogBHandle*) handle; 224 | 225 | chandle->topos.push_back(CLog::CLogB::TagCHITopologies::Node { 226 | .type = CLog::NodeType(nodeType), 227 | .id = uint16_t(nodeId) 228 | }); 229 | } 230 | 231 | extern "C" void CLogB_WriteTopoEnd( 232 | void* handle) 233 | { 234 | CLogBHandle* chandle = (CLogBHandle*) handle; 235 | 236 | CLog::CLogB::TagCHITopologies tag; 237 | tag.nodes = chandle->topos; 238 | 239 | CLog::CLogB::Writer().Next(*chandle->ofs, &tag); 240 | } 241 | 242 | extern "C" void CLogB_SharedWriteTopo( 243 | const char* id, 244 | uint32_t nodeId, 245 | uint32_t nodeType) 246 | { 247 | auto iter = SHARED_HANDLES.find(std::string(id)); 248 | 249 | if (iter == SHARED_HANDLES.end()) 250 | return; 251 | 252 | CLogB_WriteTopo( 253 | iter->second, 254 | nodeId, 255 | nodeType 256 | ); 257 | } 258 | 259 | extern "C" void CLogB_SharedWriteTopoEnd( 260 | const char* id) 261 | { 262 | auto iter = SHARED_HANDLES.find(std::string(id)); 263 | 264 | if (iter == SHARED_HANDLES.end()) 265 | return; 266 | 267 | CLogB_WriteTopoEnd( 268 | iter->second 269 | ); 270 | } 271 | 272 | 273 | /* 274 | * CLog.B log record write operations. 275 | */ 276 | extern "C" void CLogB_WriteRecord( 277 | void* handle, 278 | uint64_t time, 279 | uint32_t nodeId, 280 | uint32_t channel, 281 | const uint32_t* flit, 282 | uint32_t flitLength) 283 | { 284 | // 285 | size_t flitLength8 = (flitLength + 7) >> 3; 286 | 287 | // 288 | CLogBHandle* chandle = (CLogBHandle*) handle; 289 | 290 | uint64_t timeShift = chandle->records ? (time - ( 291 | chandle->records->records.empty() ? chandle->records->head.timeBase 292 | : chandle->lastRecordTime 293 | )) : 0; 294 | 295 | // allocate or split block 296 | if ((!chandle->records) // allocate 297 | || (chandle->records->records.size() >= CLOG_B_RECORD_BLOCK_LIMIT) // split on block limit 298 | || (timeShift >= uint64_t(UINT32_MAX))) // split on time limit 299 | { 300 | if (chandle->records) 301 | while(!chandle->queue->try_enqueue(chandle->records)); // dispatch block to worker thread 302 | 303 | chandle->records = new CLog::CLogB::TagCHIRecords; 304 | chandle->records->head.timeBase = time; 305 | 306 | #if CLOG_B_RECORD_BLOCK_COMPRESSION 307 | chandle->records->head.compressed = 1; 308 | #else 309 | chandle->records->head.compressed = 0; 310 | #endif 311 | 312 | timeShift = 0; 313 | } 314 | 315 | // append record 316 | size_t flitLength32 = (flitLength8 + 3) >> 2; 317 | std::shared_ptr flitData(new uint32_t[flitLength32]); 318 | 319 | std::memcpy(flitData.get(), flit, flitLength8); 320 | 321 | chandle->records->records.push_back({ 322 | .timeShift = uint32_t(timeShift), 323 | .nodeId = uint16_t(nodeId), 324 | .channel = CLog::Channel(channel), 325 | .flitLength = uint8_t(flitLength8), 326 | .flit = flitData 327 | }); 328 | 329 | chandle->lastRecordTime = time; 330 | } 331 | 332 | extern "C" void CLogB_SharedWriteRecord( 333 | const char* id, 334 | uint64_t time, 335 | uint32_t nodeId, 336 | uint32_t channel, 337 | const uint32_t* flit, 338 | uint32_t flitLength) 339 | { 340 | auto iter = SHARED_HANDLES.find(std::string(id)); 341 | 342 | if (iter == SHARED_HANDLES.end()) 343 | return; 344 | 345 | CLogB_WriteRecord( 346 | iter->second, 347 | time, 348 | nodeId, 349 | channel, 350 | flit, 351 | flitLength 352 | ); 353 | } 354 | -------------------------------------------------------------------------------- /main/Utils/Common.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Kaifan Wang on 2021/10/27. 3 | // 4 | // Modified by Haonan Ding on 2024/04/11 5 | // 6 | 7 | #ifndef TLC_TEST_COMMON_H 8 | #define TLC_TEST_COMMON_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "../Base/TLGlobal.hpp" 20 | #include "../Base/TLLocal.hpp" 21 | 22 | #include "TLDefault.h" 23 | #include "gravity_utility.hpp" 24 | #include "assert.hpp" 25 | 26 | 27 | enum { 28 | DATASIZE = 64, // Cache line is 64B 29 | BEATSIZE = 32, 30 | BEATSIZE_MEMORY = 32, 31 | DATASIZE_MMIO = 8, 32 | NR_SOURCEID = 16, 33 | NR_SOURCEID_MMIO = 16, 34 | TIMEOUT_INTERVAL = 50000, 35 | }; 36 | 37 | // 38 | template 39 | using tldata_t = uint8_t[N]; 40 | 41 | template 42 | class wrapped_tldata_t { 43 | /* NOTICE: It's disappointing that GCC-11 still doen't obtain full C++20 library support. 44 | * And C++20 support is still not that general on today's machine. :( 45 | * So we need this wrapper to pseudoly implement C++20 shared_ptr feature. 46 | */ 47 | public: 48 | tldata_t data; 49 | 50 | public: 51 | operator uint8_t*() noexcept { return data; } 52 | operator const uint8_t*() const noexcept { return data; }; 53 | operator tldata_t&() noexcept { return data; } 54 | operator const tldata_t&() const noexcept { return data; } 55 | uint8_t& operator[](size_t index) noexcept { return data[index]; }; 56 | uint8_t operator[](size_t index) const noexcept { return data[index]; }; 57 | }; 58 | 59 | template 60 | using shared_tldata_t = std::shared_ptr>; 61 | 62 | template 63 | inline shared_tldata_t make_shared_tldata() noexcept 64 | { 65 | return std::make_shared>(); 66 | } 67 | 68 | template 69 | inline shared_tldata_t make_shared_tldata_zero() noexcept 70 | { 71 | auto data = make_shared_tldata(); 72 | std::memset(data->data, 0, N); 73 | return data; 74 | } 75 | 76 | // 77 | 78 | typedef uint64_t paddr_t; 79 | 80 | class MemoryBackend { 81 | public: 82 | virtual uint8_t& access(paddr_t addr) noexcept = 0; 83 | virtual uint8_t access(paddr_t addr) const noexcept = 0; 84 | 85 | virtual bool accessible(paddr_t addr) const noexcept = 0; 86 | }; 87 | 88 | 89 | inline std::string GetDeviceName(const TLLocalContext* ctx) 90 | { 91 | /* Cache the result of GetDeviceName for 64 cores (with 1 TL-C and 2 TL-UL) */ 92 | static constexpr int DEVICE_NAME_CACHE_SIZE = 192; 93 | static std::string cached[DEVICE_NAME_CACHE_SIZE]; 94 | 95 | if (!ctx->mainSys()) 96 | return Gravity::StringAppender("#", ctx->sysId()).ToString(); 97 | 98 | if (ctx->sysId() < DEVICE_NAME_CACHE_SIZE) 99 | if (!cached[ctx->sysId()].empty()) 100 | return cached[ctx->sysId()]; 101 | 102 | Gravity::StringAppender strapp; 103 | 104 | int64_t coreId = int64_t(ctx->sysId() / (ctx->config().masterCountPerCoreTLC + ctx->config().masterCountPerCoreTLUL)); 105 | int64_t tlcId = int64_t(ctx->sysId() % (ctx->config().masterCountPerCoreTLC + ctx->config().masterCountPerCoreTLUL)); 106 | int64_t tlulId = int64_t(ctx->sysId() % (ctx->config().masterCountPerCoreTLC + ctx->config().masterCountPerCoreTLUL)) - ctx->config().masterCountPerCoreTLC; 107 | 108 | strapp.Append("#", ctx->sysId(), " L2[", coreId, "]."); 109 | 110 | if (tlulId < 0) 111 | strapp.Append("C[", tlcId, "]"); 112 | else 113 | strapp.Append("UL[", tlulId, "]"); 114 | 115 | if (ctx->sysId() < DEVICE_NAME_CACHE_SIZE) 116 | cached[ctx->sysId()] = strapp.ToString(); 117 | 118 | return strapp.ToString(); 119 | } 120 | 121 | template 122 | inline std::string GetBase1024B(_TIntegral val, int width = 6, const char** baseString = nullptr) 123 | { 124 | static const char* BASE[] = {"B ", "KB", "MB", "GB", "TB"}; 125 | 126 | Gravity::StringAppender str; 127 | 128 | int i; 129 | for (i = 0; i < 4; i++) 130 | { 131 | if (val / 1024 >= 1) 132 | { 133 | val /= 1024; 134 | continue; 135 | } 136 | else 137 | break; 138 | } 139 | 140 | str.Right().NextWidth(width).Precision(3).Append(val).Append(baseString ? baseString[i] : BASE[i]); 141 | 142 | return str.ToString(); 143 | } 144 | 145 | 146 | #define Log(ctx, str_app) \ 147 | do { \ 148 | if (glbl.cfg.verbose) { \ 149 | const TLLocalContext* __tlc_assert__ctx = ctx; /* suppress the warning: -Wnonnull-compare */ \ 150 | if (__tlc_assert__ctx) \ 151 | std::cout << "[" << ctx->cycle() << "] [tl-test-new-INFO] " << GetDeviceName(ctx) << " "; \ 152 | std::cout << (Gravity::StringAppender().str_app.ToString()); \ 153 | fflush(stdout); \ 154 | fflush(stderr); \ 155 | } \ 156 | } while(0) 157 | 158 | #define LogEx(action) \ 159 | do { \ 160 | if (glbl.cfg.verbose) { \ 161 | action; \ 162 | } \ 163 | } while(0) 164 | 165 | 166 | #define LogInfo(time, str_app) \ 167 | do { \ 168 | if (glbl.cfg.verbose) { \ 169 | std::cout << "[" << time << "] [tl-test-new-INFO] "; \ 170 | std::cout << (Gravity::StringAppender().str_app.ToString()); \ 171 | fflush(stdout); \ 172 | fflush(stderr); \ 173 | } \ 174 | } while(0) 175 | 176 | #define LogWarn(time, str_app) \ 177 | do { \ 178 | { \ 179 | std::cout << "[" << time << "] [tl-test-new-WARN] "; \ 180 | std::cout << (Gravity::StringAppender().str_app.ToString()); \ 181 | fflush(stdout); \ 182 | fflush(stderr); \ 183 | } \ 184 | } while(0) 185 | 186 | #define LogFinal(time, str_app) \ 187 | do { \ 188 | { \ 189 | std::cout << "[" << time << "] [tl-test-new-FINAL] "; \ 190 | std::cout << (Gravity::StringAppender().str_app.ToString()); \ 191 | fflush(stdout); \ 192 | fflush(stderr); \ 193 | } \ 194 | } while(0) 195 | 196 | #define LogError(time, str_app) \ 197 | do { \ 198 | { \ 199 | std::cout << "[" << time << "]\033[31m [tl-test-new-ERROR] \033[1;31m"; \ 200 | std::cout << (Gravity::StringAppender().str_app.Append("\033[0m").ToString()); \ 201 | fflush(stdout); \ 202 | fflush(stderr); \ 203 | } \ 204 | } while(0) 205 | 206 | #define LogFatal(time, str_app) \ 207 | do { \ 208 | { \ 209 | std::cout << "[" << time << "]\033[31m [tl-test-new-FATAL] \033[0m"; \ 210 | std::cout << (Gravity::StringAppender().str_app.ToString()); \ 211 | fflush(stdout); \ 212 | fflush(stderr); \ 213 | } \ 214 | } while(0) 215 | 216 | 217 | #define tlc_assert(cond, ctx, info) \ 218 | do { \ 219 | if (!(cond)) { \ 220 | const TLLocalContext* __tlc_assert__ctx = ctx; /* suppress the warning: -Wnonnull-compare */ \ 221 | if (__tlc_assert__ctx) \ 222 | { \ 223 | LogError(ctx->cycle(), Append("[tlc_assert failure at ", __PRETTY_FUNCTION__, ":", __LINE__, "]").EndLine()); \ 224 | LogError(ctx->cycle(), Append("[tlc_assert failure from system #", ctx->sysId(), "]").EndLine()); \ 225 | } \ 226 | LogError(ctx->cycle(), Append("info: ", info).EndLine()); \ 227 | LogError(ctx->cycle(), Append("\033[0m", "stack backtrace: ").EndLine()); \ 228 | { \ 229 | size_t bktr_i, bktr_size; \ 230 | void* array[1024]; \ 231 | bktr_size = backtrace(array, 1024); \ 232 | char** bktr_strings = backtrace_symbols(array, bktr_size); \ 233 | for (bktr_i = 0; bktr_i < bktr_size; bktr_i++) \ 234 | { \ 235 | size_t pos; \ 236 | std::string bktr_str(bktr_strings[bktr_i]); \ 237 | if ((pos = bktr_str.find_last_of('/')) != std::string::npos) \ 238 | bktr_str = bktr_str.substr(pos); \ 239 | if ((pos = bktr_str.find_last_of('\\')) != std::string::npos) \ 240 | bktr_str = bktr_str.substr(pos); \ 241 | LogError(ctx->cycle(), Append("\033[0m", "#", bktr_i, " ", bktr_str).EndLine()); \ 242 | } \ 243 | free(bktr_strings); \ 244 | } \ 245 | fflush(stdout); \ 246 | fflush(stderr); \ 247 | TLAssertFailureEvent assert_event(__PRETTY_FUNCTION__, info); \ 248 | assert_event.Fire(); \ 249 | throw TLAssertFailureException(assert_event); \ 250 | assert(false); \ 251 | } \ 252 | } while (0) 253 | 254 | #define tlsys_assert(cond, info) \ 255 | do { \ 256 | if (!(cond)) { \ 257 | LogError("tlsys_assert", Append("tlsys_assert() failure at ", __PRETTY_FUNCTION__, ":", __LINE__, " ").EndLine()); \ 258 | LogError("tlsys_assert", Append(info).EndLine()); \ 259 | fflush(stdout); \ 260 | fflush(stderr); \ 261 | TLAssertFailureEvent assert_event(__PRETTY_FUNCTION__, info); \ 262 | assert_event.Fire(); \ 263 | throw TLAssertFailureException(assert_event); \ 264 | assert(false); \ 265 | } \ 266 | } while (0) 267 | 268 | 269 | #define Debug(ctx, str_app) \ 270 | do { \ 271 | if (glbl.cfg.verbose) { \ 272 | const TLLocalContext* __tlc_assert__ctx = ctx; /* suppress the warning: -Wnonnull-compare */ \ 273 | if (__tlc_assert__ctx) \ 274 | std::cout << "[" << ctx->cycle() << "] [tl-test-new-DEBUG] #" << ctx->sysId() << " "; \ 275 | std::cout << (Gravity::StringAppender().str_app.ToString()); \ 276 | fflush(stdout); \ 277 | fflush(stderr); \ 278 | } \ 279 | } while(0) 280 | 281 | #define DebugEx(action) \ 282 | do { \ 283 | if (glbl.cfg.verbose) { \ 284 | action; \ 285 | } \ 286 | } while(0) 287 | 288 | 289 | #define Dump(str_app) \ 290 | do { \ 291 | if (glbl.cfg.verbose) { \ 292 | std::cout << (Gravity::StringAppender().str_app.ToString()); \ 293 | fflush(stdout); \ 294 | fflush(stderr); \ 295 | } \ 296 | } while(0) 297 | 298 | #define DumpEx(action) \ 299 | do { \ 300 | if (glbl.cfg.verbose) { \ 301 | action; \ 302 | } \ 303 | } while(0) 304 | 305 | /* 306 | #define Log(...) \ 307 | do {} while(0) 308 | 309 | #define Dump(...) \ 310 | do {} while(0) 311 | */ 312 | 313 | #endif //TLC_TEST_COMMON_H 314 | -------------------------------------------------------------------------------- /main/PortGen/portgen_dynamic.cpp: -------------------------------------------------------------------------------- 1 | #include "portgen_dynamic.hpp" 2 | 3 | #include "portgen_static.hpp" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | 14 | #ifndef CXX_COMPILER 15 | # define CXX_COMPILER "g++" 16 | #endif 17 | 18 | 19 | namespace V3::PortGen { 20 | 21 | // 22 | typedef void (*LoadedPortGen)(VTestTop* verilated, TLSequencer* tltest); 23 | typedef uint64_t (*LoadedPortInfo)(); 24 | 25 | static LoadedPortInfo loadedGetCoreCount; 26 | static LoadedPortInfo loadedGetULPortCountPerCore; 27 | 28 | static LoadedPortGen loadedPushChannelA; 29 | static LoadedPortGen loadedPullChannelA; 30 | static LoadedPortGen loadedPushChannelB; 31 | static LoadedPortGen loadedPullChannelB; 32 | static LoadedPortGen loadedPushChannelC; 33 | static LoadedPortGen loadedPullChannelC; 34 | static LoadedPortGen loadedPushChannelD; 35 | static LoadedPortGen loadedPullChannelD; 36 | static LoadedPortGen loadedPushChannelE; 37 | static LoadedPortGen loadedPullChannelE; 38 | 39 | void LoadDynamic(std::vector includePaths, int coreCount, int tlULPerCore) 40 | { 41 | // 42 | Gravity::StringAppender cpp_file_name("/tmp/tltest_portgen"); 43 | 44 | auto time = std::chrono::system_clock::now().time_since_epoch(); 45 | auto time_ns = std::chrono::duration_cast(time); 46 | 47 | cpp_file_name.Append("-").Append(time_ns.count()); 48 | 49 | // 50 | std::ofstream fout(cpp_file_name.Append(".cpp").ToString()); 51 | 52 | if (!fout.is_open()) 53 | { 54 | tlsys_assert(false, 55 | Gravity::StringAppender("Failed to create temporary file for TileLink PortGen: ") 56 | .Append(cpp_file_name.ToString()) 57 | .EndLine() 58 | .ToString()); 59 | 60 | return; // 61 | } 62 | 63 | fout << Generate(coreCount, tlULPerCore); 64 | fout.flush(); 65 | fout.close(); 66 | 67 | // 68 | Gravity::StringAppender cc_command; 69 | cc_command 70 | .Append(CXX_COMPILER, " ") 71 | .Append("-fPIC ") 72 | .Append("-shared ") 73 | .Append(cpp_file_name.ToString(), " ") 74 | .Append("-o ", cpp_file_name.Append(".so").ToString(), " "); 75 | 76 | for (auto iter = includePaths.begin(); iter != includePaths.end(); iter++) 77 | cc_command.Append("-I\"", *iter, "\" "); 78 | 79 | LogInfo("PortGen", Append("CXX ", cc_command.ToString()).EndLine()); 80 | 81 | int cc = system(cc_command.ToString().c_str()); 82 | 83 | if (WEXITSTATUS(cc) != EXIT_SUCCESS) 84 | { 85 | tlsys_assert(false, 86 | Gravity::StringAppender("Failed to compile TileLink PortGen: ") 87 | .Append(cpp_file_name.ToString()) 88 | .EndLine() 89 | .ToString()); 90 | 91 | return; // 92 | } 93 | 94 | // 95 | void* dlib = dlopen(cpp_file_name.ToString().c_str(), RTLD_NOW); 96 | if (!dlib) 97 | { 98 | tlsys_assert(false, 99 | Gravity::StringAppender("Failed to load dynamic TileLink PortGen: ") 100 | .Append(cpp_file_name.ToString()) 101 | .Append(": ") 102 | .Append(dlerror()) 103 | .EndLine() 104 | .ToString()); 105 | 106 | return; // 107 | } 108 | 109 | // 110 | # define LOAD_PORTGEN_SYM(type, target, name) \ 111 | { \ 112 | void* sym = dlsym(dlib, name); \ 113 | const char* dlsym_error = dlerror(); \ 114 | if (dlsym_error != NULL) \ 115 | { \ 116 | tlsys_assert(false, \ 117 | Gravity::StringAppender("Failed to load dynamic TileLink PortGen: ") \ 118 | .Append("symbol=", name) \ 119 | .EndLine() \ 120 | .ToString()); \ 121 | return; \ 122 | } \ 123 | target = reinterpret_cast(sym); \ 124 | } 125 | 126 | LOAD_PORTGEN_SYM(LoadedPortInfo, loadedGetCoreCount, "GetCoreCount"); 127 | LOAD_PORTGEN_SYM(LoadedPortInfo, loadedGetULPortCountPerCore, "GetULPortCountPerCore"); 128 | 129 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelA, "PushChannelA"); 130 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelA, "PullChannelA"); 131 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelB, "PushChannelB"); 132 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelB, "PullChannelB"); 133 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelC, "PushChannelC"); 134 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelC, "PullChannelC"); 135 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelD, "PushChannelD"); 136 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelD, "PullChannelD"); 137 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelE, "PushChannelE"); 138 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelE, "PullChannelE"); 139 | 140 | # undef LOAD_PORTGEN_SYM 141 | 142 | // 143 | LogInfo("PortGen", 144 | Append("Dynamic TileLink PortGen module loaded: ", cpp_file_name.ToString()).EndLine()); 145 | } 146 | 147 | void LoadStatic() 148 | { 149 | static constexpr char dlname[] = "tltest_portgen.so"; 150 | 151 | // 152 | std::string abs_dlname = Gravity::StringAppender() 153 | .Append(std::filesystem::current_path().generic_string(), "/") 154 | .Append(dlname) 155 | .ToString(); 156 | 157 | // 158 | void* dlib = dlopen(abs_dlname.c_str(), RTLD_NOW); 159 | if (!dlib) 160 | { 161 | tlsys_assert(false, 162 | Gravity::StringAppender("Failed to load dynamic TileLink PortGen: ") 163 | .Append(abs_dlname) 164 | .Append(": ") 165 | .Append(dlerror()) 166 | .EndLine() 167 | .ToString()); 168 | 169 | return; // 170 | } 171 | 172 | // 173 | # define LOAD_PORTGEN_SYM(type, target, name) \ 174 | { \ 175 | void* sym = dlsym(dlib, name); \ 176 | const char* dlsym_error = dlerror(); \ 177 | if (dlsym_error != NULL) \ 178 | { \ 179 | tlsys_assert(false, \ 180 | Gravity::StringAppender("Failed to load dynamic TileLink PortGen: ") \ 181 | .Append("symbol=", name) \ 182 | .EndLine() \ 183 | .ToString()); \ 184 | return; \ 185 | } \ 186 | target = reinterpret_cast(sym); \ 187 | } 188 | 189 | LOAD_PORTGEN_SYM(LoadedPortInfo, loadedGetCoreCount, "GetCoreCount"); 190 | LOAD_PORTGEN_SYM(LoadedPortInfo, loadedGetULPortCountPerCore, "GetULPortCountPerCore"); 191 | 192 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelA, "PushChannelA"); 193 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelA, "PullChannelA"); 194 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelB, "PushChannelB"); 195 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelB, "PullChannelB"); 196 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelC, "PushChannelC"); 197 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelC, "PullChannelC"); 198 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelD, "PushChannelD"); 199 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelD, "PullChannelD"); 200 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPushChannelE, "PushChannelE"); 201 | LOAD_PORTGEN_SYM(LoadedPortGen, loadedPullChannelE, "PullChannelE"); 202 | 203 | # undef LOAD_PORTGEN_SYM 204 | 205 | // 206 | LogInfo("PortGen", 207 | Append("Static TileLink PortGen module loaded: ", abs_dlname).EndLine()); 208 | } 209 | } 210 | 211 | uint64_t V3::PortGen::GetCoreCount() 212 | { 213 | tlsys_assert(V3::PortGen::loadedGetCoreCount, 214 | "PortGen not available"); 215 | 216 | return V3::PortGen::loadedGetCoreCount(); 217 | } 218 | 219 | uint64_t V3::PortGen::GetULPortCountPerCore() 220 | { 221 | tlsys_assert(V3::PortGen::loadedGetULPortCountPerCore, 222 | "PortGen not available"); 223 | 224 | return V3::PortGen::loadedGetULPortCountPerCore(); 225 | } 226 | 227 | void V3::PortGen::PushChannelA(VTestTop* verilated, TLSequencer* tltest) 228 | { 229 | tlsys_assert(V3::PortGen::loadedPushChannelA, 230 | "PortGen not available"); 231 | 232 | V3::PortGen::loadedPushChannelA(verilated, tltest); 233 | } 234 | 235 | void V3::PortGen::PullChannelA(VTestTop* verilated, TLSequencer* tltest) 236 | { 237 | tlsys_assert(V3::PortGen::loadedPullChannelA, 238 | "PortGen not available"); 239 | 240 | V3::PortGen::loadedPullChannelA(verilated, tltest); 241 | } 242 | 243 | void V3::PortGen::PushChannelB(VTestTop* verilated, TLSequencer* tltest) 244 | { 245 | tlsys_assert(V3::PortGen::loadedPushChannelB, 246 | "PortGen not available"); 247 | 248 | V3::PortGen::loadedPushChannelB(verilated, tltest); 249 | } 250 | 251 | void V3::PortGen::PullChannelB(VTestTop* verilated, TLSequencer* tltest) 252 | { 253 | tlsys_assert(V3::PortGen::loadedPullChannelB, 254 | "PortGen not available"); 255 | 256 | V3::PortGen::loadedPullChannelB(verilated, tltest); 257 | } 258 | 259 | void V3::PortGen::PushChannelC(VTestTop* verilated, TLSequencer* tltest) 260 | { 261 | tlsys_assert(V3::PortGen::loadedPushChannelC, 262 | "PortGen not available"); 263 | 264 | V3::PortGen::loadedPushChannelC(verilated, tltest); 265 | } 266 | 267 | void V3::PortGen::PullChannelC(VTestTop* verilated, TLSequencer* tltest) 268 | { 269 | tlsys_assert(V3::PortGen::loadedPullChannelC, 270 | "PortGen not available"); 271 | 272 | V3::PortGen::loadedPullChannelC(verilated, tltest); 273 | } 274 | 275 | void V3::PortGen::PushChannelD(VTestTop* verilated, TLSequencer* tltest) 276 | { 277 | tlsys_assert(V3::PortGen::loadedPushChannelD, 278 | "PortGen not available"); 279 | 280 | V3::PortGen::loadedPushChannelD(verilated, tltest); 281 | } 282 | 283 | void V3::PortGen::PullChannelD(VTestTop* verilated, TLSequencer* tltest) 284 | { 285 | tlsys_assert(V3::PortGen::loadedPullChannelD, 286 | "PortGen not available"); 287 | 288 | V3::PortGen::loadedPullChannelD(verilated, tltest); 289 | } 290 | 291 | void V3::PortGen::PushChannelE(VTestTop* verilated, TLSequencer* tltest) 292 | { 293 | tlsys_assert(V3::PortGen::loadedPushChannelE, 294 | "PortGen not available"); 295 | 296 | V3::PortGen::loadedPushChannelE(verilated, tltest); 297 | } 298 | 299 | void V3::PortGen::PullChannelE(VTestTop* verilated, TLSequencer* tltest) 300 | { 301 | tlsys_assert(V3::PortGen::loadedPullChannelE, 302 | "PortGen not available"); 303 | 304 | V3::PortGen::loadedPullChannelE(verilated, tltest); 305 | } 306 | 307 | -------------------------------------------------------------------------------- /main/TLAgent/BaseAgent.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by ljw on 10/21/21. 3 | // 4 | 5 | #ifndef TLC_TEST_BASEAGENT_H 6 | #define TLC_TEST_BASEAGENT_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include "Bundle.h" 12 | #include "../Utils/Common.h" 13 | #include "../Utils/ScoreBoard.h" 14 | #include "../Utils/ULScoreBoard.h" 15 | #include "../Base/TLLocal.hpp" 16 | 17 | 18 | namespace tl_agent { 19 | 20 | class ActionDenialEnumBack { 21 | public: 22 | const bool accepted; 23 | const int ordinal; 24 | 25 | public: 26 | inline constexpr ActionDenialEnumBack(bool accepted, int ordinal) noexcept : accepted(accepted), ordinal(ordinal) {} 27 | inline constexpr operator bool() const noexcept { return accepted; } 28 | inline constexpr operator const ActionDenialEnumBack*() const noexcept { return this; } 29 | inline constexpr bool operator==(const ActionDenialEnumBack& obj) const noexcept { return (this->ordinal == obj.ordinal); } 30 | inline constexpr bool operator!=(const ActionDenialEnumBack& obj) const noexcept { return !(*this == obj); } 31 | }; 32 | 33 | using ActionDenialEnum = ActionDenialEnumBack; 34 | 35 | namespace ActionDenial { 36 | inline constexpr ActionDenialEnumBack ACCEPTED (true , 0); 37 | inline constexpr ActionDenialEnumBack MISS (false , 1); 38 | inline constexpr ActionDenialEnumBack CHANNEL_CONGESTION (false , 2); 39 | inline constexpr ActionDenialEnumBack CHANNEL_RESOURCE (false , 3); 40 | inline constexpr ActionDenialEnumBack DENIED (false , 4); 41 | inline constexpr ActionDenialEnumBack REJECTED_BY_PENDING_A (false , 5); 42 | inline constexpr ActionDenialEnumBack REJECTED_BY_PENDING_B (false , 6); 43 | inline constexpr ActionDenialEnumBack REJECTED_BY_PENDING_C (false , 7); 44 | inline constexpr ActionDenialEnumBack LIMITED_OUTSTANDING (false , 8); 45 | inline constexpr ActionDenialEnumBack PERMISSION (false , 9); 46 | inline constexpr ActionDenialEnumBack REJECTED_BY_INFLIGHT (false , 10); 47 | } 48 | 49 | enum Resp {OK, FAIL}; 50 | 51 | enum { 52 | S_INVALID = 0, 53 | S_VALID, 54 | S_SENDING_A, // ready to send A request actively 55 | S_SENDING_C, // ready to send C request actively 56 | S_SENDING_A_NESTED_SENDING_C, // nested ProbeAck/ProbeAckData on sending AcquirePerm/AcquireBlock 57 | S_A_WAITING_D_NESTED_SENDING_C, // nested ProbeAck/ProbeAckData on waiting for Grant 58 | // S_SENDING_E_NESTED_SENDING_C, // ** prohibited ** Grant not allowed on pending ProbeAck/ProbeAckData 59 | S_C_WAITING_D, // C wait for D response 60 | S_A_WAITING_D, // A wait for D response 61 | S_A_WAITING_D_INTR, // A wait for D response while probe interrupted 62 | S_SENDING_E, // ready to send E request actively 63 | S_CBO_SENDING_A, 64 | S_CBO_A_WAITING_D, 65 | S_CBO_SENDING_A_NESTED_SENDING_C, 66 | S_CBO_SENDING_A_NESTED_C_WAITING_D, 67 | S_CBO_A_WAITING_D_NESTED_SENDING_C, 68 | S_CBO_A_WAITING_D_NESTED_C_WAITING_D 69 | }; 70 | 71 | inline std::string StatusToString(int status) noexcept 72 | { 73 | switch (status) 74 | { 75 | case S_INVALID: return "S_INVALID"; 76 | case S_VALID: return "S_VALID"; 77 | case S_SENDING_A: return "S_SENDING_A"; 78 | case S_SENDING_C: return "S_SENDING_C"; 79 | case S_C_WAITING_D: return "S_C_WAITING_D"; 80 | case S_A_WAITING_D: return "S_A_WAITING_D"; 81 | case S_A_WAITING_D_INTR: return "S_A_WAITING_D_INTR"; 82 | case S_SENDING_E: return "S_SENDING_E"; 83 | case S_CBO_SENDING_A: return "S_CBO_SENDING_A"; 84 | case S_CBO_A_WAITING_D: return "S_CBO_A_WAITING_D"; 85 | case S_CBO_SENDING_A_NESTED_SENDING_C: return "S_CBO_SENDING_A_NESTED_SENDING_C"; 86 | case S_CBO_SENDING_A_NESTED_C_WAITING_D: return "S_CBO_SENDING_A_NESTED_C_WAITING_D"; 87 | case S_CBO_A_WAITING_D_NESTED_SENDING_C: return "S_CBO_A_WAITING_D_NESTED_SENDING_C"; 88 | case S_CBO_A_WAITING_D_NESTED_C_WAITING_D: return "S_CBO_A_WAITING_D_NESTED_C_WAITING_D"; 89 | default: return Gravity::StringAppender("").ToString(); 90 | } 91 | } 92 | 93 | inline std::string StatusToDescription(int status) noexcept 94 | { 95 | switch(status) 96 | { 97 | case S_INVALID: return "invalid"; 98 | case S_VALID: return "valid"; 99 | case S_SENDING_A: return "ready to send A request actively"; 100 | case S_SENDING_C: return "ready to send C request actively"; 101 | case S_C_WAITING_D: return "C wait for D response"; 102 | case S_A_WAITING_D: return "A wait for D response"; 103 | case S_A_WAITING_D_INTR: return "A wait for D response while probe interrupted"; 104 | case S_SENDING_E: return "ready to send E request actively"; 105 | case S_CBO_SENDING_A: return "ready to send A CBO request actively"; 106 | case S_CBO_A_WAITING_D: return "A CBO waiting for D CBO response"; 107 | case S_CBO_SENDING_A_NESTED_SENDING_C: return "ready to send A CBO nested ready to send C request actively"; 108 | case S_CBO_SENDING_A_NESTED_C_WAITING_D: return "ready to send A CBO nested C wait for D response"; 109 | case S_CBO_A_WAITING_D_NESTED_SENDING_C: return "A CBO waiting for D nested ready to send C request actively"; 110 | case S_CBO_A_WAITING_D_NESTED_C_WAITING_D: return "A CBO waiting for D nested C wait for D response"; 111 | default: return ""; 112 | } 113 | } 114 | 115 | class ReqField { 116 | public: 117 | uint8_t value; 118 | }; 119 | 120 | class RespField { 121 | public: 122 | uint8_t value; 123 | }; 124 | 125 | class EchoField { 126 | public: 127 | uint8_t value; 128 | }; 129 | 130 | template 131 | class PendingTrans { 132 | public: 133 | int beat_cnt; 134 | int nr_beat; 135 | std::shared_ptr info; 136 | 137 | PendingTrans() { 138 | nr_beat = 0; 139 | beat_cnt = 0; 140 | } 141 | ~PendingTrans() = default; 142 | 143 | bool is_multiBeat() { return (this->nr_beat != 1); }; 144 | bool is_pending() { return (beat_cnt != 0); } 145 | void init(std::shared_ptr &info, int nr_beat) { 146 | this->info = info; 147 | this->nr_beat = nr_beat; 148 | beat_cnt = nr_beat; 149 | } 150 | void update(TLLocalContext* ctx) { 151 | beat_cnt--; 152 | tlc_assert(beat_cnt >= 0, ctx, "More beats received than expected!"); 153 | } 154 | }; 155 | 156 | class IDPool { 157 | private: 158 | std::set *idle_ids; 159 | std::set *used_ids; 160 | int pending_freeid; 161 | public: 162 | IDPool(int start, int end) { 163 | idle_ids = new std::set(); 164 | used_ids = new std::set(); 165 | for (int i = start; i < end; i++) { 166 | idle_ids->insert(i); 167 | } 168 | used_ids->clear(); 169 | pending_freeid = -1; 170 | } 171 | ~IDPool() { 172 | delete idle_ids; 173 | delete used_ids; 174 | } 175 | int getid() { 176 | if (idle_ids->size() == 0) 177 | return -1; 178 | int ret = *idle_ids->begin(); 179 | used_ids->insert(ret); 180 | idle_ids->erase(ret); 181 | return ret; 182 | } 183 | void freeid(int id) { 184 | this->pending_freeid = id; 185 | } 186 | void update(TLLocalContext* ctx) { 187 | if (pending_freeid != -1) { 188 | tlc_assert(used_ids->count(pending_freeid) > 0, ctx, "Try to free unused SourceID!"); 189 | used_ids->erase(pending_freeid); 190 | idle_ids->insert(pending_freeid); 191 | pending_freeid = -1; 192 | } 193 | } 194 | bool full() { 195 | return idle_ids->empty(); 196 | } 197 | }; 198 | 199 | template 200 | class BaseAgent : public TLLocalContext { 201 | public: 202 | using tlport_t = Bundle; 203 | using l1hintport_t = BundleL2ToL1Hint; 204 | 205 | protected: 206 | TLLocalConfig* cfg; 207 | const int core; 208 | const int id; 209 | tlport_t* port; 210 | l1hintport_t* l2ToL1HintPort; 211 | GlobalBoard* globalBoard; 212 | UncachedBoard* uncachedBoards; 213 | MemoryBackend* mem; 214 | IDPool idpool; 215 | virtual void timeout_check() = 0; 216 | 217 | const unsigned int seed; 218 | 219 | private: 220 | std::mt19937_64 rand; 221 | 222 | public: 223 | # if AGENT_DEBUG == 1 224 | uint64_t aux_rand_counter = 0; 225 | uint64_t aux_rand_value; 226 | # endif 227 | 228 | public: 229 | inline int sys() const noexcept override { return core; } 230 | inline int sysId() const noexcept override { return id; } 231 | inline unsigned int sysSeed() const noexcept override { return seed; } 232 | 233 | inline TLLocalConfig& config() noexcept override { return *cfg; } 234 | inline const TLLocalConfig& config() const noexcept override { return *cfg; } 235 | 236 | virtual Resp send_a (std::shared_ptr>& a) = 0; 237 | virtual void handle_b (std::shared_ptr& b) = 0; 238 | virtual Resp send_c (std::shared_ptr>& c) = 0; 239 | virtual void fire_a() = 0; 240 | virtual void fire_b() = 0; 241 | virtual void fire_c() = 0; 242 | virtual void fire_d() = 0; 243 | virtual void fire_e() = 0; 244 | virtual void handle_channel() = 0; 245 | virtual void update_signal() = 0; 246 | BaseAgent(TLLocalConfig* cfg, MemoryBackend* mem, int sys, int sysId, unsigned int seed, unsigned int limitSource): cfg(cfg), core(sys), id(sysId), mem(mem), idpool(0, limitSource), seed(seed), rand(sysId + seed) {}; 247 | BaseAgent(TLLocalConfig* cfg, MemoryBackend* mem, int sys, int sysId, unsigned int seed): cfg(cfg), core(sys), id(sysId), mem(mem), idpool(0, NR_SOURCEID), seed(seed), rand(sysId + seed) {}; 248 | virtual ~BaseAgent() = default; 249 | 250 | inline void connect(tlport_t* p){ this->port = p; } 251 | inline void connect(l1hintport_t* p) { this->l2ToL1HintPort = p; } 252 | 253 | inline uint64_t rand64() noexcept { return rand(); } 254 | }; 255 | 256 | } 257 | 258 | #endif //TLC_TEST_BASEAGENT_H 259 | --------------------------------------------------------------------------------