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: Minor fixes w.r.t bfrt and context json output and name shortening #3958

Merged
merged 1 commit into from
Apr 3, 2023
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
13 changes: 13 additions & 0 deletions backends/dpdk/control-plane/bfruntime_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ bool BFRuntimeSchemaGenerator::addActionProfIds(const p4configv1::Table &table,
return true;
}

void BFRuntimeSchemaGenerator::addConstTableAttr(Util::JsonArray *) const {
// Intentionally empty function body to skip attribute addition for const entries
return;
}

void BFRuntimeSchemaGenerator::addActionProfs(Util::JsonArray *tablesJson) const {
for (const auto &actionProf : p4info.action_profiles()) {
auto actionProfInstance = ActionProf::from(p4info, actionProf);
Expand All @@ -192,6 +197,14 @@ void BFRuntimeSchemaGenerator::addActionProfs(Util::JsonArray *tablesJson) const
}
}

bool BFRuntimeSchemaGenerator::addMatchTypePriority(std::optional<cstring> &matchType) const {
if (*matchType == "Ternary" || *matchType == "Range" || *matchType == "Optional") {
*matchType = "Ternary";
return true;
}
return false;
}

std::optional<bool> BFRuntimeSchemaGenerator::actProfHasSelector(P4Id actProfId) const {
if (isOfType(actProfId, p4configv1::P4Ids::ACTION_PROFILE)) {
auto *actionProf = Standard::findActionProf(p4info, actProfId);
Expand Down
2 changes: 2 additions & 0 deletions backends/dpdk/control-plane/bfruntime_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class BFRuntimeSchemaGenerator : public BFRuntimeGenerator {
const ActionSelector &actionProf) const;
void addActionSelectorGetMemberCommon(Util::JsonArray *tablesJson,
const ActionSelector &actionProf) const;
void addConstTableAttr(Util::JsonArray *attrJson) const override;
bool addMatchTypePriority(std::optional<cstring> &matchType) const override;
void addActionProfs(Util::JsonArray *tablesJson) const override;
bool addActionProfIds(const p4configv1::Table &table,
Util::JsonObject *tableJson) const override;
Expand Down
2 changes: 1 addition & 1 deletion backends/dpdk/dpdkAsmOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class ShortenTokenLength : public Transform {
static ordered_map<cstring, cstring> origNameMap;

const IR::Node *preorder(IR::Member *m) override {
if (m->toString().startsWith("m."))
if (m->toString().startsWith("m.") || m->toString().startsWith("t."))
m->member = shortenString(m->member);
else
m->member = shortenString(m->member, 30);
Expand Down
4 changes: 3 additions & 1 deletion backends/dpdk/dpdkContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ void DpdkContextGenerator::addKeyField(Util::JsonArray *keyJson, const cstring n
keyField->emplace("name", nameAnnotation);
keyField->emplace("instance_name", instanceName);
keyField->emplace("field_name", fieldName);
keyField->emplace("match_type", toStr(key->matchType));
auto match_kind = toStr(key->matchType);
if (match_kind == "optional" || match_kind == "range") match_kind = "ternary";
keyField->emplace("match_type", match_kind);
keyField->emplace("start_bit", 0);
keyField->emplace("bit_width", key->expression->type->width_bits());
keyField->emplace("bit_width_full", key->expression->type->width_bits());
Expand Down
17 changes: 13 additions & 4 deletions control-plane/bfruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,17 @@ bool BFRuntimeGenerator::addActionProfIds(const p4configv1::Table &table,
return true;
}

void BFRuntimeGenerator::addConstTableAttr(Util::JsonArray *attrJson) const {
attrJson->append("ConstTable");
}

bool BFRuntimeGenerator::addMatchTypePriority(std::optional<cstring> &matchType) const {
if (*matchType == "Ternary" || *matchType == "Range" || *matchType == "Optional") {
return true;
}
return false;
}

void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const {
for (const auto &table : p4info.tables()) {
const auto &pre = table.preamble();
Expand Down Expand Up @@ -675,8 +686,7 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const {
int(mf.match_type()));
continue;
}
if (*matchType == "Ternary" || *matchType == "Range" || *matchType == "Optional")
needsPriority = true;
needsPriority |= addMatchTypePriority(matchType);
auto *annotations =
transformAnnotations(mf.annotations().begin(), mf.annotations().end());

Expand Down Expand Up @@ -773,8 +783,7 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const {
"@dynamic_table_key_masks(1)");
if (supportsDynMask) attributesJson->append("DynamicKeyMask");

if (table.is_const_table()) attributesJson->append("ConstTable");

if (table.is_const_table()) addConstTableAttr(attributesJson);
if (table.idle_timeout_behavior() == p4configv1::Table::NOTIFY_CONTROL) {
auto pollModeOnly = std::count(pre.annotations().begin(), pre.annotations().end(),
"@idletime_precision(1)");
Expand Down
2 changes: 2 additions & 0 deletions control-plane/bfruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ class BFRuntimeGenerator {
};

void addMatchTables(Util::JsonArray *tablesJson) const;
virtual bool addMatchTypePriority(std::optional<cstring> &matchType) const;
virtual void addConstTableAttr(Util::JsonArray *attrJson) const;
virtual void addActionProfs(Util::JsonArray *tablesJson) const;
virtual bool addActionProfIds(const p4configv1::Table &table,
Util::JsonObject *tableJson) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
],
"data" : [],
"supported_operations" : [],
"attributes" : ["EntryScope", "ConstTable"]
"attributes" : ["EntryScope"]
},
{
"name" : "pipe.MainControlImpl.ct_tcp_table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
],
"data" : [],
"supported_operations" : [],
"attributes" : ["EntryScope", "ConstTable"]
"attributes" : ["EntryScope"]
},
{
"name" : "pipe.MainControlImpl.ct_tcp_table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"repeated" : false,
"annotations" : [],
"mandatory" : false,
"match_type" : "Optional",
"match_type" : "Ternary",
"type" : {
"type" : "bytes",
"width" : 32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
],
"data" : [],
"supported_operations" : [],
"attributes" : ["EntryScope", "ConstTable"]
"attributes" : ["EntryScope"]
},
{
"name" : "pipe.MainControlImpl.ct_tcp_table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
],
"data" : [],
"supported_operations" : [],
"attributes" : ["EntryScope", "ConstTable"]
"attributes" : ["EntryScope"]
}
],
"learn_filters" : []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"repeated" : false,
"annotations" : [],
"mandatory" : false,
"match_type" : "Optional",
"match_type" : "Ternary",
"type" : {
"type" : "bytes",
"width" : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"repeated" : false,
"annotations" : [],
"mandatory" : false,
"match_type" : "Optional",
"match_type" : "Ternary",
"type" : {
"type" : "bytes",
"width" : 48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
],
"supported_operations" : ["SyncCounters"],
"attributes" : ["EntryScope", "ConstTable"]
"attributes" : ["EntryScope"]
}
],
"learn_filters" : []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"repeated" : false,
"annotations" : [],
"mandatory" : false,
"match_type" : "Range",
"match_type" : "Ternary",
"type" : {
"type" : "bytes",
"width" : 48
Expand Down