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

create dpdk specific pna.p4 and extend it #3658

Merged
merged 11 commits into from
Nov 11, 2022
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ add_custom_target(update_includes ALL
if (ENABLE_DPDK)
add_custom_target(dpdk_includes ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/dpdk
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/dpdk/psa.p4 ${P4C_BINARY_DIR}/p4include/dpdk)
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/dpdk/psa.p4 ${P4C_BINARY_DIR}/p4include/dpdk
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/dpdk/pna.p4 ${P4C_BINARY_DIR}/p4include/dpdk)
endif ()

# Installation
Expand Down
18 changes: 12 additions & 6 deletions backends/dpdk/DpdkXfail.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
p4c_add_xfail_reason("dpdk"
"use dpdk specific `dpdk_execute` method"
testdata/p4_16_samples/psa-example-dpdk-meter-execute-err.p4
testdata/p4_16_samples/psa-meter3.p4
testdata/p4_16_samples/psa-meter7-bmv2.p4
)

p4c_add_xfail_reason("dpdk"
"Meter function execute not implemented, use dpdk_execute"
testdata/p4_16_samples/psa-meter1.p4
)

p4c_add_xfail_reason("dpdk"
"not implemented"
testdata/p4_16_samples/psa-example-dpdk-byte-alignment_4.p4
Expand Down Expand Up @@ -39,9 +51,3 @@ p4c_add_xfail_reason("dpdk"
"Direct counters and direct meters are unsupported for wildcard match"
testdata/p4_16_samples/psa-example-counters-bmv2.p4
)

p4c_add_xfail_reason("dpdk"
"Expected atleast 2 arguments"
testdata/p4_16_samples/psa-meter3.p4
testdata/p4_16_samples/psa-meter7-bmv2.p4
)
7 changes: 7 additions & 0 deletions backends/dpdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ In P4 the second argument of the extract method is the number of bits.
Compiler generates instructions which compute the size in bytes from the value in bits.
If the value in bits is not a multiple of 8, the value is rounded down to the lower
multiple of 8 bits.
- Currently dpdk target does not support standard count and execute methods for Counter and Meter externs as defined in PSA and PNA specifications. It requires packet length as parameter in count and execute methods.
```Meter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does DPDK development have any plans in the future to support the standard count and execute methods, without a packet length parameter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no plan in the near future. There was an earlier discussion of providing ethernet frame size as default packet length, however it seems that it wouldn't be correct as DPDK implements trCM which do not work on ethernet frame length.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"which do not work on ethernet frame length" Meters/policers can work on whatever length in bytes you give for a packet, whether it matches the packet's length or not, so it isn't clear to me what your statement means. If DPDK implements meters by default with ethernet frame length, then I would recommend enabling them to do so, and DOCUMENTING that the methods that do not take a packet length as input, use the ethernet frame length in bytes. If they work as documented, then I'd say that they work :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take this up with the DPDK target team again and see if they can have this in their worklist. We can enable the p4c support when we have the default packet length available from the target side.

PNA_MeterColor_t dpdk_execute(in S index, in PNA_MeterColor_t color, in bit<32> pkt_len);
```
```Counter
void count(in S index, in bit<32> pkt_len);
```

## Contacts

Expand Down
10 changes: 5 additions & 5 deletions backends/dpdk/dpdkArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2465,13 +2465,13 @@ bool CollectDirectCounterMeter::ifMethodFound(const IR::P4Action *a,
return methodCallFound;
}

/* ifMethodFound() is called from here to make sure that an action only contains count/execute
/* ifMethodFound() is called from here to make sure that an action only contains count/dpdk_execute
* method calls for only one Direct counter/meter instance. The error for the same is emitted
* in the ifMethodFound function itself and return value is not required to be checked here.
*/
bool CollectDirectCounterMeter::preorder(const IR::P4Action* a) {
ifMethodFound(a, "count");
ifMethodFound(a, "execute");
ifMethodFound(a, "dpdk_execute");
return false;
}

Expand Down Expand Up @@ -2526,10 +2526,10 @@ bool CollectDirectCounterMeter::preorder(const IR::P4Table* tbl) {
return false;
}
}
if (!ifMethodFound(defaultActionDecl, "execute", meterExternName)) {
if (!ifMethodFound(defaultActionDecl, "dpdk_execute", meterExternName)) {
if (meterInstance) {
::error(ErrorType::ERR_EXPECTED, "Expected default action %1% to have "
"'execute' method call for DirectMeter extern instance %2%",
"'dpdk_execute' method call for DirectMeter extern instance %2%",
defaultActionDecl->name, *meterInstance->name);
return false;
}
Expand Down Expand Up @@ -2557,7 +2557,7 @@ void ValidateDirectCounterMeter::validateMethodInvocation(P4::ExternMethod *a) {
}

if ((externName == "DirectCounter" && methodName != "count") ||
(externName == "DirectMeter" && methodName != "execute")) {
(externName == "DirectMeter" && methodName != "dpdk_execute")) {
::error(ErrorType::ERR_UNEXPECTED, "%1% method not supported for %2% extern",
methodName, externName);
return;
Expand Down
16 changes: 12 additions & 4 deletions backends/dpdk/dpdkHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) {
}
} else if (e->originalExternType->getName().name == "Meter") {
if (e->method->getName().name == "execute") {
::error(ErrorType::ERR_UNEXPECTED,
"use dpdk specific `dpdk_execute` method, `%1%`"
" not supported by dpdk",
e->method->getName());
return false;
}
if (e->method->getName().name == "dpdk_execute") {
auto argSize = e->expr->arguments->size();

// DPDK target needs index and packet length as mandatory parameters
Expand All @@ -371,7 +378,7 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) {
e->object->getName(), index, length, color_in, left);
}
} else if (e->originalExternType->getName().name == "DirectMeter") {
if (e->method->getName().name == "execute") {
if (e->method->getName().name == "dpdk_execute") {
auto argSize = e->expr->arguments->size();

// DPDK target needs packet length as mandatory parameters
Expand Down Expand Up @@ -1054,11 +1061,12 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) {
}
}
} else if (a->originalExternType->getName().name == "Meter") {
if (a->method->getName().name != "execute") {
BUG("Meter function not implemented.");
if (a->method->getName().name != "dpdk_execute") {
BUG("Meter function %1% not implemented, use dpdk_execute",
a->method->getName());
}
} else if (a->originalExternType->getName().name == "DirectMeter") {
if (a->method->getName().name != "execute") {
if (a->method->getName().name != "dpdk_execute") {
BUG("Direct Meter function %1% not implemented.", a->method->getName().name);
}
} else if (a->originalExternType->getName().name == "DirectCounter") {
Expand Down
1 change: 1 addition & 0 deletions backends/dpdk/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ DpdkMidEnd::DpdkMidEnd(CompilerOptions &options,
{"Register", "write"},
{"Counter", "count"},
{"Meter", "execute"},
{"Meter", "dpdk_execute"},
{"Digest", "pack"},
};
for (auto f : doNotCopyPropList) {
Expand Down
Loading