Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dpdk Backend: Register extern support for bfrt.json #3723

Merged
merged 1 commit into from
Nov 29, 2022
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
8 changes: 8 additions & 0 deletions backends/dpdk/control-plane/bfruntime_arch_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon<arch> {
break;
}
}
} else if (externBlock->type->name == "Register") {
for (auto& extType : *p4info->mutable_registers()) {
auto* pre = extType.mutable_preamble();
if (pre->name() == decl->controlPlaneName()) {
pre->set_name(prefix(pipeName, pre->name()));
break;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion backends/dpdk/control-plane/bfruntime_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const Util::JsonObject* BFRuntimeSchemaGenerator::genSchema() const {
addActionProfs(tablesJson);
addCounters(tablesJson);
addMeters(tablesJson);
// TODO(antonin): handle "standard" (v1model / PSA) registers
addRegisters(tablesJson);

auto* learnFiltersJson = new Util::JsonArray();
json->emplace("learn_filters", learnFiltersJson);
Expand Down
54 changes: 30 additions & 24 deletions control-plane/bfruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ boost::optional<BFRuntimeGenerator::Meter> BFRuntimeGenerator::Meter::fromDirect
return Meter{pre.name(), id, 0, unit, transformAnnotations(pre)};
}

// Register
boost::optional<BFRuntimeGenerator::Register> BFRuntimeGenerator::Register::from(
const p4configv1::Register& regInstance) {
const auto& pre = regInstance.preamble();
auto id = makeBFRuntimeId(pre.id(), p4configv1::P4Ids::REGISTER);
return Register{pre.name(), "$REGISTER_INDEX", id,
regInstance.size(), regInstance.type_spec(), transformAnnotations(pre)};
}

// ActionProfile
P4Id BFRuntimeGenerator::ActionProf::makeActProfId(P4Id implementationId) {
return makeBFRuntimeId(implementationId, p4configv1::P4Ids::ACTION_PROFILE);
Expand Down Expand Up @@ -397,40 +406,29 @@ void BFRuntimeGenerator::transformTypeSpecToDataFields(Util::JsonArray* fieldsJs
void BFRuntimeGenerator::addRegisterDataFields(Util::JsonArray* dataJson,
const BFRuntimeGenerator::Register& register_,
P4Id idOffset) const {
auto* fieldsJson = new Util::JsonArray();
transformTypeSpecToDataFields(fieldsJson, register_.typeSpec, "Register", register_.name,
nullptr, register_.dataFieldName + ".", "", idOffset);
for (auto* f : *fieldsJson) {
auto* fObj = f->to<Util::JsonObject>();
CHECK_NULL(fObj);
auto* fAnnotations = fObj->get("annotations")->to<Util::JsonArray>();
CHECK_NULL(fAnnotations);
// Add BF-RT "native" annotation to indicate to the BF-RT implementation
// - and potentially applications - that this data field is stateful
// data. The specific string for this annotation may be changed in the
// future if we start introducing more BF-RT annotations, in order to
// keep the syntax consistent.
{
auto* classAnnotation = new Util::JsonObject();
classAnnotation->emplace("name", "$bfrt_field_class");
classAnnotation->emplace("value", "register_data");
fAnnotations->append(classAnnotation);
}
addSingleton(dataJson, fObj, true /* mandatory */, false /* read-only */);
auto parser = TypeSpecParser::make(p4info, register_.typeSpec, "Register", register_.name,
nullptr, "", "", idOffset);

BUG_CHECK(parser.size() == 1, "Expected only one data field for Register extern %1%",
register_.name);
for (const auto& f : parser) {
auto* fJson =
makeCommonDataField(idOffset, "$REGISTER_INDEX", f.type, false /* repeated */);
addSingleton(dataJson, fJson, false /* mandatory */, false /* read-only */);
}
}

void BFRuntimeGenerator::addRegisterCommon(Util::JsonArray* tablesJson,
const BFRuntimeGenerator::Register& register_) const {
auto* tableJson = initTableJson(register_.name, register_.id, "Register", register_.size);

auto* tableJson = initTableJson(register_.name, register_.id, "Register", register_.size,
register_.annotations);
auto* keyJson = new Util::JsonArray();
addKeyField(keyJson, TD_DATA_REGISTER_INDEX, "$REGISTER_INDEX", true /* mandatory */, "Exact",
makeType("uint32"));
tableJson->emplace("key", keyJson);

auto* dataJson = new Util::JsonArray();
addRegisterDataFields(dataJson, register_);
addRegisterDataFields(dataJson, register_, TD_DATA_REGISTER_INDEX);
tableJson->emplace("data", dataJson);

auto* operationsJson = new Util::JsonArray();
Expand Down Expand Up @@ -827,6 +825,14 @@ void BFRuntimeGenerator::addMeters(Util::JsonArray* tablesJson) const {
}
}

void BFRuntimeGenerator::addRegisters(Util::JsonArray* tablesJson) const {
for (const auto& reg : p4info.registers()) {
auto regInstance = Register::from(reg);
if (regInstance == boost::none) continue;
addRegisterCommon(tablesJson, *regInstance);
}
}

const Util::JsonObject* BFRuntimeGenerator::genSchema() const {
auto* json = new Util::JsonObject();

Expand All @@ -839,7 +845,7 @@ const Util::JsonObject* BFRuntimeGenerator::genSchema() const {
addActionProfs(tablesJson);
addCounters(tablesJson);
addMeters(tablesJson);
// TODO(antonin): handle "standard" (v1model / PSA) registers
addRegisters(tablesJson);

auto* learnFiltersJson = new Util::JsonArray();
json->emplace("learn_filters", learnFiltersJson);
Expand Down
7 changes: 4 additions & 3 deletions control-plane/bfruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class TypeSpecParser {
const_iterator cbegin() { return fields.cbegin(); }
iterator end() { return fields.end(); }
const_iterator cend() { return fields.cend(); }
size_t size() { return fields.size(); }

private:
explicit TypeSpecParser(Fields&& fields) : fields(std::move(fields)) {}
Expand Down Expand Up @@ -380,8 +381,7 @@ class BFRuntimeGenerator {
p4configv1::P4DataTypeSpec typeSpec;
Util::JsonArray* annotations;

// static boost::optional<Register>
// from(const p4configv1::ExternInstance& externInstance);
static boost::optional<Register> from(const p4configv1::Register& regInstance);
};

void addMatchTables(Util::JsonArray* tablesJson) const;
Expand All @@ -390,10 +390,11 @@ class BFRuntimeGenerator {
Util::JsonObject* tableJson) const;
void addCounters(Util::JsonArray* tablesJson) const;
void addMeters(Util::JsonArray* tablesJson) const;
void addRegisters(Util::JsonArray* tablesJson) const;

void addCounterCommon(Util::JsonArray* tablesJson, const Counter& counter) const;
void addMeterCommon(Util::JsonArray* tablesJson, const Meter& meter) const;
void addRegisterCommon(Util::JsonArray* tablesJson, const Register& meter) const;
void addRegisterCommon(Util::JsonArray* tablesJson, const Register& reg) const;
void addActionProfCommon(Util::JsonArray* tablesJson, const ActionProf& actionProf) const;
void addLearnFilters(Util::JsonArray* learnFiltersJson) const;
void addLearnFilterCommon(Util::JsonArray* learnFiltersJson, const Digest& digest) const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"schema_version" : "1.0.0",
"tables" : [],
"tables" : [
{
"name" : "ep.cEgress.egress_pkt_seen",
"id" : 369999048,
"table_type" : "Register",
"size" : 256,
"annotations" : [],
"depends_on" : [],
"key" : [
{
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"mandatory" : true,
"match_type" : "Exact",
"type" : {
"type" : "uint32"
}
}
],
"data" : [
{
"mandatory" : false,
"read_only" : false,
"singleton" : {
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"type" : {
"type" : "bytes",
"width" : 16
}
}
}
],
"supported_operations" : ["Sync"],
"attributes" : []
}
],
"learn_filters" : []
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,45 @@
],
"supported_operations" : [],
"attributes" : ["MeterByteCountAdjust"]
},
{
"name" : "ip.ingress.reg",
"id" : 382856063,
"table_type" : "Register",
"size" : 1024,
"annotations" : [],
"depends_on" : [],
"key" : [
{
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"mandatory" : true,
"match_type" : "Exact",
"type" : {
"type" : "uint32"
}
}
],
"data" : [
{
"mandatory" : false,
"read_only" : false,
"singleton" : {
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"type" : {
"type" : "bytes",
"width" : 32
}
}
}
],
"supported_operations" : ["Sync"],
"attributes" : []
}
],
"learn_filters" : []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,45 @@
],
"supported_operations" : [],
"attributes" : ["MeterByteCountAdjust"]
},
{
"name" : "ip.ingress.reg",
"id" : 382856063,
"table_type" : "Register",
"size" : 1024,
"annotations" : [],
"depends_on" : [],
"key" : [
{
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"mandatory" : true,
"match_type" : "Exact",
"type" : {
"type" : "uint32"
}
}
],
"data" : [
{
"mandatory" : false,
"read_only" : false,
"singleton" : {
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"type" : {
"type" : "bytes",
"width" : 32
}
}
}
],
"supported_operations" : ["Sync"],
"attributes" : []
}
],
"learn_filters" : []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,45 @@
],
"supported_operations" : [],
"attributes" : ["MeterByteCountAdjust"]
},
{
"name" : "ip.ingress.reg",
"id" : 382856063,
"table_type" : "Register",
"size" : 1024,
"annotations" : [],
"depends_on" : [],
"key" : [
{
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"mandatory" : true,
"match_type" : "Exact",
"type" : {
"type" : "uint32"
}
}
],
"data" : [
{
"mandatory" : false,
"read_only" : false,
"singleton" : {
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"type" : {
"type" : "bytes",
"width" : 32
}
}
}
],
"supported_operations" : ["Sync"],
"attributes" : []
}
],
"learn_filters" : []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,45 @@
],
"supported_operations" : [],
"attributes" : ["MeterByteCountAdjust"]
},
{
"name" : "ip.ingress.reg",
"id" : 382856063,
"table_type" : "Register",
"size" : 1024,
"annotations" : [],
"depends_on" : [],
"key" : [
{
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"mandatory" : true,
"match_type" : "Exact",
"type" : {
"type" : "uint32"
}
}
],
"data" : [
{
"mandatory" : false,
"read_only" : false,
"singleton" : {
"id" : 65557,
"name" : "$REGISTER_INDEX",
"repeated" : false,
"annotations" : [],
"type" : {
"type" : "bytes",
"width" : 32
}
}
}
],
"supported_operations" : ["Sync"],
"attributes" : []
}
],
"learn_filters" : []
Expand Down
Loading