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
Prev Previous commit
Next Next commit
change names to resolve ambiguity
  • Loading branch information
kamleshbhalui committed Nov 11, 2022
commit 5a8b2d474f1755ed4b47cee9ea4f0bfafd70b93b
8 changes: 5 additions & 3 deletions backends/dpdk/dpdkHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) {
left, e->object->getName(), intermediate);
}
} else if (e->originalExternType->getName().name == "Meter") {
if (e->method->getName().name == "execute") {
if (e->method->getName().name == "execute"
|| e->method->getName().name == "dpdk_execute") {
auto argSize = e->expr->arguments->size();

// DPDK target needs index and packet length as mandatory parameters
Expand Down Expand Up @@ -1054,8 +1055,9 @@ 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 != "execute"
&& a->method->getName().name != "dpdk_execute") {
BUG("Meter function %1% not implemented.", a->method->getName());
}
} else if (a->originalExternType->getName().name == "DirectMeter") {
if (a->method->getName().name != "execute") {
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
10 changes: 8 additions & 2 deletions p4include/dpdk/pna.p4
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ enum PNA_CounterType_t {
@noWarn("unused")
extern Counter<W, S> {
Counter(bit<32> n_counters, PNA_CounterType_t type);
void count(in S index);
void count(in S index, in bit<32> pkt_len);
}
// END:Counter_extern
Expand All @@ -381,6 +382,7 @@ extern Counter<W, S> {
@noWarn("unused")
extern DirectCounter<W> {
DirectCounter(PNA_CounterType_t type);
void count();
void count(in bit<32> pkt_len);
}
// END:DirectCounter_extern
Expand All @@ -404,21 +406,25 @@ extern Meter<S> {
// Use this method call to perform a color aware meter update (see
// RFC 2698). The color of the packet before the method call was
// made is specified by the color parameter.
PNA_MeterColor_t execute(in S index, in PNA_MeterColor_t color);
PNA_MeterColor_t execute(in S index, in PNA_MeterColor_t color, in bit<32> pkt_len);

// Use this method call to perform a color blind meter update (see
// RFC 2698). It may be implemented via a call to execute(index,
// MeterColor_t.GREEN), which has the same behavior.
PNA_MeterColor_t execute(in S index, in bit<32> pkt_len);
PNA_MeterColor_t execute(in S index);
PNA_MeterColor_t dpdk_execute(in S index, in bit<32> pkt_len);
}
// END:Meter_extern

// BEGIN:DirectMeter_extern
extern DirectMeter {
DirectMeter(PNA_MeterType_t type);
// See the corresponding methods for extern Meter.
PNA_MeterColor_t execute(in PNA_MeterColor_t color);
PNA_MeterColor_t execute();
PNA_MeterColor_t execute(in PNA_MeterColor_t color, in bit<32> pkt_len);
PNA_MeterColor_t execute(in bit<32> pkt_len);
PNA_MeterColor_t dpdk_execute(in bit<32> pkt_len);
}
// END:DirectMeter_extern

Expand Down
14 changes: 10 additions & 4 deletions p4include/dpdk/psa.p4
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ enum PSA_CounterType_t {
@noWarn("unused")
extern Counter<W, S> {
Counter(bit<32> n_counters, PSA_CounterType_t type);
void count(in S index, in bit<32> increment);
void count(in S index);
Copy link
Contributor

Choose a reason for hiding this comment

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

What does DPDK do when a PSA program calls the original count method that does not have a pkt_len parameter? Nothing? It would be good to have a comment here if it does anything other than what PSA defines.

Copy link
Contributor

Choose a reason for hiding this comment

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

And also for the corresponding method in the DirectCounter extern. And for Meter and DirectMeter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added the comments

void count(in S index, in bit<32> pkt_len);

/*
/// The control plane API uses 64-bit wide counter values. It is
Expand Down Expand Up @@ -628,7 +629,8 @@ extern Counter<W, S> {
@noWarn("unused")
extern DirectCounter<W> {
DirectCounter(PSA_CounterType_t type);
void count(in bit<32> increment);
void count();
void count(in bit<32> pkt_len);

/*
@ControlPlaneAPI
Expand Down Expand Up @@ -664,12 +666,14 @@ extern Meter<S> {
// Use this method call to perform a color aware meter update (see
// RFC 2698). The color of the packet before the method call was
// made is specified by the color parameter.
PSA_MeterColor_t execute(in S index, in PSA_MeterColor_t color);
PSA_MeterColor_t execute(in S index, in PSA_MeterColor_t color, in bit<32> pkt_len);

// Use this method call to perform a color blind meter update (see
// RFC 2698). It may be implemented via a call to execute(index,
// MeterColor_t.GREEN), which has the same behavior.
PSA_MeterColor_t execute(in S index, in bit<32> pkt_len);
PSA_MeterColor_t execute(in S index);
PSA_MeterColor_t dpdk_execute(in S index, in bit<32> pkt_len);

/*
@ControlPlaneAPI
Expand All @@ -687,7 +691,9 @@ extern DirectMeter {
DirectMeter(PSA_MeterType_t type);
// See the corresponding methods for extern Meter.
PSA_MeterColor_t execute(in PSA_MeterColor_t color);
PSA_MeterColor_t execute(in bit<32> pkt_len);
PSA_MeterColor_t execute(in PSA_MeterColor_t color, in bit<32> pkt_len);
PSA_MeterColor_t execute();
PSA_MeterColor_t dpdk_execute(in bit<32> pkt_len);

/*
@ControlPlaneAPI
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_psa_errors/psa-counter6.p4
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ control MyIC(

DirectCounter<bit<12>>(PSA_CounterType_t.PACKETS) counter0;
action execute() {
counter0.count(64);
counter0.count();
}
table tbl {
key = {
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_samples/psa-example-dpdk-meter.p4
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ control ingress(inout headers hdr, inout metadata_t user_meta, in psa_ingress_in
PSA_MeterColor_t color_out;
PSA_MeterColor_t color_in = PSA_MeterColor_t.RED;
action execute(bit<12> index) {
color_out = meter0.execute(index, color_in, (bit<32>)hdr.ipv4.totalLen);
color_out = meter0.dpdk_execute(index, /*color_in,*/ (bit<32>)hdr.ipv4.totalLen);
user_meta.port_out = (color_out == PSA_MeterColor_t.GREEN ? 32w1 : 32w0);
}
table tbl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ control ingress(inout headers hdr, inout metadata_t user_meta, in psa_ingress_in
PSA_MeterColor_t color_out;
PSA_MeterColor_t color_in = PSA_MeterColor_t.RED;
action execute(bit<12> index) {
color_out = meter0.execute(index, color_in, (bit<32>)hdr.ipv4.totalLen);
color_out = meter0.dpdk_execute(index, (bit<32>)hdr.ipv4.totalLen);
user_meta.port_out = (color_out == PSA_MeterColor_t.GREEN ? 32w1 : 32w0);
}
table tbl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ parser IngressParserImpl(packet_in buffer, out headers hdr, inout metadata_t use

control ingress(inout headers hdr, inout metadata_t user_meta, in psa_ingress_input_metadata_t istd, inout psa_ingress_output_metadata_t ostd) {
@name("ingress.color_out") PSA_MeterColor_t color_out_0;
@name("ingress.color_in") PSA_MeterColor_t color_in_0;
@name("ingress.tmp") bit<32> tmp;
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name("ingress.meter0") Meter<bit<12>>(32w1024, PSA_MeterType_t.BYTES) meter0_0;
@name("ingress.execute") action execute_1(@name("index") bit<12> index_1) {
color_out_0 = meter0_0.execute(index_1, color_in_0, (bit<32>)hdr.ipv4.totalLen);
color_out_0 = meter0_0.dpdk_execute(index_1, (bit<32>)hdr.ipv4.totalLen);
if (color_out_0 == PSA_MeterColor_t.GREEN) {
tmp = 32w1;
} else {
Expand All @@ -78,6 +77,7 @@ control ingress(inout headers hdr, inout metadata_t user_meta, in psa_ingress_in
}
apply {
color_in_0 = PSA_MeterColor_t.RED;
hasReturned = false;
if (user_meta.port_out == 32w1) {
tbl_0.apply();
} else {
Expand Down
13 changes: 1 addition & 12 deletions testdata/p4_16_samples_outputs/psa-example-dpdk-meter-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ parser IngressParserImpl(packet_in buffer, out headers hdr, inout metadata_t use

control ingress(inout headers hdr, inout metadata_t user_meta, in psa_ingress_input_metadata_t istd, inout psa_ingress_output_metadata_t ostd) {
@name("ingress.color_out") PSA_MeterColor_t color_out_0;
@name("ingress.color_in") PSA_MeterColor_t color_in_0;
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name("ingress.meter0") Meter<bit<12>>(32w1024, PSA_MeterType_t.BYTES) meter0_0;
@name("ingress.execute") action execute_1(@name("index") bit<12> index_1) {
color_out_0 = meter0_0.execute(index_1, color_in_0, (bit<32>)hdr.ipv4.totalLen);
color_out_0 = meter0_0.dpdk_execute(index_1, (bit<32>)hdr.ipv4.totalLen);
user_meta.port_out = (color_out_0 == PSA_MeterColor_t.GREEN ? 32w1 : 32w0);
}
@name("ingress.tbl") table tbl_0 {
Expand All @@ -69,17 +68,7 @@ control ingress(inout headers hdr, inout metadata_t user_meta, in psa_ingress_in
}
default_action = NoAction_1();
}
@hidden action psaexampledpdkmeter56() {
color_in_0 = PSA_MeterColor_t.RED;
}
@hidden table tbl_psaexampledpdkmeter56 {
actions = {
psaexampledpdkmeter56();
}
const default_action = psaexampledpdkmeter56();
}
apply {
tbl_psaexampledpdkmeter56.apply();
if (user_meta.port_out == 32w1) {
tbl_0.apply();
} else {
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/psa-example-dpdk-meter.p4
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ control ingress(inout headers hdr, inout metadata_t user_meta, in psa_ingress_in
PSA_MeterColor_t color_out;
PSA_MeterColor_t color_in = PSA_MeterColor_t.RED;
action execute(bit<12> index) {
color_out = meter0.execute(index, color_in, (bit<32>)hdr.ipv4.totalLen);
color_out = meter0.dpdk_execute(index, (bit<32>)hdr.ipv4.totalLen);
user_meta.port_out = (color_out == PSA_MeterColor_t.GREEN ? 32w1 : 32w0);
}
table tbl {
Expand Down
6 changes: 2 additions & 4 deletions testdata/p4_16_samples_outputs/psa-example-dpdk-meter.p4.spec
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct metadata_t {
bit<32> psa_ingress_output_metadata_egress_port
bit<32> local_metadata_port_out
bit<32> Ingress_color_out
bit<32> Ingress_color_in
bit<32> Ingress_tmp_0
}
metadata instanceof metadata_t
Expand All @@ -64,7 +63,7 @@ action NoAction args none {
}

action execute_1 args instanceof execute_1_arg_t {
meter meter0_0 t.index h.ipv4.totalLen m.Ingress_color_in m.Ingress_color_out
meter meter0_0 t.index h.ipv4.totalLen 0x1 m.Ingress_color_out
jmpneq LABEL_FALSE_0 m.Ingress_color_out 0x0
mov m.Ingress_tmp_0 0x1
jmp LABEL_END_0
Expand Down Expand Up @@ -93,8 +92,7 @@ apply {
jmpeq INGRESSPARSERIMPL_PARSE_IPV4 h.ethernet.etherType 0x800
jmp INGRESSPARSERIMPL_ACCEPT
INGRESSPARSERIMPL_PARSE_IPV4 : extract h.ipv4
INGRESSPARSERIMPL_ACCEPT : mov m.Ingress_color_in 0x2
jmpneq LABEL_END m.local_metadata_port_out 0x1
INGRESSPARSERIMPL_ACCEPT : jmpneq LABEL_END m.local_metadata_port_out 0x1
table tbl
LABEL_END : jmpneq LABEL_DROP m.psa_ingress_output_metadata_drop 0x0
emit h.ethernet
Expand Down