Skip to content

Commit

Permalink
Dpdk Backend: Fixed target_name and action parameter bitwidth (#4025)
Browse files Browse the repository at this point in the history
* Fixed target_name and action parameter bitwidth
* Add utility function for getting Metadata width
  • Loading branch information
usha1830 authored Jun 14, 2023
1 parent dff9347 commit 31efd57
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 1 addition & 4 deletions backends/dpdk/dpdkArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,7 @@ const IR::Node *ReplaceHdrMetaField::postorder(IR::Type_Struct *st) {
if (auto t = (*field).type->to<IR::Type_Bits>()) {
auto width = t->width_bits();
if (width % 8 != 0) {
if (width < 32)
width = 32;
else
width = 64;
width = getMetadataFieldWidth(width);
fields->push_back(
new IR::StructField(IR::ID(field->name), IR::Type_Bits::get(width)));
} else {
Expand Down
5 changes: 4 additions & 1 deletion backends/dpdk/dpdkContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.

#include "backend.h"
#include "control-plane/bfruntime_ext.h"
#include "dpdkUtils.h"
#include "printUtils.h"
namespace DPDK {

Expand Down Expand Up @@ -190,7 +191,7 @@ void DpdkContextGenerator::addKeyField(Util::JsonArray *keyJson, const cstring n
Util::JsonObject *DpdkContextGenerator::initTableCommonJson(const cstring name,
const struct TableAttributes &attr) {
auto *tableJson = new Util::JsonObject();
cstring tableName = attr.controlName + "." + name;
cstring tableName = name;
tableJson->emplace("name", attr.externalName);
tableJson->emplace("target_name", tableName);
tableJson->emplace("direction", attr.direction);
Expand Down Expand Up @@ -349,6 +350,7 @@ Util::JsonObject *DpdkContextGenerator::addMatchAttributes(const IR::P4Table *ta
for (auto param : *(attr.params)) {
if (param->type->is<IR::Type_Bits>()) {
param_width = param->type->width_bits();
param_width = getMetadataFieldWidth(param_width);
} else if (!param->type->is<IR::Type_Boolean>()) {
BUG("Unsupported parameter type %1%", param->type);
}
Expand Down Expand Up @@ -411,6 +413,7 @@ Util::JsonArray *DpdkContextGenerator::addActions(const IR::P4Table *table,
for (auto param : *(attr.params)) {
if (param->type->is<IR::Type_Bits>()) {
param_width = param->type->width_bits();
param_width = getMetadataFieldWidth(param_width);
} else if (!param->type->is<IR::Type_Boolean>()) {
BUG("Unsupported parameter type %1%", param->type);
}
Expand Down
12 changes: 12 additions & 0 deletions backends/dpdk/dpdkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ bool reservedNames(P4::ReferenceMap *refMap, std::vector<cstring> names, cstring
return true;
}

// Update bitwidth of Metadata fields to 32 or 64 bits if it 8-bit aligned.
int getMetadataFieldWidth(int width) {
BUG_CHECK(width <= 64, "Metadata bit-width expected to be within 64-bits");
if (width % 8 != 0) {
if (width < 32)
return 32;
else
return 64;
}
return width;
}

} // namespace DPDK
2 changes: 1 addition & 1 deletion backends/dpdk/dpdkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool isDirection(const IR::Member *m);
bool isHeadersStruct(const IR::Type_Struct *st);
bool isLargeFieldOperand(const IR::Expression *e);
bool isInsideHeader(const IR::Expression *e);

int getMetadataFieldWidth(int width);
const IR::Type_Bits *getEightBitAlignedType(const IR::Type_Bits *tb);

// Check for reserved names for DPDK target
Expand Down

0 comments on commit 31efd57

Please sign in to comment.