P4C
The P4 Compiler
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
stage.h
1
17
18#ifndef BACKENDS_TOFINO_BF_ASM_STAGE_H_
19#define BACKENDS_TOFINO_BF_ASM_STAGE_H_
20
21#include <fstream>
22#include <vector>
23
24#include "alloc.h"
25#include "backends/tofino/bf-asm/tables.h"
26#include "error_mode.h"
27#include "input_xbar.h"
28#include "lib/bitvec.h"
29
30class Stage_data {
31 /* we encapsulate all the Stage non-static fields in a base class to automate the
32 * generation of the move construtor properly */
33 public:
34 int stageno;
35 std::vector<Table *> tables;
36 std::set<Stage **> all_refs;
38 BFN::Alloc2D<Table *, SRAM_ROWS, 2> sram_search_bus_use;
39 BFN::Alloc3Dbase<Table *> stm_hbus_use;
40 BFN::Alloc2D<Table *, SRAM_ROWS, 2> match_result_bus_use;
43 BFN::Alloc2Dbase<Table *> tcam_match_bus_use;
44 BFN::Alloc2D<std::pair<Table *, int>, TCAM_ROWS, 2> tcam_byte_group_use;
45 BFN::Alloc1Dbase<Table *> local_tind_use;
46 BFN::Alloc2D<Table *, SRAM_ROWS, 2> tcam_indirect_bus_use;
57 BFN::Alloc1Dbase<ActionTable *> action_unit_use;
60 BFN::Alloc1D<Table *, LOGICAL_SRAM_ROWS> action_data_use, meter_bus_use, stats_bus_use,
61 selector_adr_bus_use, overflow_bus_use;
63 bitvec action_bus_use_bit_mask;
65 bitvec imem_use[ACTION_IMEM_SLOTS];
67 unsigned long_branch_thread[3] = {0};
68 unsigned long_branch_terminate = 0;
69
70 // for timing, ghost thread is tied to ingress, so we track ghost as ingress here
71 enum {
72 USE_TCAM = 1,
73 USE_STATEFUL = 4,
74 USE_METER = 8,
75 USE_METER_LPF_RED = 16,
76 USE_SELECTOR = 32,
77 USE_WIDE_SELECTOR = 64,
78 USE_STATEFUL_DIVIDE = 128
79 };
80 int /* enum */ table_use[2], group_table_use[2];
81
82 enum { NONE = 0, CONCURRENT = 1, ACTION_DEP = 2, MATCH_DEP = 3 } stage_dep[2];
83 bitvec match_use[3], action_use[3], action_set[3];
84
85 // there's no error mode registers for ghost thread, so we don't allow it to be set
86 ErrorMode error_mode[2];
87
88 // MPR stage config
89 int mpr_stage_id[3] = {0}; // per-gress
90 int mpr_always_run = 0;
91 int mpr_bus_dep_glob_exec[3] = {0};
92 int mpr_bus_dep_long_branch[3] = {0};
93 // per gress, per logical table
95 // per global execute bit
97 // per long branch tag
99
100 int pass1_logical_id = -1, pass1_tcam_id = -1;
101
102 // True egress accounting (4 buses) Tofino2
103 static std::map<int, std::pair<bool, int>> teop;
104
105 protected:
106 Stage_data(int stage, bool egress_only)
107 : stageno(stage),
108 sram_use(Target::SRAM_ROWS(egress_only ? EGRESS : INGRESS), Target::SRAM_UNITS_PER_ROW()),
109 stm_hbus_use(Target::SRAM_ROWS(egress_only ? EGRESS : INGRESS),
110 Target::SRAM_HBUS_SECTIONS_PER_STAGE(), Target::SRAM_HBUSSES_PER_ROW()),
111 tcam_use(Target::TCAM_ROWS(), Target::TCAM_UNITS_PER_ROW()),
112 tcam_match_bus_use(Target::TCAM_ROWS(), Target::TCAM_MATCH_BUSSES()),
113 local_tind_use(Target::LOCAL_TIND_UNITS()),
114 hash_table_use(Target::EXACT_HASH_TABLES()),
115 hash_group_use(Target::EXACT_HASH_GROUPS()),
116 action_unit_use(Target::ARAM_UNITS_PER_STAGE()),
117 dp_unit_use(Target::DP_UNITS_PER_STAGE()) {}
118 Stage_data(const Stage_data &) = delete;
119 Stage_data(Stage_data &&) = default;
120 ~Stage_data() {}
121};
122
123class Stage : public Stage_data {
124 public:
125 static unsigned char action_bus_slot_map[ACTION_DATA_BUS_BYTES];
126 static unsigned char action_bus_slot_size[ACTION_DATA_BUS_SLOTS]; // size in bits
127
128 explicit Stage(int stageno, bool egress_only);
129 Stage(const Stage &) = delete;
130 Stage(Stage &&);
131 ~Stage();
132 template <class TARGET>
133 void output(json::map &ctxt_json, bool egress_only = false);
134 template <class REGS>
135 void fixup_regs(REGS &regs);
136 template <class REGS>
137 void gen_configuration_cache_common(REGS &regs, json::vector &cfg_cache);
138 template <class REGS>
139 void gen_configuration_cache(REGS &regs, json::vector &cfg_cache);
140 template <class REGS>
141 void gen_gfm_json_info(REGS &regs, std::ostream &out);
142 template <class REGS>
143 void gen_mau_stage_characteristics(REGS &regs, json::vector &stg_characteristics);
144 template <class REGS>
145 void gen_mau_stage_extension(REGS &regs, json::map &extend);
146 template <class REGS>
147 void write_regs(REGS &regs, bool egress_only);
148 template <class TARGET>
149 void write_common_regs(typename TARGET::mau_regs &regs);
150 template <class REGS>
151 void write_teop_regs(REGS &regs);
152 int adr_dist_delay(gress_t gress) const;
153 int meter_alu_delay(gress_t gress, bool uses_divmod) const;
154 int pipelength(gress_t gress) const;
155 int pred_cycle(gress_t gress) const;
156 int tcam_delay(gress_t gress) const;
157 int cycles_contribute_to_latency(gress_t gress);
158 void verify_have_mpr(std::string key, int line_number);
159 static int first_table(gress_t gress);
160 static unsigned end_of_pipe() { return Target::END_OF_PIPE(); }
161 static Stage *stage(gress_t gress, int stageno);
162 void log_hashes(std::ofstream &out) const;
163 bitvec imem_use_all() const;
164};
165
166class AsmStage : public Section {
167 void start(int lineno, VECTOR(value_t) args);
168 void input(VECTOR(value_t) args, value_t data);
169 void output(json::map &);
170
172 void propagate_group_table_use();
173
174 unsigned compute_latency(gress_t gress);
175 AsmStage();
176 ~AsmStage() {}
177 std::vector<Stage> pipe;
178 static AsmStage singleton_object;
179 bitvec stages_seen[NUM_GRESS_T];
180
181 public:
182 void process();
183 static int numstages() { return singleton_object.pipe.size(); }
184 static std::vector<Stage> &stages(gress_t gress) { return singleton_object.pipe; }
185
186 // for gtest
187 void reset_stage(Stage &stage) {
188 for (auto &tbl : stage.tables) tbl->all->clear();
189 stage.tables.clear();
190 stage.all_refs.clear();
191 stage.sram_use.clear();
192 stage.sram_search_bus_use.clear();
193 stage.stm_hbus_use.clear();
194 stage.match_result_bus_use.clear();
195 stage.mapram_use.clear();
196 stage.tcam_use.clear();
197 stage.tcam_match_bus_use.clear();
198 stage.tcam_byte_group_use.clear();
199 stage.gw_unit_use.clear();
200 stage.gw_payload_use.clear();
201 stage.logical_id_use.clear();
202 stage.physical_id_use.clear();
203 stage.tcam_id_use.clear();
204 stage.ixbar_use.clear();
205 stage.tcam_ixbar_input.clear();
206 stage.hash_table_use.clear();
207 stage.hash_group_use.clear();
208 stage.hash_dist_use.clear();
209 stage.action_bus_use.clear();
210 stage.action_data_use.clear();
211 stage.meter_bus_use.clear();
212 stage.stats_bus_use.clear();
213 stage.selector_adr_bus_use.clear();
214 stage.overflow_bus_use.clear();
215 stage.idletime_bus_use.clear();
216 stage.imem_addr_use.clear();
217 stage.long_branch_use.clear();
218 }
219
220 void reset() {
221 stages_seen[INGRESS].clear();
222 stages_seen[EGRESS].clear();
223 for (auto &stage : pipe) reset_stage(stage);
224 }
225};
226
227#endif /* BACKENDS_TOFINO_BF_ASM_STAGE_H_ */
void process()
optionally process the data if not done during parsing
Definition stage.cpp:241
Definition bf-asm/alloc.h:48
Definition bf-asm/alloc.h:13
Definition bf-asm/alloc.h:135
Definition bf-asm/alloc.h:59
Definition bf-p4c/common/alloc.h:159
Definition error_mode.h:25
Definition bitvec.h:120
Definition ordered_map.h:32
Definition stage.h:123
Definition backends/tofino/bf-asm/json.h:300
Definition backends/tofino/bf-asm/json.h:222
Definition asm-types.h:114