Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions example/topology.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"modules": [
{
"name": "init0",
"type": "initiator",
"id": 0,
"neighbors": ["ic0"],
"config": {
"clock_period_ps": 1000,
"home_id": 1
}
},
{
"name": "ic0",
"type": "interconnect",
"id": 100,
"neighbors": ["init0", "ha0", "tgt0"]
},
{
"name": "ha0",
"type": "home_agent",
"id": 1,
"neighbors": ["ic0"],
"config": {
"clock_period_ps": 1000,
"downstream_target_id": 2,
"cache_hit_latency_cycles": 3,
"pipeline_latency_cycles": 5,
"tq_capacity": 8
}
},
{
"name": "tgt0",
"type": "target",
"id": 2,
"neighbors": ["ic0"],
"config": {
"clock_period_ps": 1000,
"data_latency_cycles": 50
}
}
]
}
1 change: 1 addition & 0 deletions include/csim/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ auto write_json_file(const std::string& filename) -> void;
auto print_help() -> void;
auto check_for_help(int argc, char* argv[]) -> void;
auto get_knob(const std::string& full_name) -> KnobBase*;
auto get_topology_file() -> std::string;

// Lifecycle
auto reset_all() -> void;
Expand Down
8 changes: 8 additions & 0 deletions include/csim/core/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "sim_types.h"
#include "csim/tracing/tracer.h"
#include "csim/core/port.h"

namespace csim {

Expand All @@ -24,6 +25,9 @@ class Module {

[[nodiscard]] auto id() const -> uint32_t { return stored_id; }

auto add_port(uint32_t neighbor_id) -> Port&;
auto get_port(uint32_t neighbor_id) -> Port&;

sim_t& sim;
const std::string name;

Expand All @@ -33,6 +37,10 @@ class Module {
protected:
tracing::Tracer& tracer = tracing::Tracer::instance();

std::unordered_map<uint32_t, std::unique_ptr<Port>> port_map;

auto single_port() const -> Port&;

private:
uint32_t stored_id;
};
Expand Down
17 changes: 9 additions & 8 deletions include/csim/core/port.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include <functional>
#include <memory>
#include "csim/core/sim_types.h"
#include "payload.h"

namespace csim {

class Port {
public:
using callback_t = std::function<void(payload_ptr)>;
Expand All @@ -15,21 +15,22 @@ class Port {
rx_ = [self, method](payload_ptr p) -> auto { (self->*method)(std::move(p)); };
}

auto send(payload_ptr p) -> void { peer_rx_(std::move(p)); }

[[nodiscard]] auto rx() const -> callback_t { return rx_; }
auto send(payload_ptr p) -> void { peer_->rx_(std::move(p)); }

auto set_peer(callback_t peer_rx) -> void { peer_rx_ = std::move(peer_rx); }
auto set_peer(Port* peer) -> void { peer_ = peer; }

private:
callback_t rx_;
callback_t peer_rx_;
Port* peer_ = nullptr;

friend auto bind(Port& a, Port& b) -> void;
};

inline auto
bind(Port& a, Port& b) -> void
{
a.set_peer(b.rx());
b.set_peer(a.rx());
a.peer_ = &b;
b.peer_ = &a;
}

} // namespace csim
39 changes: 24 additions & 15 deletions include/models/home_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
#include "csim/core/sim_types.h"
#include "csim/utilities/work_queue.h"
#include "csim/utilities/cache.h"
#include "csim/config/knob_system.h"
#include "models/transaction_inbox.h"
#include "models/transaction_queue.h"

namespace csim {

class HomeAgent : public Module {
public:
Port port;

HomeAgent(sim_t& sim, System& sys, uint32_t id, std::string name, uint32_t downstream_target_id,
time_ps clock_period_ps);
HomeAgent(sim_t& sim, System& sys, uint32_t id, std::string name);

auto elaborate() -> void override;
auto start() -> void override;

private:
Expand All @@ -31,18 +30,32 @@ class HomeAgent : public Module {
~InboxGuard() { ha.inboxes.erase(txn_uid); }
};

uint32_t downstream_target_id;
KnobList& knob_list;
Knob<int>& clock_period_ps_knob =
knob_list.add_knob<int>("clock_period_ps", "Clock period in picoseconds", 1000);
Knob<int>& downstream_target_id_knob =
knob_list.add_knob<int>("downstream_target_id", "Target agent ID for transactions", 1);
Knob<int>& cache_hit_latency_cycles_knob =
knob_list.add_knob<int>("cache_hit_latency_cycles", "Cache hit latency in cycles", 3);
Knob<int>& pipeline_latency_cycles_knob =
knob_list.add_knob<int>("pipeline_latency_cycles", "Pipeline latency in cycles", 5);
Knob<int>& tq_capacity_knob =
knob_list.add_knob<int>("tq_capacity", "Number of TQ entries", 16);

// Captured at elaborate:
time_ps clock_period_ps;
uint32_t downstream_target_id;
uint32_t cache_hit_latency_cycles;
uint32_t pipeline_latency_cycles;

// Outbound channel queues.
WorkQueue outbound_req;
WorkQueue outbound_dat;
WorkQueue outbound_crsp;
// Constructed at elaborate:
std::unique_ptr<WorkQueue> outbound_req;
std::unique_ptr<WorkQueue> outbound_dat;
std::unique_ptr<WorkQueue> outbound_crsp;
std::unique_ptr<TransactionQueue> tq;

Cache cache;

TransactionQueue tq;

// Service coroutines.
auto service_req_queue() -> proc_t;
auto service_dat_queue() -> proc_t;
Expand Down Expand Up @@ -72,10 +85,6 @@ class HomeAgent : public Module {

// Generic helpers
auto should_use_dmt(const Payload& req) -> bool;

// Defaults — future config will override.
uint32_t cache_hit_latency_cycles = 3;
uint32_t pipeline_latency_cycles = 5;
};

} // namespace csim
14 changes: 10 additions & 4 deletions include/models/initiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
#include "csim/core/port.h"
#include "csim/core/sim_types.h"
#include "protocols/chi.h"
#include "csim/config/knob_system.h"

namespace csim {

class Initiator : public Module {
public:
Port port;

Initiator(sim_t& sim, System& sys, uint32_t id, std::string name, uint32_t home_id,
time_ps clock_period_ps);
Initiator(sim_t& sim, System& sys, uint32_t id, std::string name);

auto elaborate() -> void override;
auto start() -> void override;

private:
Expand All @@ -32,8 +31,15 @@ class Initiator : public Module {
auto handle_crsp(payload_ptr response) -> void;
auto get_next_txn_id() -> uint32_t { return next_txn_id++; }

KnobList& knob_list;
Knob<int>& clock_period_ps_knob =
knob_list.add_knob<int>("clock_period_ps", "Clock period in picoseconds", 1000);
Knob<int>& home_id_knob =
knob_list.add_knob<int>("home_id", "Home agent ID for transactions", 1);

time_ps clock_period_ps;
uint32_t home_id;

uint32_t next_txn_id = 0;

DelayChannel outbound_req;
Expand Down
11 changes: 1 addition & 10 deletions include/models/interconnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#include <cstdint>
#include <string>
#include <unordered_map>

#include "csim/core/module.h"
#include "csim/core/payload.h"
#include "csim/core/port.h"
#include "csim/core/sim_types.h"

namespace csim {
Expand All @@ -15,18 +13,11 @@ class Interconnect : public Module {
public:
Interconnect(sim_t& sim, System& sys, uint32_t id, std::string name);

auto elaborate() -> void override;
auto start() -> void override;

// Wire up an agent. Agent's port becomes bound to one of our internal
// ports; we record the mapping so we can route flits with tgt_id
// matching the agent's id.
auto attach(Module& m, Port& agent_port) -> void;

private:
auto handle_incoming(payload_ptr payload) -> void;

// One per attached agent. Owned by us; bound to the agent's port.
std::unordered_map<uint32_t, std::unique_ptr<Port>> ports;
};

} // namespace csim
21 changes: 14 additions & 7 deletions include/models/target.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include <cstdint>
#include <memory>
#include <string>

#include "csim/config/knob_system.h"
#include "csim/core/module.h"
#include "csim/core/payload.h"
#include "csim/core/port.h"
#include "csim/core/sim_types.h"
#include "csim/utilities/work_queue.h"
#include "protocols/chi.h"
Expand All @@ -14,18 +15,24 @@ namespace csim {

class Target : public Module {
public:
Port port;

Target(sim_t& sim, System& sys, uint32_t id, std::string name, time_ps clock_period_ps);
Target(sim_t& sim, System& sys, uint32_t id, std::string name);

auto elaborate() -> void override;
auto start() -> void override;

private:
KnobList& knob_list;
Knob<int>& clock_period_ps_knob =
knob_list.add_knob<int>("clock_period_ps", "Clock period in picoseconds", 1000);
Knob<int>& data_latency_cycles_knob =
knob_list.add_knob<int>("data_latency_cycles", "Data response latency in cycles", 50);

// Captured at elaborate:
time_ps clock_period_ps;
uint32_t data_latency_cycles = 50;
uint32_t response_latency_cycles = 1;
uint32_t data_latency_cycles;

WorkQueue outbound_data;
// Constructed at elaborate:
std::unique_ptr<WorkQueue> outbound_data;

auto handle_request(payload_ptr payload) -> void;
auto service_data_queue() -> proc_t;
Expand Down
38 changes: 38 additions & 0 deletions include/models/topology_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include "csim/core/module.h"
#include "csim/core/sim_types.h"
#include "csim/core/system.h"

#include <nlohmann/json.hpp>

#include <set>
#include <string>
#include <unordered_map>

namespace csim {

class TopologyLoader {
public:
TopologyLoader(sim_t& sim, System& sys);

auto load(const std::string& filename) -> void;
auto get_module(const std::string& name) const -> Module*;

private:
sim_t& sim;
System& sys;

std::unordered_map<std::string, std::unique_ptr<Module>> modules;

auto construct_module(const nlohmann::json& spec) -> void;
auto construct_initiator(const nlohmann::json& spec) -> std::unique_ptr<Module>;
auto construct_home_agent(const nlohmann::json& spec) -> std::unique_ptr<Module>;
auto construct_target(const nlohmann::json& spec) -> std::unique_ptr<Module>;
auto construct_interconnect(const nlohmann::json& spec) -> std::unique_ptr<Module>;
auto apply_module_config(const std::string& name, const nlohmann::json& config) -> void;
auto wire_neighbors(const nlohmann::json& spec,
std::set<std::pair<std::string, std::string>>& seen) -> void;
};

} // namespace csim
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_library(csim_models STATIC
models/home_agent.cpp
models/transaction_inbox.cpp
models/transaction_queue.cpp
models/topology_loader.cpp
)
target_link_libraries(csim_models PUBLIC csim_infra)
target_include_directories(csim_models PUBLIC ../include)
Expand Down
Loading
Loading